Move votes partials to components
We're going to change the code quite a bit, and with components we can easily extract methods when necessary.
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
<% voted_classes = css_classes_for_vote(legislation_proposal_votes, proposal) %>
|
||||
<div class="votes">
|
||||
<% if proposal.process.proposals_phase.open? %>
|
||||
<div class="in-favor inline-block">
|
||||
<% if user_signed_in? %>
|
||||
<%= link_to vote_legislation_process_proposal_path(process_id: proposal.process, id: proposal, value: "yes"),
|
||||
class: "like #{voted_classes[:in_favor]}", title: t("votes.agree"), method: "post", remote: true do %>
|
||||
<span class="icon-like">
|
||||
<span class="show-for-sr"><%= t("votes.agree") %></span>
|
||||
</span>
|
||||
<span class="percentage"><%= votes_percentage("likes", proposal) %></span>
|
||||
<% end %>
|
||||
<% else %>
|
||||
<div class="like">
|
||||
<span class="icon-like">
|
||||
<span class="show-for-sr"><%= t("votes.agree") %></span>
|
||||
</span>
|
||||
<span class="percentage"><%= votes_percentage("likes", proposal) %></span>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<span class="divider"></span>
|
||||
|
||||
<div class="against inline-block">
|
||||
<% if user_signed_in? %>
|
||||
<%= link_to vote_legislation_process_proposal_path(process_id: proposal.process, id: proposal, value: "no"), class: "unlike #{voted_classes[:against]}", title: t("votes.disagree"), method: "post", remote: true do %>
|
||||
<span class="icon-unlike">
|
||||
<span class="show-for-sr"><%= t("votes.disagree") %></span>
|
||||
</span>
|
||||
<span class="percentage"><%= votes_percentage("dislikes", proposal) %></span>
|
||||
<% end %>
|
||||
<% else %>
|
||||
<div class="unlike">
|
||||
<span class="icon-unlike">
|
||||
<span class="show-for-sr"><%= t("votes.disagree") %></span>
|
||||
</span>
|
||||
<span class="percentage"><%= votes_percentage("dislikes", proposal) %></span>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<span class="total-votes">
|
||||
<%= t("proposals.proposal.votes", count: proposal.votes_score) %>
|
||||
</span>
|
||||
|
||||
<% if user_signed_in? && current_user.organization? %>
|
||||
<div class="participation-not-allowed" style="display:none" aria-hidden="false">
|
||||
<p>
|
||||
<%= t("votes.organizations") %>
|
||||
</p>
|
||||
</div>
|
||||
<% elsif user_signed_in? && !proposal.votable_by?(current_user) %>
|
||||
<div class="participation-not-allowed" style="display:none" aria-hidden="false">
|
||||
<p>
|
||||
<%= sanitize(t("legislation.proposals.not_verified",
|
||||
verify_account: link_to_verify_account)) %>
|
||||
</p>
|
||||
</div>
|
||||
<% elsif !user_signed_in? %>
|
||||
<div tabindex="0">
|
||||
<%= render "shared/login_to_vote" %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<% if voted_for?(legislation_proposal_votes, proposal) && setting["twitter_handle"] %>
|
||||
<div class="share-supported">
|
||||
<%= render "shared/social_share",
|
||||
title: proposal.title,
|
||||
url: proposal_url(proposal),
|
||||
description: proposal.summary,
|
||||
mobile: proposal.title %>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
9
app/components/legislation/proposals/votes_component.rb
Normal file
9
app/components/legislation/proposals/votes_component.rb
Normal file
@@ -0,0 +1,9 @@
|
||||
class Legislation::Proposals::VotesComponent < ApplicationComponent
|
||||
attr_reader :proposal, :legislation_proposal_votes
|
||||
delegate :css_classes_for_vote, :current_user, :link_to_verify_account, :user_signed_in?, :voted_for?, :votes_percentage, to: :helpers
|
||||
|
||||
def initialize(proposal, legislation_proposal_votes:)
|
||||
@proposal = proposal
|
||||
@legislation_proposal_votes = legislation_proposal_votes
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user