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| %>
|
||||
<%= hidden_field_tag(:mode, helpers.budget_mode) if helpers.respond_to?(:budget_mode) %>
|
||||
<%= render Admin::BudgetsWizard::ModelFieldComponent.new %>
|
||||
|
||||
<fieldset>
|
||||
<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,19 +1,23 @@
|
||||
<div class="budget-creation-step">
|
||||
<button type="button" class="add" aria-expanded="<%= show_form? %>">
|
||||
<%= t("admin.#{i18n_namespace_with_budget}.index.new_button") %>
|
||||
</button>
|
||||
|
||||
<%= content %>
|
||||
|
||||
<button type="button" class="cancel delete"><%= t("links.form.cancel_button") %></button>
|
||||
|
||||
<% if next_step_path %>
|
||||
<%= link_to t("admin.budgets_wizard.#{i18n_namespace}.continue"),
|
||||
next_step_path,
|
||||
class: "next-step" %>
|
||||
<% if single_heading? %>
|
||||
<%= content %>
|
||||
<% else %>
|
||||
<p class="next-step">
|
||||
<%= t("admin.budgets_wizard.#{i18n_namespace}.continue") %>
|
||||
</p>
|
||||
<button type="button" class="add" aria-expanded="<%= show_form? %>">
|
||||
<%= t("admin.#{i18n_namespace_with_budget}.index.new_button") %>
|
||||
</button>
|
||||
|
||||
<%= content %>
|
||||
|
||||
<button type="button" class="cancel delete"><%= t("links.form.cancel_button") %></button>
|
||||
|
||||
<% if next_step_path %>
|
||||
<%= link_to t("admin.budgets_wizard.#{i18n_namespace}.continue"),
|
||||
next_step_path,
|
||||
class: "next-step" %>
|
||||
<% else %>
|
||||
<p class="next-step">
|
||||
<%= t("admin.budgets_wizard.#{i18n_namespace}.continue") %>
|
||||
</p>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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) %>
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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 %>
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
|
||||
<%= render "shared/errors", resource: group %>
|
||||
|
||||
<%= render Admin::BudgetsWizard::ModelFieldComponent.new %>
|
||||
|
||||
<%= f.translatable_fields do |translations_form| %>
|
||||
<div class="small-12 medium-6 column end">
|
||||
<%= translations_form.text_field :name, maxlength: 50 %>
|
||||
@@ -18,6 +20,10 @@
|
||||
<% end %>
|
||||
|
||||
<div class="clear">
|
||||
<%= 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 %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
@@ -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."
|
||||
|
||||
@@ -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."
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user