From e3510fc29dbac304f348e5b7957215f1433a3106 Mon Sep 17 00:00:00 2001 From: Julian Herrero Date: Sun, 15 Mar 2020 06:51:52 +0100 Subject: [PATCH] Adapt heading step to single and multiple budget mode Co-Authored-By: decabeza --- .../admin/budgets_wizard/base_component.rb | 4 ++ .../headings/creation_step_component.rb | 6 ++- .../headings/index_component.html.erb | 6 ++- .../phases/index_component.html.erb | 2 +- .../budgets_wizard/phases/index_component.rb | 8 +++- .../budgets_wizard/headings_controller.rb | 12 +++++- .../admin/budgets_wizard/phases_controller.rb | 2 +- .../admin/budget_headings/_form.html.erb | 8 +++- config/locales/en/admin.yml | 5 ++- config/locales/es/admin.yml | 5 ++- .../admin/budgets_wizard/headings_spec.rb | 23 +++++++++++ .../admin/budgets_wizard/wizard_spec.rb | 39 +++++++++++++++++++ 12 files changed, 108 insertions(+), 12 deletions(-) diff --git a/app/components/admin/budgets_wizard/base_component.rb b/app/components/admin/budgets_wizard/base_component.rb index 3d96f6a07..b2aba71cd 100644 --- a/app/components/admin/budgets_wizard/base_component.rb +++ b/app/components/admin/budgets_wizard/base_component.rb @@ -1,3 +1,7 @@ class Admin::BudgetsWizard::BaseComponent < ApplicationComponent delegate :single_heading?, :url_params, to: :helpers + + def budget_mode + helpers.budget_mode || "multiple" + 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 6c07c6670..cd8e0ada1 100644 --- a/app/components/admin/budgets_wizard/headings/creation_step_component.rb +++ b/app/components/admin/budgets_wizard/headings/creation_step_component.rb @@ -12,7 +12,11 @@ class Admin::BudgetsWizard::Headings::CreationStepComponent < ApplicationCompone end def form_path - admin_budgets_wizard_budget_group_headings_path(heading.group.budget, heading.group) + if heading.persisted? + admin_budgets_wizard_budget_group_heading_path(heading.group.budget, heading.group, heading) + else + admin_budgets_wizard_budget_group_headings_path(heading.group.budget, heading.group) + end end def next_step_path diff --git a/app/components/admin/budgets_wizard/headings/index_component.html.erb b/app/components/admin/budgets_wizard/headings/index_component.html.erb index 631bb2286..b2ce1fd4f 100644 --- a/app/components/admin/budgets_wizard/headings/index_component.html.erb +++ b/app/components/admin/budgets_wizard/headings/index_component.html.erb @@ -5,6 +5,8 @@ <%= render Admin::Budgets::HelpComponent.new("budget_headings") %> <%= render Admin::BudgetsWizard::CreationTimelineComponent.new("headings") %> -<%= render Admin::BudgetsWizard::Headings::GroupSwitcherComponent.new(group) %> -<%= render Admin::BudgetHeadings::HeadingsComponent.new(headings) %> +<% unless single_heading? %> + <%= render Admin::BudgetsWizard::Headings::GroupSwitcherComponent.new(group) %> + <%= render Admin::BudgetHeadings::HeadingsComponent.new(headings) %> +<% end %> <%= render Admin::BudgetsWizard::Headings::CreationStepComponent.new(new_heading) %> 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 a97812cfb..a613e34d0 100644 --- a/app/components/admin/budgets_wizard/phases/index_component.html.erb +++ b/app/components/admin/budgets_wizard/phases/index_component.html.erb @@ -1,4 +1,4 @@ -<%= back_link_to back_link_path, t("admin.budgets_wizard.phases.back") %> +<%= back_link_to back_link_path, back_link_text %> <%= header %> diff --git a/app/components/admin/budgets_wizard/phases/index_component.rb b/app/components/admin/budgets_wizard/phases/index_component.rb index a1b680003..b0236804f 100644 --- a/app/components/admin/budgets_wizard/phases/index_component.rb +++ b/app/components/admin/budgets_wizard/phases/index_component.rb @@ -1,4 +1,4 @@ -class Admin::BudgetsWizard::Phases::IndexComponent < ApplicationComponent +class Admin::BudgetsWizard::Phases::IndexComponent < Admin::BudgetsWizard::BaseComponent include Header attr_reader :budget @@ -13,6 +13,10 @@ class Admin::BudgetsWizard::Phases::IndexComponent < ApplicationComponent private def back_link_path - admin_budgets_wizard_budget_group_headings_path(budget, budget.groups.first) + admin_budgets_wizard_budget_group_headings_path(budget, budget.groups.first, url_params) + end + + def back_link_text + t("admin.budgets_wizard.phases.#{budget_mode}.back") end end diff --git a/app/controllers/admin/budgets_wizard/headings_controller.rb b/app/controllers/admin/budgets_wizard/headings_controller.rb index 505536ca3..3b4ee532f 100644 --- a/app/controllers/admin/budgets_wizard/headings_controller.rb +++ b/app/controllers/admin/budgets_wizard/headings_controller.rb @@ -4,13 +4,21 @@ class Admin::BudgetsWizard::HeadingsController < Admin::BudgetsWizard::BaseContr before_action :load_headings, only: [:index, :create] def index - @heading = @group.headings.new + if single_heading? + @heading = @group.headings.first_or_initialize + else + @heading = @group.headings.new + end end private def headings_index - admin_budgets_wizard_budget_group_headings_path(@budget, @group) + if single_heading? + admin_budgets_wizard_budget_budget_phases_path(@budget, url_params) + else + admin_budgets_wizard_budget_group_headings_path(@budget, @group, url_params) + end end def new_action diff --git a/app/controllers/admin/budgets_wizard/phases_controller.rb b/app/controllers/admin/budgets_wizard/phases_controller.rb index 5376e93b7..785f092f9 100644 --- a/app/controllers/admin/budgets_wizard/phases_controller.rb +++ b/app/controllers/admin/budgets_wizard/phases_controller.rb @@ -1,4 +1,4 @@ -class Admin::BudgetsWizard::PhasesController < Admin::BaseController +class Admin::BudgetsWizard::PhasesController < Admin::BudgetsWizard::BaseController include Admin::BudgetPhasesActions def index diff --git a/app/views/admin/budget_headings/_form.html.erb b/app/views/admin/budget_headings/_form.html.erb index f1424bb10..ba8110542 100644 --- a/app/views/admin/budget_headings/_form.html.erb +++ b/app/views/admin/budget_headings/_form.html.erb @@ -3,6 +3,8 @@ <%= render "shared/errors", resource: heading %> + <%= render Admin::BudgetsWizard::ModelFieldComponent.new %> + <%= f.translatable_fields do |translations_form| %>
<%= translations_form.text_field :name, maxlength: 50 %> @@ -35,6 +37,10 @@
- <%= f.submit t("admin.budget_headings.form.#{action}"), class: "button hollow" %> + <% if respond_to?(:single_heading?) && single_heading? %> + <%= f.submit t("admin.budgets_wizard.headings.continue"), class: "button success" %> + <% else %> + <%= f.submit t("admin.budget_headings.form.#{action}"), class: "button hollow" %> + <% end %>
<% end %> diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml index c5bdd6707..d17e64eb3 100644 --- a/config/locales/en/admin.yml +++ b/config/locales/en/admin.yml @@ -330,8 +330,11 @@ en: title: "Single heading budget" title: "Participatory budget type" phases: - back: "Go back to headings" continue: "Finish" + multiple: + back: "Go back to headings" + single: + back: "Go back to edit heading" update_all: notice: "Phases configured successfully" milestones: diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml index b1902d74d..f6c1ce87c 100644 --- a/config/locales/es/admin.yml +++ b/config/locales/es/admin.yml @@ -330,8 +330,11 @@ es: title: "Presupuesto de partida única" title: Tipo de presupuesto participativo phases: - back: "Volver a partidas" continue: "Finalizar" + multiple: + back: "Volver a partidas" + single: + back: "Volver a editar partida" update_all: notice: "Fases configuradas con éxito" milestones: diff --git a/spec/system/admin/budgets_wizard/headings_spec.rb b/spec/system/admin/budgets_wizard/headings_spec.rb index d3823347e..de4c9dfcb 100644 --- a/spec/system/admin/budgets_wizard/headings_spec.rb +++ b/spec/system/admin/budgets_wizard/headings_spec.rb @@ -118,6 +118,29 @@ describe "Budgets wizard, headings step", :admin do expect(page).to have_css ".creation-timeline" expect(page).to have_css "td", exact_text: "Heading without typos" end + + scenario "update heading in single heading budget" do + visit admin_budgets_wizard_budget_group_headings_path(budget, group, mode: "single") + fill_in "Heading name", with: "Heading wiht typo" + fill_in "Money amount", with: "300000" + click_button "Continue to phases" + + expect(page).to have_content "Heading created successfully" + + click_link "Go back to edit heading" + + expect(page).to have_field "Heading name", with: "Heading wiht typo" + + fill_in "Heading name", with: "Heading without typos" + click_button "Continue to phases" + + expect(page).to have_content "Heading updated successfully" + + visit admin_budget_group_headings_path(budget, group) + + expect(page).to have_content "There is 1 heading" + within("tbody tr") { expect(page).to have_content "Heading without typos" } + end end describe "Destroy" do diff --git a/spec/system/admin/budgets_wizard/wizard_spec.rb b/spec/system/admin/budgets_wizard/wizard_spec.rb index afbc7abbe..0d2216ef6 100644 --- a/spec/system/admin/budgets_wizard/wizard_spec.rb +++ b/spec/system/admin/budgets_wizard/wizard_spec.rb @@ -15,6 +15,12 @@ describe "Budgets creation wizard", :admin do click_button "Continue to headings" expect(page).to have_content "Group created successfully" + + fill_in "Heading name", with: "One and only heading" + fill_in "Money amount", with: "1000000" + click_button "Continue to phases" + + expect(page).to have_css ".budget-phases-table" end scenario "Creation of a multiple-headings budget by steps" do @@ -47,5 +53,38 @@ describe "Budgets creation wizard", :admin do expect(page).to have_content "Showing headings from the All city group" expect(page).to have_content "There are no headings." + + click_button "Add new heading" + fill_in "Heading name", with: "All city" + fill_in "Money amount", with: "1000000" + click_button "Create new heading" + + expect(page).to have_content "Heading created successfully!" + within("table") { expect(page).to have_content "All city" } + expect(page).not_to have_content "There are no headings." + + click_link "Manage headings from the Districts group." + expect(page).to have_content "There are no headings." + + click_button "Add new heading" + fill_in "Heading name", with: "North" + fill_in "Money amount", with: "500000" + click_button "Create new heading" + + expect(page).to have_content "Heading created successfully!" + within("table") { expect(page).to have_content "North" } + expect(page).not_to have_content "There are no headings." + + click_button "Add new heading" + fill_in "Heading name", with: "South" + fill_in "Money amount", with: "500000" + click_button "Create new heading" + + expect(page).to have_content "Heading created successfully!" + within("table") { expect(page).to have_content "South" } + + click_link "Continue to phases" + + expect(page).to have_css ".budget-phases-table" end end