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) : {}
|
||||
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)
|
||||
@comment_flags = current_user ? current_user.comment_flags(comments) : {}
|
||||
end
|
||||
|
||||
@@ -24,8 +24,8 @@ module Budgets
|
||||
respond_to :html, :js
|
||||
|
||||
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
|
||||
load_investment_votes(@investments)
|
||||
end
|
||||
|
||||
def new
|
||||
@@ -35,15 +35,18 @@ module Budgets
|
||||
@commentable = @investment
|
||||
@comment_tree = CommentTree.new(@commentable, params[:page], @current_order)
|
||||
set_comment_flags(@comment_tree.comments)
|
||||
set_budget_investment_votes(@investment)
|
||||
load_investment_votes(@investment)
|
||||
end
|
||||
|
||||
def create
|
||||
@investment.author = current_user
|
||||
|
||||
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>")
|
||||
redirect_to @investment, notice: notice, flash: { html_safe: true }
|
||||
activity_link = view_context.link_to(t('layouts.header.my_activity_link'),
|
||||
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
|
||||
render :new
|
||||
end
|
||||
@@ -56,11 +59,15 @@ module Budgets
|
||||
|
||||
def vote
|
||||
@investment.register_selection(current_user)
|
||||
set_budget_investment_votes(@investment)
|
||||
load_investment_votes(@investment)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def load_investment_votes(investments)
|
||||
@investment_votes = current_user ? current_user.budget_investment_votes(investments) : {}
|
||||
end
|
||||
|
||||
def set_random_seed
|
||||
if params[:order] == 'random' || params[:order].blank?
|
||||
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]
|
||||
|
||||
def index
|
||||
set_investment_votes(@investments)
|
||||
@investments = @investments.apply_filters_and_search(params).page(params[:page])
|
||||
load_investment_votes(@investments)
|
||||
end
|
||||
|
||||
def new
|
||||
@@ -27,22 +27,22 @@ class Management::Budgets::InvestmentsController < Management::BaseController
|
||||
end
|
||||
|
||||
def show
|
||||
set_investment_votes(@investment)
|
||||
load_investment_votes(@investment)
|
||||
end
|
||||
|
||||
def vote
|
||||
@investment.register_selection(managed_user)
|
||||
set_investment_votes(@investment)
|
||||
load_investment_votes(@investment)
|
||||
end
|
||||
|
||||
def print
|
||||
set_investment_votes(@investments)
|
||||
@investments = @investments.apply_filters_and_search(params).order(cached_votes_up: :desc).for_render.limit(15)
|
||||
load_investment_votes(@investments)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_investment_votes(investments)
|
||||
def load_investment_votes(investments)
|
||||
@investment_votes = managed_user ? managed_user.budget_investment_votes(investments) : {}
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user