Commit 586c53ea0594a327b346c6fed38528a1f508c9e1

Authored by Dmitriy Zaporozhets
1 parent 0b0e0225

fixed notes loading/paging

app/assets/javascripts/note.js
@@ -31,6 +31,15 @@ append: @@ -31,6 +31,15 @@ append:
31 this.initLoadMore(); 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 prepend: 43 prepend:
35 function(id, html) { 44 function(id, html) {
36 this.last_id = id; 45 this.last_id = id;
@@ -47,10 +56,23 @@ getNew: @@ -47,10 +56,23 @@ getNew:
47 dataType: "script"}); 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 initRefresh: 71 initRefresh:
51 function() { 72 function() {
52 // init timer 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 initLoadMore: 78 initLoadMore:
app/controllers/application_controller.rb
@@ -83,4 +83,16 @@ class ApplicationController < ActionController::Base @@ -83,4 +83,16 @@ class ApplicationController < ActionController::Base
83 cookies[:view_style] = "" 83 cookies[:view_style] = ""
84 end 84 end
85 end 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 end 98 end
app/controllers/commits_controller.rb
@@ -33,10 +33,7 @@ class CommitsController &lt; ApplicationController @@ -33,10 +33,7 @@ class CommitsController &lt; ApplicationController
33 33
34 respond_to do |format| 34 respond_to do |format|
35 format.html 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 end 37 end
41 end 38 end
42 end 39 end
app/controllers/issues_controller.rb
@@ -40,10 +40,7 @@ class IssuesController &lt; ApplicationController @@ -40,10 +40,7 @@ class IssuesController &lt; ApplicationController
40 40
41 respond_to do |format| 41 respond_to do |format|
42 format.html 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 end 44 end
48 end 45 end
49 46
app/controllers/projects_controller.rb
@@ -90,10 +90,7 @@ class ProjectsController &lt; ApplicationController @@ -90,10 +90,7 @@ class ProjectsController &lt; ApplicationController
90 90
91 respond_to do |format| 91 respond_to do |format|
92 format.html 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 end 94 end
98 end 95 end
99 96
app/views/notes/_load.js.haml
1 - unless @notes.blank? 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 :plain 9 :plain
5 NoteList.prepend(#{@notes.first.id}, "#{escape_javascript(render(:partial => 'notes/notes_list'))}"); 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 :plain 13 :plain
9 NoteList.append(#{@notes.last.id}, "#{escape_javascript(render(:partial => 'notes/notes_list'))}"); 14 NoteList.append(#{@notes.last.id}, "#{escape_javascript(render(:partial => 'notes/notes_list'))}");
10 15
  16 + - else
  17 + :plain