Extract groups and headings tables to components

This commit is contained in:
Julian Herrero
2020-03-17 12:55:35 +07:00
committed by Javi Martín
parent 2115eb5274
commit b16fe80ba5
6 changed files with 104 additions and 74 deletions

View File

@@ -0,0 +1,33 @@
<% if groups.any? %>
<h3><%= t("admin.budget_groups.amount", count: groups.count) %></h3>
<table>
<thead>
<tr id="<%= dom_id(budget) %>">
<th><%= t("admin.budget_groups.name") %></th>
<th><%= Budget::Group.human_attribute_name(:max_votable_headings) %></th>
<th><%= t("admin.budget_groups.headings_name") %></th>
<th><%= t("admin.actions.actions") %></th>
</tr>
</thead>
<tbody>
<% groups.each do |group| %>
<tr id="<%= dom_id(group) %>">
<td><%= group.name %></td>
<td><%= group.max_votable_headings %></td>
<td><%= group.headings.count %></td>
<td>
<%= render Admin::TableActionsComponent.new(group) do |actions| %>
<%= actions.link_to t("admin.budget_groups.headings_manage"),
admin_budget_group_headings_path(budget, group),
class: "headings-link" %>
<% end %>
</td>
</tr>
<% end %>
</tbody>
</table>
<% else %>
<div class="callout primary clear">
<%= t("admin.budget_groups.no_groups") %>
</div>
<% end %>

View File

@@ -0,0 +1,13 @@
class Admin::BudgetGroups::GroupsComponent < ApplicationComponent
attr_reader :groups
def initialize(groups)
@groups = groups
end
private
def budget
@budget ||= groups.first.budget
end
end

View File

@@ -0,0 +1,39 @@
<% if headings.any? %>
<h3><%= t("admin.budget_headings.amount", count: headings.count) %></h3>
<table>
<thead>
<tr id="<%= dom_id(group) %>">
<th><%= Budget::Heading.human_attribute_name(:name) %></th>
<th><%= Budget::Heading.human_attribute_name(:price) %></th>
<% if budget.approval_voting? %>
<th><%= Budget::Heading.human_attribute_name(:max_ballot_lines) %></th>
<% end %>
<th><%= Budget::Heading.human_attribute_name(:population) %></th>
<th><%= Budget::Heading.human_attribute_name(:allow_custom_content) %></th>
<th><%= t("admin.actions.actions") %></th>
</tr>
</thead>
<tbody>
<% headings.each do |heading| %>
<tr id="<%= dom_id(heading) %>" class="heading">
<td><%= heading.name %></td>
<td><%= budget.formatted_heading_price(heading) %></td>
<% if budget.approval_voting? %>
<td><%= heading.max_ballot_lines %></td>
<% end %>
<td><%= heading.population %></td>
<td>
<%= heading.allow_custom_content ? t("admin.shared.true_value") : t("admin.shared.false_value") %>
</td>
<td>
<%= render Admin::TableActionsComponent.new(heading) %>
</td>
</tr>
<% end %>
</tbody>
</table>
<% else %>
<div class="callout primary clear">
<%= t("admin.budget_headings.no_headings") %>
</div>
<% end %>

View File

@@ -0,0 +1,17 @@
class Admin::BudgetHeadings::HeadingsComponent < ApplicationComponent
attr_reader :headings
def initialize(headings)
@headings = headings
end
private
def group
@group ||= headings.first.group
end
def budget
@budget ||= headings.first.budget
end
end

View File

@@ -8,37 +8,4 @@
</header> </header>
<%= render Admin::Budgets::HelpComponent.new("budget_groups") %> <%= render Admin::Budgets::HelpComponent.new("budget_groups") %>
<%= render Admin::BudgetGroups::GroupsComponent.new(@groups) %>
<% if @groups.any? %>
<h3><%= t("admin.budget_groups.amount", count: @groups.count) %></h3>
<table>
<thead>
<tr id="<%= dom_id(@budget) %>">
<th><%= t("admin.budget_groups.name") %></th>
<th><%= Budget::Group.human_attribute_name(:max_votable_headings) %></th>
<th><%= t("admin.budget_groups.headings_name") %></th>
<th><%= t("admin.actions.actions") %></th>
</tr>
</thead>
<tbody>
<% @groups.each do |group| %>
<tr id="<%= dom_id(group) %>">
<td><%= group.name %></td>
<td><%= group.max_votable_headings %></td>
<td><%= group.headings.count %></td>
<td>
<%= render Admin::TableActionsComponent.new(group) do |actions| %>
<%= actions.link_to t("admin.budget_groups.headings_manage"),
admin_budget_group_headings_path(@budget, group),
class: "headings-link" %>
<% end %>
</td>
</tr>
<% end %>
</tbody>
</table>
<% else %>
<div class="callout primary clear">
<%= t("admin.budget_groups.no_groups") %>
</div>
<% end %>

View File

@@ -6,43 +6,4 @@
</header> </header>
<%= render Admin::Budgets::HelpComponent.new("budget_headings") %> <%= render Admin::Budgets::HelpComponent.new("budget_headings") %>
<%= render Admin::BudgetHeadings::HeadingsComponent.new(@headings) %>
<% if @headings.any? %>
<h3><%= t("admin.budget_headings.amount", count: @headings.count) %></h3>
<table>
<thead>
<tr id="<%= dom_id(@group) %>">
<th><%= Budget::Heading.human_attribute_name(:name) %></th>
<th><%= Budget::Heading.human_attribute_name(:price) %></th>
<% if @budget.approval_voting? %>
<th><%= Budget::Heading.human_attribute_name(:max_ballot_lines) %></th>
<% end %>
<th><%= Budget::Heading.human_attribute_name(:population) %></th>
<th><%= Budget::Heading.human_attribute_name(:allow_custom_content) %></th>
<th><%= t("admin.actions.actions") %></th>
</tr>
</thead>
<tbody>
<% @headings.each do |heading| %>
<tr id="<%= dom_id(heading) %>" class="heading">
<td><%= heading.name %></td>
<td><%= @budget.formatted_heading_price(heading) %></td>
<% if @budget.approval_voting? %>
<td><%= heading.max_ballot_lines %></td>
<% end %>
<td><%= heading.population %></td>
<td>
<%= heading.allow_custom_content ? t("admin.shared.true_value") : t("admin.shared.false_value") %>
</td>
<td>
<%= render Admin::TableActionsComponent.new(heading) %>
</td>
</tr>
<% end %>
</tbody>
</table>
<% else %>
<div class="callout primary clear">
<%= t("admin.budget_headings.no_headings") %>
</div>
<% end %>