From c505337fc59c72d68f7e7ccff22e01ee9ddb22af Mon Sep 17 00:00:00 2001 From: "t.felgentreff" Date: Thu, 21 Oct 2010 16:51:08 +0000 Subject: [PATCH] refactoring: split set_cost_types git-svn-id: https://dev.finn.de/svn/cockpit/branches/deployment_merge@2071 7926756e-e54e-46e6-9721-ed318f58905e --- app/controllers/cost_reports_controller.rb | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/app/controllers/cost_reports_controller.rb b/app/controllers/cost_reports_controller.rb index a7b5ed9714..d8085f1cb5 100644 --- a/app/controllers/cost_reports_controller.rb +++ b/app/controllers/cost_reports_controller.rb @@ -159,23 +159,23 @@ class CostReportsController < ApplicationController end ## - # FIXME: Split, also ugly - # This method does three things: - # set the @unit_id -> this is used in the index for determining the active unit tab - # set the @cost_types -> this is used to determine which tabs to display - # possibly set the @cost_type -> this is used to select the proper units for display - def set_cost_types(value = nil) - @cost_types = session[:cost_query][:filters][:values][:cost_type_id].try(:collect, &:to_i) || (-1..CostType.count) + # Determine active cost types, the currently selected unit and corresponding cost type + def set_cost_types + set_active_cost_types set_unit set_cost_type end + # Determine the currently active unit from the parameters or session + # sets the @unit_id -> this is used in the index for determining the active unit tab def set_unit - @unit_id = value || params[:unit].try(:to_i) || session[:unit_id].to_i + @unit_id = params[:unit].try(:to_i) || session[:unit_id].to_i @unit_id = 0 unless @cost_types.include? @unit_id session[:unit_id] = @unit_id end + # Determine the active cost type, if it is not labor or money, and add a hidden filter to the query + # sets the @cost_type -> this is used to select the proper units for display def set_cost_type if @unit_id != 0 @query.filter :cost_type_id, :operator => '=', :value => @unit_id.to_s, :display => false @@ -183,6 +183,12 @@ class CostReportsController < ApplicationController end end + # set the @cost_types -> this is used to determine which tabs to display + def set_active_cost_types + @cost_types = session[:cost_query][:filters][:values][:cost_type_id].try(:collect, &:to_i) + @cost_types ||= (-1..CostType.count) + end + def load_all CostQuery::GroupBy.all CostQuery::Filter.all