Commit 7ec5ff4dbae71d147f413da5cea64116e7eb305d

Authored by Jacob Vosmaer
1 parent bbfa4a77

Pass last_fetched_at for notes to javascript

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