diff --git a/app/components/admin/budget_phases/form_component.html.erb b/app/components/admin/budget_phases/form_component.html.erb index 125f2c9e4..78f10c235 100644 --- a/app/components/admin/budget_phases/form_component.html.erb +++ b/app/components/admin/budget_phases/form_component.html.erb @@ -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 %> diff --git a/app/components/admin/budget_phases/form_component.rb b/app/components/admin/budget_phases/form_component.rb index 0b890c9f4..49c6cf36c 100644 --- a/app/components/admin/budget_phases/form_component.rb +++ b/app/components/admin/budget_phases/form_component.rb @@ -1,6 +1,7 @@ class Admin::BudgetPhases::FormComponent < ApplicationComponent include TranslatableFormHelper include GlobalizeHelper + include Admin::Namespace attr_reader :phase diff --git a/app/components/admin/budgets_wizard/creation_timeline_component.rb b/app/components/admin/budgets_wizard/creation_timeline_component.rb index a4f4ed24f..7fe7ffcf2 100644 --- a/app/components/admin/budgets_wizard/creation_timeline_component.rb +++ b/app/components/admin/budgets_wizard/creation_timeline_component.rb @@ -8,6 +8,6 @@ class Admin::BudgetsWizard::CreationTimelineComponent < ApplicationComponent private def steps - %w[budget groups headings] + %w[budget groups headings phases] end end diff --git a/app/components/admin/budgets_wizard/headings/creation_step_component.rb b/app/components/admin/budgets_wizard/headings/creation_step_component.rb index 8758c6bbc..6c07c6670 100644 --- a/app/components/admin/budgets_wizard/headings/creation_step_component.rb +++ b/app/components/admin/budgets_wizard/headings/creation_step_component.rb @@ -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? diff --git a/app/components/admin/budgets_wizard/phases/edit_component.html.erb b/app/components/admin/budgets_wizard/phases/edit_component.html.erb new file mode 100644 index 000000000..44131384c --- /dev/null +++ b/app/components/admin/budgets_wizard/phases/edit_component.html.erb @@ -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" %> diff --git a/app/components/admin/budgets_wizard/phases/edit_component.rb b/app/components/admin/budgets_wizard/phases/edit_component.rb new file mode 100644 index 000000000..68645ed95 --- /dev/null +++ b/app/components/admin/budgets_wizard/phases/edit_component.rb @@ -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 diff --git a/app/components/admin/budgets_wizard/phases/index_component.html.erb b/app/components/admin/budgets_wizard/phases/index_component.html.erb new file mode 100644 index 000000000..816dc0d91 --- /dev/null +++ b/app/components/admin/budgets_wizard/phases/index_component.html.erb @@ -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" %> diff --git a/app/components/admin/budgets_wizard/phases/index_component.rb b/app/components/admin/budgets_wizard/phases/index_component.rb new file mode 100644 index 000000000..a1b680003 --- /dev/null +++ b/app/components/admin/budgets_wizard/phases/index_component.rb @@ -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 diff --git a/app/controllers/admin/budget_phases_controller.rb b/app/controllers/admin/budget_phases_controller.rb index 1ff8dcedb..ac2a763e1 100644 --- a/app/controllers/admin/budget_phases_controller.rb +++ b/app/controllers/admin/budget_phases_controller.rb @@ -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 diff --git a/app/controllers/admin/budgets_wizard/phases_controller.rb b/app/controllers/admin/budgets_wizard/phases_controller.rb new file mode 100644 index 000000000..889b22c4f --- /dev/null +++ b/app/controllers/admin/budgets_wizard/phases_controller.rb @@ -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 diff --git a/app/controllers/concerns/admin/budget_phases_actions.rb b/app/controllers/concerns/admin/budget_phases_actions.rb new file mode 100644 index 000000000..80a1af51c --- /dev/null +++ b/app/controllers/concerns/admin/budget_phases_actions.rb @@ -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 diff --git a/app/views/admin/budget_phases/edit.html.erb b/app/views/admin/budget_phases/edit.html.erb index 452c11f96..27fbdd585 100644 --- a/app/views/admin/budget_phases/edit.html.erb +++ b/app/views/admin/budget_phases/edit.html.erb @@ -1,5 +1 @@ -<%= back_link_to edit_admin_budget_path(@phase.budget) %> - -