Allow enabling/disabling phases in budgets wizard
So now there's no need to edit each phase individually to enable/disable them. We aren't doing the same thing in the form to edit a budget because we aren't sure about possible usability issues. On one hand, in some tables we automatically update records when we mark a checkbox, so users might expect that. On the other hand, having a checkbox in the middle of a form which updates the database automatically is counter-intuitive, particularly when right below that table there are other checkboxes which don't update the database until the form is submitted. So, either way, chances are users would think they've updated the phases (or kept them intact) while the opposite would be true. In the form within the wizard to create a budget that problem isn't that important because there aren't any other fields in the form and it's pretty intuitive that what users do will have no effect until they press the "Finish" button. Co-Authored-By: Julian Nicolas Herrero <microweb10@gmail.com>
This commit is contained in:
@@ -258,6 +258,11 @@ $table-header: #ecf1f6;
|
|||||||
[type="submit"] ~ a {
|
[type="submit"] ~ a {
|
||||||
margin-left: $line-height / 2;
|
margin-left: $line-height / 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[type="checkbox"] {
|
||||||
|
margin-bottom: 0;
|
||||||
|
vertical-align: middle;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
hr {
|
hr {
|
||||||
|
|||||||
@@ -26,7 +26,7 @@
|
|||||||
<% end %>
|
<% end %>
|
||||||
</td>
|
</td>
|
||||||
<td class="text-center">
|
<td class="text-center">
|
||||||
<%= enabled_text(phase) %>
|
<%= enabled_cell(phase) %>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<%= render Admin::TableActionsComponent.new(phase,
|
<%= render Admin::TableActionsComponent.new(phase,
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
class Admin::BudgetPhases::PhasesComponent < ApplicationComponent
|
class Admin::BudgetPhases::PhasesComponent < ApplicationComponent
|
||||||
attr_reader :budget
|
attr_reader :budget, :form
|
||||||
|
|
||||||
def initialize(budget)
|
def initialize(budget, form: nil)
|
||||||
@budget = budget
|
@budget = budget
|
||||||
|
@form = form
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
@@ -15,6 +16,20 @@ class Admin::BudgetPhases::PhasesComponent < ApplicationComponent
|
|||||||
Admin::Budgets::DurationComponent.new(phase).dates
|
Admin::Budgets::DurationComponent.new(phase).dates
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def enabled_cell(phase)
|
||||||
|
if form
|
||||||
|
form.fields_for :phases, phase do |phase_fields|
|
||||||
|
phase_fields.check_box :enabled,
|
||||||
|
label: false,
|
||||||
|
aria: {
|
||||||
|
label: t("admin.budgets.edit.enable_phase", phase: phase.name)
|
||||||
|
}
|
||||||
|
end
|
||||||
|
else
|
||||||
|
enabled_text(phase)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def enabled_text(phase)
|
def enabled_text(phase)
|
||||||
if phase.enabled?
|
if phase.enabled?
|
||||||
tag.span t("shared.yes"), class: "budget-phase-enabled"
|
tag.span t("shared.yes"), class: "budget-phase-enabled"
|
||||||
|
|||||||
@@ -5,8 +5,7 @@
|
|||||||
<%= render Admin::Budgets::HelpComponent.new("budget_phases") %>
|
<%= render Admin::Budgets::HelpComponent.new("budget_phases") %>
|
||||||
<%= render Admin::BudgetsWizard::CreationTimelineComponent.new("phases") %>
|
<%= render Admin::BudgetsWizard::CreationTimelineComponent.new("phases") %>
|
||||||
|
|
||||||
<%= render Admin::BudgetPhases::PhasesComponent.new(budget) %>
|
<%= form_for budget, url: update_all_admin_budgets_wizard_budget_budget_phases_path(budget) do |f| %>
|
||||||
|
<%= render Admin::BudgetPhases::PhasesComponent.new(budget, form: f) %>
|
||||||
<%= link_to t("admin.budgets_wizard.phases.continue"),
|
<%= f.submit t("admin.budgets_wizard.phases.continue"), class: "button success" %>
|
||||||
admin_budget_path(budget),
|
<% end %>
|
||||||
class: "button success" %>
|
|
||||||
|
|||||||
@@ -4,9 +4,23 @@ class Admin::BudgetsWizard::PhasesController < Admin::BaseController
|
|||||||
def index
|
def index
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def update_all
|
||||||
|
@budget.update!(phases_params)
|
||||||
|
|
||||||
|
redirect_to admin_budgets_path, notice: t("admin.budgets_wizard.phases.update_all.notice")
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def phases_index
|
def phases_index
|
||||||
admin_budgets_wizard_budget_budget_phases_path(@phase.budget)
|
admin_budgets_wizard_budget_budget_phases_path(@phase.budget)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def phases_params
|
||||||
|
params.require(:budget).permit(allowed_phases_params)
|
||||||
|
end
|
||||||
|
|
||||||
|
def allowed_phases_params
|
||||||
|
{ phases_attributes: [:id, :enabled] }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ class Budget < ApplicationRecord
|
|||||||
has_one :poll
|
has_one :poll
|
||||||
|
|
||||||
after_create :generate_phases
|
after_create :generate_phases
|
||||||
|
accepts_nested_attributes_for :phases
|
||||||
|
|
||||||
scope :published, -> { where(published: true) }
|
scope :published, -> { where(published: true) }
|
||||||
scope :drafting, -> { where.not(id: published) }
|
scope :drafting, -> { where.not(id: published) }
|
||||||
|
|||||||
@@ -106,6 +106,7 @@ en:
|
|||||||
enabled: Enabled
|
enabled: Enabled
|
||||||
actions: Actions
|
actions: Actions
|
||||||
edit_phase: Edit phase
|
edit_phase: Edit phase
|
||||||
|
enable_phase: "Enable %{phase} phase"
|
||||||
active: Active
|
active: Active
|
||||||
blank_dates: Dates are blank
|
blank_dates: Dates are blank
|
||||||
administrators:
|
administrators:
|
||||||
@@ -308,6 +309,8 @@ en:
|
|||||||
phases:
|
phases:
|
||||||
back: "Go back to headings"
|
back: "Go back to headings"
|
||||||
continue: "Finish"
|
continue: "Finish"
|
||||||
|
update_all:
|
||||||
|
notice: "Phases configured successfully"
|
||||||
milestones:
|
milestones:
|
||||||
index:
|
index:
|
||||||
table_id: "ID"
|
table_id: "ID"
|
||||||
|
|||||||
@@ -106,6 +106,7 @@ es:
|
|||||||
enabled: Habilitada
|
enabled: Habilitada
|
||||||
actions: Acciones
|
actions: Acciones
|
||||||
edit_phase: Editar fase
|
edit_phase: Editar fase
|
||||||
|
enable_phase: "Habilitar fase de %{phase}"
|
||||||
active: Activa
|
active: Activa
|
||||||
blank_dates: Sin fechas
|
blank_dates: Sin fechas
|
||||||
administrators:
|
administrators:
|
||||||
@@ -308,6 +309,8 @@ es:
|
|||||||
phases:
|
phases:
|
||||||
back: "Volver a partidas"
|
back: "Volver a partidas"
|
||||||
continue: "Finalizar"
|
continue: "Finalizar"
|
||||||
|
update_all:
|
||||||
|
notice: "Fases configuradas con éxito"
|
||||||
milestones:
|
milestones:
|
||||||
index:
|
index:
|
||||||
table_id: "ID"
|
table_id: "ID"
|
||||||
|
|||||||
@@ -78,7 +78,9 @@ namespace :admin do
|
|||||||
resources :headings, only: [:index, :create, :edit, :update, :destroy]
|
resources :headings, only: [:index, :create, :edit, :update, :destroy]
|
||||||
end
|
end
|
||||||
|
|
||||||
resources :phases, as: "budget_phases", only: [:index, :edit, :update]
|
resources :phases, as: "budget_phases", only: [:index, :edit, :update] do
|
||||||
|
collection { patch :update_all }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,35 @@ describe "Budgets wizard, phases step", :admin do
|
|||||||
expect(page).to have_css "tr", text: "Main Park"
|
expect(page).to have_css "tr", text: "Main Park"
|
||||||
expect(page).to have_css ".creation-timeline"
|
expect(page).to have_css ".creation-timeline"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
scenario "Enable and disable phases" do
|
||||||
|
visit admin_budgets_wizard_budget_budget_phases_path(budget)
|
||||||
|
|
||||||
|
uncheck "Enable Information phase"
|
||||||
|
uncheck "Enable Reviewing voting phase"
|
||||||
|
|
||||||
|
click_button "Finish"
|
||||||
|
|
||||||
|
expect(page).to have_content "Phases configured successfully"
|
||||||
|
|
||||||
|
visit edit_admin_budget_path(budget)
|
||||||
|
|
||||||
|
within "tr", text: "Information" do
|
||||||
|
expect(page).to have_css ".budget-phase-disabled", visible: :all
|
||||||
|
end
|
||||||
|
|
||||||
|
within "tr", text: "Reviewing voting" do
|
||||||
|
expect(page).to have_css ".budget-phase-disabled", visible: :all
|
||||||
|
end
|
||||||
|
|
||||||
|
within "tr", text: "Accepting projects" do
|
||||||
|
expect(page).to have_css ".budget-phase-enabled", visible: :all
|
||||||
|
end
|
||||||
|
|
||||||
|
within "tr", text: "Voting projects" do
|
||||||
|
expect(page).to have_css ".budget-phase-enabled", visible: :all
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "Edit" do
|
describe "Edit" do
|
||||||
|
|||||||
Reference in New Issue
Block a user