Extract component to render my ballot
This is the only part of the sidebar that needs to be re-rendered after an AJAX request adding or removing investments to a ballot, so having a separate view just for it will make it easier to simplify the code.
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
<div class="my-ballot">
|
||||
<h2 class="sidebar-title">
|
||||
<%= t("budgets.investments.index.sidebar.my_ballot") %>
|
||||
</h2>
|
||||
|
||||
<% if ballot.investments.by_heading(heading.id).count > 0 %>
|
||||
<p>
|
||||
<em><%= sanitize(ballot.voted_info(heading)) %></em>
|
||||
</p>
|
||||
<% elsif assigned_heading.present? %>
|
||||
<p>
|
||||
<%= sanitize(t("budgets.investments.index.sidebar.different_heading_assigned",
|
||||
heading_link: heading_link(assigned_heading, budget)
|
||||
)) %>
|
||||
<br>
|
||||
<small>
|
||||
<%= sanitize(t("budgets.investments.index.sidebar.change_ballot",
|
||||
check_ballot: link_to(t("budgets.investments.index.sidebar.check_ballot_link"),
|
||||
budget_ballot_path(budget)))) %>
|
||||
</small>
|
||||
</p>
|
||||
<% else %>
|
||||
<p><strong><%= t("budgets.investments.index.sidebar.zero") %></strong></p>
|
||||
<% end %>
|
||||
|
||||
<p>
|
||||
<%= sanitize(ballot.change_vote_info(
|
||||
link: link_to(t("budgets.investments.index.sidebar.change_vote_link"),
|
||||
budget_ballot_path(budget)))) %>
|
||||
</p>
|
||||
|
||||
<ul class="ballot-list">
|
||||
<% if heading %>
|
||||
<%= render Budgets::Ballot::InvestmentForSidebarComponent.with_collection(
|
||||
ballot.investments.by_heading(heading.id),
|
||||
investment_ids: investment_ids
|
||||
) %>
|
||||
<% end %>
|
||||
</ul>
|
||||
|
||||
<%= link_to t("budgets.investments.header.check_ballot"),
|
||||
budget_ballot_path(budget),
|
||||
class: "button hollow expanded" %>
|
||||
</div>
|
||||
17
app/components/budgets/investments/my_ballot_component.rb
Normal file
17
app/components/budgets/investments/my_ballot_component.rb
Normal file
@@ -0,0 +1,17 @@
|
||||
class Budgets::Investments::MyBallotComponent < ApplicationComponent
|
||||
attr_reader :ballot, :heading, :investment_ids, :assigned_heading
|
||||
delegate :heading_link, to: :helpers
|
||||
|
||||
def initialize(ballot:, heading:, investment_ids:, assigned_heading:)
|
||||
@ballot = ballot
|
||||
@heading = heading
|
||||
@investment_ids = investment_ids
|
||||
@assigned_heading = assigned_heading
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def budget
|
||||
ballot.budget
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user