Merge branch 'master' into polls
This commit is contained in:
17
app/controllers/admin/budget_groups_controller.rb
Normal file
17
app/controllers/admin/budget_groups_controller.rb
Normal file
@@ -0,0 +1,17 @@
|
||||
class Admin::BudgetGroupsController < Admin::BaseController
|
||||
include FeatureFlags
|
||||
feature_flag :budgets
|
||||
|
||||
def create
|
||||
@budget = Budget.find params[:budget_id]
|
||||
@budget.groups.create(budget_group_params)
|
||||
@groups = @budget.groups.includes(:headings)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def budget_group_params
|
||||
params.require(:budget_group).permit(:name)
|
||||
end
|
||||
|
||||
end
|
||||
18
app/controllers/admin/budget_headings_controller.rb
Normal file
18
app/controllers/admin/budget_headings_controller.rb
Normal file
@@ -0,0 +1,18 @@
|
||||
class Admin::BudgetHeadingsController < Admin::BaseController
|
||||
include FeatureFlags
|
||||
feature_flag :budgets
|
||||
|
||||
def create
|
||||
@budget = Budget.find params[:budget_id]
|
||||
@budget_group = @budget.groups.find params[:budget_group_id]
|
||||
@budget_group.headings.create(budget_heading_params)
|
||||
@headings = @budget_group.headings
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def budget_heading_params
|
||||
params.require(:budget_heading).permit(:name, :price, :geozone_id)
|
||||
end
|
||||
|
||||
end
|
||||
86
app/controllers/admin/budget_investments_controller.rb
Normal file
86
app/controllers/admin/budget_investments_controller.rb
Normal file
@@ -0,0 +1,86 @@
|
||||
class Admin::BudgetInvestmentsController < Admin::BaseController
|
||||
include FeatureFlags
|
||||
feature_flag :budgets
|
||||
|
||||
has_filters(%w{valuation_open without_admin managed valuating valuation_finished
|
||||
valuation_finished_feasible selected all},
|
||||
only: [:index, :toggle_selection])
|
||||
|
||||
before_action :load_budget
|
||||
before_action :load_investment, only: [:show, :edit, :update, :toggle_selection]
|
||||
before_action :load_ballot, only: [:show, :index]
|
||||
before_action :load_investments, only: [:index, :toggle_selection]
|
||||
|
||||
def index
|
||||
end
|
||||
|
||||
def show
|
||||
end
|
||||
|
||||
def edit
|
||||
load_admins
|
||||
load_valuators
|
||||
load_tags
|
||||
end
|
||||
|
||||
def update
|
||||
set_valuation_tags
|
||||
if @investment.update(budget_investment_params)
|
||||
redirect_to admin_budget_budget_investment_path(@budget, @investment, Budget::Investment.filter_params(params)),
|
||||
notice: t("flash.actions.update.budget_investment")
|
||||
else
|
||||
load_admins
|
||||
load_valuators
|
||||
load_tags
|
||||
render :edit
|
||||
end
|
||||
end
|
||||
|
||||
def toggle_selection
|
||||
@investment.toggle :selected
|
||||
@investment.save
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def load_investments
|
||||
@investments = Budget::Investment.scoped_filter(params, @current_filter)
|
||||
.order(cached_votes_up: :desc, created_at: :desc)
|
||||
.page(params[:page])
|
||||
end
|
||||
|
||||
def budget_investment_params
|
||||
params.require(:budget_investment)
|
||||
.permit(:title, :description, :external_url, :heading_id, :administrator_id, :valuation_tag_list, valuator_ids: [])
|
||||
end
|
||||
|
||||
def load_budget
|
||||
@budget = Budget.includes(:groups).find params[:budget_id]
|
||||
end
|
||||
|
||||
def load_investment
|
||||
@investment = Budget::Investment.where(budget_id: @budget.id).find params[:id]
|
||||
end
|
||||
|
||||
def load_admins
|
||||
@admins = Administrator.includes(:user).all
|
||||
end
|
||||
|
||||
def load_valuators
|
||||
@valuators = Valuator.includes(:user).all.order("description ASC").order("users.email ASC")
|
||||
end
|
||||
|
||||
def load_tags
|
||||
@tags = Budget::Investment.tags_on(:valuation).order(:name).uniq
|
||||
end
|
||||
|
||||
def load_ballot
|
||||
query = Budget::Ballot.where(user: current_user, budget: @budget)
|
||||
@ballot = @budget.balloting? ? query.first_or_create : query.first_or_initialize
|
||||
end
|
||||
|
||||
def set_valuation_tags
|
||||
@investment.set_tag_list_on(:valuation, budget_investment_params[:valuation_tag_list])
|
||||
params[:budget_investment] = params[:budget_investment].except(:valuation_tag_list)
|
||||
end
|
||||
end
|
||||
48
app/controllers/admin/budgets_controller.rb
Normal file
48
app/controllers/admin/budgets_controller.rb
Normal file
@@ -0,0 +1,48 @@
|
||||
class Admin::BudgetsController < Admin::BaseController
|
||||
include FeatureFlags
|
||||
feature_flag :budgets
|
||||
|
||||
has_filters %w{current finished}, only: :index
|
||||
|
||||
load_and_authorize_resource
|
||||
|
||||
def index
|
||||
@budgets = Budget.send(@current_filter).order(created_at: :desc).page(params[:page])
|
||||
end
|
||||
|
||||
def show
|
||||
@budget = Budget.includes(groups: :headings).find(params[:id])
|
||||
end
|
||||
|
||||
def new
|
||||
end
|
||||
|
||||
def edit
|
||||
end
|
||||
|
||||
def update
|
||||
if @budget.update(budget_params)
|
||||
redirect_to admin_budget_path(@budget), notice: t('admin.budgets.update.notice')
|
||||
else
|
||||
render :edit
|
||||
end
|
||||
end
|
||||
|
||||
def create
|
||||
@budget = Budget.new(budget_params)
|
||||
if @budget.save
|
||||
redirect_to admin_budget_path(@budget), notice: t('admin.budgets.create.notice')
|
||||
else
|
||||
render :new
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def budget_params
|
||||
descriptions = Budget::PHASES.map{|p| "description_#{p}"}.map(&:to_sym)
|
||||
valid_attributes = [:name, :phase, :currency_symbol] + descriptions
|
||||
params.require(:budget).permit(*valid_attributes)
|
||||
end
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user