From e616da490c0012e2c69c052b98b67f405e7288c2 Mon Sep 17 00:00:00 2001 From: "t.felgentreff" Date: Wed, 30 Jun 2010 13:05:08 +0000 Subject: [PATCH] re-organize cost_reports_controller git-svn-id: https://dev.finn.de/svn/cockpit/branches/reporting_merge@1266 7926756e-e54e-46e6-9721-ed318f58905e --- app/controllers/cost_reports_controller.rb | 39 +++++++++++++--------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/app/controllers/cost_reports_controller.rb b/app/controllers/cost_reports_controller.rb index cb89f53ea1..c3c09e72e9 100644 --- a/app/controllers/cost_reports_controller.rb +++ b/app/controllers/cost_reports_controller.rb @@ -1,8 +1,18 @@ class CostReportsController < ApplicationController before_filter :find_optional_project, :only => [:index] + before_filter :set_query, :only => [:index] helper :reporting - include ReportingHelper + include ReportingHelper + + def index + render :layout => !request.xhr? + end + + def set_query + @query = query + @walker = walker(@query) + end ## # Determines if the request contains filters to set @@ -23,30 +33,33 @@ class CostReportsController < ApplicationController end ## - # Find a query to search on + # Find a query to search on and put it in the session def query_params filters = session[:cost_query] if session_query? if set_filter? filters = {} - filters[:operators] = params[:operators] + filters[:operators] = Hash[*params[:operators].select do |filter, op| + params[:fields].include? filter.to_s + end.flatten] filters[:values] = params[:values] end filters ||= {:operators => {:user_id => "=", :tweek => "="}, - :values => {:user_id => [User.current.id], :tweek => [Date.today.cweek]}} + :values => {:user_id => [User.current.id], :tweek => [Date.today.cweek]}} + session[:cost_query] = filters + filters end ## # Build the query from the current request and save it to # the session. def query - session[:cost_query] = query_params + filters = query_params CostQuery.new.tap do |q| - (session[:cost_query][:operators] || []).each do |filter, operator| - unless (session[:cost_query][:values] || {})[filter].nil? - require 'ruby-debug'; debugger + filters[:operators].each do |filter, operator| + unless filters[:values][filter].nil? q.filter(filter.to_sym, :operator => operator, - :values => session[:cost_query][:values][filter]) + :values => filters[:values][filter]) end end end. @@ -54,12 +67,6 @@ class CostReportsController < ApplicationController row(:project_id).row(:user_id) end - def index - @query = query - @walker = walker(@query) - render :layout => !request.xhr? - end - private def find_optional_project @project = Project.find(params[:project_id]) unless params[:project_id].blank? @@ -68,4 +75,4 @@ class CostReportsController < ApplicationController rescue ActiveRecord::RecordNotFound render_404 end -end \ No newline at end of file +end