Add phases step to budget creation
This commit is contained in:
committed by
Javi Martín
parent
9421f1673a
commit
eb77d09425
@@ -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 %>
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
class Admin::BudgetPhases::FormComponent < ApplicationComponent
|
||||
include TranslatableFormHelper
|
||||
include GlobalizeHelper
|
||||
include Admin::Namespace
|
||||
|
||||
attr_reader :phase
|
||||
|
||||
|
||||
@@ -8,6 +8,6 @@ class Admin::BudgetsWizard::CreationTimelineComponent < ApplicationComponent
|
||||
private
|
||||
|
||||
def steps
|
||||
%w[budget groups headings]
|
||||
%w[budget groups headings phases]
|
||||
end
|
||||
end
|
||||
|
||||
@@ -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?
|
||||
|
||||
@@ -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" %>
|
||||
22
app/components/admin/budgets_wizard/phases/edit_component.rb
Normal file
22
app/components/admin/budgets_wizard/phases/edit_component.rb
Normal file
@@ -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
|
||||
@@ -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" %>
|
||||
@@ -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
|
||||
@@ -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
|
||||
|
||||
12
app/controllers/admin/budgets_wizard/phases_controller.rb
Normal file
12
app/controllers/admin/budgets_wizard/phases_controller.rb
Normal file
@@ -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
|
||||
36
app/controllers/concerns/admin/budget_phases_actions.rb
Normal file
36
app/controllers/concerns/admin/budget_phases_actions.rb
Normal file
@@ -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
|
||||
@@ -1,5 +1 @@
|
||||
<%= back_link_to edit_admin_budget_path(@phase.budget) %>
|
||||
|
||||
<h2><%= t("admin.budgets.edit.title") %> - <%= @phase.name %></h2>
|
||||
|
||||
<%= render "/admin/budget_phases/form" %>
|
||||
<%= render Admin::BudgetsWizard::Phases::EditComponent.new(@phase) %>
|
||||
|
||||
1
app/views/admin/budgets_wizard/phases/edit.html.erb
Normal file
1
app/views/admin/budgets_wizard/phases/edit.html.erb
Normal file
@@ -0,0 +1 @@
|
||||
<%= render Admin::BudgetsWizard::Phases::EditComponent.new(@phase) %>
|
||||
1
app/views/admin/budgets_wizard/phases/index.html.erb
Normal file
1
app/views/admin/budgets_wizard/phases/index.html.erb
Normal file
@@ -0,0 +1 @@
|
||||
<%= render Admin::BudgetsWizard::Phases::IndexComponent.new(@budget) %>
|
||||
@@ -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*"
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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"
|
||||
|
||||
57
spec/system/admin/budgets_wizard/phases_spec.rb
Normal file
57
spec/system/admin/budgets_wizard/phases_spec.rb
Normal file
@@ -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
|
||||
Reference in New Issue
Block a user