fixed the filter logic

added special operator for integer tests of costs

git-svn-id: https://dev.finn.de/svn/cockpit/trunk@216 7926756e-e54e-46e6-9721-ed318f58905e
pull/6827/head
hjust 15 years ago
parent 42001cc213
commit 1adf8f062e
  1. 6
      app/controllers/cost_reports_controller.rb
  2. 25
      app/models/cost_query.rb

@ -139,18 +139,18 @@ private
if @query.display_time_entries && !@query.display_cost_entries if @query.display_time_entries && !@query.display_cost_entries
@entry_count = TimeEntry.count(cost_statement) @entry_count = TimeEntry.count(:conditions => time_statement)
@entry_pages = Paginator.new self, @entry_count, limit, params['page'] @entry_pages = Paginator.new self, @entry_count, limit, params['page']
@entries = TimeEntry.find :all, {:order => (sort_clause if time_sort_column), @entries = TimeEntry.find :all, {:order => (sort_clause if time_sort_column),
:include => [:issue, :activity, :user], :include => [:issue, :activity, :user],
:conditions => cost_statement, :conditions => time_statement,
:limit => limit, :limit => limit,
:offset => @entry_pages.current.offset} :offset => @entry_pages.current.offset}
return return
elsif @query.display_cost_entries && !@query.display_time_entries elsif @query.display_cost_entries && !@query.display_time_entries
@entry_count = CostEntry.count(cost_statement) @entry_count = CostEntry.count(:conditions => cost_statement)
@entry_pages = Paginator.new self, @entry_count, limit, params['page'] @entry_pages = Paginator.new self, @entry_count, limit, params['page']
@entries = CostEntry.find :all, {:order => (sort_clause if cost_sort_column), @entries = CostEntry.find :all, {:order => (sort_clause if cost_sort_column),

@ -38,7 +38,7 @@ class Filter
if available_values if available_values
available_value_keys = available_values.collect {|o| o[1]} available_value_keys = available_values.collect {|o| o[1]}
v.each do |value| v.each do |value|
raise ArgumentException("Forbidden value") unless available_value_keys.include? value raise ArgumentError.new("Forbidden value") unless available_value_keys.include? value
end end
end end
@ -47,7 +47,7 @@ class Filter
attr_reader :operator attr_reader :operator
def operator=(o) def operator=(o)
raise ArgumentException("Forbidden operator") unless available_operators.include? o raise ArgumentError.new("Forbidden operator #{o}") unless available_operators.include? o
@operator = o @operator = o
end end
@ -104,7 +104,8 @@ class CostQuery < ActiveRecord::Base
operators.merge( operators.merge(
{ {
"0" => {:label => :label_zero, :simple => true}, "n=" => {:label => :label_equals, :simple => false},
"0" => {:label => :label_none, :simple => true},
"y" => {:label => :label_yes, :simple => true}, "y" => {:label => :label_yes, :simple => true},
"n" => {:label => :label_no, :simple => true} "n" => {:label => :label_no, :simple => true}
} }
@ -121,7 +122,7 @@ class CostQuery < ActiveRecord::Base
end end
@filter_types = filter_types.merge( @filter_types = filter_types.merge(
{ {
:integer_zero => {:operators => [ "=", ">=", "<=", "0", "*" ], :multiple => true}, :integer_zero => {:operators => [ "n=", ">=", "<=", "0", "*" ], :multiple => true},
:boolean => {:operators => [ "y", "n" ], :multiple => false} :boolean => {:operators => [ "y", "n" ], :multiple => false}
} }
) )
@ -166,11 +167,19 @@ class CostQuery < ActiveRecord::Base
v[:db_field] = 'user_id' v[:db_field] = 'user_id'
v[:flags] << :watcher v[:flags] << :watcher
else else
if ["labor_costs", "material_costs", "overall_costs"].include? k
v[:type] = :integer_zero
end
v[:db_table] = Issue.table_name v[:db_table] = Issue.table_name
v[:db_field] = k v[:db_field] = k
end end
end end
@available_filters[:issues].each_pair do |k,v|
puts "#{k}: #{v[:type]}, #{v[:db_table]}"
end
if @available_filters[:issues]["author_id"] if @available_filters[:issues]["author_id"]
# add a filter on cost entries for user_id if it is available # add a filter on cost entries for user_id if it is available
user_values = @available_filters[:issues]["author_id"][:values] user_values = @available_filters[:issues]["author_id"][:values]
@ -378,7 +387,7 @@ private
# filter.column_name, filter.operator, filter.values, db_table, db_field, string_as_null) # filter.column_name, filter.operator, filter.values, db_table, db_field, string_as_null)
sql = sql_for_field(filter.column_name, filter.operator, filter.values, db_table, db_field, string_as_null) sql = sql_for_field(filter.column_name, filter.operator, filter.values, db_table, db_field, string_as_null)
return sql unless sql.blank? return sql unless sql == "1=1"
# We have an operator that was added by us. So we provide the logic here # We have an operator that was added by us. So we provide the logic here
case filter.operator case filter.operator
@ -388,6 +397,8 @@ private
sql = "#{db_table}.#{db_field} IS NOT NULL" sql = "#{db_table}.#{db_field} IS NOT NULL"
when "n" when "n"
sql = "#{db_table}.#{db_field} IS NULL" sql = "#{db_table}.#{db_field} IS NULL"
when "n="
sql = "#{db_table}.#{db_field} = #{CostRate.clean_currency(filter.values).to_f.to_s}"
end end
return sql return sql
@ -399,7 +410,7 @@ private
sql = '' sql = ''
case operator case operator
when "=" when "="
sql = "#{db_table}.#{db_field} IN (" + value.collect{|val| "'#{connection.quote_string(val)}'"}.join(",") + ")" sql = "#{db_table}.#{db_field} IN (" + value.collect{|val| "'#{connection.quote_string(val)}'"}.join(",") + ")" unless value.blank?
when "!" when "!"
sql = "(#{db_table}.#{db_field} IS NULL OR #{db_table}.#{db_field} NOT IN (" + value.collect{|val| "'#{connection.quote_string(val)}'"}.join(",") + "))" sql = "(#{db_table}.#{db_field} IS NULL OR #{db_table}.#{db_field} NOT IN (" + value.collect{|val| "'#{connection.quote_string(val)}'"}.join(",") + "))"
when "!*" when "!*"
@ -443,7 +454,7 @@ private
sql = "LOWER(#{db_table}.#{db_field}) NOT LIKE '%#{connection.quote_string(value.first.to_s.downcase)}%'" sql = "LOWER(#{db_table}.#{db_field}) NOT LIKE '%#{connection.quote_string(value.first.to_s.downcase)}%'"
end end
return sql return sql.blank? ? "1=1" : sql
end end
# Returns a SQL clause for a date or datetime field. # Returns a SQL clause for a date or datetime field.

Loading…
Cancel
Save