Added admin budget phases controller and routes
This commit is contained in:
26
app/controllers/admin/budget_phases_controller.rb
Normal file
26
app/controllers/admin/budget_phases_controller.rb
Normal 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
|
||||
@@ -3,6 +3,7 @@ class Budget
|
||||
PHASE_KINDS = %w(drafting accepting reviewing selecting valuating 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
|
||||
|
||||
belongs_to :budget
|
||||
@@ -11,6 +12,7 @@ class Budget
|
||||
|
||||
validates :budget, presence: true
|
||||
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 }
|
||||
validate :invalid_dates_range?
|
||||
validate :prev_phase_dates_valid?
|
||||
|
||||
@@ -51,6 +51,8 @@ namespace :admin do
|
||||
resources :budget_investment_milestones
|
||||
member { patch :toggle_selection }
|
||||
end
|
||||
|
||||
resources :budget_phases, only: [:edit, :update]
|
||||
end
|
||||
|
||||
resources :signature_sheets, only: [:index, :new, :create, :show]
|
||||
|
||||
Reference in New Issue
Block a user