Commit ecf5200db83ee308fd64823c2964fbb202c7854e
1 parent
04962ef3
Exists in
master
and in
29 other branches
adding pagination in comment group plugin
Showing
8 changed files
with
94 additions
and
11 deletions
Show diff stats
app/helpers/application_helper.rb
... | ... | @@ -1402,7 +1402,7 @@ module ApplicationHelper |
1402 | 1402 | |
1403 | 1403 | def filter_html(html, source) |
1404 | 1404 | if @plugins && source.has_macro? |
1405 | - html = convert_macro(html, source) | |
1405 | + html = convert_macro(html, source) unless @plugins.enabled_macros.blank? | |
1406 | 1406 | #TODO This parse should be done through the macro infra, but since there |
1407 | 1407 | # are old things that do not support it we are keeping this hot spot. |
1408 | 1408 | html = @plugins.pipeline(:parse_content, html, source).first | ... | ... |
plugins/comment_group/controllers/profile/comment_group_plugin_profile_controller.rb
... | ... | @@ -2,15 +2,21 @@ class CommentGroupPluginProfileController < ProfileController |
2 | 2 | append_view_path File.join(File.dirname(__FILE__) + '/../views') |
3 | 3 | |
4 | 4 | def view_comments |
5 | - article_id = params[:article_id] | |
6 | - group_id = params[:group_id] | |
5 | + @article_id = params[:article_id] | |
6 | + @group_id = params[:group_id] | |
7 | 7 | |
8 | - article = profile.articles.find(article_id) | |
9 | - comments = article.group_comments.without_spam.in_group(group_id) | |
10 | - render :update do |page| | |
11 | - page.replace_html "comments_list_group_#{group_id}", :partial => 'comment/comment.rhtml', :collection => comments | |
12 | - page.replace_html "comment-count-#{group_id}", comments.count | |
13 | - end | |
8 | + article = profile.articles.find(@article_id) | |
9 | + @group_comment_page = (params[:group_comment_page] || 1).to_i | |
10 | + | |
11 | + @comments = article.comments.without_spam.in_group(@group_id) | |
12 | + @comments_count = @comments.count | |
13 | + @comments = @comments.without_reply.paginate(:per_page => per_page, :page => @group_comment_page ) | |
14 | + | |
15 | + @no_more_pages = @comments_count <= @group_comment_page * per_page | |
16 | + end | |
17 | + | |
18 | + def per_page | |
19 | + 3 | |
14 | 20 | end |
15 | 21 | |
16 | 22 | end | ... | ... |
plugins/comment_group/lib/comment_group_plugin.rb
plugins/comment_group/test/functional/comment_group_plugin_profile_controller_test.rb
... | ... | @@ -35,4 +35,38 @@ class CommentGroupPluginProfileControllerTest < ActionController::TestCase |
35 | 35 | assert_match /\"comment-count-0\", \"1\"/, @response.body |
36 | 36 | end |
37 | 37 | |
38 | + should 'show first page comments only' do | |
39 | + comment = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'firstpage 1', :group_id => 0) | |
40 | + comment = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'firstpage 2', :group_id => 0) | |
41 | + comment = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'firstpage 3', :group_id => 0) | |
42 | + comment = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'secondpage', :body => 'secondpage', :group_id => 0) | |
43 | + xhr :get, :view_comments, :profile => @profile.identifier, :article_id => article.id, :group_id => 0 | |
44 | + assert_match /firstpage 1/, @response.body | |
45 | + assert_match /firstpage 2/, @response.body | |
46 | + assert_match /firstpage 3/, @response.body | |
47 | + assert_no_match /secondpage/, @response.body | |
48 | + end | |
49 | + | |
50 | + should 'show link to display more comments' do | |
51 | + comment = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'lalala', :group_id => 0) | |
52 | + comment = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'lalala', :group_id => 0) | |
53 | + comment = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'lalala', :group_id => 0) | |
54 | + comment = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'secondpage', :body => 'secondpage', :group_id => 0) | |
55 | + xhr :get, :view_comments, :profile => @profile.identifier, :article_id => article.id, :group_id => 0 | |
56 | + assert_match /group_comment_page=2/, @response.body | |
57 | + end | |
58 | + | |
59 | + should 'do not show link to display more comments if do not have more pages' do | |
60 | + comment = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'lalala', :group_id => 0) | |
61 | + comment = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'lalala', :group_id => 0) | |
62 | + comment = fast_create(Comment, :source_id => article, :author_id => profile, :title => 'a comment', :body => 'lalala', :group_id => 0) | |
63 | + xhr :get, :view_comments, :profile => @profile.identifier, :article_id => article.id, :group_id => 0 | |
64 | + assert_no_match /group_comment_page/, @response.body | |
65 | + end | |
66 | + | |
67 | + should 'do not show link to display more comments if do not have any comments' do | |
68 | + xhr :get, :view_comments, :profile => @profile.identifier, :article_id => article.id, :group_id => 0 | |
69 | + assert_no_match /group_comment_page/, @response.body | |
70 | + end | |
71 | + | |
38 | 72 | end | ... | ... |
plugins/comment_group/views/_comment_group.rhtml
... | ... | @@ -20,7 +20,13 @@ |
20 | 20 | <div class="comment-group-loading-<%= group_id %>"/> |
21 | 21 | |
22 | 22 | <div class="comments_list_toggle_group_<%= group_id %>" style="display:none"> |
23 | - <div class="article-comments-list" id="comments_list_group_<%= group_id %>"></div> | |
24 | - <div id="page-comment-form-<%= group_id %>" class='post_comment_box closed'><%= render :partial => 'comment/comment_form', :locals => {:comment => Comment.new, :display_link => true, :cancel_triggers_hide => true, :group_id => group_id}%></div> | |
23 | + <div class="article-comments-list" id="comments_list_group_<%= group_id %>"> | |
24 | + </div> | |
25 | + <div class ="article-comments-list-more" id="comments_list_group_<%= group_id %>_more"> | |
26 | + </div> | |
27 | + <div id="page-comment-form-<%= group_id %>" class='post_comment_box closed'> | |
28 | + <%= render :partial => 'comment/comment_form', :locals => {:comment => Comment.new, :display_link => true, :cancel_triggers_hide => true, :group_id => group_id}%> | |
29 | + </div> | |
30 | + | |
25 | 31 | </div> |
26 | 32 | </div> | ... | ... |
plugins/comment_group/views/comment_group_plugin_profile/view_comments.rjs
0 → 100644
... | ... | @@ -0,0 +1,12 @@ |
1 | +if @group_comment_page == 1 | |
2 | + page.replace_html "comments_list_group_#{@group_id}", :partial => 'comment/comment.rhtml', :collection => @comments | |
3 | +else | |
4 | + page.insert_html :bottom, "comments_list_group_#{@group_id}", :partial => 'comment/comment.rhtml', :collection => @comments | |
5 | +end | |
6 | +page.replace_html "comment-count-#{@group_id}", @comments_count | |
7 | + | |
8 | +if @no_more_pages | |
9 | + page.replace_html "comments_list_group_#{@group_id}_more", "" | |
10 | +else | |
11 | + page.replace_html "comments_list_group_#{@group_id}_more", link_to_remote(_('More'), :url => { :profile => profile.identifier, :controller => 'comment_group_plugin_profile', :action => 'view_comments', :group_id => @group_id, :article_id => @article_id, :group_comment_page => @group_comment_page + 1}, :loaded => visual_effect(:highlight, "comments_list_group_#{@group_id}"), :method => :post, :complete => "loadCompleted(#{@group_id})") | |
12 | +end | ... | ... |
test/unit/application_helper_test.rb
... | ... | @@ -814,6 +814,19 @@ class ApplicationHelperTest < ActiveSupport::TestCase |
814 | 814 | assert_no_match /Test1/, parsed_html |
815 | 815 | end |
816 | 816 | |
817 | + should 'not convert macro if there is no macro plugin active' do | |
818 | + profile = create_user('testuser').person | |
819 | + article = fast_create(Article, :profile_id => profile.id) | |
820 | + class Plugin1 < Noosfero::Plugin; end | |
821 | + | |
822 | + environment = Environment.default | |
823 | + environment.enable_plugin(Plugin1) | |
824 | + @plugins = Noosfero::Plugin::Manager.new(environment, self) | |
825 | + | |
826 | + expects(:convert_macro).never | |
827 | + filter_html(article.body, nil) | |
828 | + end | |
829 | + | |
817 | 830 | protected |
818 | 831 | include NoosferoTestHelper |
819 | 832 | ... | ... |