diff --git a/app/components/management/budgets/print_investments/table_component.html.erb b/app/components/management/budgets/print_investments/table_component.html.erb index 2159a0cfe903..4259ecabe61d 100644 --- a/app/components/management/budgets/print_investments/table_component.html.erb +++ b/app/components/management/budgets/print_investments/table_component.html.erb @@ -7,13 +7,17 @@ - - <%= budget.name %> - <%= budget.current_phase.name %> - - <%= link_to t("management.budgets.print_investments"), - print_management_budget_investments_path(budget) %> - - + <% budgets.each do |budget| %> + + <%= budget.name %> + <%= budget.current_phase.name %> + + <%= link_to t("management.budgets.print_investments.link"), + print_management_budget_investments_path(budget) %> + + + <% end %> + +<%= paginate budgets %> diff --git a/app/components/management/budgets/print_investments/table_component.rb b/app/components/management/budgets/print_investments/table_component.rb index 4f13e14e4d9a..95f896297dde 100644 --- a/app/components/management/budgets/print_investments/table_component.rb +++ b/app/components/management/budgets/print_investments/table_component.rb @@ -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 diff --git a/app/controllers/management/base_controller.rb b/app/controllers/management/base_controller.rb index f426cbd3cf06..b408d01fa646 100644 --- a/app/controllers/management/base_controller.rb +++ b/app/controllers/management/base_controller.rb @@ -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 diff --git a/app/controllers/management/budgets_controller.rb b/app/controllers/management/budgets_controller.rb index 36f0a8f1d2ae..2c2e3607ed2d 100644 --- a/app/controllers/management/budgets_controller.rb +++ b/app/controllers/management/budgets_controller.rb @@ -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 diff --git a/app/views/management/budgets/print_investments.html.erb b/app/views/management/budgets/print_investments.html.erb index 6e34bfe2f5e2..3b5c4d410dc7 100644 --- a/app/views/management/budgets/print_investments.html.erb +++ b/app/views/management/budgets/print_investments.html.erb @@ -1,3 +1,9 @@ -

<%= t("management.budgets.print_investments") %>

+

<%= t("management.budgets.print_investments.title") %>

-<%= render Management::Budgets::PrintInvestments::TableComponent.new(@budget) %> +<% if @budgets.any? %> + <%= render Management::Budgets::PrintInvestments::TableComponent.new(@budgets) %> +<% else %> +
+ <%= t("management.budgets.print_investments.no_budgets") %> +
+<% end %> diff --git a/config/locales/en/management.yml b/config/locales/en/management.yml index 85ad93a644c4..6c3743faa39a 100644 --- a/config/locales/en/management.yml +++ b/config/locales/en/management.yml @@ -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 diff --git a/config/locales/es/management.yml b/config/locales/es/management.yml index 3740fc3daadb..bc378d08c098 100644 --- a/config/locales/es/management.yml +++ b/config/locales/es/management.yml @@ -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 diff --git a/spec/system/management/budget_investments_spec.rb b/spec/system/management/budget_investments_spec.rb index 857a1f146982..f76b9a17e587 100644 --- a/spec/system/management/budget_investments_spec.rb +++ b/spec/system/management/budget_investments_spec.rb @@ -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) }