Adapt group step to single and multiple budget mode
Co-Authored-By: decabeza <alberto@decabeza.es>
This commit is contained in:
committed by
Javi Martín
parent
0b81f7f621
commit
9fcae141a6
@@ -1,5 +1,5 @@
|
|||||||
<%= translatable_form_for [namespace, budget], html: { class: "budgets-form" } do |f| %>
|
<%= translatable_form_for [namespace, budget], html: { class: "budgets-form" } do |f| %>
|
||||||
<%= hidden_field_tag(:mode, helpers.budget_mode) if helpers.respond_to?(:budget_mode) %>
|
<%= render Admin::BudgetsWizard::ModelFieldComponent.new %>
|
||||||
|
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<legend><%= t("admin.budgets.edit.info.budget_settings") %></legend>
|
<legend><%= t("admin.budgets.edit.info.budget_settings") %></legend>
|
||||||
|
|||||||
3
app/components/admin/budgets_wizard/base_component.rb
Normal file
3
app/components/admin/budgets_wizard/base_component.rb
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
class Admin::BudgetsWizard::BaseComponent < ApplicationComponent
|
||||||
|
delegate :single_heading?, :url_params, to: :helpers
|
||||||
|
end
|
||||||
@@ -1,4 +1,7 @@
|
|||||||
<div class="budget-creation-step">
|
<div class="budget-creation-step">
|
||||||
|
<% if single_heading? %>
|
||||||
|
<%= content %>
|
||||||
|
<% else %>
|
||||||
<button type="button" class="add" aria-expanded="<%= show_form? %>">
|
<button type="button" class="add" aria-expanded="<%= show_form? %>">
|
||||||
<%= t("admin.#{i18n_namespace_with_budget}.index.new_button") %>
|
<%= t("admin.#{i18n_namespace_with_budget}.index.new_button") %>
|
||||||
</button>
|
</button>
|
||||||
@@ -16,4 +19,5 @@
|
|||||||
<%= t("admin.budgets_wizard.#{i18n_namespace}.continue") %>
|
<%= t("admin.budgets_wizard.#{i18n_namespace}.continue") %>
|
||||||
</p>
|
</p>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
class Admin::BudgetsWizard::CreationStepComponent < ApplicationComponent
|
class Admin::BudgetsWizard::CreationStepComponent < Admin::BudgetsWizard::BaseComponent
|
||||||
attr_reader :record, :next_step_path
|
attr_reader :record, :next_step_path
|
||||||
|
|
||||||
def initialize(record, next_step_path)
|
def initialize(record, next_step_path)
|
||||||
|
|||||||
@@ -13,8 +13,12 @@ class Admin::BudgetsWizard::Groups::CreationStepComponent < ApplicationComponent
|
|||||||
end
|
end
|
||||||
|
|
||||||
def form_path
|
def form_path
|
||||||
|
if group.persisted?
|
||||||
|
admin_budgets_wizard_budget_group_path(budget, group)
|
||||||
|
else
|
||||||
admin_budgets_wizard_budget_groups_path(budget)
|
admin_budgets_wizard_budget_groups_path(budget)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def next_step_path
|
def next_step_path
|
||||||
admin_budgets_wizard_budget_group_headings_path(budget, next_step_group) if next_step_enabled?
|
admin_budgets_wizard_budget_group_headings_path(budget, next_step_group) if next_step_enabled?
|
||||||
|
|||||||
@@ -5,5 +5,7 @@
|
|||||||
<%= render Admin::Budgets::HelpComponent.new("budget_groups") %>
|
<%= render Admin::Budgets::HelpComponent.new("budget_groups") %>
|
||||||
<%= render Admin::BudgetsWizard::CreationTimelineComponent.new("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) %>
|
<%= render Admin::BudgetsWizard::Groups::CreationStepComponent.new(new_group, groups.first) %>
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
class Admin::BudgetsWizard::Groups::IndexComponent < ApplicationComponent
|
class Admin::BudgetsWizard::Groups::IndexComponent < Admin::BudgetsWizard::BaseComponent
|
||||||
include Header
|
include Header
|
||||||
attr_reader :groups, :new_group
|
attr_reader :groups, :new_group
|
||||||
|
|
||||||
|
|||||||
@@ -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 %>
|
<%= header %>
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
class Admin::BudgetsWizard::Headings::IndexComponent < ApplicationComponent
|
class Admin::BudgetsWizard::Headings::IndexComponent < Admin::BudgetsWizard::BaseComponent
|
||||||
include Header
|
include Header
|
||||||
attr_reader :headings, :new_heading
|
attr_reader :headings, :new_heading
|
||||||
|
|
||||||
@@ -18,4 +18,12 @@ class Admin::BudgetsWizard::Headings::IndexComponent < ApplicationComponent
|
|||||||
def title
|
def title
|
||||||
t("admin.budget_headings.index.title", budget: budget.name, group: group.name)
|
t("admin.budget_headings.index.title", budget: budget.name, group: group.name)
|
||||||
end
|
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
|
end
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
<%= hidden_field_tag(:mode, helpers.budget_mode) if helpers.respond_to?(:budget_mode) %>
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
class Admin::BudgetsWizard::ModelFieldComponent < ApplicationComponent
|
||||||
|
end
|
||||||
17
app/controllers/admin/budgets_wizard/base_controller.rb
Normal file
17
app/controllers/admin/budgets_wizard/base_controller.rb
Normal file
@@ -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
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
class Admin::BudgetsWizard::BudgetsController < Admin::BaseController
|
class Admin::BudgetsWizard::BudgetsController < Admin::BudgetsWizard::BaseController
|
||||||
include Translatable
|
include Translatable
|
||||||
include ImageAttributes
|
include ImageAttributes
|
||||||
include FeatureFlags
|
include FeatureFlags
|
||||||
@@ -6,8 +6,6 @@ class Admin::BudgetsWizard::BudgetsController < Admin::BaseController
|
|||||||
|
|
||||||
load_and_authorize_resource
|
load_and_authorize_resource
|
||||||
|
|
||||||
helper_method :budget_mode, :single_heading?
|
|
||||||
|
|
||||||
def new
|
def new
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -48,16 +46,4 @@ class Admin::BudgetsWizard::BudgetsController < Admin::BaseController
|
|||||||
def groups_index
|
def groups_index
|
||||||
admin_budgets_wizard_budget_groups_path(@budget, url_params)
|
admin_budgets_wizard_budget_groups_path(@budget, url_params)
|
||||||
end
|
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
|
end
|
||||||
|
|||||||
@@ -1,16 +1,24 @@
|
|||||||
class Admin::BudgetsWizard::GroupsController < Admin::BaseController
|
class Admin::BudgetsWizard::GroupsController < Admin::BudgetsWizard::BaseController
|
||||||
include Admin::BudgetGroupsActions
|
include Admin::BudgetGroupsActions
|
||||||
|
|
||||||
before_action :load_groups, only: [:index, :create]
|
before_action :load_groups, only: [:index, :create]
|
||||||
|
|
||||||
def index
|
def index
|
||||||
|
if single_heading?
|
||||||
|
@group = @budget.groups.first_or_initialize("name_#{I18n.locale}" => @budget.name)
|
||||||
|
else
|
||||||
@group = @budget.groups.new
|
@group = @budget.groups.new
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def groups_index
|
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
|
end
|
||||||
|
|
||||||
def new_action
|
def new_action
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
class Admin::BudgetsWizard::HeadingsController < Admin::BaseController
|
class Admin::BudgetsWizard::HeadingsController < Admin::BudgetsWizard::BaseController
|
||||||
include Admin::BudgetHeadingsActions
|
include Admin::BudgetHeadingsActions
|
||||||
|
|
||||||
before_action :load_headings, only: [:index, :create]
|
before_action :load_headings, only: [:index, :create]
|
||||||
|
|||||||
@@ -3,6 +3,8 @@
|
|||||||
|
|
||||||
<%= render "shared/errors", resource: group %>
|
<%= render "shared/errors", resource: group %>
|
||||||
|
|
||||||
|
<%= render Admin::BudgetsWizard::ModelFieldComponent.new %>
|
||||||
|
|
||||||
<%= f.translatable_fields do |translations_form| %>
|
<%= f.translatable_fields do |translations_form| %>
|
||||||
<div class="small-12 medium-6 column end">
|
<div class="small-12 medium-6 column end">
|
||||||
<%= translations_form.text_field :name, maxlength: 50 %>
|
<%= translations_form.text_field :name, maxlength: 50 %>
|
||||||
@@ -18,6 +20,10 @@
|
|||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<div class="clear">
|
<div class="clear">
|
||||||
|
<% 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" %>
|
<%= f.submit t("admin.budget_groups.form.#{action}"), class: "button hollow" %>
|
||||||
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
@@ -317,6 +317,8 @@ en:
|
|||||||
continue: "Continue to headings"
|
continue: "Continue to headings"
|
||||||
headings:
|
headings:
|
||||||
continue: "Continue to phases"
|
continue: "Continue to phases"
|
||||||
|
single:
|
||||||
|
back: "Go back to edit group"
|
||||||
heading_mode:
|
heading_mode:
|
||||||
multiple:
|
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."
|
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."
|
||||||
|
|||||||
@@ -317,6 +317,8 @@ es:
|
|||||||
continue: "Continuar a partidas"
|
continue: "Continuar a partidas"
|
||||||
headings:
|
headings:
|
||||||
continue: "Continuar a fases"
|
continue: "Continuar a fases"
|
||||||
|
single:
|
||||||
|
back: "Volver a editar grupo"
|
||||||
heading_mode:
|
heading_mode:
|
||||||
multiple:
|
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."
|
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."
|
||||||
|
|||||||
@@ -97,6 +97,26 @@ describe "Budgets wizard, groups step", :admin do
|
|||||||
expect(page).to have_css ".creation-timeline"
|
expect(page).to have_css ".creation-timeline"
|
||||||
expect(page).to have_css "td", exact_text: "Group without typos"
|
expect(page).to have_css "td", exact_text: "Group without typos"
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
describe "Destroy" do
|
describe "Destroy" do
|
||||||
|
|||||||
@@ -10,6 +10,11 @@ describe "Budgets creation wizard", :admin do
|
|||||||
click_button "Continue to groups"
|
click_button "Continue to groups"
|
||||||
|
|
||||||
expect(page).to have_content "New participatory budget created successfully!"
|
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
|
end
|
||||||
|
|
||||||
scenario "Creation of a multiple-headings budget by steps" do
|
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 "New participatory budget created successfully!"
|
||||||
expect(page).to have_content "There are no groups."
|
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
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user