diff --git a/app/components/admin/budget_phases/form_component.html.erb b/app/components/admin/budget_phases/form_component.html.erb index 125f2c9e4..78f10c235 100644 --- a/app/components/admin/budget_phases/form_component.html.erb +++ b/app/components/admin/budget_phases/form_component.html.erb @@ -1,6 +1,6 @@ <%= render "shared/globalize_locales", resource: phase %> -<%= translatable_form_for [:admin, phase.budget, phase], html: { class: "budget-phases-form" } do |f| %> +<%= translatable_form_for [namespace, phase.budget, phase], html: { class: "budget-phases-form" } do |f| %> <%= render "shared/errors", resource: phase %> diff --git a/app/components/admin/budget_phases/form_component.rb b/app/components/admin/budget_phases/form_component.rb index 0b890c9f4..49c6cf36c 100644 --- a/app/components/admin/budget_phases/form_component.rb +++ b/app/components/admin/budget_phases/form_component.rb @@ -1,6 +1,7 @@ class Admin::BudgetPhases::FormComponent < ApplicationComponent include TranslatableFormHelper include GlobalizeHelper + include Admin::Namespace attr_reader :phase diff --git a/app/components/admin/budgets_wizard/creation_timeline_component.rb b/app/components/admin/budgets_wizard/creation_timeline_component.rb index a4f4ed24f..7fe7ffcf2 100644 --- a/app/components/admin/budgets_wizard/creation_timeline_component.rb +++ b/app/components/admin/budgets_wizard/creation_timeline_component.rb @@ -8,6 +8,6 @@ class Admin::BudgetsWizard::CreationTimelineComponent < ApplicationComponent private def steps - %w[budget groups headings] + %w[budget groups headings phases] end end diff --git a/app/components/admin/budgets_wizard/headings/creation_step_component.rb b/app/components/admin/budgets_wizard/headings/creation_step_component.rb index 8758c6bbc..6c07c6670 100644 --- a/app/components/admin/budgets_wizard/headings/creation_step_component.rb +++ b/app/components/admin/budgets_wizard/headings/creation_step_component.rb @@ -16,7 +16,7 @@ class Admin::BudgetsWizard::Headings::CreationStepComponent < ApplicationCompone end def next_step_path - admin_budget_path(budget) if next_step_enabled? + admin_budgets_wizard_budget_budget_phases_path(budget) if next_step_enabled? end def next_step_enabled? diff --git a/app/components/admin/budgets_wizard/phases/edit_component.html.erb b/app/components/admin/budgets_wizard/phases/edit_component.html.erb new file mode 100644 index 000000000..44131384c --- /dev/null +++ b/app/components/admin/budgets_wizard/phases/edit_component.html.erb @@ -0,0 +1,6 @@ +<%= back_link_to admin_budgets_wizard_budget_budget_phases_path(budget) %> + +<%= header %> + +<%= render Admin::BudgetsWizard::CreationTimelineComponent.new("phases") %> +<%= render "/admin/budget_phases/form" %> diff --git a/app/components/admin/budgets_wizard/phases/edit_component.rb b/app/components/admin/budgets_wizard/phases/edit_component.rb new file mode 100644 index 000000000..68645ed95 --- /dev/null +++ b/app/components/admin/budgets_wizard/phases/edit_component.rb @@ -0,0 +1,22 @@ +class Admin::BudgetsWizard::Phases::EditComponent < ApplicationComponent + include Header + attr_reader :phase + + def initialize(phase) + @phase = phase + end + + def budget + phase.budget + end + + def title + "#{t("admin.budget_phases.edit.title")} - #{phase.name}" + end + + private + + def form_path + admin_budgets_wizard_budget_budget_phases_path(budget) + end +end diff --git a/app/components/admin/budgets_wizard/phases/index_component.html.erb b/app/components/admin/budgets_wizard/phases/index_component.html.erb new file mode 100644 index 000000000..816dc0d91 --- /dev/null +++ b/app/components/admin/budgets_wizard/phases/index_component.html.erb @@ -0,0 +1,12 @@ +<%= back_link_to back_link_path, t("admin.budgets_wizard.phases.back") %> + +<%= header %> + +<%= 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" %> diff --git a/app/components/admin/budgets_wizard/phases/index_component.rb b/app/components/admin/budgets_wizard/phases/index_component.rb new file mode 100644 index 000000000..a1b680003 --- /dev/null +++ b/app/components/admin/budgets_wizard/phases/index_component.rb @@ -0,0 +1,18 @@ +class Admin::BudgetsWizard::Phases::IndexComponent < ApplicationComponent + include Header + attr_reader :budget + + def initialize(budget) + @budget = budget + end + + def title + t("admin.budget_phases.index.title", budget: budget.name) + end + + private + + def back_link_path + admin_budgets_wizard_budget_group_headings_path(budget, budget.groups.first) + end +end diff --git a/app/controllers/admin/budget_phases_controller.rb b/app/controllers/admin/budget_phases_controller.rb index 1ff8dcedb..ac2a763e1 100644 --- a/app/controllers/admin/budget_phases_controller.rb +++ b/app/controllers/admin/budget_phases_controller.rb @@ -1,28 +1,9 @@ class Admin::BudgetPhasesController < Admin::BaseController - include Translatable - - before_action :load_phase, only: [:edit, :update] - - def edit - end - - def update - if @phase.update(budget_phase_params) - notice = t("flash.actions.save_changes.notice") - redirect_to edit_admin_budget_path(@phase.budget), notice: notice - else - render :edit - end - end + include Admin::BudgetPhasesActions private - def load_phase - @phase = Budget::Phase.find(params[:id]) - end - - def budget_phase_params - valid_attributes = [:starts_at, :ends_at, :enabled] - params.require(:budget_phase).permit(*valid_attributes, translation_params(Budget::Phase)) + def phases_index + edit_admin_budget_path(@phase.budget) end end diff --git a/app/controllers/admin/budgets_wizard/phases_controller.rb b/app/controllers/admin/budgets_wizard/phases_controller.rb new file mode 100644 index 000000000..889b22c4f --- /dev/null +++ b/app/controllers/admin/budgets_wizard/phases_controller.rb @@ -0,0 +1,12 @@ +class Admin::BudgetsWizard::PhasesController < Admin::BaseController + include Admin::BudgetPhasesActions + + def index + end + + private + + def phases_index + admin_budgets_wizard_budget_budget_phases_path(@phase.budget) + end +end diff --git a/app/controllers/concerns/admin/budget_phases_actions.rb b/app/controllers/concerns/admin/budget_phases_actions.rb new file mode 100644 index 000000000..80a1af51c --- /dev/null +++ b/app/controllers/concerns/admin/budget_phases_actions.rb @@ -0,0 +1,36 @@ +module Admin::BudgetPhasesActions + extend ActiveSupport::Concern + + included do + include Translatable + + before_action :load_budget + before_action :load_phase, only: [:edit, :update] + end + + def edit + end + + def update + if @phase.update(budget_phase_params) + redirect_to phases_index, notice: t("flash.actions.save_changes.notice") + else + render :edit + end + end + + private + + def load_budget + @budget = Budget.find_by_slug_or_id!(params[:budget_id]) + end + + def load_phase + @phase = @budget.phases.find(params[:id]) + end + + def budget_phase_params + valid_attributes = [:starts_at, :ends_at, :enabled] + params.require(:budget_phase).permit(*valid_attributes, translation_params(Budget::Phase)) + end +end diff --git a/app/views/admin/budget_phases/edit.html.erb b/app/views/admin/budget_phases/edit.html.erb index 452c11f96..27fbdd585 100644 --- a/app/views/admin/budget_phases/edit.html.erb +++ b/app/views/admin/budget_phases/edit.html.erb @@ -1,5 +1 @@ -<%= back_link_to edit_admin_budget_path(@phase.budget) %> - -

