Extract valuation budget index view to components
This commit is contained in:
21
app/components/valuation/budgets/index_component.html.erb
Normal file
21
app/components/valuation/budgets/index_component.html.erb
Normal 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 %>
|
||||
7
app/components/valuation/budgets/index_component.rb
Normal file
7
app/components/valuation/budgets/index_component.rb
Normal file
@@ -0,0 +1,7 @@
|
||||
class Valuation::Budgets::IndexComponent < ApplicationComponent
|
||||
attr_reader :budget
|
||||
|
||||
def initialize(budget)
|
||||
@budget = budget
|
||||
end
|
||||
end
|
||||
16
app/components/valuation/budgets/row_component.html.erb
Normal file
16
app/components/valuation/budgets/row_component.html.erb
Normal 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>
|
||||
13
app/components/valuation/budgets/row_component.rb
Normal file
13
app/components/valuation/budgets/row_component.rb
Normal 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
|
||||
@@ -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
|
||||
|
||||
@@ -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) %>
|
||||
|
||||
Reference in New Issue
Block a user