From ca5ebf95375cd5dbb80a047dc79f4c31e36df899 Mon Sep 17 00:00:00 2001 From: Eduardo Tourinho Edington Date: Wed, 20 Nov 2013 14:27:01 -0300 Subject: [PATCH] Pagination of comments and replies on profile wall. The comments and replies are fetched only after the View all and More links are clicked. --- app/controllers/public/profile_controller.rb | 44 ++++++++++++++++++++++++++++++++++++++++++++ app/views/profile/_more_comments.rhtml | 3 +++ app/views/profile/_more_replies.rhtml | 3 +++ app/views/profile/_profile_activities_list.rhtml | 2 +- app/views/profile/_profile_comments.rhtml | 13 ++++++------- app/views/profile/_profile_scrap.rhtml | 8 +------- app/views/profile/_profile_scraps.rhtml | 33 ++++++++++++++++++++++++++++++++- public/stylesheets/application.css | 7 +++++++ test/functional/profile_controller_test.rb | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/plugins/action_tracker_has_comments/init.rb | 17 ++++------------- 10 files changed, 153 insertions(+), 29 deletions(-) create mode 100644 app/views/profile/_more_comments.rhtml create mode 100644 app/views/profile/_more_replies.rhtml diff --git a/app/controllers/public/profile_controller.rb b/app/controllers/public/profile_controller.rb index c4eb18e..2463ae0 100644 --- a/app/controllers/public/profile_controller.rb +++ b/app/controllers/public/profile_controller.rb @@ -210,6 +210,48 @@ class ProfileController < PublicController render :partial => 'profile_network_activities', :locals => {:network_activities => @activities} end + def more_comments + activity_id = params[:activity].to_i + activity = ActionTracker::Record.find(:first, :conditions => {:id => activity_id, :user_id => @profile.id}) + comments_count = activity.comments.count + comment_page = (params[:comment_page] || 1).to_i + comments_per_page = 5 + no_more_pages = comments_count <= comment_page * comments_per_page + + render :update do |page| + page.insert_html :bottom, 'profile-wall-activities-comments-'+params[:activity], + :partial => 'comment', :collection => activity.comments.paginate(:per_page => comments_per_page, :page => comment_page) + + if no_more_pages + page.remove 'profile-wall-activities-comments-more-'+params[:activity] + else + page.replace_html 'profile-wall-activities-comments-more-'+params[:activity], + :partial => 'more_comments', :locals => {:activity => activity, :comment_page => comment_page} + end + end + end + + def more_replies + activity_id = params[:activity].to_i + activity = Scrap.find(:first, :conditions => {:id => activity_id, :receiver_id => @profile.id, :scrap_id => nil}) + comments_count = activity.replies.count + comment_page = (params[:comment_page] || 1).to_i + comments_per_page = 5 + no_more_pages = comments_count <= comment_page * comments_per_page + + render :update do |page| + page.insert_html :bottom, 'profile-wall-activities-comments-'+params[:activity], + :partial => 'profile_scrap', :collection => activity.replies.paginate(:per_page => comments_per_page, :page => comment_page), :as => :scrap + + if no_more_pages + page.remove 'profile-wall-activities-comments-more-'+params[:activity] + else + page.replace_html 'profile-wall-activities-comments-more-'+params[:activity], + :partial => 'more_replies', :locals => {:activity => activity, :comment_page => comment_page} + end + end + end + def remove_scrap begin scrap = current_user.person.scraps(params[:scrap_id]) @@ -343,6 +385,7 @@ class ProfileController < PublicController end end + protected def check_access_to_profile @@ -393,4 +436,5 @@ class ProfileController < PublicController def relations_to_include [:image, :domains, :preferred_domain, :environment] end + end diff --git a/app/views/profile/_more_comments.rhtml b/app/views/profile/_more_comments.rhtml new file mode 100644 index 0000000..875c1e9 --- /dev/null +++ b/app/views/profile/_more_comments.rhtml @@ -0,0 +1,3 @@ +
+ <%= link_to_remote(_('More'), :url => { :profile => @profile.identifier, :controller => 'profile', :action => 'more_comments', :activity => activity, :comment_page => (comment_page + 1)}) %> +
diff --git a/app/views/profile/_more_replies.rhtml b/app/views/profile/_more_replies.rhtml new file mode 100644 index 0000000..800b608 --- /dev/null +++ b/app/views/profile/_more_replies.rhtml @@ -0,0 +1,3 @@ +
+ <%= link_to_remote(_('More'), :url => { :profile => @profile.identifier, :controller => 'profile', :action => 'more_replies', :activity => activity, :comment_page => (comment_page + 1)}) %> +
diff --git a/app/views/profile/_profile_activities_list.rhtml b/app/views/profile/_profile_activities_list.rhtml index 462cc1d..2f59ab8 100644 --- a/app/views/profile/_profile_activities_list.rhtml +++ b/app/views/profile/_profile_activities_list.rhtml @@ -4,7 +4,7 @@ <% if activity.kind_of?(ActionTracker::Record) %> <%= render :partial => 'profile_activity', :locals => { :activity => activity, :tab_action => 'wall' } if activity.visible? %> <% else %> - <%= render :partial => 'profile_scrap', :locals => {:scrap => activity } %> + <%= render :partial => 'profile_scraps', :locals => { :activity => activity, :scrap => activity } %> <% end %> <% end %> <% end %> diff --git a/app/views/profile/_profile_comments.rhtml b/app/views/profile/_profile_comments.rhtml index 40496c7..c4a4db1 100644 --- a/app/views/profile/_profile_comments.rhtml +++ b/app/views/profile/_profile_comments.rhtml @@ -1,13 +1,12 @@
-<% if activity.comments_count > 2 %> + +<% if activity.comments_count > 0 %> +
- <%= link_to(_("View all %s comments") % activity.comments_count, '#') %> + <%= link_to_remote(_("View all %s comments") % activity.comments_count, :url => { :profile => profile.identifier, :controller => 'profile', :action => 'more_comments', :activity => activity, :comment_page => (1)}) %>
+
<% end %> - - - <%= render :partial => 'profile_comment_form', :locals => { :activity => activity, :tab_action => tab_action } %> diff --git a/app/views/profile/_profile_scrap.rhtml b/app/views/profile/_profile_scrap.rhtml index 670e33a..ef6231c 100644 --- a/app/views/profile/_profile_scrap.rhtml +++ b/app/views/profile/_profile_scrap.rhtml @@ -16,13 +16,7 @@ - <% if scrap.replies.count > 2 %> -
- <%= link_to(_("View all %s comments") % scrap.replies.count, '#') %> -
- <% end %> - -