Skip to content

Commit

Permalink
Allow printing investments from any budget in the management interface
Browse files Browse the repository at this point in the history
  • Loading branch information
Senen committed Jan 16, 2023
1 parent 569138c commit 64e6144
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.link"),
print_management_budget_investments_path(budget) %>
</td>
</tr>
<% end %>
</tbody>
</table>

<%= paginate budgets %>
Original file line number Diff line number Diff line change
@@ -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
4 changes: 0 additions & 4 deletions app/controllers/management/base_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,6 @@ def switch_locale(&action)
I18n.with_locale(session[:locale], &action)
end

def current_budget
Budget.current
end

def clear_password
session[:new_password] = nil
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/management/budgets_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def support_investments
end

def print_investments
@budget = current_budget
@budgets = Budget.published.order(created_at: :desc).page(params[:page])
end

private
Expand Down
10 changes: 8 additions & 2 deletions app/views/management/budgets/print_investments.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
<h2><%= t("management.budgets.print_investments") %></h2>
<h2><%= t("management.budgets.print_investments.title") %></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.print_investments.no_budgets") %>
</div>
<% end %>
5 changes: 4 additions & 1 deletion config/locales/en/management.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@ en:
title: Support proposals
budgets:
create_new_investment: Create budget investment
print_investments: Print budget investments
print_investments:
link: Print budget investments
no_budgets: There are no participatory budgets.
title: Print budget investments
support_investments: Support budget investments
table_name: Name
table_phase: Phase
Expand Down
5 changes: 4 additions & 1 deletion config/locales/es/management.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@ es:
title: Apoyar propuestas
budgets:
create_new_investment: Crear proyectos de gasto
print_investments: Imprimir proyectos de gasto
print_investments:
link: Imprimir proyectos de gasto
no_budgets: No hay presupuestos participativos.
title: Imprimir proyectos de gasto
support_investments: Apoyar proyectos de gasto
table_name: Nombre
table_phase: Fase
Expand Down
45 changes: 45 additions & 0 deletions spec/system/management/budget_investments_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,51 @@
end

context "Printing" do
scenario "Shows all published budgets, last created first" do
finished_budget = create(:budget, :finished)
accepting_budget = create(:budget)
draft_budget = create(:budget, published: false)
login_as_manager(manager)

click_link "Print budget investments"

within "#budget_#{accepting_budget.id}" do
expect(page).to have_link("Print budget investments")
end
within "#budget_#{finished_budget.id}" do
expect(page).to have_link("Print budget investments")
end
expect(page).not_to have_content draft_budget.name
expect(accepting_budget.name).to appear_before(finished_budget.name)
end

scenario "Shows a message when there are no budgets to show" do
login_as_manager(manager)

click_link "Print budget investments"

expect(page).to have_content("There are no participatory budgets.")
end

scenario "Show pagination when needed" do
allow(Budget).to receive(:default_per_page).and_return(1)
create(:budget, name: "Children")
create(:budget, name: "Sports")
login_as_manager(manager)
click_link "Print budget investments"

expect(page).to have_content("Sports")

within("ul.pagination") do
expect(page).to have_content("1")
expect(page).to have_link("2", href: print_investments_management_budgets_path(page: "2"))
expect(page).not_to have_content("3")
click_link "Next", exact: false
end

expect(page).to have_content("Children")
end

scenario "Printing budget investments" do
16.times { create(:budget_investment, heading: heading) }

Expand Down

0 comments on commit 64e6144

Please sign in to comment.