summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-03-19 12:35:55 +0200
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-03-19 12:35:55 +0200
commit4d378f3c9a7bec3cbdbd2b2e59150702849e65f7 (patch)
tree78883ac77ab50e0e7d2f50184010e5e10f31732e
parent57f3409bcc6a4bee6bc29f8cd03f501c117655b0 (diff)
downloadgitlab-ce-4d378f3c9a7bec3cbdbd2b2e59150702849e65f7.tar.gz
load notes for wall via api
-rw-r--r--app/assets/javascripts/wall.js.coffee46
-rw-r--r--lib/api/notes.rb4
2 files changed, 50 insertions, 0 deletions
diff --git a/app/assets/javascripts/wall.js.coffee b/app/assets/javascripts/wall.js.coffee
new file mode 100644
index 00000000000..43d50b6ba29
--- /dev/null
+++ b/app/assets/javascripts/wall.js.coffee
@@ -0,0 +1,46 @@
+@Wall =
+ note_ids: []
+ notes_path: null
+ notes_params: null
+ project_id: null
+
+ init: (project_id) ->
+ Wall.project_id = project_id
+ Wall.notes_path = "/api/" + gon.api_version + "/projects/" + project_id + "/notes.json"
+ Wall.getContent()
+ Wall.initRefresh()
+
+ #
+ # Gets an initial set of notes.
+ #
+ getContent: ->
+ $.ajax
+ url: Wall.notes_path,
+ data:
+ private_token: gon.api_token
+ gfm: true
+ recent: true
+ dataType: "json"
+ success: (notes) ->
+ notes.sort (a, b) ->
+ return a.id - b.id
+ $.each notes, (i, note)->
+ if $.inArray(note.id, Wall.note_ids) == -1
+ Wall.note_ids.push(note.id)
+ Wall.renderNote(note)
+
+ complete: ->
+ $('.js-notes-busy').removeClass("loading")
+ beforeSend: ->
+ $('.js-notes-busy').addClass("loading")
+
+ renderNote: (note) ->
+ author = '<strong>' + note.author.name + ': &nbsp;</strong>'
+ html = '<li>' + author + note.body + '</li>'
+ $('ul.notes').append(html)
+
+ initRefresh: ->
+ setInterval("Wall.refresh()", 10000)
+
+ refresh: ->
+ Wall.getContent()
diff --git a/lib/api/notes.rb b/lib/api/notes.rb
index 097cc7ea475..450faae535a 100644
--- a/lib/api/notes.rb
+++ b/lib/api/notes.rb
@@ -14,6 +14,10 @@ module Gitlab
# GET /projects/:id/notes
get ":id/notes" do
@notes = user_project.notes.common
+
+ # Get recent notes if recent = true
+ @notes = @notes.order('id DESC') if params[:recent]
+
present paginate(@notes), with: Entities::Note
end