Extract valuation budget index view to components

This commit is contained in:
Senén Rodero Rodríguez
2023-01-04 12:31:17 +01:00
parent f9ec038671
commit ee80b3f4a2
6 changed files with 58 additions and 39 deletions

View File

@@ -0,0 +1,21 @@
<h2 class="inline-block"><%= t("valuation.budgets.index.title") %></h2>
<% if budget.present? %>
<table>
<thead>
<tr>
<th><%= t("valuation.budgets.index.table_name") %></th>
<th><%= t("valuation.budgets.index.table_phase") %></th>
<th><%= t("valuation.budgets.index.table_assigned_investments_valuation_open") %></th>
<th><%= t("valuation.budgets.index.table_actions") %></th>
</tr>
</thead>
<tbody>
<%= render Valuation::Budgets::RowComponent.new(budget) %>
</tbody>
</table>
<% else %>
<div class="callout primary clear">
<%= t("valuation.budgets.index.no_budgets") %>
</div>
<% end %>

View File

@@ -0,0 +1,7 @@
class Valuation::Budgets::IndexComponent < ApplicationComponent
attr_reader :budget
def initialize(budget)
@budget = budget
end
end

View File

@@ -0,0 +1,16 @@
<tr id="<%= dom_id(budget) %>" class="budget">
<td>
<%= budget.name %>
</td>
<td>
<%= budget.current_phase.name %>
</td>
<td>
<%= investments_count %>
</td>
<td>
<%= link_to t("valuation.budgets.index.evaluate"),
valuation_budget_budget_investments_path(budget_id: budget.id),
class: "button hollow expanded" %>
</td>
</tr>

View File

@@ -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

View File

@@ -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

View File

@@ -1,36 +1 @@
<h2 class="inline-block"><%= t("valuation.budgets.index.title") %></h2>
<% if @budget.present? %>
<table>
<thead>
<tr>
<th><%= t("valuation.budgets.index.table_name") %></th>
<th><%= t("valuation.budgets.index.table_phase") %></th>
<th><%= t("valuation.budgets.index.table_assigned_investments_valuation_open") %></th>
<th><%= t("valuation.budgets.index.table_actions") %></th>
</tr>
</thead>
<tbody>
<tr id="<%= dom_id(@budget) %>" class="budget">
<td>
<%= @budget.name %>
</td>
<td>
<%= @budget.current_phase.name %>
</td>
<td>
<%= @investments.count %>
</td>
<td>
<%= link_to t("valuation.budgets.index.evaluate"),
valuation_budget_budget_investments_path(budget_id: @budget.id),
class: "button hollow expanded" %>
</td>
</tr>
</tbody>
</table>
<% else %>
<div class="callout primary clear">
<%= t("valuation.budgets.index.no_budgets") %>
</div>
<% end %>
<%= render Valuation::Budgets::IndexComponent.new(@budget) %>