diff --git a/app/assets/stylesheets/admin.scss b/app/assets/stylesheets/admin.scss index 8aede0497..17e221cf7 100644 --- a/app/assets/stylesheets/admin.scss +++ b/app/assets/stylesheets/admin.scss @@ -258,6 +258,11 @@ $table-header: #ecf1f6; [type="submit"] ~ a { margin-left: $line-height / 2; } + + [type="checkbox"] { + margin-bottom: 0; + vertical-align: middle; + } } hr { diff --git a/app/components/admin/budget_phases/phases_component.html.erb b/app/components/admin/budget_phases/phases_component.html.erb index 6f663578c..787508634 100644 --- a/app/components/admin/budget_phases/phases_component.html.erb +++ b/app/components/admin/budget_phases/phases_component.html.erb @@ -26,7 +26,7 @@ <% end %> - <%= enabled_text(phase) %> + <%= enabled_cell(phase) %> <%= render Admin::TableActionsComponent.new(phase, diff --git a/app/components/admin/budget_phases/phases_component.rb b/app/components/admin/budget_phases/phases_component.rb index b27958f18..25a2d0280 100644 --- a/app/components/admin/budget_phases/phases_component.rb +++ b/app/components/admin/budget_phases/phases_component.rb @@ -1,8 +1,9 @@ class Admin::BudgetPhases::PhasesComponent < ApplicationComponent - attr_reader :budget + attr_reader :budget, :form - def initialize(budget) + def initialize(budget, form: nil) @budget = budget + @form = form end private @@ -15,6 +16,20 @@ class Admin::BudgetPhases::PhasesComponent < ApplicationComponent Admin::Budgets::DurationComponent.new(phase).dates end + def enabled_cell(phase) + if form + form.fields_for :phases, phase do |phase_fields| + phase_fields.check_box :enabled, + label: false, + aria: { + label: t("admin.budgets.edit.enable_phase", phase: phase.name) + } + end + else + enabled_text(phase) + end + end + def enabled_text(phase) if phase.enabled? tag.span t("shared.yes"), class: "budget-phase-enabled" diff --git a/app/components/admin/budgets_wizard/phases/index_component.html.erb b/app/components/admin/budgets_wizard/phases/index_component.html.erb index 816dc0d91..a97812cfb 100644 --- a/app/components/admin/budgets_wizard/phases/index_component.html.erb +++ b/app/components/admin/budgets_wizard/phases/index_component.html.erb @@ -5,8 +5,7 @@ <%= render Admin::Budgets::HelpComponent.new("budget_phases") %> <%= render Admin::BudgetsWizard::CreationTimelineComponent.new("phases") %> -<%= render Admin::BudgetPhases::PhasesComponent.new(budget) %> - -<%= link_to t("admin.budgets_wizard.phases.continue"), - admin_budget_path(budget), - class: "button success" %> +<%= form_for budget, url: update_all_admin_budgets_wizard_budget_budget_phases_path(budget) do |f| %> + <%= render Admin::BudgetPhases::PhasesComponent.new(budget, form: f) %> + <%= f.submit t("admin.budgets_wizard.phases.continue"), class: "button success" %> +<% end %> diff --git a/app/controllers/admin/budgets_wizard/phases_controller.rb b/app/controllers/admin/budgets_wizard/phases_controller.rb index 889b22c4f..5376e93b7 100644 --- a/app/controllers/admin/budgets_wizard/phases_controller.rb +++ b/app/controllers/admin/budgets_wizard/phases_controller.rb @@ -4,9 +4,23 @@ class Admin::BudgetsWizard::PhasesController < Admin::BaseController def index end + def update_all + @budget.update!(phases_params) + + redirect_to admin_budgets_path, notice: t("admin.budgets_wizard.phases.update_all.notice") + end + private def phases_index admin_budgets_wizard_budget_budget_phases_path(@phase.budget) end + + def phases_params + params.require(:budget).permit(allowed_phases_params) + end + + def allowed_phases_params + { phases_attributes: [:id, :enabled] } + end end diff --git a/app/models/budget.rb b/app/models/budget.rb index c685323f5..dba0d6e0b 100644 --- a/app/models/budget.rb +++ b/app/models/budget.rb @@ -42,6 +42,7 @@ class Budget < ApplicationRecord has_one :poll after_create :generate_phases + accepts_nested_attributes_for :phases scope :published, -> { where(published: true) } scope :drafting, -> { where.not(id: published) } diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml index c884a88e8..8e2db9f36 100644 --- a/config/locales/en/admin.yml +++ b/config/locales/en/admin.yml @@ -106,6 +106,7 @@ en: enabled: Enabled actions: Actions edit_phase: Edit phase + enable_phase: "Enable %{phase} phase" active: Active blank_dates: Dates are blank administrators: @@ -308,6 +309,8 @@ en: phases: back: "Go back to headings" continue: "Finish" + update_all: + notice: "Phases configured successfully" milestones: index: table_id: "ID" diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml index 1ea8f48f7..58c44349e 100644 --- a/config/locales/es/admin.yml +++ b/config/locales/es/admin.yml @@ -106,6 +106,7 @@ es: enabled: Habilitada actions: Acciones edit_phase: Editar fase + enable_phase: "Habilitar fase de %{phase}" active: Activa blank_dates: Sin fechas administrators: @@ -308,6 +309,8 @@ es: phases: back: "Volver a partidas" continue: "Finalizar" + update_all: + notice: "Fases configuradas con éxito" milestones: index: table_id: "ID" diff --git a/config/routes/admin.rb b/config/routes/admin.rb index ea97b859f..cbdaab6eb 100644 --- a/config/routes/admin.rb +++ b/config/routes/admin.rb @@ -78,7 +78,9 @@ namespace :admin do resources :headings, only: [:index, :create, :edit, :update, :destroy] end - resources :phases, as: "budget_phases", only: [:index, :edit, :update] + resources :phases, as: "budget_phases", only: [:index, :edit, :update] do + collection { patch :update_all } + end end end diff --git a/spec/system/admin/budgets_wizard/phases_spec.rb b/spec/system/admin/budgets_wizard/phases_spec.rb index d9ae34101..eb2e0b50b 100644 --- a/spec/system/admin/budgets_wizard/phases_spec.rb +++ b/spec/system/admin/budgets_wizard/phases_spec.rb @@ -19,6 +19,35 @@ describe "Budgets wizard, phases step", :admin do expect(page).to have_css "tr", text: "Main Park" expect(page).to have_css ".creation-timeline" end + + scenario "Enable and disable phases" do + visit admin_budgets_wizard_budget_budget_phases_path(budget) + + uncheck "Enable Information phase" + uncheck "Enable Reviewing voting phase" + + click_button "Finish" + + expect(page).to have_content "Phases configured successfully" + + visit edit_admin_budget_path(budget) + + within "tr", text: "Information" do + expect(page).to have_css ".budget-phase-disabled", visible: :all + end + + within "tr", text: "Reviewing voting" do + expect(page).to have_css ".budget-phase-disabled", visible: :all + end + + within "tr", text: "Accepting projects" do + expect(page).to have_css ".budget-phase-enabled", visible: :all + end + + within "tr", text: "Voting projects" do + expect(page).to have_css ".budget-phase-enabled", visible: :all + end + end end describe "Edit" do