Extract methods to get investments in a ballot

This commit is contained in:
Javi Martín
2024-03-30 00:24:28 +01:00
parent f9d9fe8f23
commit 05a6021938
4 changed files with 11 additions and 5 deletions

View File

@@ -36,9 +36,7 @@
<% end %> <% end %>
<ul class="ballot-list"> <ul class="ballot-list">
<%= render Budgets::Ballot::InvestmentComponent.with_collection( <%= render Budgets::Ballot::InvestmentComponent.with_collection(group_investments(group)) %>
ballot.investments.by_group(group.id)
) %>
</ul> </ul>
</div> </div>
</div> </div>

View File

@@ -26,4 +26,8 @@ class Budgets::Ballot::BallotComponent < ApplicationComponent
budget_investments_path(budget, heading_id: group.headings.first) budget_investments_path(budget, heading_id: group.headings.first)
end end
end end
def group_investments(group)
ballot.investments.by_group(group.id)
end
end end

View File

@@ -3,7 +3,7 @@
<%= t("budgets.investments.index.sidebar.my_ballot") %> <%= t("budgets.investments.index.sidebar.my_ballot") %>
</h2> </h2>
<% if ballot.investments.by_heading(heading.id).count > 0 %> <% if investments.count > 0 %>
<p> <p>
<em><%= sanitize(ballot.voted_info(heading)) %></em> <em><%= sanitize(ballot.voted_info(heading)) %></em>
</p> </p>
@@ -32,7 +32,7 @@
<ul class="ballot-list"> <ul class="ballot-list">
<% if heading %> <% if heading %>
<%= render Budgets::Ballot::InvestmentForSidebarComponent.with_collection( <%= render Budgets::Ballot::InvestmentForSidebarComponent.with_collection(
ballot.investments.by_heading(heading.id), investments,
investment_ids: investment_ids investment_ids: investment_ids
) %> ) %>
<% end %> <% end %>

View File

@@ -18,4 +18,8 @@ class Budgets::Investments::MyBallotComponent < ApplicationComponent
def budget def budget
ballot.budget ballot.budget
end end
def investments
ballot.investments.by_heading(heading.id)
end
end end