Refactors set_investment_votes
This commit is contained in:
@@ -80,10 +80,6 @@ class ApplicationController < ActionController::Base
|
|||||||
@spending_proposal_votes = current_user ? current_user.spending_proposal_votes(spending_proposals) : {}
|
@spending_proposal_votes = current_user ? current_user.spending_proposal_votes(spending_proposals) : {}
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_budget_investment_votes(budget_investments)
|
|
||||||
@budget_investment_votes = current_user ? current_user.budget_investment_votes(budget_investments) : {}
|
|
||||||
end
|
|
||||||
|
|
||||||
def set_comment_flags(comments)
|
def set_comment_flags(comments)
|
||||||
@comment_flags = current_user ? current_user.comment_flags(comments) : {}
|
@comment_flags = current_user ? current_user.comment_flags(comments) : {}
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -24,8 +24,8 @@ module Budgets
|
|||||||
respond_to :html, :js
|
respond_to :html, :js
|
||||||
|
|
||||||
def index
|
def index
|
||||||
set_budget_investment_votes(@investments)
|
|
||||||
@investments = @investments.apply_filters_and_search(params).send("sort_by_#{@current_order}").page(params[:page]).per(10).for_render
|
@investments = @investments.apply_filters_and_search(params).send("sort_by_#{@current_order}").page(params[:page]).per(10).for_render
|
||||||
|
load_investment_votes(@investments)
|
||||||
end
|
end
|
||||||
|
|
||||||
def new
|
def new
|
||||||
@@ -35,15 +35,18 @@ module Budgets
|
|||||||
@commentable = @investment
|
@commentable = @investment
|
||||||
@comment_tree = CommentTree.new(@commentable, params[:page], @current_order)
|
@comment_tree = CommentTree.new(@commentable, params[:page], @current_order)
|
||||||
set_comment_flags(@comment_tree.comments)
|
set_comment_flags(@comment_tree.comments)
|
||||||
set_budget_investment_votes(@investment)
|
load_investment_votes(@investment)
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
@investment.author = current_user
|
@investment.author = current_user
|
||||||
|
|
||||||
if @investment.save
|
if @investment.save
|
||||||
notice = t('flash.actions.create.budget_investment', activity: "<a href='#{user_path(current_user, filter: :budget_investments)}'>#{t('layouts.header.my_activity_link')}</a>")
|
activity_link = view_context.link_to(t('layouts.header.my_activity_link'),
|
||||||
redirect_to @investment, notice: notice, flash: { html_safe: true }
|
user_path(current_user, filter: :budget_investments))
|
||||||
|
redirect_to @investment,
|
||||||
|
flash: { html_safe: true },
|
||||||
|
notice: t('flash.actions.create.budget_investment', activity: activity_link)
|
||||||
else
|
else
|
||||||
render :new
|
render :new
|
||||||
end
|
end
|
||||||
@@ -56,11 +59,15 @@ module Budgets
|
|||||||
|
|
||||||
def vote
|
def vote
|
||||||
@investment.register_selection(current_user)
|
@investment.register_selection(current_user)
|
||||||
set_budget_investment_votes(@investment)
|
load_investment_votes(@investment)
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def load_investment_votes(investments)
|
||||||
|
@investment_votes = current_user ? current_user.budget_investment_votes(investments) : {}
|
||||||
|
end
|
||||||
|
|
||||||
def set_random_seed
|
def set_random_seed
|
||||||
if params[:order] == 'random' || params[:order].blank?
|
if params[:order] == 'random' || params[:order].blank?
|
||||||
params[:random_seed] ||= rand(99)/100.0
|
params[:random_seed] ||= rand(99)/100.0
|
||||||
|
|||||||
@@ -7,8 +7,8 @@ class Management::Budgets::InvestmentsController < Management::BaseController
|
|||||||
before_action :load_heading, only: [:index, :show, :print]
|
before_action :load_heading, only: [:index, :show, :print]
|
||||||
|
|
||||||
def index
|
def index
|
||||||
set_investment_votes(@investments)
|
|
||||||
@investments = @investments.apply_filters_and_search(params).page(params[:page])
|
@investments = @investments.apply_filters_and_search(params).page(params[:page])
|
||||||
|
load_investment_votes(@investments)
|
||||||
end
|
end
|
||||||
|
|
||||||
def new
|
def new
|
||||||
@@ -27,22 +27,22 @@ class Management::Budgets::InvestmentsController < Management::BaseController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
set_investment_votes(@investment)
|
load_investment_votes(@investment)
|
||||||
end
|
end
|
||||||
|
|
||||||
def vote
|
def vote
|
||||||
@investment.register_selection(managed_user)
|
@investment.register_selection(managed_user)
|
||||||
set_investment_votes(@investment)
|
load_investment_votes(@investment)
|
||||||
end
|
end
|
||||||
|
|
||||||
def print
|
def print
|
||||||
set_investment_votes(@investments)
|
|
||||||
@investments = @investments.apply_filters_and_search(params).order(cached_votes_up: :desc).for_render.limit(15)
|
@investments = @investments.apply_filters_and_search(params).order(cached_votes_up: :desc).for_render.limit(15)
|
||||||
|
load_investment_votes(@investments)
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def set_investment_votes(investments)
|
def load_investment_votes(investments)
|
||||||
@investment_votes = managed_user ? managed_user.budget_investment_votes(investments) : {}
|
@investment_votes = managed_user ? managed_user.budget_investment_votes(investments) : {}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user