Commit 586c53ea0594a327b346c6fed38528a1f508c9e1
1 parent
0b0e0225
Exists in
master
and in
4 other branches
fixed notes loading/paging
Showing
6 changed files
with
47 additions
and
15 deletions
Show diff stats
app/assets/javascripts/note.js
| ... | ... | @@ -31,6 +31,15 @@ append: |
| 31 | 31 | this.initLoadMore(); |
| 32 | 32 | }, |
| 33 | 33 | |
| 34 | +replace: | |
| 35 | + function(fid, lid, html) { | |
| 36 | + this.first_id = fid; | |
| 37 | + this.last_id = lid; | |
| 38 | + $("#notes-list").html(html); | |
| 39 | + this.initLoadMore(); | |
| 40 | + }, | |
| 41 | + | |
| 42 | + | |
| 34 | 43 | prepend: |
| 35 | 44 | function(id, html) { |
| 36 | 45 | this.last_id = id; |
| ... | ... | @@ -47,10 +56,23 @@ getNew: |
| 47 | 56 | dataType: "script"}); |
| 48 | 57 | }, |
| 49 | 58 | |
| 59 | +refresh: | |
| 60 | + function() { | |
| 61 | + // refersh notes list | |
| 62 | + $.ajax({ | |
| 63 | + type: "GET", | |
| 64 | + url: location.href, | |
| 65 | + data: "first_id=" + this.first_id + "&last_id=" + this.last_id, | |
| 66 | + dataType: "script"}); | |
| 67 | + }, | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 50 | 71 | initRefresh: |
| 51 | 72 | function() { |
| 52 | 73 | // init timer |
| 53 | - var int = setInterval("NoteList.getNew()", 20000); | |
| 74 | + var intNew = setInterval("NoteList.getNew()", 15000); | |
| 75 | + var intRefresh = setInterval("NoteList.refresh()", 90000); | |
| 54 | 76 | }, |
| 55 | 77 | |
| 56 | 78 | initLoadMore: | ... | ... |
app/controllers/application_controller.rb
| ... | ... | @@ -83,4 +83,16 @@ class ApplicationController < ActionController::Base |
| 83 | 83 | cookies[:view_style] = "" |
| 84 | 84 | end |
| 85 | 85 | end |
| 86 | + | |
| 87 | + def respond_with_notes | |
| 88 | + if params[:last_id] && params[:first_id] | |
| 89 | + @notes = @notes.where("id >= ?", params[:first_id]) | |
| 90 | + elsif params[:last_id] | |
| 91 | + @notes = @notes.where("id > ?", params[:last_id]) | |
| 92 | + elsif params[:first_id] | |
| 93 | + @notes = @notes.where("id < ?", params[:first_id]) | |
| 94 | + else | |
| 95 | + nil | |
| 96 | + end | |
| 97 | + end | |
| 86 | 98 | end | ... | ... |
app/controllers/commits_controller.rb
| ... | ... | @@ -33,10 +33,7 @@ class CommitsController < ApplicationController |
| 33 | 33 | |
| 34 | 34 | respond_to do |format| |
| 35 | 35 | format.html |
| 36 | - format.js do | |
| 37 | - @notes = @notes.where("id > ?", params[:last_id]) if params[:last_id] | |
| 38 | - @notes = @notes.where("id < ?", params[:first_id]) if params[:first_id] | |
| 39 | - end | |
| 36 | + format.js { respond_with_notes } | |
| 40 | 37 | end |
| 41 | 38 | end |
| 42 | 39 | end | ... | ... |
app/controllers/issues_controller.rb
| ... | ... | @@ -40,10 +40,7 @@ class IssuesController < ApplicationController |
| 40 | 40 | |
| 41 | 41 | respond_to do |format| |
| 42 | 42 | format.html |
| 43 | - format.js do | |
| 44 | - @notes = @notes.where("id > ?", params[:last_id]) if params[:last_id] | |
| 45 | - @notes = @notes.where("id < ?", params[:first_id]) if params[:first_id] | |
| 46 | - end | |
| 43 | + format.js { respond_with_notes } | |
| 47 | 44 | end |
| 48 | 45 | end |
| 49 | 46 | ... | ... |
app/controllers/projects_controller.rb
| ... | ... | @@ -90,10 +90,7 @@ class ProjectsController < ApplicationController |
| 90 | 90 | |
| 91 | 91 | respond_to do |format| |
| 92 | 92 | format.html |
| 93 | - format.js do | |
| 94 | - @notes = @notes.where("id > ?", params[:last_id]) if params[:last_id] | |
| 95 | - @notes = @notes.where("id < ?", params[:first_id]) if params[:first_id] | |
| 96 | - end | |
| 93 | + format.js { respond_with_notes } | |
| 97 | 94 | end |
| 98 | 95 | end |
| 99 | 96 | ... | ... |
app/views/notes/_load.js.haml
| 1 | 1 | - unless @notes.blank? |
| 2 | 2 | |
| 3 | - - if params[:last_id] | |
| 3 | + - if params[:last_id] && params[:first_id] | |
| 4 | + :plain | |
| 5 | + NoteList.replace(#{@notes.last.id}, #{@notes.first.id}, "#{escape_javascript(render(:partial => 'notes/notes_list'))}"); | |
| 6 | + | |
| 7 | + | |
| 8 | + - elsif params[:last_id] | |
| 4 | 9 | :plain |
| 5 | 10 | NoteList.prepend(#{@notes.first.id}, "#{escape_javascript(render(:partial => 'notes/notes_list'))}"); |
| 6 | 11 | |
| 7 | - - if params[:first_id] | |
| 12 | + - elsif params[:first_id] | |
| 8 | 13 | :plain |
| 9 | 14 | NoteList.append(#{@notes.last.id}, "#{escape_javascript(render(:partial => 'notes/notes_list'))}"); |
| 10 | 15 | |
| 16 | + - else | |
| 17 | + :plain | ... | ... |