Files
nairobi/app/controllers/budgets/executions_controller.rb
Javi Martín 70a07c095f Add and apply Style/BlockDelimiters rubocop rule
We were already using it most of the time, but there were a few places
were we used brackets for multiline blocks.
2019-10-05 14:44:14 +02:00

50 lines
1.5 KiB
Ruby

module Budgets
class ExecutionsController < ApplicationController
include DownloadSettingsHelper
before_action :load_budget
load_and_authorize_resource :budget
def show
authorize! :read_executions, @budget
@statuses = Milestone::Status.all
@investments_by_heading = investments_by_heading_ordered_alphabetically.to_h
downloadables = []
investments_by_heading_ordered_alphabetically
.map { |heading| downloadables.concat heading[1] }
respond_to do |format|
format.html
format.csv do
send_data to_csv(downloadables, Budget::Investment, 1),
type: "text/csv",
disposition: "attachment",
filename: "budget_investment_milestones.csv"
end
end
end
private
def investments_by_heading
base = @budget.investments.winners
base = base.joins(milestones: :translations).includes(:milestones)
base = base.tagged_with(params[:milestone_tag]) if params[:milestone_tag].present?
if params[:status].present?
base = base.with_milestone_status_id(params[:status])
base.uniq.group_by(&:heading)
else
base.distinct.group_by(&:heading)
end
end
def load_budget
@budget = Budget.find_by_slug_or_id params[:budget_id]
end
def investments_by_heading_ordered_alphabetically
investments_by_heading.sort { |a, b| a[0].name <=> b[0].name }
end
end
end