-
-
- <%= content %>
-
-
-
- <% if next_step_path %>
- <%= link_to t("admin.budgets_wizard.#{i18n_namespace}.continue"),
- next_step_path,
- class: "next-step" %>
+ <% if single_heading? %>
+ <%= content %>
<% else %>
-
- <%= t("admin.budgets_wizard.#{i18n_namespace}.continue") %>
-
+
+
+ <%= content %>
+
+
+
+ <% if next_step_path %>
+ <%= link_to t("admin.budgets_wizard.#{i18n_namespace}.continue"),
+ next_step_path,
+ class: "next-step" %>
+ <% else %>
+
+ <%= t("admin.budgets_wizard.#{i18n_namespace}.continue") %>
+
+ <% end %>
<% end %>
diff --git a/app/components/admin/budgets_wizard/creation_step_component.rb b/app/components/admin/budgets_wizard/creation_step_component.rb
index 2bd220146..575ac11e1 100644
--- a/app/components/admin/budgets_wizard/creation_step_component.rb
+++ b/app/components/admin/budgets_wizard/creation_step_component.rb
@@ -1,4 +1,4 @@
-class Admin::BudgetsWizard::CreationStepComponent < ApplicationComponent
+class Admin::BudgetsWizard::CreationStepComponent < Admin::BudgetsWizard::BaseComponent
attr_reader :record, :next_step_path
def initialize(record, next_step_path)
diff --git a/app/components/admin/budgets_wizard/groups/creation_step_component.rb b/app/components/admin/budgets_wizard/groups/creation_step_component.rb
index 8a5e3bfa9..f2faeea77 100644
--- a/app/components/admin/budgets_wizard/groups/creation_step_component.rb
+++ b/app/components/admin/budgets_wizard/groups/creation_step_component.rb
@@ -13,7 +13,11 @@ class Admin::BudgetsWizard::Groups::CreationStepComponent < ApplicationComponent
end
def form_path
- admin_budgets_wizard_budget_groups_path(budget)
+ if group.persisted?
+ admin_budgets_wizard_budget_group_path(budget, group)
+ else
+ admin_budgets_wizard_budget_groups_path(budget)
+ end
end
def next_step_path
diff --git a/app/components/admin/budgets_wizard/groups/index_component.html.erb b/app/components/admin/budgets_wizard/groups/index_component.html.erb
index 04a0059aa..f79361821 100644
--- a/app/components/admin/budgets_wizard/groups/index_component.html.erb
+++ b/app/components/admin/budgets_wizard/groups/index_component.html.erb
@@ -5,5 +5,7 @@
<%= render Admin::Budgets::HelpComponent.new("budget_groups") %>
<%= render Admin::BudgetsWizard::CreationTimelineComponent.new("groups") %>
-<%= render Admin::BudgetGroups::GroupsComponent.new(groups) %>
+<% unless single_heading? %>
+ <%= render Admin::BudgetGroups::GroupsComponent.new(groups) %>
+<% end %>
<%= render Admin::BudgetsWizard::Groups::CreationStepComponent.new(new_group, groups.first) %>
diff --git a/app/components/admin/budgets_wizard/groups/index_component.rb b/app/components/admin/budgets_wizard/groups/index_component.rb
index d15414e54..5c9b206b1 100644
--- a/app/components/admin/budgets_wizard/groups/index_component.rb
+++ b/app/components/admin/budgets_wizard/groups/index_component.rb
@@ -1,4 +1,4 @@
-class Admin::BudgetsWizard::Groups::IndexComponent < ApplicationComponent
+class Admin::BudgetsWizard::Groups::IndexComponent < Admin::BudgetsWizard::BaseComponent
include Header
attr_reader :groups, :new_group
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 21e0d538d..631bb2286 100644
--- a/app/components/admin/budgets_wizard/headings/index_component.html.erb
+++ b/app/components/admin/budgets_wizard/headings/index_component.html.erb
@@ -1,4 +1,4 @@
-<%= back_link_to admin_budgets_wizard_budget_groups_path(budget), t("admin.budget_headings.index.back") %>
+<%= back_link_to admin_budgets_wizard_budget_groups_path(budget, url_params), back_link_text %>
<%= header %>
diff --git a/app/components/admin/budgets_wizard/headings/index_component.rb b/app/components/admin/budgets_wizard/headings/index_component.rb
index 76aa584a9..f789a00e8 100644
--- a/app/components/admin/budgets_wizard/headings/index_component.rb
+++ b/app/components/admin/budgets_wizard/headings/index_component.rb
@@ -1,4 +1,4 @@
-class Admin::BudgetsWizard::Headings::IndexComponent < ApplicationComponent
+class Admin::BudgetsWizard::Headings::IndexComponent < Admin::BudgetsWizard::BaseComponent
include Header
attr_reader :headings, :new_heading
@@ -18,4 +18,12 @@ class Admin::BudgetsWizard::Headings::IndexComponent < ApplicationComponent
def title
t("admin.budget_headings.index.title", budget: budget.name, group: group.name)
end
+
+ def back_link_text
+ if single_heading?
+ t("admin.budgets_wizard.headings.single.back")
+ else
+ t("admin.budget_headings.index.back")
+ end
+ end
end
diff --git a/app/components/admin/budgets_wizard/model_field_component.html.erb b/app/components/admin/budgets_wizard/model_field_component.html.erb
new file mode 100644
index 000000000..f862d30b7
--- /dev/null
+++ b/app/components/admin/budgets_wizard/model_field_component.html.erb
@@ -0,0 +1 @@
+<%= hidden_field_tag(:mode, helpers.budget_mode) if helpers.respond_to?(:budget_mode) %>
diff --git a/app/components/admin/budgets_wizard/model_field_component.rb b/app/components/admin/budgets_wizard/model_field_component.rb
new file mode 100644
index 000000000..adb2d32ad
--- /dev/null
+++ b/app/components/admin/budgets_wizard/model_field_component.rb
@@ -0,0 +1,2 @@
+class Admin::BudgetsWizard::ModelFieldComponent < ApplicationComponent
+end
diff --git a/app/controllers/admin/budgets_wizard/base_controller.rb b/app/controllers/admin/budgets_wizard/base_controller.rb
new file mode 100644
index 000000000..d8798c8e7
--- /dev/null
+++ b/app/controllers/admin/budgets_wizard/base_controller.rb
@@ -0,0 +1,17 @@
+class Admin::BudgetsWizard::BaseController < Admin::BaseController
+ helper_method :budget_mode, :single_heading?, :url_params
+
+ private
+
+ def budget_mode
+ params[:mode]
+ end
+
+ def single_heading?
+ budget_mode == "single"
+ end
+
+ def url_params
+ budget_mode.present? ? { mode: budget_mode } : {}
+ end
+end
diff --git a/app/controllers/admin/budgets_wizard/budgets_controller.rb b/app/controllers/admin/budgets_wizard/budgets_controller.rb
index aaa5a7b73..e3efe9739 100644
--- a/app/controllers/admin/budgets_wizard/budgets_controller.rb
+++ b/app/controllers/admin/budgets_wizard/budgets_controller.rb
@@ -1,4 +1,4 @@
-class Admin::BudgetsWizard::BudgetsController < Admin::BaseController
+class Admin::BudgetsWizard::BudgetsController < Admin::BudgetsWizard::BaseController
include Translatable
include ImageAttributes
include FeatureFlags
@@ -6,8 +6,6 @@ class Admin::BudgetsWizard::BudgetsController < Admin::BaseController
load_and_authorize_resource
- helper_method :budget_mode, :single_heading?
-
def new
end
@@ -48,16 +46,4 @@ class Admin::BudgetsWizard::BudgetsController < Admin::BaseController
def groups_index
admin_budgets_wizard_budget_groups_path(@budget, url_params)
end
-
- def budget_mode
- params[:mode]
- end
-
- def single_heading?
- budget_mode == "single"
- end
-
- def url_params
- budget_mode.present? ? { mode: budget_mode } : {}
- end
end
diff --git a/app/controllers/admin/budgets_wizard/groups_controller.rb b/app/controllers/admin/budgets_wizard/groups_controller.rb
index 4d8c8895c..b8d180a64 100644
--- a/app/controllers/admin/budgets_wizard/groups_controller.rb
+++ b/app/controllers/admin/budgets_wizard/groups_controller.rb
@@ -1,16 +1,24 @@
-class Admin::BudgetsWizard::GroupsController < Admin::BaseController
+class Admin::BudgetsWizard::GroupsController < Admin::BudgetsWizard::BaseController
include Admin::BudgetGroupsActions
before_action :load_groups, only: [:index, :create]
def index
- @group = @budget.groups.new
+ if single_heading?
+ @group = @budget.groups.first_or_initialize("name_#{I18n.locale}" => @budget.name)
+ else
+ @group = @budget.groups.new
+ end
end
private
def groups_index
- admin_budgets_wizard_budget_groups_path(@budget)
+ if single_heading?
+ admin_budgets_wizard_budget_group_headings_path(@budget, @group, url_params)
+ else
+ admin_budgets_wizard_budget_groups_path(@budget, url_params)
+ end
end
def new_action
diff --git a/app/controllers/admin/budgets_wizard/headings_controller.rb b/app/controllers/admin/budgets_wizard/headings_controller.rb
index 5eb78e5d3..505536ca3 100644
--- a/app/controllers/admin/budgets_wizard/headings_controller.rb
+++ b/app/controllers/admin/budgets_wizard/headings_controller.rb
@@ -1,4 +1,4 @@
-class Admin::BudgetsWizard::HeadingsController < Admin::BaseController
+class Admin::BudgetsWizard::HeadingsController < Admin::BudgetsWizard::BaseController
include Admin::BudgetHeadingsActions
before_action :load_headings, only: [:index, :create]
diff --git a/app/views/admin/budget_groups/_form.html.erb b/app/views/admin/budget_groups/_form.html.erb
index 5e86059c0..4c70672cf 100644
--- a/app/views/admin/budget_groups/_form.html.erb
+++ b/app/views/admin/budget_groups/_form.html.erb
@@ -3,6 +3,8 @@
<%= render "shared/errors", resource: group %>
+ <%= render Admin::BudgetsWizard::ModelFieldComponent.new %>
+
<%= f.translatable_fields do |translations_form| %>
<%= translations_form.text_field :name, maxlength: 50 %>
@@ -18,6 +20,10 @@
<% end %>
- <%= f.submit t("admin.budget_groups.form.#{action}"), class: "button hollow" %>
+ <% if respond_to?(:single_heading?) && single_heading? %>
+ <%= f.submit t("admin.budgets_wizard.groups.continue"), class: "button success" %>
+ <% else %>
+ <%= f.submit t("admin.budget_groups.form.#{action}"), class: "button hollow" %>
+ <% end %>
<% end %>
diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml
index a9c4cf03a..c5bdd6707 100644
--- a/config/locales/en/admin.yml
+++ b/config/locales/en/admin.yml
@@ -317,6 +317,8 @@ en:
continue: "Continue to headings"
headings:
continue: "Continue to phases"
+ single:
+ back: "Go back to edit group"
heading_mode:
multiple:
description: "Create a process with multiple groups, districts or topics. You have something like several bags of money. For example, 25,000€ for \"North District\", 30,000€ for \"Center District\", 28,000€ for \"South District\" and the whole city. Or for several themes like sport, culture or health."
diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml
index 40f196d30..b1902d74d 100644
--- a/config/locales/es/admin.yml
+++ b/config/locales/es/admin.yml
@@ -317,6 +317,8 @@ es:
continue: "Continuar a partidas"
headings:
continue: "Continuar a fases"
+ single:
+ back: "Volver a editar grupo"
heading_mode:
multiple:
description: "Crea un proceso con múltiples grupos, distritos o temas. Tienes algo como varias bolsas de dinero. Por ejemplo, 25.000€ para \"Distrito norte\", 30.000€ para \"Distrito centro\", 28.000€ para \"Distrito sur\" y toda la ciudad. O para varios temas como deporte, cultura o salud."
diff --git a/spec/system/admin/budgets_wizard/groups_spec.rb b/spec/system/admin/budgets_wizard/groups_spec.rb
index be2e84d05..e5e237c87 100644
--- a/spec/system/admin/budgets_wizard/groups_spec.rb
+++ b/spec/system/admin/budgets_wizard/groups_spec.rb
@@ -97,6 +97,26 @@ describe "Budgets wizard, groups step", :admin do
expect(page).to have_css ".creation-timeline"
expect(page).to have_css "td", exact_text: "Group without typos"
end
+
+ scenario "update group in single heading budget" do
+ visit admin_budgets_wizard_budget_groups_path(budget, mode: "single")
+ fill_in "Group name", with: "Group wiht typo"
+ click_button "Continue to headings"
+
+ click_link "Go back to edit group"
+
+ expect(page).to have_field "Group name", with: "Group wiht typo"
+
+ fill_in "Group name", with: "Group without typos"
+ click_button "Continue to headings"
+
+ expect(page).to have_content "Group updated successfully"
+
+ visit admin_budget_groups_path(budget)
+
+ expect(page).to have_content "There is 1 group"
+ within("tbody tr") { expect(page).to have_content "Group 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 f042ab2a3..afbc7abbe 100644
--- a/spec/system/admin/budgets_wizard/wizard_spec.rb
+++ b/spec/system/admin/budgets_wizard/wizard_spec.rb
@@ -10,6 +10,11 @@ describe "Budgets creation wizard", :admin do
click_button "Continue to groups"
expect(page).to have_content "New participatory budget created successfully!"
+ expect(page).to have_field "Group name", with: "Single heading budget"
+
+ click_button "Continue to headings"
+
+ expect(page).to have_content "Group created successfully"
end
scenario "Creation of a multiple-headings budget by steps" do
@@ -22,5 +27,25 @@ describe "Budgets creation wizard", :admin do
expect(page).to have_content "New participatory budget created successfully!"
expect(page).to have_content "There are no groups."
+
+ click_button "Add new group"
+ fill_in "Group name", with: "All city"
+ click_button "Create new group"
+
+ expect(page).to have_content "Group created successfully!"
+ within("table") { expect(page).to have_content "All city" }
+ expect(page).not_to have_content "There are no groups."
+
+ click_button "Add new group"
+ fill_in "Group name", with: "Districts"
+ click_button "Create new group"
+
+ expect(page).to have_content "Group created successfully!"
+ within("table") { expect(page).to have_content "Districts" }
+
+ click_link "Continue to headings"
+
+ expect(page).to have_content "Showing headings from the All city group"
+ expect(page).to have_content "There are no headings."
end
end