introduces Query#to_params for firing the correct param hashes for saved queries

pull/6827/head
jwollert 14 years ago
parent 9a66fe30af
commit 67018cf7f2
  1. 25
      redmine_reporting/app/models/cost_query.rb

@ -24,14 +24,14 @@ class CostQuery < ActiveRecord::Base
def self.deserialize(hash) def self.deserialize(hash)
self.new.tap do |q| self.new.tap do |q|
# have to take the reverse to regain the original order hash[:filters].each {|name, opts| q.filter(name, opts) }
hash[:filters].reverse.each {|name, opts| q.filter(name, opts) } hash[:group_bys].each {|name, opts| q.group_by(name, opts) }
hash[:group_bys].reverse.each {|name, opts| q.group_by(name, opts) }
end end
end end
def serialize def serialize
{ :filters => filters.collect(&:serialize), :group_bys => group_bys.collect(&:serialize) } # have to take the reverse to regain the original order when deserializing
{ :filters => filters.collect(&:serialize).reverse, :group_bys => group_bys.collect(&:serialize).reverse }
end end
def yamlize! def yamlize!
@ -118,6 +118,23 @@ class CostQuery < ActiveRecord::Base
chain.to_s chain.to_s
end end
def to_params
params = {}
sel_filters = filters.select { |f| f.class.selectable? }
params[:operators] = sel_filters.inject({}) do |hash, filter|
hash[filter.class.underscore_name.to_sym] = filter.operator.name
hash
end
params[:values] = sel_filters.inject({}) do |hash, filter|
hash[filter.class.underscore_name.to_sym] = filter.values
hash
end
rows = group_bys.select &:row?
columns = group_bys - rows
params[:groups] = { :rows => rows.map { |gb| gb.class.field }, :columns => columns.map { |gb| gb.class.field } }
params
end
private private
def minimal_chain! def minimal_chain!

Loading…
Cancel
Save