Commit 7ec5ff4dbae71d147f413da5cea64116e7eb305d

Authored by Jacob Vosmaer
1 parent bbfa4a77

Pass last_fetched_at for notes to javascript

app/assets/javascripts/notes.js.coffee
1 class Notes 1 class Notes
2 @interval: null 2 @interval: null
3 3
4 - constructor: (notes_url, note_ids) -> 4 + constructor: (notes_url, note_ids, last_fetched_at) ->
5 @notes_url = notes_url 5 @notes_url = notes_url
6 @notes_url = gon.relative_url_root + @notes_url if gon.relative_url_root? 6 @notes_url = gon.relative_url_root + @notes_url if gon.relative_url_root?
7 @note_ids = note_ids 7 @note_ids = note_ids
  8 + @last_fetched_at = last_fetched_at
8 @initRefresh() 9 @initRefresh()
9 @setupMainTargetNoteForm() 10 @setupMainTargetNoteForm()
10 @cleanBinding() 11 @cleanBinding()
@@ -76,9 +77,11 @@ class Notes @@ -76,9 +77,11 @@ class Notes
76 getContent: -> 77 getContent: ->
77 $.ajax 78 $.ajax
78 url: @notes_url 79 url: @notes_url
  80 + data: "last_fetched_at=" + @last_fetched_at
79 dataType: "json" 81 dataType: "json"
80 success: (data) => 82 success: (data) =>
81 notes = data.notes 83 notes = data.notes
  84 + @last_fetched_at = data.last_fetched_at
82 $.each notes, (i, note) => 85 $.each notes, (i, note) =>
83 @renderNote(note) 86 @renderNote(note)
84 87
app/controllers/projects/notes_controller.rb
@@ -5,9 +5,10 @@ class Projects::NotesController < Projects::ApplicationController @@ -5,9 +5,10 @@ class Projects::NotesController < Projects::ApplicationController
5 before_filter :authorize_admin_note!, only: [:update, :destroy] 5 before_filter :authorize_admin_note!, only: [:update, :destroy]
6 6
7 def index 7 def index
  8 + current_fetched_at = Time.now
8 @notes = NotesFinder.new.execute(project, current_user, params) 9 @notes = NotesFinder.new.execute(project, current_user, params)
9 10
10 - notes_json = { notes: [] } 11 + notes_json = { notes: [], last_fetched_at: current_fetched_at }
11 12
12 @notes.each do |note| 13 @notes.each do |note|
13 notes_json[:notes] << { 14 notes_json[:notes] << {
app/views/projects/notes/_notes_with_form.html.haml
@@ -7,4 +7,4 @@ @@ -7,4 +7,4 @@
7 = render "projects/notes/form" 7 = render "projects/notes/form"
8 8
9 :javascript 9 :javascript
10 - new Notes("#{project_notes_path(target_id: @noteable.id, target_type: @noteable.class.name.underscore)}", #{@notes.map(&:id).to_json}) 10 + new Notes("#{project_notes_path(target_id: @noteable.id, target_type: @noteable.class.name.underscore)}", #{@notes.map(&:id).to_json}, Time.now)