Extract component for ballot investment

Using component inheritance we can remove duplication and share the same
view.
This commit is contained in:
Javi Martín
2021-03-17 17:58:15 +01:00
parent 72a24128a6
commit fb8c476fb2
9 changed files with 111 additions and 79 deletions

View File

@@ -0,0 +1,15 @@
<li id="<%= list_item_id %>">
<%= investment_title %>
<span><%= investment.formatted_price %></span>
<% if budget.balloting? %>
<%= link_to delete_path,
title: t("budgets.ballots.show.remove"),
class: "remove-investment-project",
method: :delete,
remote: true do %>
<span class="show-for-sr"><%= t("budgets.ballots.show.remove") %></span>
<span class="icon-x"></span>
<% end %>
<% end %>
</li>

View File

@@ -0,0 +1,25 @@
class Budgets::Ballot::InvestmentComponent < ApplicationComponent
attr_reader :investment
def initialize(investment:)
@investment = investment
end
private
def budget
investment.budget
end
def list_item_id
dom_id(investment)
end
def investment_title
link_to investment.title, budget_investment_path(budget, investment)
end
def delete_path
budget_ballot_line_path(budget, id: investment.id)
end
end

View File

@@ -0,0 +1,23 @@
class Budgets::Ballot::InvestmentForSidebarComponent < Budgets::Ballot::InvestmentComponent
with_collection_parameter :investment
attr_reader :investment_ids
def initialize(investment:, investment_ids:)
super(investment: investment)
@investment_ids = investment_ids
end
private
def list_item_id
"#{super}_sidebar"
end
def investment_title
investment.title
end
def delete_path
budget_ballot_line_path(id: investment.id, investments_ids: investment_ids)
end
end