Commit 4d378f3c9a7bec3cbdbd2b2e59150702849e65f7
1 parent
57f3409b
Exists in
master
and in
4 other branches
load notes for wall via api
Showing
2 changed files
with
50 additions
and
0 deletions
Show diff stats
... | ... | @@ -0,0 +1,46 @@ |
1 | +@Wall = | |
2 | + note_ids: [] | |
3 | + notes_path: null | |
4 | + notes_params: null | |
5 | + project_id: null | |
6 | + | |
7 | + init: (project_id) -> | |
8 | + Wall.project_id = project_id | |
9 | + Wall.notes_path = "/api/" + gon.api_version + "/projects/" + project_id + "/notes.json" | |
10 | + Wall.getContent() | |
11 | + Wall.initRefresh() | |
12 | + | |
13 | + # | |
14 | + # Gets an initial set of notes. | |
15 | + # | |
16 | + getContent: -> | |
17 | + $.ajax | |
18 | + url: Wall.notes_path, | |
19 | + data: | |
20 | + private_token: gon.api_token | |
21 | + gfm: true | |
22 | + recent: true | |
23 | + dataType: "json" | |
24 | + success: (notes) -> | |
25 | + notes.sort (a, b) -> | |
26 | + return a.id - b.id | |
27 | + $.each notes, (i, note)-> | |
28 | + if $.inArray(note.id, Wall.note_ids) == -1 | |
29 | + Wall.note_ids.push(note.id) | |
30 | + Wall.renderNote(note) | |
31 | + | |
32 | + complete: -> | |
33 | + $('.js-notes-busy').removeClass("loading") | |
34 | + beforeSend: -> | |
35 | + $('.js-notes-busy').addClass("loading") | |
36 | + | |
37 | + renderNote: (note) -> | |
38 | + author = '<strong>' + note.author.name + ': </strong>' | |
39 | + html = '<li>' + author + note.body + '</li>' | |
40 | + $('ul.notes').append(html) | |
41 | + | |
42 | + initRefresh: -> | |
43 | + setInterval("Wall.refresh()", 10000) | |
44 | + | |
45 | + refresh: -> | |
46 | + Wall.getContent() | ... | ... |
lib/api/notes.rb
... | ... | @@ -14,6 +14,10 @@ module Gitlab |
14 | 14 | # GET /projects/:id/notes |
15 | 15 | get ":id/notes" do |
16 | 16 | @notes = user_project.notes.common |
17 | + | |
18 | + # Get recent notes if recent = true | |
19 | + @notes = @notes.order('id DESC') if params[:recent] | |
20 | + | |
17 | 21 | present paginate(@notes), with: Entities::Note |
18 | 22 | end |
19 | 23 | ... | ... |