From fb9a87f53ecd1bce3afef08cea0237e227cd400d Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sun, 9 Dec 2012 13:19:32 +0000 Subject: [PATCH] Use inheritable class attributes in Query model. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10963 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/models/query.rb | 95 +++++++++++++++++++++------------------------ 1 file changed, 44 insertions(+), 51 deletions(-) diff --git a/app/models/query.rb b/app/models/query.rb index 381d18745..4999cce12 100644 --- a/app/models/query.rb +++ b/app/models/query.rb @@ -101,48 +101,51 @@ class Query < ActiveRecord::Base validates_length_of :name, :maximum => 255 validate :validate_query_filters - @@operators = { "=" => :label_equals, - "!" => :label_not_equals, - "o" => :label_open_issues, - "c" => :label_closed_issues, - "!*" => :label_none, - "*" => :label_any, - ">=" => :label_greater_or_equal, - "<=" => :label_less_or_equal, - "><" => :label_between, - " :label_in_less_than, - ">t+" => :label_in_more_than, - "> :label_in_the_next_days, - "t+" => :label_in, - "t" => :label_today, - "w" => :label_this_week, - ">t-" => :label_less_than_ago, - " :label_more_than_ago, - "> :label_in_the_past_days, - "t-" => :label_ago, - "~" => :label_contains, - "!~" => :label_not_contains, - "=p" => :label_any_issues_in_project, - "=!p" => :label_any_issues_not_in_project, - "!p" => :label_no_issues_in_project} + class_attribute :operators + self.operators = { + "=" => :label_equals, + "!" => :label_not_equals, + "o" => :label_open_issues, + "c" => :label_closed_issues, + "!*" => :label_none, + "*" => :label_any, + ">=" => :label_greater_or_equal, + "<=" => :label_less_or_equal, + "><" => :label_between, + " :label_in_less_than, + ">t+" => :label_in_more_than, + "> :label_in_the_next_days, + "t+" => :label_in, + "t" => :label_today, + "w" => :label_this_week, + ">t-" => :label_less_than_ago, + " :label_more_than_ago, + "> :label_in_the_past_days, + "t-" => :label_ago, + "~" => :label_contains, + "!~" => :label_not_contains, + "=p" => :label_any_issues_in_project, + "=!p" => :label_any_issues_not_in_project, + "!p" => :label_no_issues_in_project + } - cattr_reader :operators + class_attribute :operators_by_filter_type + self.operators_by_filter_type = { + :list => [ "=", "!" ], + :list_status => [ "o", "=", "!", "c", "*" ], + :list_optional => [ "=", "!", "!*", "*" ], + :list_subprojects => [ "*", "!*", "=" ], + :date => [ "=", ">=", "<=", "><", "t+", ">t-", " [ "=", ">=", "<=", "><", ">t-", " [ "=", "~", "!", "!~", "!*", "*" ], + :text => [ "~", "!~", "!*", "*" ], + :integer => [ "=", ">=", "<=", "><", "!*", "*" ], + :float => [ "=", ">=", "<=", "><", "!*", "*" ], + :relation => ["=", "=p", "=!p", "!p", "!*", "*"] + } - @@operators_by_filter_type = { :list => [ "=", "!" ], - :list_status => [ "o", "=", "!", "c", "*" ], - :list_optional => [ "=", "!", "!*", "*" ], - :list_subprojects => [ "*", "!*", "=" ], - :date => [ "=", ">=", "<=", "><", "t+", ">t-", " [ "=", ">=", "<=", "><", ">t-", " [ "=", "~", "!", "!~", "!*", "*" ], - :text => [ "~", "!~", "!*", "*" ], - :integer => [ "=", ">=", "<=", "><", "!*", "*" ], - :float => [ "=", ">=", "<=", "><", "!*", "*" ], - :relation => ["=", "=p", "=!p", "!p", "!*", "*"]} - - cattr_reader :operators_by_filter_type - - @@available_columns = [ + class_attribute :available_columns + self.available_columns = [ QueryColumn.new(:project, :sortable => "#{Project.table_name}.name", :groupable => true), QueryColumn.new(:tracker, :sortable => "#{Tracker.table_name}.position", :groupable => true), QueryColumn.new(:parent, :sortable => ["#{Issue.table_name}.root_id", "#{Issue.table_name}.lft ASC"], :default_order => 'desc', :caption => :field_parent_issue), @@ -162,7 +165,6 @@ class Query < ActiveRecord::Base QueryColumn.new(:relations, :caption => :label_related_issues), QueryColumn.new(:description, :inline => false) ] - cattr_reader :available_columns scope :visible, lambda {|*args| user = args.shift || User.current @@ -398,11 +400,6 @@ class Query < ActiveRecord::Base # check if field is defined as an available filter if available_filters.has_key? field filter_options = available_filters[field] - # check if operator is allowed for that filter - #if @@operators_by_filter_type[filter_options[:type]].include? operator - # allowed_values = values & ([""] + (filter_options[:values] || []).collect {|val| val[1]}) - # filters[field] = {:operator => operator, :values => allowed_values } if (allowed_values.first and !allowed_values.first.empty?) or ["o", "c", "!*", "*", "t"].include? operator - #end filters[field] = {:operator => operator, :values => (values || [''])} end end @@ -410,7 +407,7 @@ class Query < ActiveRecord::Base def add_short_filter(field, expression) return unless expression && available_filters.has_key?(field) field_type = available_filters[field][:type] - @@operators_by_filter_type[field_type].sort.reverse.detect do |operator| + operators_by_filter_type[field_type].sort.reverse.detect do |operator| next unless expression =~ /^#{Regexp.escape(operator)}(.*)$/ add_filter field, operator, $1.present? ? $1.split('|') : [''] end || add_filter(field, '=', expression.split('|')) @@ -483,10 +480,6 @@ class Query < ActiveRecord::Base @available_columns end - def self.available_columns=(v) - self.available_columns = (v) - end - def self.add_available_column(column) self.available_columns << (column) if column.is_a?(QueryColumn) end