Commit 6f9071dfa027540dc8a444e336d92c6d1d02628e

Authored by Victor Costa
2 parents 8868b597 8b8eca62

Merge branch 'AI3220_proposals' into stable

plugins/proposals_discussion/controllers/public/proposals_discussion_plugin_public_controller.rb
... ... @@ -20,6 +20,12 @@ class ProposalsDiscussionPluginPublicController < ApplicationController
20 20 case order
21 21 when 'alphabetical'
22 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 29 else
24 30 set_seed
25 31 proposals.reorder('random()')
... ...
plugins/proposals_discussion/lib/proposals_discussion_plugin/proposal_helper.rb
... ... @@ -1,8 +0,0 @@
1   -module ProposalsDiscussionPlugin::ProposalHelper
2   -
3   - def visibility_options(article, tokenized_children)
4   - article.published = false if article.new_record?
5   - super
6   - end
7   -
8   -end
plugins/proposals_discussion/lib/proposals_discussion_plugin/proposals_list_helper.rb
1 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 7 def more_proposals(text, holder, order, page=1)
4 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 9 end
... ...
plugins/proposals_discussion/lib/proposals_discussion_plugin/topic_helper.rb 0 → 100644
... ... @@ -0,0 +1,8 @@
  1 +module ProposalsDiscussionPlugin::TopicHelper
  2 +
  3 + def topic_title(topic)
  4 + content_tag(:div, '', :class=>'topic-color', :style => "background-color: #{topic.color};") +
  5 + content_tag(:h2, link_to(topic.title, topic.view_url))
  6 + end
  7 +
  8 +end
... ...
plugins/proposals_discussion/public/proposals_list.js
... ... @@ -10,9 +10,9 @@ jQuery(document).ready(function($) {
10 10 });
11 11  
12 12 function proposalsScroll() {
13   - var scroll = $('.article-body-proposals-discussion-plugin_topic .topic-content .proposals_list');
  13 + var scroll = $('.article-body-proposals-discussion-plugin_topic .topic-content .proposals_list .proposals');
14 14 var nextSelector = 'div.more a';
15   - if(scroll.data('jscroll')) scroll.jscroll.destroy();
  15 + if(scroll.data('jscroll')) scroll.data('jscroll', null);
16 16  
17 17 if(scroll.find(nextSelector).length > 0) {
18 18 scroll.jscroll({
... ...
plugins/proposals_discussion/test/functional/proposals_discussion_plugin_public_controller_test.rb
... ... @@ -35,4 +35,48 @@ class ProposalsDiscussionPluginPublicControllerTest < ActionController::TestCase
35 35 assert_equal [proposal2, proposal3, proposal1], assigns(:proposals)
36 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 82 end
... ...
plugins/proposals_discussion/views/cms/proposals_discussion_plugin/_proposal.html.erb
... ... @@ -5,7 +5,14 @@
5 5 <% title_limit = 70 %>
6 6 <% abstract_limit = 140 %>
7 7  
  8 +<% extend ProposalsDiscussionPlugin::TopicHelper %>
  9 +
8 10 <div class="proposals-discussion-plugin">
  11 +
  12 + <div class="topic">
  13 + <%= topic_title @article.topic %>
  14 + </div>
  15 +
9 16 <div class="title">
10 17 <%= required labelled_form_field _('Title'), limited_text_area(:article, :name, title_limit, 'title_textarea', :rows => 1) %>
11 18 </div>
... ...
plugins/proposals_discussion/views/content_viewer/_proposals_list.html.erb
... ... @@ -12,7 +12,7 @@
12 12 <% order ||= 'random' %>
13 13 <div class="proposals_list">
14 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 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 17 <% end %>
18 18 </div>
... ...
plugins/proposals_discussion/views/content_viewer/topic.html.erb
... ... @@ -4,8 +4,8 @@
4 4 <%= javascript_include_tag 'plugins/proposals_discussion/proposals_list.js' %>
5 5 <% end %>
6 6  
7   -<div class="topic-color" style="background-color: <%= topic.color %>;"></div>
8   -<h2><%= link_to topic.title, topic.view_url %></h2>
  7 +<% extend ProposalsDiscussionPlugin::TopicHelper %>
  8 +<%= topic_title topic %>
9 9  
10 10 <div class="topic-content">
11 11  
... ...