Commit e6de84f70b57ca4eda65948d714028819b51b30d
1 parent
8de4f2de
Exists in
fix_comments_pagination
Fix comments pagination and ordering
Signed-off-by: Gabriel Silva <gabriel93.silva@gmail.com> Signed-off-by: Pedro de Lyra <pedrodelyra@gmail.com>
Showing
3 changed files
with
15 additions
and
13 deletions
Show diff stats
app/controllers/public/content_viewer_controller.rb
@@ -64,10 +64,6 @@ class ContentViewerController < ApplicationController | @@ -64,10 +64,6 @@ class ContentViewerController < ApplicationController | ||
64 | process_comments(params) | 64 | process_comments(params) |
65 | 65 | ||
66 | if request.xhr? and params[:comment_order] | 66 | if request.xhr? and params[:comment_order] |
67 | - if @comment_order == 'newest' | ||
68 | - @comments = @comments.reverse | ||
69 | - end | ||
70 | - | ||
71 | return render :partial => 'comment/comment', :collection => @comments | 67 | return render :partial => 'comment/comment', :collection => @comments |
72 | end | 68 | end |
73 | 69 | ||
@@ -272,8 +268,10 @@ class ContentViewerController < ApplicationController | @@ -272,8 +268,10 @@ class ContentViewerController < ApplicationController | ||
272 | @comments = @page.comments.without_spam | 268 | @comments = @page.comments.without_spam |
273 | @comments = @plugins.filter(:unavailable_comments, @comments) | 269 | @comments = @plugins.filter(:unavailable_comments, @comments) |
274 | @comments_count = @comments.count | 270 | @comments_count = @comments.count |
275 | - @comments = @comments.without_reply.paginate(:per_page => per_page, :page => params[:comment_page] ) | ||
276 | @comment_order = params[:comment_order].nil? ? 'oldest' : params[:comment_order] | 271 | @comment_order = params[:comment_order].nil? ? 'oldest' : params[:comment_order] |
272 | + @comments = @comments.without_reply | ||
273 | + @comments = @comments.reverse if @comment_order == 'newest' | ||
274 | + @comments = @comments.paginate(:per_page => per_page, :page => params[:comment_page] ) | ||
277 | end | 275 | end |
278 | 276 | ||
279 | private | 277 | private |
app/views/content_viewer/view_page.html.erb
@@ -78,12 +78,12 @@ | @@ -78,12 +78,12 @@ | ||
78 | </div> | 78 | </div> |
79 | <% end %> | 79 | <% end %> |
80 | 80 | ||
81 | - <ul class="article-comments-list"> | ||
82 | - <% if @comments.present? %> | 81 | + <% if @comments.present? %> |
82 | + <ul class="article-comments-list"> | ||
83 | <%= render :partial => 'comment/comment', :collection => @comments %> | 83 | <%= render :partial => 'comment/comment', :collection => @comments %> |
84 | - <%= pagination_links @comments, :param_name => 'comment_page' %> | ||
85 | - <% end %> | ||
86 | - </ul> | 84 | + </ul> |
85 | + <%= pagination_links @comments, :param_name => 'comment_page', :comment_order => params[:comment_order] %> | ||
86 | + <% end %> | ||
87 | 87 | ||
88 | <% if @page.accept_comments? %> | 88 | <% if @page.accept_comments? %> |
89 | <div id='page-comment-form' class='page-comment-form'><%= render :partial => 'comment/comment_form', :locals =>{:url => {:controller => :comment, :action => :create}, :display_link => true, :cancel_triggers_hide => true}%></div> | 89 | <div id='page-comment-form' class='page-comment-form'><%= render :partial => 'comment/comment_form', :locals =>{:url => {:controller => :comment, :action => :create}, :display_link => true, :cancel_triggers_hide => true}%></div> |
public/javascripts/comment_order.js
@@ -2,7 +2,7 @@ function send_order(order, url) { | @@ -2,7 +2,7 @@ function send_order(order, url) { | ||
2 | jQuery('.article-comments-list').addClass('fetching'); | 2 | jQuery('.article-comments-list').addClass('fetching'); |
3 | jQuery.ajax({ | 3 | jQuery.ajax({ |
4 | url:url, | 4 | url:url, |
5 | - data: {"comment_order":order}, | 5 | + data: {"comment_order": order, "comment_page": jQuery(".pagination em").html()}, |
6 | success: function(response) { | 6 | success: function(response) { |
7 | jQuery(".article-comments-list").html(response); | 7 | jQuery(".article-comments-list").html(response); |
8 | }, | 8 | }, |
@@ -10,10 +10,14 @@ function send_order(order, url) { | @@ -10,10 +10,14 @@ function send_order(order, url) { | ||
10 | }); | 10 | }); |
11 | } | 11 | } |
12 | 12 | ||
13 | - | ||
14 | jQuery(document).ready(function(){ | 13 | jQuery(document).ready(function(){ |
15 | jQuery("#comment_order").change(function(){ | 14 | jQuery("#comment_order").change(function(){ |
16 | var url = jQuery("#page_url").val(); | 15 | var url = jQuery("#page_url").val(); |
17 | send_order(this.value, url); | 16 | send_order(this.value, url); |
18 | }); | 17 | }); |
19 | -}); | ||
20 | \ No newline at end of file | 18 | \ No newline at end of file |
19 | + | ||
20 | + jQuery(".pagination a").click(function(){ | ||
21 | + url_with_param = jQuery(this).attr('href') + '&comment_order=' + jQuery("#comment_order").find(":selected").val(); | ||
22 | + jQuery(this).attr('href', url_with_param); | ||
23 | + }); | ||
24 | +}); |