adds featured proposals

via new action featured_vote
Featured proposals are never duplicated in the filtered lists
Featured are not calculated/shown in searches.
This commit is contained in:
Juanjo Bazán
2015-10-22 11:49:14 +02:00
committed by Juanjo Bazán
parent c896fc3eef
commit 1136c5546a
9 changed files with 125 additions and 59 deletions

View File

@@ -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

View File

@@ -12,48 +12,7 @@
</div>
<div id="<%= dom_id(proposal) %>_votes" class="small-12 medium-3 left">
<div class="supports">
<div class="in-favor">
<% if voted_for?(@proposal_votes, proposal) %>
<div class="supported">
<%= t("proposals.proposal.already_supported") %>
</div>
<% 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 %>
</div>
<% if user_signed_in? && current_user.organization? %>
<div class="organizations-votes" style='display:none'>
<p>
<%= t("votes.organizations") %>
</p>
</div>
<% elsif user_signed_in? && !proposal.votable_by?(current_user)%>
<div class="anonymous-votes" style='display:none'>
<p>
<%= t("votes.verified_only",
verify_account: link_to(t("votes.verify_account"), verification_path )).html_safe %>
</p>
</div>
<% elsif !user_signed_in? %>
<div class="not-logged" style='display:none'>
<%= t("votes.unauthenticated",
signin: link_to(t("votes.signin"), new_user_session_path),
signup: link_to(t("votes.signup"), new_user_registration_path)).html_safe %>
</div>
<% end %>
<% if voted_for?(@proposal_votes, proposal) %>
<div class="share-supported">
<%= social_share_button_tag(proposal.title, url: proposal_url(proposal), via: "AbriendoMadrid") %>
</div>
<% end %>
</div>
<%= render 'featured_votes', proposal: proposal %>
</div>
</div>
</div>

View File

@@ -0,0 +1,42 @@
<div class="supports">
<div class="in-favor">
<% if voted_for?(@featured_proposals_votes, proposal) %>
<div class="supported">
<%= t("proposals.proposal.already_supported") %>
</div>
<% 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 %>
</div>
<% if user_signed_in? && current_user.organization? %>
<div class="organizations-votes" style='display:none'>
<p>
<%= t("votes.organizations") %>
</p>
</div>
<% elsif user_signed_in? && !proposal.votable_by?(current_user)%>
<div class="anonymous-votes" style='display:none'>
<p>
<%= t("votes.verified_only",
verify_account: link_to(t("votes.verify_account"), verification_path )).html_safe %>
</p>
</div>
<% elsif !user_signed_in? %>
<div class="not-logged" style='display:none'>
<%= t("votes.unauthenticated",
signin: link_to(t("votes.signin"), new_user_session_path),
signup: link_to(t("votes.signup"), new_user_registration_path)).html_safe %>
</div>
<% end %>
<% if voted_for?(@featured_proposals_votes, proposal) %>
<div class="share-supported">
<%= social_share_button_tag(proposal.title, url: proposal_url(proposal), via: "AbriendoMadrid") %>
</div>
<% end %>
</div>

View File

@@ -44,21 +44,23 @@
<%= link_to t("proposals.index.start_proposal"), new_proposal_path, class: 'button radius expand' %>
</div>
<div class="row featured-proposals-container">
<div class="small-12 medium-3 column">
<h2>
<%= t("proposals.index.featured_proposals_html") %>
</h2>
<span class="show-for-medium-up">
<%= image_tag("featured_proposals.jpg", size: "210x135") %>
</span>
<% if @featured_proposals.present? %>
<div id="featured-proposals" class="row featured-proposals-container">
<div class="small-12 medium-3 column">
<h2>
<%= t("proposals.index.featured_proposals_html") %>
</h2>
<span class="show-for-medium-up">
<%= image_tag("featured_proposals.jpg", size: "210x135") %>
</span>
</div>
<div class="small-12 medium-9 column proposals-list">
<% @featured_proposals.each do |featured_proposal| %>
<%= render "featured_proposal", proposal: featured_proposal %>
<% end %>
</div>
</div>
<div class="small-12 medium-9 column proposals-list">
<% @proposals.limit(3).each do |proposal| %>
<%= render "featured_proposal", proposal: proposal %>
<% end %>
</div>
</div>
<% end %>
<%= render partial: 'proposals/proposal', collection: @proposals %>
<%= paginate @proposals %>

View File

@@ -0,0 +1 @@
$("#<%= dom_id(@proposal) %>_votes").html('<%= j render("proposals/featured_votes", proposal: @proposal) %>');