Added admin budget phases controller and routes

This commit is contained in:
María Checa
2018-01-18 21:32:58 +01:00
parent 26656a8dfd
commit 1abb7f0310
3 changed files with 30 additions and 0 deletions

View File

@@ -0,0 +1,26 @@
class Admin::BudgetPhasesController < Admin::BaseController
before_action :load_phase, only: [:edit, :update]
def edit; end
def update
if @phase.update(budget_phase_params)
redirect_to edit_admin_budget_path(@phase.budget), notice: t("flash.actions.save_changes.notice")
else
render :edit
end
end
private
def load_phase
@phase = Budget::Phase.find(params[:id])
end
def budget_phase_params
valid_attributes = [:starts_at, :ends_at, :summary, :description, :enabled]
params.require(:budget_phase).permit(*valid_attributes)
end
end

View File

@@ -3,6 +3,7 @@ class Budget
PHASE_KINDS = %w(drafting accepting reviewing selecting valuating publishing_prices balloting PHASE_KINDS = %w(drafting accepting reviewing selecting valuating publishing_prices balloting
reviewing_ballots finished).freeze reviewing_ballots finished).freeze
PUBLISHED_PRICES_PHASES = %w(publishing_prices balloting reviewing_ballots finished).freeze PUBLISHED_PRICES_PHASES = %w(publishing_prices balloting reviewing_ballots finished).freeze
SUMMARY_MAX_LENGTH = 1000
DESCRIPTION_MAX_LENGTH = 2000 DESCRIPTION_MAX_LENGTH = 2000
belongs_to :budget belongs_to :budget
@@ -11,6 +12,7 @@ class Budget
validates :budget, presence: true validates :budget, presence: true
validates :kind, presence: true, uniqueness: { scope: :budget }, inclusion: { in: PHASE_KINDS } validates :kind, presence: true, uniqueness: { scope: :budget }, inclusion: { in: PHASE_KINDS }
validates :summary, length: { maximum: SUMMARY_MAX_LENGTH }
validates :description, length: { maximum: DESCRIPTION_MAX_LENGTH } validates :description, length: { maximum: DESCRIPTION_MAX_LENGTH }
validate :invalid_dates_range? validate :invalid_dates_range?
validate :prev_phase_dates_valid? validate :prev_phase_dates_valid?

View File

@@ -51,6 +51,8 @@ namespace :admin do
resources :budget_investment_milestones resources :budget_investment_milestones
member { patch :toggle_selection } member { patch :toggle_selection }
end end
resources :budget_phases, only: [:edit, :update]
end end
resources :signature_sheets, only: [:index, :new, :create, :show] resources :signature_sheets, only: [:index, :new, :create, :show]