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) %> +
+ <%= social_share_button_tag(proposal.title, url: proposal_url(proposal), via: "AbriendoMadrid") %> +
+ <% 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' %> -