From b16fe80ba5c89e8196f13fd3a26d0f6e4acc7a62 Mon Sep 17 00:00:00 2001 From: Julian Herrero Date: Tue, 17 Mar 2020 12:55:35 +0700 Subject: [PATCH] Extract groups and headings tables to components --- .../budget_groups/groups_component.html.erb | 33 +++++++++++++++ .../admin/budget_groups/groups_component.rb | 13 ++++++ .../headings_component.html.erb | 39 ++++++++++++++++++ .../budget_headings/headings_component.rb | 17 ++++++++ app/views/admin/budget_groups/index.html.erb | 35 +--------------- .../admin/budget_headings/index.html.erb | 41 +------------------ 6 files changed, 104 insertions(+), 74 deletions(-) create mode 100644 app/components/admin/budget_groups/groups_component.html.erb create mode 100644 app/components/admin/budget_groups/groups_component.rb create mode 100644 app/components/admin/budget_headings/headings_component.html.erb create mode 100644 app/components/admin/budget_headings/headings_component.rb diff --git a/app/components/admin/budget_groups/groups_component.html.erb b/app/components/admin/budget_groups/groups_component.html.erb new file mode 100644 index 000000000..00bcc18fc --- /dev/null +++ b/app/components/admin/budget_groups/groups_component.html.erb @@ -0,0 +1,33 @@ +<% if groups.any? %> +

<%= t("admin.budget_groups.amount", count: groups.count) %>

+ + + + + + + + + + + <% groups.each do |group| %> + + + + + + + <% end %> + +
<%= t("admin.budget_groups.name") %><%= Budget::Group.human_attribute_name(:max_votable_headings) %><%= t("admin.budget_groups.headings_name") %><%= t("admin.actions.actions") %>
<%= group.name %><%= group.max_votable_headings %><%= group.headings.count %> + <%= 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 %> +
+<% else %> +
+ <%= t("admin.budget_groups.no_groups") %> +
+<% end %> diff --git a/app/components/admin/budget_groups/groups_component.rb b/app/components/admin/budget_groups/groups_component.rb new file mode 100644 index 000000000..87012734d --- /dev/null +++ b/app/components/admin/budget_groups/groups_component.rb @@ -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 diff --git a/app/components/admin/budget_headings/headings_component.html.erb b/app/components/admin/budget_headings/headings_component.html.erb new file mode 100644 index 000000000..9e32dcbe5 --- /dev/null +++ b/app/components/admin/budget_headings/headings_component.html.erb @@ -0,0 +1,39 @@ +<% if headings.any? %> +

<%= t("admin.budget_headings.amount", count: headings.count) %>

+ + + + + + <% if budget.approval_voting? %> + + <% end %> + + + + + + + <% headings.each do |heading| %> + + + + <% if budget.approval_voting? %> + + <% end %> + + + + + <% end %> + +
<%= Budget::Heading.human_attribute_name(:name) %><%= Budget::Heading.human_attribute_name(:price) %><%= Budget::Heading.human_attribute_name(:max_ballot_lines) %><%= Budget::Heading.human_attribute_name(:population) %><%= Budget::Heading.human_attribute_name(:allow_custom_content) %><%= t("admin.actions.actions") %>
<%= heading.name %><%= budget.formatted_heading_price(heading) %><%= heading.max_ballot_lines %><%= heading.population %> + <%= heading.allow_custom_content ? t("admin.shared.true_value") : t("admin.shared.false_value") %> + + <%= render Admin::TableActionsComponent.new(heading) %> +
+<% else %> +
+ <%= t("admin.budget_headings.no_headings") %> +
+<% end %> diff --git a/app/components/admin/budget_headings/headings_component.rb b/app/components/admin/budget_headings/headings_component.rb new file mode 100644 index 000000000..3b6594f23 --- /dev/null +++ b/app/components/admin/budget_headings/headings_component.rb @@ -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 diff --git a/app/views/admin/budget_groups/index.html.erb b/app/views/admin/budget_groups/index.html.erb index 2e20ac1ac..f89d3ee20 100644 --- a/app/views/admin/budget_groups/index.html.erb +++ b/app/views/admin/budget_groups/index.html.erb @@ -8,37 +8,4 @@ <%= render Admin::Budgets::HelpComponent.new("budget_groups") %> - -<% if @groups.any? %> -

<%= t("admin.budget_groups.amount", count: @groups.count) %>

- - - - - - - - - - - <% @groups.each do |group| %> - - - - - - - <% end %> - -
<%= t("admin.budget_groups.name") %><%= Budget::Group.human_attribute_name(:max_votable_headings) %><%= t("admin.budget_groups.headings_name") %><%= t("admin.actions.actions") %>
<%= group.name %><%= group.max_votable_headings %><%= group.headings.count %> - <%= 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 %> -
-<% else %> -
- <%= t("admin.budget_groups.no_groups") %> -
-<% end %> +<%= render Admin::BudgetGroups::GroupsComponent.new(@groups) %> diff --git a/app/views/admin/budget_headings/index.html.erb b/app/views/admin/budget_headings/index.html.erb index 4487a8f4b..f154b5ae9 100644 --- a/app/views/admin/budget_headings/index.html.erb +++ b/app/views/admin/budget_headings/index.html.erb @@ -6,43 +6,4 @@ <%= render Admin::Budgets::HelpComponent.new("budget_headings") %> - -<% if @headings.any? %> -

<%= t("admin.budget_headings.amount", count: @headings.count) %>

- - - - - - <% if @budget.approval_voting? %> - - <% end %> - - - - - - - <% @headings.each do |heading| %> - - - - <% if @budget.approval_voting? %> - - <% end %> - - - - - <% end %> - -
<%= Budget::Heading.human_attribute_name(:name) %><%= Budget::Heading.human_attribute_name(:price) %><%= Budget::Heading.human_attribute_name(:max_ballot_lines) %><%= Budget::Heading.human_attribute_name(:population) %><%= Budget::Heading.human_attribute_name(:allow_custom_content) %><%= t("admin.actions.actions") %>
<%= heading.name %><%= @budget.formatted_heading_price(heading) %><%= heading.max_ballot_lines %><%= heading.population %> - <%= heading.allow_custom_content ? t("admin.shared.true_value") : t("admin.shared.false_value") %> - - <%= render Admin::TableActionsComponent.new(heading) %> -
-<% else %> -
- <%= t("admin.budget_headings.no_headings") %> -
-<% end %> +<%= render Admin::BudgetHeadings::HeadingsComponent.new(@headings) %>