Extract component for ballot investment
Using component inheritance we can remove duplication and share the same view.
This commit is contained in:
15
app/components/budgets/ballot/investment_component.html.erb
Normal file
15
app/components/budgets/ballot/investment_component.html.erb
Normal 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>
|
||||
25
app/components/budgets/ballot/investment_component.rb
Normal file
25
app/components/budgets/ballot/investment_component.rb
Normal 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
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user