Extract component for budget groups and headings

This commit is contained in:
Julian Herrero
2020-03-16 12:54:00 +01:00
committed by Javi Martín
parent 45135bb87e
commit 16c582f282
6 changed files with 67 additions and 59 deletions

View File

@@ -0,0 +1,21 @@
<div id="groups_and_headings" class="groups-and-headings">
<% budget.groups.each do |group| %>
<h2 id="<%= group.name.parameterize %>"><%= group.name %></h2>
<ul class="no-bullet" data-equalizer data-equalizer-on="medium">
<% group.headings.sort_by_name.each do |heading| %>
<li class="heading small-12 medium-4 large-2" data-equalizer-watch>
<% unless budget.informing? || budget.finished? %>
<%= link_to budget_investments_path(budget.id,
heading_id: heading.id) do %>
<%= heading_name_and_price_html(heading) %>
<% end %>
<% else %>
<div class="heading-name">
<%= heading_name_and_price_html(heading) %>
</div>
<% end %>
</li>
<% end %>
</ul>
<% end %>
</div>

View File

@@ -0,0 +1,16 @@
class Budgets::GroupsAndHeadingsComponent < ApplicationComponent
attr_reader :budget
def initialize(budget)
@budget = budget
end
private
def heading_name_and_price_html(heading)
tag.div do
concat(heading.name + " ")
concat(tag.span(budget.formatted_heading_price(heading)))
end
end
end