<%= t("admin.budgets.edit.title") %> - <%= @phase.name %>

- -<%= render "/admin/budget_phases/form" %> +<%= render Admin::BudgetsWizard::Phases::EditComponent.new(@phase) %> diff --git a/app/views/admin/budgets_wizard/phases/edit.html.erb b/app/views/admin/budgets_wizard/phases/edit.html.erb new file mode 100644 index 000000000..27fbdd585 --- /dev/null +++ b/app/views/admin/budgets_wizard/phases/edit.html.erb @@ -0,0 +1 @@ +<%= render Admin::BudgetsWizard::Phases::EditComponent.new(@phase) %> diff --git a/app/views/admin/budgets_wizard/phases/index.html.erb b/app/views/admin/budgets_wizard/phases/index.html.erb new file mode 100644 index 000000000..1fa77a2d1 --- /dev/null +++ b/app/views/admin/budgets_wizard/phases/index.html.erb @@ -0,0 +1 @@ +<%= render Admin::BudgetsWizard::Phases::IndexComponent.new(@budget) %> diff --git a/config/i18n-tasks.yml b/config/i18n-tasks.yml index 5fee91c88..97bb35653 100644 --- a/config/i18n-tasks.yml +++ b/config/i18n-tasks.yml @@ -149,6 +149,7 @@ ignore_unused: - "admin.budgets.edit.(administrators|valuators).*" - "admin.budget_groups.index.*.help_block" - "admin.budget_headings.index.*.help_block" + - "admin.budget_phases.index.help_block" - "admin.budget_investments.index.filter*" - "admin.organizations.index.filter*" - "admin.hidden_users.index.filter*" diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml index 427faae50..c884a88e8 100644 --- a/config/locales/en/admin.yml +++ b/config/locales/en/admin.yml @@ -188,6 +188,7 @@ en: title: "%{budget} / %{group} headings" budget_phases: edit: + title: "Edit phase" description_help_text: This text will appear in the header when the phase is active duration: "Phase's duration" duration_description: "The period of time this phase will be active." @@ -196,6 +197,7 @@ en: save_changes: Save changes index: help: "Participatory budgets have different phases. Here you can enable or disable phases and also customize each individual phase." + title: "%{budget} phases" budget_investments: index: heading_filter_all: All headings @@ -296,12 +298,16 @@ en: budget: Budget groups: Groups headings: Headings + phases: Phases budgets: continue: "Continue to groups" groups: continue: "Continue to headings" headings: continue: "Continue to phases" + phases: + back: "Go back to headings" + continue: "Finish" milestones: index: table_id: "ID" diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml index b6b2d06d5..1ea8f48f7 100644 --- a/config/locales/es/admin.yml +++ b/config/locales/es/admin.yml @@ -194,8 +194,10 @@ es: enabled_help_text: Esta fase será pública en el calendario de fases del presupuesto y estará activa para otros propósitos name_help_text: "Este es el título de la fase que los usuarios leerán en el encabezado cuando la fase esté activa." save_changes: Guardar cambios + title: "Editar fase" index: help: "Los presupuestos participativos tienen distintas fases. Aquí puedes habilitar o deshabilitar fases y también personalizar cada una de las fases." + title: "Fases de %{budget}" budget_investments: index: heading_filter_all: Todas las partidas @@ -296,12 +298,16 @@ es: budget: Presupuesto groups: Grupos headings: Partidas + phases: Fases budgets: continue: "Continuar a grupos" groups: continue: "Continuar a partidas" headings: continue: "Continuar a fases" + phases: + back: "Volver a partidas" + continue: "Finalizar" milestones: index: table_id: "ID" diff --git a/config/routes/admin.rb b/config/routes/admin.rb index bb28dfa0f..ea97b859f 100644 --- a/config/routes/admin.rb +++ b/config/routes/admin.rb @@ -77,6 +77,8 @@ namespace :admin do resources :groups, only: [:index, :create, :edit, :update, :destroy] do resources :headings, only: [:index, :create, :edit, :update, :destroy] end + + resources :phases, as: "budget_phases", only: [:index, :edit, :update] end end diff --git a/spec/system/admin/budget_phases_spec.rb b/spec/system/admin/budget_phases_spec.rb index ce5c22c1c..36dff7ade 100644 --- a/spec/system/admin/budget_phases_spec.rb +++ b/spec/system/admin/budget_phases_spec.rb @@ -32,7 +32,7 @@ describe "Admin budget phases" do within("tr", text: "Accepting projects") { click_link "Edit phase" } end - expect(page).to have_css "h2", exact_text: "Edit Participatory budget - Accepting projects" + expect(page).to have_css "h2", exact_text: "Edit phase - Accepting projects" fill_in "Name", with: "My phase custom name" click_button "Save changes" diff --git a/spec/system/admin/budgets_wizard/phases_spec.rb b/spec/system/admin/budgets_wizard/phases_spec.rb new file mode 100644 index 000000000..d9ae34101 --- /dev/null +++ b/spec/system/admin/budgets_wizard/phases_spec.rb @@ -0,0 +1,57 @@ +require "rails_helper" + +describe "Budgets wizard, phases step", :admin do + let(:budget) { create(:budget, :drafting) } + let!(:heading) { create(:budget_heading, budget: budget) } + + describe "Index" do + scenario "back to a previous step" do + heading.update!(name: "Main Park") + + visit admin_budgets_wizard_budget_budget_phases_path(budget) + + within "#side_menu" do + expect(page).to have_css ".is-active", exact_text: "Participatory budgets" + end + + click_link "Go back to headings" + + expect(page).to have_css "tr", text: "Main Park" + expect(page).to have_css ".creation-timeline" + end + end + + describe "Edit" do + scenario "update phase" do + visit admin_budgets_wizard_budget_budget_phases_path(budget) + + expect(page).to have_css ".creation-timeline" + + within("tr", text: "Selecting projects") { click_link "Edit phase" } + fill_in "Name", with: "Choosing projects" + click_button "Save changes" + + expect(page).to have_content "Changes saved" + expect(page).to have_css ".creation-timeline" + within_table("Phases") { expect(page).to have_content "Choosing projects" } + end + + scenario "submit the form with errors and then without errors" do + phase = budget.phases.accepting + + visit edit_admin_budgets_wizard_budget_budget_phase_path(budget, phase) + fill_in "Name", with: "" + click_button "Save changes" + + expect(page).to have_css "#error_explanation" + expect(page).to have_css ".creation-timeline" + + fill_in "Name", with: "Welcoming projects" + click_button "Save changes" + + expect(page).to have_content "Changes saved" + expect(page).to have_css ".creation-timeline" + within_table("Phases") { expect(page).to have_content "Welcoming projects" } + end + end +end