From e6de84f70b57ca4eda65948d714028819b51b30d Mon Sep 17 00:00:00 2001 From: Gabriel Silva Date: Fri, 15 Jan 2016 19:54:48 +0000 Subject: [PATCH] Fix comments pagination and ordering --- app/controllers/public/content_viewer_controller.rb | 8 +++----- app/views/content_viewer/view_page.html.erb | 10 +++++----- public/javascripts/comment_order.js | 10 +++++++--- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/app/controllers/public/content_viewer_controller.rb b/app/controllers/public/content_viewer_controller.rb index c3856a1..594d4c3 100644 --- a/app/controllers/public/content_viewer_controller.rb +++ b/app/controllers/public/content_viewer_controller.rb @@ -64,10 +64,6 @@ class ContentViewerController < ApplicationController process_comments(params) if request.xhr? and params[:comment_order] - if @comment_order == 'newest' - @comments = @comments.reverse - end - return render :partial => 'comment/comment', :collection => @comments end @@ -272,8 +268,10 @@ class ContentViewerController < ApplicationController @comments = @page.comments.without_spam @comments = @plugins.filter(:unavailable_comments, @comments) @comments_count = @comments.count - @comments = @comments.without_reply.paginate(:per_page => per_page, :page => params[:comment_page] ) @comment_order = params[:comment_order].nil? ? 'oldest' : params[:comment_order] + @comments = @comments.without_reply + @comments = @comments.reverse if @comment_order == 'newest' + @comments = @comments.paginate(:per_page => per_page, :page => params[:comment_page] ) end private diff --git a/app/views/content_viewer/view_page.html.erb b/app/views/content_viewer/view_page.html.erb index f089768..b1ea064 100644 --- a/app/views/content_viewer/view_page.html.erb +++ b/app/views/content_viewer/view_page.html.erb @@ -78,12 +78,12 @@ <% end %> - + <%= pagination_links @comments, :param_name => 'comment_page', :comment_order => params[:comment_order] %> + <% end %> <% if @page.accept_comments? %>
<%= render :partial => 'comment/comment_form', :locals =>{:url => {:controller => :comment, :action => :create}, :display_link => true, :cancel_triggers_hide => true}%>
diff --git a/public/javascripts/comment_order.js b/public/javascripts/comment_order.js index b47b2a8..73a60ea 100644 --- a/public/javascripts/comment_order.js +++ b/public/javascripts/comment_order.js @@ -2,7 +2,7 @@ function send_order(order, url) { jQuery('.article-comments-list').addClass('fetching'); jQuery.ajax({ url:url, - data: {"comment_order":order}, + data: {"comment_order": order, "comment_page": jQuery(".pagination em").html()}, success: function(response) { jQuery(".article-comments-list").html(response); }, @@ -10,10 +10,14 @@ function send_order(order, url) { }); } - jQuery(document).ready(function(){ jQuery("#comment_order").change(function(){ var url = jQuery("#page_url").val(); send_order(this.value, url); }); -}); \ No newline at end of file + + jQuery(".pagination a").click(function(){ + url_with_param = jQuery(this).attr('href') + '&comment_order=' + jQuery("#comment_order").find(":selected").val(); + jQuery(this).attr('href', url_with_param); + }); +}); -- libgit2 0.21.2