Use inheritable class attributes in Query model.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10963 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2012-12-09 13:19:32 +00:00
parent 8ead410f98
commit fb9a87f53e
1 changed files with 44 additions and 51 deletions

View File

@ -101,7 +101,9 @@ class Query < ActiveRecord::Base
validates_length_of :name, :maximum => 255
validate :validate_query_filters
@@operators = { "=" => :label_equals,
class_attribute :operators
self.operators = {
"=" => :label_equals,
"!" => :label_not_equals,
"o" => :label_open_issues,
"c" => :label_closed_issues,
@ -124,11 +126,12 @@ class Query < ActiveRecord::Base
"!~" => :label_not_contains,
"=p" => :label_any_issues_in_project,
"=!p" => :label_any_issues_not_in_project,
"!p" => :label_no_issues_in_project}
"!p" => :label_no_issues_in_project
}
cattr_reader :operators
@@operators_by_filter_type = { :list => [ "=", "!" ],
class_attribute :operators_by_filter_type
self.operators_by_filter_type = {
:list => [ "=", "!" ],
:list_status => [ "o", "=", "!", "c", "*" ],
:list_optional => [ "=", "!", "!*", "*" ],
:list_subprojects => [ "*", "!*", "=" ],
@ -138,11 +141,11 @@ class Query < ActiveRecord::Base
:text => [ "~", "!~", "!*", "*" ],
:integer => [ "=", ">=", "<=", "><", "!*", "*" ],
:float => [ "=", ">=", "<=", "><", "!*", "*" ],
:relation => ["=", "=p", "=!p", "!p", "!*", "*"]}
: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