Files
nairobi/app/controllers/budgets/executions_controller.rb
Javi Martín 91d91f2ebf Remove city heading specific code
This code accidentally made it to consul, and it's specific to Madrid.
2018-12-14 18:15:51 +01:00

39 lines
1.2 KiB
Ruby

module Budgets
class ExecutionsController < ApplicationController
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
end
private
def investments_by_heading
if params[:status].present?
@budget.investments.winners
.joins(:milestones).includes(:milestones)
.select { |i| i.milestones.published.with_status
.order_by_publication_date.last
.try(:status_id) == params[:status].to_i }
.uniq
.group_by(&:heading)
else
@budget.investments.winners
.joins(:milestones).includes(:milestones)
.distinct.group_by(&:heading)
end
end
def load_budget
@budget = Budget.find_by(slug: params[:id]) || Budget.find_by(id: params[:id])
end
def investments_by_heading_ordered_alphabetically
investments_by_heading.sort { |a, b| a[0].name <=> b[0].name }
end
end
end