Commit f9ab314ec4b6d0e70eb2514b37b236bae441767c
Committed by
Daniela Feitosa
1 parent
79818886
Exists in
master
and in
29 other branches
comment_order_improvement: Add an option to order comments by the newest or oldest comments.
(ActionItem2911) Signed-off-by: Luiz Matos <luizff.matos@gmail.com> Signed-off-by: Marcos Ramos <ms.ramos@outlook.com> Signed-off-by: Gabriela Navarro <navarro1703@gmail.com> Signed-off-by: David Carlos <ddavidcarlos1392@gmail.com> Signed-off-by: Fabio Teixeira <fabio1079@gmail.com> Signed-off-by: Matheus Faria <matheus.sousa.faria@gmail.com>
Showing
6 changed files
with
84 additions
and
1 deletions
Show diff stats
app/controllers/public/content_viewer_controller.rb
... | ... | @@ -111,6 +111,15 @@ class ContentViewerController < ApplicationController |
111 | 111 | @comments = @plugins.filter(:unavailable_comments, @comments) |
112 | 112 | @comments_count = @comments.count |
113 | 113 | @comments = @comments.without_reply.paginate(:per_page => per_page, :page => params[:comment_page] ) |
114 | + @comment_order = params[:comment_order].nil? ? 'oldest' : params[:comment_order] | |
115 | + | |
116 | + if request.xhr? and params[:comment_order] | |
117 | + if @comment_order == 'newest' | |
118 | + @comments = @comments.reverse | |
119 | + end | |
120 | + | |
121 | + return render :partial => 'comment/comment', :collection => @comments | |
122 | + end | |
114 | 123 | |
115 | 124 | if params[:slideshow] |
116 | 125 | render :action => 'slideshow', :layout => 'slideshow' | ... | ... |
app/views/content_viewer/view_page.rhtml
... | ... | @@ -84,6 +84,16 @@ |
84 | 84 | <%= link_to(_('Post a comment'), '#', :class => 'display-comment-form', :id => 'top-post-comment-button', :onclick => "jQuery('#page-comment-form .display-comment-form').first().click();") %> |
85 | 85 | <% end %> |
86 | 86 | |
87 | + <% if @page.accept_comments? and @comments.count > 1 %> | |
88 | + <%= hidden_field_tag("page_url", url_for(:controller=>'content_viewer', :action=>'view_page', :profile=>profile.identifier)) %> | |
89 | + <%= javascript_include_tag "comment_order.js" %> | |
90 | + <div class="comment-order"> | |
91 | + <% form_tag({:controller=>'content_viewer' , :action=>'view_page'}, {:method=>'get', :id=>"form_order"}) do %> | |
92 | + <%= select_tag 'comment_order', options_for_select({_('Oldest first')=>'oldest', _('Newest first')=>'newest'}, @comment_order) %> | |
93 | + <% end %> | |
94 | + </div> | |
95 | + <% end %> | |
96 | + | |
87 | 97 | <ul class="article-comments-list"> |
88 | 98 | <%= render :partial => 'comment/comment', :collection => @comments %> |
89 | 99 | <%= pagination_links @comments, :param_name => 'comment_page' %> | ... | ... |
features/comment.feature
... | ... | @@ -97,3 +97,41 @@ Feature: comment |
97 | 97 | Given I am on /booking/article-to-comment |
98 | 98 | And I follow "Post a comment" |
99 | 99 | Then "Post a comment" should not be visible within "#article" |
100 | + | |
101 | + @selenium | |
102 | + Scenario: the newest post from a forum should be displayed first. | |
103 | + Given the following users | |
104 | + | login | name | | |
105 | + | joaosilva | Joao Silva | | |
106 | + And the following forums | |
107 | + | owner | name | | |
108 | + | joaosilva | Forum | | |
109 | + And the following articles | |
110 | + | owner | name | parent | | |
111 | + | joaosilva | Post one | Forum | | |
112 | + And the following comments | |
113 | + | article | author | title | body | | |
114 | + | Post one | joaosilva | Hi all | Hi all | | |
115 | + | Post one | joaosilva | Hello | Hello | | |
116 | + When I go to /joaosilva/forum/post-one | |
117 | + And I select "Newest first" from "comment_order" within ".comment-order" | |
118 | + Then I should see "Hello" within ".article-comment" | |
119 | + | |
120 | + @selenium | |
121 | + Scenario: the oldest post from a forum should be displayed first. | |
122 | + Given the following users | |
123 | + | login | name | | |
124 | + | joaosilva | Joao Silva | | |
125 | + And the following forums | |
126 | + | owner | name | | |
127 | + | joaosilva | Forum | | |
128 | + And the following articles | |
129 | + | owner | name | parent | | |
130 | + | joaosilva | Post one | Forum | | |
131 | + And the following comments | |
132 | + | article | author | title | body | | |
133 | + | Post one | joaosilva | Hi all | Hi all | | |
134 | + | Post one | joaosilva | Hello | Hello | | |
135 | + When I go to /joaosilva/forum/post-one | |
136 | + And I select "Oldest first" from "comment_order" within ".comment-order" | |
137 | + Then I should see "Hi all" within ".article-comment" | |
100 | 138 | \ No newline at end of file | ... | ... |
public/designs/themes/base/style.css
public/javascripts/application.js
... | ... | @@ -0,0 +1,21 @@ |
1 | +function send_order(order, url) { | |
2 | + open_loading(DEFAULT_LOADING_MESSAGE); | |
3 | + | |
4 | + jQuery.ajax({ | |
5 | + url:url, | |
6 | + data: {"comment_order":order}, | |
7 | + success: function(response) { | |
8 | + close_loading(); | |
9 | + jQuery(".article-comments-list").html(response); | |
10 | + }, | |
11 | + error: function() { close_loading() } | |
12 | + }); | |
13 | +} | |
14 | + | |
15 | + | |
16 | +jQuery(document).ready(function(){ | |
17 | + jQuery("#comment_order").change(function(){ | |
18 | + var url = jQuery("#page_url").val(); | |
19 | + send_order(this.value, url); | |
20 | + }); | |
21 | +}); | |
0 | 22 | \ No newline at end of file | ... | ... |