re-organize cost_reports_controller

git-svn-id: https://dev.finn.de/svn/cockpit/branches/reporting_merge@1266 7926756e-e54e-46e6-9721-ed318f58905e
pull/6827/head
t.felgentreff 15 years ago
parent a0a55fa008
commit e616da490c
  1. 39
      app/controllers/cost_reports_controller.rb

@ -1,8 +1,18 @@
class CostReportsController < ApplicationController class CostReportsController < ApplicationController
before_filter :find_optional_project, :only => [:index] before_filter :find_optional_project, :only => [:index]
before_filter :set_query, :only => [:index]
helper :reporting 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 # Determines if the request contains filters to set
@ -23,30 +33,33 @@ class CostReportsController < ApplicationController
end end
## ##
# Find a query to search on # Find a query to search on and put it in the session
def query_params def query_params
filters = session[:cost_query] if session_query? filters = session[:cost_query] if session_query?
if set_filter? if set_filter?
filters = {} 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] filters[:values] = params[:values]
end end
filters ||= {:operators => {:user_id => "=", :tweek => "="}, 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 end
## ##
# Build the query from the current request and save it to # Build the query from the current request and save it to
# the session. # the session.
def query def query
session[:cost_query] = query_params filters = query_params
CostQuery.new.tap do |q| CostQuery.new.tap do |q|
(session[:cost_query][:operators] || []).each do |filter, operator| filters[:operators].each do |filter, operator|
unless (session[:cost_query][:values] || {})[filter].nil? unless filters[:values][filter].nil?
require 'ruby-debug'; debugger
q.filter(filter.to_sym, q.filter(filter.to_sym,
:operator => operator, :operator => operator,
:values => session[:cost_query][:values][filter]) :values => filters[:values][filter])
end end
end end
end. end.
@ -54,12 +67,6 @@ class CostReportsController < ApplicationController
row(:project_id).row(:user_id) row(:project_id).row(:user_id)
end end
def index
@query = query
@walker = walker(@query)
render :layout => !request.xhr?
end
private private
def find_optional_project def find_optional_project
@project = Project.find(params[:project_id]) unless params[:project_id].blank? @project = Project.find(params[:project_id]) unless params[:project_id].blank?
@ -68,4 +75,4 @@ class CostReportsController < ApplicationController
rescue ActiveRecord::RecordNotFound rescue ActiveRecord::RecordNotFound
render_404 render_404
end end
end end

Loading…
Cancel
Save