Allow editing the budget in budget creation wizard

When users created a budget and made a typo, they could use the link to
go back to edit a budget. However, after doing so, they were out of the
budget creation process.

So we're now letting users go back to edit the budget, fix any mistakes
they might have made, and then continue to groups.
This commit is contained in:
Javi Martín
2021-06-07 20:19:55 +02:00
parent f8008a4a6f
commit bdd5361f6a
12 changed files with 92 additions and 13 deletions

View File

@@ -37,7 +37,7 @@
<%= render "/admin/budgets/association", assignable_type: "valuators", assignables: valuators, form: f %> <%= render "/admin/budgets/association", assignable_type: "valuators", assignables: valuators, form: f %>
</fieldset> </fieldset>
<% if budget.persisted? %> <% unless wizard? %>
<fieldset> <fieldset>
<legend><%= t("admin.budgets.edit.info.phases_settings") %></legend> <legend><%= t("admin.budgets.edit.info.phases_settings") %></legend>
<div class="small-12 medium-6 column"> <div class="small-12 medium-6 column">
@@ -52,10 +52,10 @@
<div class="small-12 column"> <div class="small-12 column">
<div class="clear small-12 medium-4 large-3 inline-block"> <div class="clear small-12 medium-4 large-3 inline-block">
<% if budget.persisted? %> <% if wizard? %>
<%= f.submit nil, class: "button success" %>
<% else %>
<%= f.submit t("admin.budgets_wizard.budgets.continue"), class: "button success expanded" %> <%= f.submit t("admin.budgets_wizard.budgets.continue"), class: "button success expanded" %>
<% else %>
<%= f.submit nil, class: "button success" %>
<% end %> <% end %>
</div> </div>

View File

@@ -3,14 +3,16 @@ class Admin::Budgets::FormComponent < ApplicationComponent
include GlobalizeHelper include GlobalizeHelper
include Admin::Namespace include Admin::Namespace
attr_reader :budget attr_reader :budget, :wizard
alias_method :wizard?, :wizard
delegate :display_calculate_winners_button?, delegate :display_calculate_winners_button?,
:calculate_winner_button_text, :calculate_winner_button_text,
:calculate_winners_admin_budget_path, :calculate_winners_admin_budget_path,
to: :helpers to: :helpers
def initialize(budget) def initialize(budget, wizard: false)
@budget = budget @budget = budget
@wizard = wizard
end end
def voting_styles_select_options def voting_styles_select_options

View File

@@ -0,0 +1,6 @@
<%= back_link_to admin_budgets_path %>
<%= header %>
<%= render Admin::BudgetsWizard::CreationTimelineComponent.new("budget") %>
<%= render Admin::Budgets::FormComponent.new(budget, wizard: true) %>

View File

@@ -0,0 +1,12 @@
class Admin::BudgetsWizard::Budgets::EditComponent < ApplicationComponent
include Header
attr_reader :budget
def initialize(budget)
@budget = budget
end
def title
t("admin.budgets.edit.title")
end
end

View File

@@ -3,4 +3,4 @@
<%= header %> <%= header %>
<%= render Admin::BudgetsWizard::CreationTimelineComponent.new("budget") %> <%= render Admin::BudgetsWizard::CreationTimelineComponent.new("budget") %>
<%= render Admin::Budgets::FormComponent.new(budget) %> <%= render Admin::Budgets::FormComponent.new(budget, wizard: true) %>

View File

@@ -1,4 +1,4 @@
<%= back_link_to admin_budget_path(budget), t("admin.budget_groups.index.back") %> <%= back_link_to edit_admin_budgets_wizard_budget_path(budget), t("admin.budgets_wizard.groups.back") %>
<%= header %> <%= header %>

View File

@@ -8,16 +8,27 @@ class Admin::BudgetsWizard::BudgetsController < Admin::BaseController
def new def new
end end
def edit
end
def create def create
@budget.published = false @budget.published = false
if @budget.save if @budget.save
redirect_to admin_budgets_wizard_budget_groups_path(@budget), notice: t("admin.budgets.create.notice") redirect_to groups_index, notice: t("admin.budgets.create.notice")
else else
render :new render :new
end end
end end
def update
if @budget.update(budget_params)
redirect_to groups_index, notice: t("admin.budgets.update.notice")
else
render :edit
end
end
private private
def budget_params def budget_params
@@ -29,4 +40,8 @@ class Admin::BudgetsWizard::BudgetsController < Admin::BaseController
valid_attributes + [translation_params(Budget)] valid_attributes + [translation_params(Budget)]
end end
def groups_index
admin_budgets_wizard_budget_groups_path(@budget)
end
end end

