Allow printing investments from any budget in the management interface

This commit is contained in:
Senén Rodero Rodríguez
2023-01-16 12:58:15 +01:00
parent 569138cbae
commit 96f584c4f7
6 changed files with 69 additions and 17 deletions

View File

@@ -7,13 +7,17 @@
</tr>
</thead>
<tbody>
<tr id="<%= dom_id(budget) %>">
<td><%= budget.name %></td>
<td><%= budget.current_phase.name %></td>
<td align="right">
<%= link_to t("management.budgets.print_investments"),
print_management_budget_investments_path(budget) %>
</td>
</tr>
<% budgets.each do |budget| %>
<tr id="<%= dom_id(budget) %>">
<td><%= budget.name %></td>
<td><%= budget.current_phase.name %></td>
<td align="right">
<%= link_to t("management.budgets.print_investments"),
print_management_budget_investments_path(budget) %>
</td>
</tr>
<% end %>
</tbody>
</table>
<%= paginate budgets %>

View File

@@ -1,7 +1,8 @@
class Management::Budgets::PrintInvestments::TableComponent < ApplicationComponent
attr_reader :budget
attr_reader :budgets
delegate :paginate, to: :helpers
def initialize(budget)
@budget = budget
def initialize(budgets)
@budgets = budgets
end
end

View File

@@ -49,10 +49,6 @@ class Management::BaseController < ActionController::Base
I18n.with_locale(session[:locale], &action)
end
def current_budget
Budget.current
end
def clear_password
session[:new_password] = nil
end

View File

@@ -19,7 +19,7 @@ class Management::BudgetsController < Management::BaseController
end
def print_investments
@budget = current_budget
@budgets = Budget.published.order(created_at: :desc).page(params[:page])
end
private

View File

@@ -1,3 +1,9 @@
<h2><%= t("management.budgets.print_investments") %></h2>
<%= render Management::Budgets::PrintInvestments::TableComponent.new(@budget) %>
<% if @budgets.any? %>
<%= render Management::Budgets::PrintInvestments::TableComponent.new(@budgets) %>
<% else %>
<div class="callout primary">
<%= t("management.budgets.no_budgets") %>
</div>
<% end %>