added teh ability for filters/groups to do something on chain-creation

git-svn-id: https://dev.finn.de/svn/cockpit/branches/reporting_merge@1651 7926756e-e54e-46e6-9721-ed318f58905e
pull/6827/head
p.tessenow 14 years ago
parent cb724d02ea
commit 129c97a2b9
  1. 16
      app/models/cost_query.rb
  2. 9
      app/models/cost_query/chainable.rb

@ -12,6 +12,10 @@ class CostQuery < ActiveRecord::Base
@accepted_properties ||= []
end
def self.chain_initializer
return @chain_initializer ||= []
end
def available_filters
CostQuery::Filter.all
end
@ -19,7 +23,7 @@ class CostQuery < ActiveRecord::Base
def transformer
@transformer ||= CostQuery::Transformer.new self
end
def walker
@walker ||= CostQuery::Walker.new self
end
@ -31,12 +35,20 @@ class CostQuery < ActiveRecord::Base
end
def chain(klass = nil, options = {})
@chain ||= Filter::NoFilter.new
build_new_chain unless @chain
@chain = klass.new @chain, options if klass
@chain = @chain.parent until @chain.top?
@chain
end
def build_new_chain
#FIXME: is there a better way to load all filter and groups?
Filter.all && GroupBy.all
@chain = Filter::NoFilter.new
self.class.chain_initializer.each { |block| block.call self }
end
def filter(name, options = {})
add_chain Filter, name, options
end

@ -60,6 +60,15 @@ class CostQuery < ActiveRecord::Base
name.demodulize.underscore
end
##
# The given block is called when a new chain is created for a cost_query.
# The query will be given to the block as a parameter.
# Example:
# initialize_query_with { |query| query.filter CostQuery::Filter::City, :operators => '=', :values => 'Berlin, da great City' }
def self.initialize_query_with(&block)
CostQuery.chain_initializer.push block
end
inherited_attribute :label
inherited_attribute :properties, :list => true

Loading…
Cancel
Save