Commit c5016df0fd4f3ad8ba263f4548a4ddf99d38c864
1 parent
e994be4b
Exists in
staging
and in
4 other branches
proposals_discussion: added filter criterias
Showing
4 changed files
with
55 additions
and
1 deletions
Show diff stats
plugins/proposals_discussion/controllers/public/proposals_discussion_plugin_public_controller.rb
@@ -20,6 +20,12 @@ class ProposalsDiscussionPluginPublicController < ApplicationController | @@ -20,6 +20,12 @@ class ProposalsDiscussionPluginPublicController < ApplicationController | ||
20 | case order | 20 | case order |
21 | when 'alphabetical' | 21 | when 'alphabetical' |
22 | proposals.reorder('name') | 22 | proposals.reorder('name') |
23 | + when 'recent' | ||
24 | + proposals.reorder('created_at DESC') | ||
25 | + when 'most_commented' | ||
26 | + proposals.reorder('comments_count DESC') | ||
27 | + when 'most_recently_commented' | ||
28 | + proposals.joins("LEFT OUTER JOIN comments ON comments.source_id=articles.id AND comments.created_at >= '#{5.days.ago}'").group('articles.id').reorder('count(comments.id) DESC') | ||
23 | else | 29 | else |
24 | set_seed | 30 | set_seed |
25 | proposals.reorder('random()') | 31 | proposals.reorder('random()') |
plugins/proposals_discussion/lib/proposals_discussion_plugin/proposals_list_helper.rb
1 | module ProposalsDiscussionPlugin::ProposalsListHelper | 1 | module ProposalsDiscussionPlugin::ProposalsListHelper |
2 | 2 | ||
3 | + def sort_criteria | ||
4 | + [[_('Random'), :random], [_('Alphabetical'), :alphabetical], [_('Recent'), :recent], [_('Most Commented'), :most_commented], [_('Most Recently Commented'), :most_recently_commented]] | ||
5 | + end | ||
6 | + | ||
3 | def more_proposals(text, holder, order, page=1) | 7 | def more_proposals(text, holder, order, page=1) |
4 | link_to text, url_for({:controller => 'proposals_discussion_plugin_public', :action => 'load_proposals', :holder_id => holder.id, :profile => profile.identifier, :order => order, :page => page }) | 8 | link_to text, url_for({:controller => 'proposals_discussion_plugin_public', :action => 'load_proposals', :holder_id => holder.id, :profile => profile.identifier, :order => order, :page => page }) |
5 | end | 9 | end |
plugins/proposals_discussion/test/functional/proposals_discussion_plugin_public_controller_test.rb
@@ -35,4 +35,48 @@ class ProposalsDiscussionPluginPublicControllerTest < ActionController::TestCase | @@ -35,4 +35,48 @@ class ProposalsDiscussionPluginPublicControllerTest < ActionController::TestCase | ||
35 | assert_equal [proposal2, proposal3, proposal1], assigns(:proposals) | 35 | assert_equal [proposal2, proposal3, proposal1], assigns(:proposals) |
36 | end | 36 | end |
37 | 37 | ||
38 | + should 'load proposals with most commented order' do | ||
39 | + proposal1 = fast_create(ProposalsDiscussionPlugin::Proposal, :name => 'proposal1', :abstract => 'proposal abstract', :profile_id => profile.id, :parent_id => topic.id) | ||
40 | + proposal2 = fast_create(ProposalsDiscussionPlugin::Proposal, :name => 'proposal2', :abstract => 'proposal abstract', :profile_id => profile.id, :parent_id => topic.id) | ||
41 | + proposal3 = fast_create(ProposalsDiscussionPlugin::Proposal, :name => 'proposal3', :abstract => 'proposal abstract', :profile_id => profile.id, :parent_id => topic.id) | ||
42 | + | ||
43 | + author = fast_create(Person) | ||
44 | + Comment.create!(:source => proposal2, :body => 'text', :author => author) | ||
45 | + Comment.create!(:source => proposal2, :body => 'text', :author => author) | ||
46 | + Comment.create!(:source => proposal3, :body => 'text', :author => author) | ||
47 | + | ||
48 | + get :load_proposals, :profile => profile.identifier, :holder_id => topic.id, :order => 'most_commented' | ||
49 | + assert_equal [proposal2, proposal3, proposal1], assigns(:proposals) | ||
50 | + end | ||
51 | + | ||
52 | + should 'load proposals with most recent order' do | ||
53 | + proposal1 = fast_create(ProposalsDiscussionPlugin::Proposal, :name => 'z', :abstract => 'proposal abstract', :profile_id => profile.id, :parent_id => topic.id) | ||
54 | + proposal2 = fast_create(ProposalsDiscussionPlugin::Proposal, :name => 'b', :abstract => 'proposal abstract', :profile_id => profile.id, :parent_id => topic.id) | ||
55 | + proposal3 = fast_create(ProposalsDiscussionPlugin::Proposal, :name => 'k', :abstract => 'proposal abstract', :profile_id => profile.id, :parent_id => topic.id) | ||
56 | + | ||
57 | + author = fast_create(Person) | ||
58 | + Comment.create!(:source => proposal2, :body => 'text', :author => author) | ||
59 | + Comment.create!(:source => proposal2, :body => 'text', :author => author) | ||
60 | + Comment.create!(:source => proposal3, :body => 'text', :author => author) | ||
61 | + | ||
62 | + get :load_proposals, :profile => profile.identifier, :holder_id => topic.id, :order => 'recent' | ||
63 | + assert_equal [proposal3, proposal2, proposal1], assigns(:proposals) | ||
64 | + end | ||
65 | + | ||
66 | + should 'load proposals with most recently commented order' do | ||
67 | + proposal1 = fast_create(ProposalsDiscussionPlugin::Proposal, :name => 'proposal1', :abstract => 'proposal abstract', :profile_id => profile.id, :parent_id => topic.id) | ||
68 | + proposal2 = fast_create(ProposalsDiscussionPlugin::Proposal, :name => 'proposal2', :abstract => 'proposal abstract', :profile_id => profile.id, :parent_id => topic.id) | ||
69 | + proposal3 = fast_create(ProposalsDiscussionPlugin::Proposal, :name => 'proposal3', :abstract => 'proposal abstract', :profile_id => profile.id, :parent_id => topic.id) | ||
70 | + | ||
71 | + author = fast_create(Person) | ||
72 | + Comment.create!({:source => proposal2, :body => 'text', :author => author, :created_at => 10.days.ago}, :without_protection => true) | ||
73 | + Comment.create!({:source => proposal2, :body => 'text', :author => author, :created_at => 10.days.ago}, :without_protection => true) | ||
74 | + Comment.create!(:source => proposal3, :body => 'text', :author => author) | ||
75 | + Comment.create!(:source => proposal3, :body => 'text', :author => author) | ||
76 | + Comment.create!(:source => proposal1, :body => 'text', :author => author) | ||
77 | + | ||
78 | + get :load_proposals, :profile => profile.identifier, :holder_id => topic.id, :order => 'most_recently_commented' | ||
79 | + assert_equal [proposal3, proposal1, proposal2], assigns(:proposals) | ||
80 | + end | ||
81 | + | ||
38 | end | 82 | end |
plugins/proposals_discussion/views/content_viewer/_proposals_list.html.erb
@@ -12,7 +12,7 @@ | @@ -12,7 +12,7 @@ | ||
12 | <% order ||= 'random' %> | 12 | <% order ||= 'random' %> |
13 | <div class="proposals_list"> | 13 | <div class="proposals_list"> |
14 | <div class="filters"> | 14 | <div class="filters"> |
15 | - <% [[_('Random'), :random], [_('Aplhabetical'), :alphabetical]].each_with_index do |order, i| %> | 15 | + <% sort_criteria.each_with_index do |order, i| %> |
16 | <%= link_to order.first, url_for({:controller => 'proposals_discussion_plugin_public', :action => 'load_proposals', :holder_id => holder.id, :profile => profile.identifier, :order => order.second}), :remote => true, :class => "order #{order.second} #{i==0 ? 'selected':''}" %> | 16 | <%= link_to order.first, url_for({:controller => 'proposals_discussion_plugin_public', :action => 'load_proposals', :holder_id => holder.id, :profile => profile.identifier, :order => order.second}), :remote => true, :class => "order #{order.second} #{i==0 ? 'selected':''}" %> |
17 | <% end %> | 17 | <% end %> |
18 | </div> | 18 | </div> |