From 1136c5546aba645b80c1b42314781f2327a47b35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baza=CC=81n?= Date: Thu, 22 Oct 2015 11:49:14 +0200 Subject: [PATCH] adds featured proposals via new action featured_vote Featured proposals are never duplicated in the filtered lists Featured are not calculated/shown in searches. --- app/controllers/proposals_controller.rb | 17 ++++++++ .../proposals/_featured_proposal.html.erb | 43 +------------------ app/views/proposals/_featured_votes.html.erb | 42 ++++++++++++++++++ app/views/proposals/index.html.erb | 30 +++++++------ app/views/proposals/vote_featured.js.erb | 1 + config/routes.rb | 1 + spec/features/proposals_spec.rb | 28 +++++++++++- spec/features/votes_spec.rb | 16 ++++++- spec/support/common_actions.rb | 6 +++ 9 files changed, 125 insertions(+), 59 deletions(-) create mode 100644 app/views/proposals/_featured_votes.html.erb create mode 100644 app/views/proposals/vote_featured.js.erb diff --git a/app/controllers/proposals_controller.rb b/app/controllers/proposals_controller.rb index 14dce9de1..aa91ad02f 100644 --- a/app/controllers/proposals_controller.rb +++ b/app/controllers/proposals_controller.rb @@ -11,11 +11,24 @@ class ProposalsController < ApplicationController load_and_authorize_resource respond_to :html, :js + def index_customization + @featured_proposals = Proposal.all.sort_by_confidence_score.limit(3) if @search_terms.blank? + if @featured_proposals.present? + set_featured_proposal_votes(@featured_proposals) + @resources = @resources.where('proposals.id NOT IN (?)', @featured_proposals.map(&:id)) + end + end + def vote @proposal.register_vote(current_user, 'yes') set_proposal_votes(@proposal) end + def vote_featured + @proposal.register_vote(current_user, 'yes') + set_featured_proposal_votes(@proposal) + end + private def proposal_params @@ -25,4 +38,8 @@ class ProposalsController < ApplicationController def resource_model Proposal end + + def set_featured_proposal_votes(proposals) + @featured_proposals_votes = current_user ? current_user.proposal_votes(proposals) : {} + end end diff --git a/app/views/proposals/_featured_proposal.html.erb b/app/views/proposals/_featured_proposal.html.erb index 629a56283..d23c83ade 100644 --- a/app/views/proposals/_featured_proposal.html.erb +++ b/app/views/proposals/_featured_proposal.html.erb @@ -12,48 +12,7 @@
-
-
- <% if voted_for?(@proposal_votes, proposal) %> -
- <%= t("proposals.proposal.already_supported") %> -
- <% else %> - <%= link_to vote_proposal_path(proposal, value: 'yes'), - class: "button button-support tiny radius expand", - title: t('proposals.proposal.support_title'), method: "post", remote: true do %> - <%= t("proposals.proposal.support") %> - <% end %> - <% end %> -
- - <% if user_signed_in? && current_user.organization? %> - - <% elsif user_signed_in? && !proposal.votable_by?(current_user)%> - - <% elsif !user_signed_in? %> - - <% end %> - - <% if voted_for?(@proposal_votes, proposal) %> - - <% end %> -
+ <%= render 'featured_votes', proposal: proposal %>
diff --git a/app/views/proposals/_featured_votes.html.erb b/app/views/proposals/_featured_votes.html.erb new file mode 100644 index 000000000..bda617e96 --- /dev/null +++ b/app/views/proposals/_featured_votes.html.erb @@ -0,0 +1,42 @@ +
+
+ <% if voted_for?(@featured_proposals_votes, proposal) %> +
+ <%= t("proposals.proposal.already_supported") %> +
+ <% else %> + <%= link_to vote_featured_proposal_path(proposal, value: 'yes'), + class: "button button-support tiny radius expand", + title: t('proposals.proposal.support_title'), method: "post", remote: true do %> + <%= t("proposals.proposal.support") %> + <% end %> + <% end %> +
+ + <% if user_signed_in? && current_user.organization? %> + + <% elsif user_signed_in? && !proposal.votable_by?(current_user)%> + + <% elsif !user_signed_in? %> + + <% end %> + + <% if voted_for?(@featured_proposals_votes, proposal) %> + + <% end %> +
\ No newline at end of file diff --git a/app/views/proposals/index.html.erb b/app/views/proposals/index.html.erb index 8343cfbdb..77a0a79a0 100644 --- a/app/views/proposals/index.html.erb +++ b/app/views/proposals/index.html.erb @@ -44,21 +44,23 @@ <%= link_to t("proposals.index.start_proposal"), new_proposal_path, class: 'button radius expand' %> -