From ee80b3f4a259c945314d31ab771f1d45a7814f2e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sen=C3=A9n=20Rodero=20Rodr=C3=ADguez?=
<15726+Senen@users.noreply.github.com>
Date: Wed, 4 Jan 2023 12:31:17 +0100
Subject: [PATCH] Extract valuation budget index view to components
---
.../budgets/index_component.html.erb | 21 +++++++++++
.../valuation/budgets/index_component.rb | 7 ++++
.../valuation/budgets/row_component.html.erb | 16 ++++++++
.../valuation/budgets/row_component.rb | 13 +++++++
.../valuation/budgets_controller.rb | 3 --
app/views/valuation/budgets/index.html.erb | 37 +------------------
6 files changed, 58 insertions(+), 39 deletions(-)
create mode 100644 app/components/valuation/budgets/index_component.html.erb
create mode 100644 app/components/valuation/budgets/index_component.rb
create mode 100644 app/components/valuation/budgets/row_component.html.erb
create mode 100644 app/components/valuation/budgets/row_component.rb
diff --git a/app/components/valuation/budgets/index_component.html.erb b/app/components/valuation/budgets/index_component.html.erb
new file mode 100644
index 000000000..d4ecb28d5
--- /dev/null
+++ b/app/components/valuation/budgets/index_component.html.erb
@@ -0,0 +1,21 @@
+
<%= t("valuation.budgets.index.title") %>
+
+<% if budget.present? %>
+
+
+
+ | <%= t("valuation.budgets.index.table_name") %> |
+ <%= t("valuation.budgets.index.table_phase") %> |
+ <%= t("valuation.budgets.index.table_assigned_investments_valuation_open") %> |
+ <%= t("valuation.budgets.index.table_actions") %> |
+
+
+
+ <%= render Valuation::Budgets::RowComponent.new(budget) %>
+
+
+<% else %>
+
+ <%= t("valuation.budgets.index.no_budgets") %>
+
+<% end %>
diff --git a/app/components/valuation/budgets/index_component.rb b/app/components/valuation/budgets/index_component.rb
new file mode 100644
index 000000000..40138ac88
--- /dev/null
+++ b/app/components/valuation/budgets/index_component.rb
@@ -0,0 +1,7 @@
+class Valuation::Budgets::IndexComponent < ApplicationComponent
+ attr_reader :budget
+
+ def initialize(budget)
+ @budget = budget
+ end
+end
diff --git a/app/components/valuation/budgets/row_component.html.erb b/app/components/valuation/budgets/row_component.html.erb
new file mode 100644
index 000000000..be3fc52c5
--- /dev/null
+++ b/app/components/valuation/budgets/row_component.html.erb
@@ -0,0 +1,16 @@
+
+ |
+ <%= budget.name %>
+ |
+
+ <%= budget.current_phase.name %>
+ |
+
+ <%= investments_count %>
+ |
+
+ <%= link_to t("valuation.budgets.index.evaluate"),
+ valuation_budget_budget_investments_path(budget_id: budget.id),
+ class: "button hollow expanded" %>
+ |
+
diff --git a/app/components/valuation/budgets/row_component.rb b/app/components/valuation/budgets/row_component.rb
new file mode 100644
index 000000000..46fff464a
--- /dev/null
+++ b/app/components/valuation/budgets/row_component.rb
@@ -0,0 +1,13 @@
+class Valuation::Budgets::RowComponent < ApplicationComponent
+ attr_reader :budget
+
+ delegate :current_user, to: :helpers
+
+ def initialize(budget)
+ @budget = budget
+ end
+
+ def investments_count
+ budget.investments.by_valuator(current_user.valuator).valuation_open.count
+ end
+end
diff --git a/app/controllers/valuation/budgets_controller.rb b/app/controllers/valuation/budgets_controller.rb
index 0165fb0e2..a30ccc55e 100644
--- a/app/controllers/valuation/budgets_controller.rb
+++ b/app/controllers/valuation/budgets_controller.rb
@@ -6,8 +6,5 @@ class Valuation::BudgetsController < Valuation::BaseController
def index
@budget = current_budget
- if @budget.present?
- @investments = @budget.investments.by_valuator(current_user.valuator).valuation_open
- end
end
end
diff --git a/app/views/valuation/budgets/index.html.erb b/app/views/valuation/budgets/index.html.erb
index fae10257b..5f2db605c 100644
--- a/app/views/valuation/budgets/index.html.erb
+++ b/app/views/valuation/budgets/index.html.erb
@@ -1,36 +1 @@
-<%= t("valuation.budgets.index.title") %>
-
-<% if @budget.present? %>
-
-
-
- | <%= t("valuation.budgets.index.table_name") %> |
- <%= t("valuation.budgets.index.table_phase") %> |
- <%= t("valuation.budgets.index.table_assigned_investments_valuation_open") %> |
- <%= t("valuation.budgets.index.table_actions") %> |
-
-
-
-
- |
- <%= @budget.name %>
- |
-
- <%= @budget.current_phase.name %>
- |
-
- <%= @investments.count %>
- |
-
- <%= link_to t("valuation.budgets.index.evaluate"),
- valuation_budget_budget_investments_path(budget_id: @budget.id),
- class: "button hollow expanded" %>
- |
-
-
-
-<% else %>
-
- <%= t("valuation.budgets.index.no_budgets") %>
-
-<% end %>
+<%= render Valuation::Budgets::IndexComponent.new(@budget) %>