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,29 @@
.groups-and-headings {
.heading {
border: 1px solid $border;
border-radius: rem-calc(3);
display: inline-block;
margin-bottom: $line-height / 2;
a {
display: block;
padding: $line-height / 2;
&:hover {
background: $highlight;
text-decoration: none;
}
}
.heading-name {
padding: $line-height / 2;
}
span {
color: $text;
display: block;
font-size: $small-font-size;
}
}
}

View File

@@ -1222,36 +1222,6 @@
color: $brand;
}
.groups-and-headings {
.heading {
border: 1px solid $border;
border-radius: rem-calc(3);
display: inline-block;
margin-bottom: $line-height / 2;
a {
display: block;
padding: $line-height / 2;
&:hover {
background: $highlight;
text-decoration: none;
}
}
.heading-name {
padding: $line-height / 2;
}
span {
color: $text;
display: block;
font-size: $small-font-size;
}
}
}
.progress-votes {
position: relative;

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

View File

@@ -5,13 +5,6 @@ module BudgetsHelper
end
end
def heading_name_and_price_html(heading, budget)
tag.div do
concat(heading.name + " ")
concat(tag.span(budget.formatted_heading_price(heading)))
end
end
def csv_params
csv_params = params.clone.merge(format: :csv)
csv_params = csv_params.to_unsafe_h.map { |k, v| [k.to_sym, v] }.to_h

View File

@@ -27,28 +27,7 @@
<div id="budget_info" class="budget-info">
<div class="row margin-top">
<div class="small-12 column">
<div id="groups_and_headings" class="groups-and-headings">
<% current_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 current_budget.informing? || current_budget.finished? %>
<%= link_to budget_investments_path(current_budget.id,
heading_id: heading.id) do %>
<%= heading_name_and_price_html(heading, current_budget) %>
<% end %>
<% else %>
<div class="heading-name">
<%= heading_name_and_price_html(heading, current_budget) %>
</div>
<% end %>
</li>
<% end %>
</ul>
<% end %>
</div>
<%= render Budgets::GroupsAndHeadingsComponent.new(current_budget) %>
<% unless current_budget.informing? %>
<div class="map inline">