View File

@@ -0,0 +1 @@
<%= render Admin::BudgetsWizard::Budgets::EditComponent.new(@budget) %>

View File

@@ -306,6 +306,7 @@ en:
budgets: budgets:
continue: "Continue to groups" continue: "Continue to groups"
groups: groups:
back: "Go back to edit budget"
continue: "Continue to headings" continue: "Continue to headings"
headings: headings:
continue: "Continue to phases" continue: "Continue to phases"

View File

@@ -306,6 +306,7 @@ es:
budgets: budgets:
continue: "Continuar a grupos" continue: "Continuar a grupos"
groups: groups:
back: "Volver a editar presupuesto"
continue: "Continuar a partidas" continue: "Continuar a partidas"
headings: headings:
continue: "Continuar a fases" continue: "Continuar a fases"

View File

@@ -73,7 +73,7 @@ namespace :admin do
end end
namespace :budgets_wizard do namespace :budgets_wizard do
resources :budgets, only: [:create, :new] do resources :budgets, only: [:create, :new, :edit, :update] do
resources :groups, only: [:index, :create, :edit, :update, :destroy] do resources :groups, only: [:index, :create, :edit, :update, :destroy] do
resources :headings, only: [:index, :create, :edit, :update, :destroy] resources :headings, only: [:index, :create, :edit, :update, :destroy]
end end

View File

@@ -11,7 +11,7 @@ describe "Budgets wizard, first step", :admin do
expect(page).to have_content "New participatory budget created successfully!" expect(page).to have_content "New participatory budget created successfully!"
click_link "Go back to budgets" click_link "Go back to edit budget"
expect(page).to have_field "Name", with: "M30 - Summer campaign" expect(page).to have_field "Name", with: "M30 - Summer campaign"
expect(page).to have_select "Final voting style", selected: "Knapsack" expect(page).to have_select "Final voting style", selected: "Knapsack"
@@ -29,7 +29,7 @@ describe "Budgets wizard, first step", :admin do
expect(page).to have_content "New participatory budget created successfully!" expect(page).to have_content "New participatory budget created successfully!"
click_link "Go back to budgets" click_link "Go back to edit budget"
expect(page).to have_field "Name", with: "M30 - Summer campaign" expect(page).to have_field "Name", with: "M30 - Summer campaign"
expect(page).to have_select "Final voting style", selected: "Approval" expect(page).to have_select "Final voting style", selected: "Approval"
@@ -81,11 +81,52 @@ describe "Budgets wizard, first step", :admin do
expect(page).to have_content "New participatory budget created successfully!" expect(page).to have_content "New participatory budget created successfully!"
click_link "Go back to budgets" within("#side_menu") { click_link "Participatory budgets" }
within("tr", text: "M30 - Summer campaign") { click_link "Edit budget" }
expect(page).to have_content "This participatory budget is in draft mode" expect(page).to have_content "This participatory budget is in draft mode"
expect(page).to have_link "Preview budget" expect(page).to have_link "Preview budget"
expect(page).to have_link "Publish budget" expect(page).to have_link "Publish budget"
end end
end end
describe "Edit" do
scenario "update budget" do
budget = create(:budget, name: "Budget wiht typo")
visit admin_budgets_wizard_budget_groups_path(budget)
click_link "Go back to edit budget"
expect(page).to have_content "Edit Participatory budget"
expect(page).to have_css ".creation-timeline"
expect(page).to have_field "Name", with: "Budget wiht typo"
fill_in "Name", with: "Budget without typos"
click_button "Continue to groups"
expect(page).to have_content "Participatory budget updated successfully"
expect(page).to have_content "Budget without typos"
expect(page).to have_css ".creation-timeline"
expect(page).to have_content "There are no groups"
end
scenario "submit the form with errors and then without errors" do
budget = create(:budget, name: "Budget wiht typo")
visit edit_admin_budgets_wizard_budget_path(budget)
fill_in "Name", with: ""
click_button "Continue to groups"
expect(page).to have_css "#error_explanation"
fill_in "Name", with: "Budget without typos"
click_button "Continue to groups"
expect(page).to have_content "Participatory budget updated successfully"
expect(page).to have_content "Budget without typos"
expect(page).to have_css ".creation-timeline"
expect(page).to have_content "There are no groups"
end
end
end end