From 1adf8f062e932bdac3482d6b84b1276d063a4e25 Mon Sep 17 00:00:00 2001 From: hjust Date: Tue, 20 Oct 2009 19:11:52 +0000 Subject: [PATCH] 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 --- app/controllers/cost_reports_controller.rb | 6 +++--- app/models/cost_query.rb | 25 ++++++++++++++++------ 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/app/controllers/cost_reports_controller.rb b/app/controllers/cost_reports_controller.rb index 53e4b00ecd..addc158b97 100644 --- a/app/controllers/cost_reports_controller.rb +++ b/app/controllers/cost_reports_controller.rb @@ -139,18 +139,18 @@ private 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'] @entries = TimeEntry.find :all, {:order => (sort_clause if time_sort_column), :include => [:issue, :activity, :user], - :conditions => cost_statement, + :conditions => time_statement, :limit => limit, :offset => @entry_pages.current.offset} return 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'] @entries = CostEntry.find :all, {:order => (sort_clause if cost_sort_column), diff --git a/app/models/cost_query.rb b/app/models/cost_query.rb index 2626ed9b9d..915678bb96 100644 --- a/app/models/cost_query.rb +++ b/app/models/cost_query.rb @@ -38,7 +38,7 @@ class Filter if available_values available_value_keys = available_values.collect {|o| o[1]} 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 @@ -47,7 +47,7 @@ class Filter attr_reader :operator 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 end @@ -104,7 +104,8 @@ class CostQuery < ActiveRecord::Base 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}, "n" => {:label => :label_no, :simple => true} } @@ -121,7 +122,7 @@ class CostQuery < ActiveRecord::Base end @filter_types = filter_types.merge( { - :integer_zero => {:operators => [ "=", ">=", "<=", "0", "*" ], :multiple => true}, + :integer_zero => {:operators => [ "n=", ">=", "<=", "0", "*" ], :multiple => true}, :boolean => {:operators => [ "y", "n" ], :multiple => false} } ) @@ -166,11 +167,19 @@ class CostQuery < ActiveRecord::Base v[:db_field] = 'user_id' v[:flags] << :watcher else + if ["labor_costs", "material_costs", "overall_costs"].include? k + v[:type] = :integer_zero + end v[:db_table] = Issue.table_name v[:db_field] = k end end + @available_filters[:issues].each_pair do |k,v| + puts "#{k}: #{v[:type]}, #{v[:db_table]}" + end + + if @available_filters[:issues]["author_id"] # add a filter on cost entries for user_id if it is available 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) 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 case filter.operator @@ -388,6 +397,8 @@ private sql = "#{db_table}.#{db_field} IS NOT NULL" when "n" sql = "#{db_table}.#{db_field} IS NULL" + when "n=" + sql = "#{db_table}.#{db_field} = #{CostRate.clean_currency(filter.values).to_f.to_s}" end return sql @@ -399,7 +410,7 @@ private sql = '' case operator 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 "!" sql = "(#{db_table}.#{db_field} IS NULL OR #{db_table}.#{db_field} NOT IN (" + value.collect{|val| "'#{connection.quote_string(val)}'"}.join(",") + "))" when "!*" @@ -443,7 +454,7 @@ private sql = "LOWER(#{db_table}.#{db_field}) NOT LIKE '%#{connection.quote_string(value.first.to_s.downcase)}%'" end - return sql + return sql.blank? ? "1=1" : sql end # Returns a SQL clause for a date or datetime field.