Files
nairobi/app/controllers/budgets/executions_controller.rb
Javi Martín db97f9d08c Add and apply rubocop rules for empty lines
We were very inconsistent regarding these rules.

Personally I prefer no empty lines around blocks, clases, etc... as
recommended by the Ruby style guide [1], and they're the default values
in rubocop, so those are the settings I'm applying.

The exception is the `private` access modifier, since we were leaving
empty lines around it most of the time. That's the default rubocop rule
as well. Personally I don't have a strong preference about this one.


[1] https://rubystyle.guide/#empty-lines-around-bodies
2019-10-24 17:11:47 +02:00

51 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