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:
parent
8ead410f98
commit
fb9a87f53e
|
@ -101,48 +101,51 @@ class Query < ActiveRecord::Base
|
||||||
validates_length_of :name, :maximum => 255
|
validates_length_of :name, :maximum => 255
|
||||||
validate :validate_query_filters
|
validate :validate_query_filters
|
||||||
|
|
||||||
@@operators = { "=" => :label_equals,
|
class_attribute :operators
|
||||||
"!" => :label_not_equals,
|
self.operators = {
|
||||||
"o" => :label_open_issues,
|
"=" => :label_equals,
|
||||||
"c" => :label_closed_issues,
|
"!" => :label_not_equals,
|
||||||
"!*" => :label_none,
|
"o" => :label_open_issues,
|
||||||
"*" => :label_any,
|
"c" => :label_closed_issues,
|
||||||
">=" => :label_greater_or_equal,
|
"!*" => :label_none,
|
||||||
"<=" => :label_less_or_equal,
|
"*" => :label_any,
|
||||||
"><" => :label_between,
|
">=" => :label_greater_or_equal,
|
||||||
"<t+" => :label_in_less_than,
|
"<=" => :label_less_or_equal,
|
||||||
">t+" => :label_in_more_than,
|
"><" => :label_between,
|
||||||
"><t+"=> :label_in_the_next_days,
|
"<t+" => :label_in_less_than,
|
||||||
"t+" => :label_in,
|
">t+" => :label_in_more_than,
|
||||||
"t" => :label_today,
|
"><t+"=> :label_in_the_next_days,
|
||||||
"w" => :label_this_week,
|
"t+" => :label_in,
|
||||||
">t-" => :label_less_than_ago,
|
"t" => :label_today,
|
||||||
"<t-" => :label_more_than_ago,
|
"w" => :label_this_week,
|
||||||
"><t-"=> :label_in_the_past_days,
|
">t-" => :label_less_than_ago,
|
||||||
"t-" => :label_ago,
|
"<t-" => :label_more_than_ago,
|
||||||
"~" => :label_contains,
|
"><t-"=> :label_in_the_past_days,
|
||||||
"!~" => :label_not_contains,
|
"t-" => :label_ago,
|
||||||
"=p" => :label_any_issues_in_project,
|
"~" => :label_contains,
|
||||||
"=!p" => :label_any_issues_not_in_project,
|
"!~" => :label_not_contains,
|
||||||
"!p" => :label_no_issues_in_project}
|
"=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+", "t+", "t", "w", ">t-", "<t-", "><t-", "t-", "!*", "*" ],
|
||||||
|
:date_past => [ "=", ">=", "<=", "><", ">t-", "<t-", "><t-", "t-", "t", "w", "!*", "*" ],
|
||||||
|
:string => [ "=", "~", "!", "!~", "!*", "*" ],
|
||||||
|
:text => [ "~", "!~", "!*", "*" ],
|
||||||
|
:integer => [ "=", ">=", "<=", "><", "!*", "*" ],
|
||||||
|
:float => [ "=", ">=", "<=", "><", "!*", "*" ],
|
||||||
|
:relation => ["=", "=p", "=!p", "!p", "!*", "*"]
|
||||||
|
}
|
||||||
|
|
||||||
@@operators_by_filter_type = { :list => [ "=", "!" ],
|
class_attribute :available_columns
|
||||||
:list_status => [ "o", "=", "!", "c", "*" ],
|
self.available_columns = [
|
||||||
:list_optional => [ "=", "!", "!*", "*" ],
|
|
||||||
:list_subprojects => [ "*", "!*", "=" ],
|
|
||||||
:date => [ "=", ">=", "<=", "><", "<t+", ">t+", "><t+", "t+", "t", "w", ">t-", "<t-", "><t-", "t-", "!*", "*" ],
|
|
||||||
:date_past => [ "=", ">=", "<=", "><", ">t-", "<t-", "><t-", "t-", "t", "w", "!*", "*" ],
|
|
||||||
:string => [ "=", "~", "!", "!~", "!*", "*" ],
|
|
||||||
:text => [ "~", "!~", "!*", "*" ],
|
|
||||||
:integer => [ "=", ">=", "<=", "><", "!*", "*" ],
|
|
||||||
:float => [ "=", ">=", "<=", "><", "!*", "*" ],
|
|
||||||
:relation => ["=", "=p", "=!p", "!p", "!*", "*"]}
|
|
||||||
|
|
||||||
cattr_reader :operators_by_filter_type
|
|
||||||
|
|
||||||
@@available_columns = [
|
|
||||||
QueryColumn.new(:project, :sortable => "#{Project.table_name}.name", :groupable => true),
|
QueryColumn.new(:project, :sortable => "#{Project.table_name}.name", :groupable => true),
|
||||||
QueryColumn.new(:tracker, :sortable => "#{Tracker.table_name}.position", :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),
|
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(:relations, :caption => :label_related_issues),
|
||||||
QueryColumn.new(:description, :inline => false)
|
QueryColumn.new(:description, :inline => false)
|
||||||
]
|
]
|
||||||
cattr_reader :available_columns
|
|
||||||
|
|
||||||
scope :visible, lambda {|*args|
|
scope :visible, lambda {|*args|
|
||||||
user = args.shift || User.current
|
user = args.shift || User.current
|
||||||
|
@ -398,11 +400,6 @@ class Query < ActiveRecord::Base
|
||||||
# check if field is defined as an available filter
|
# check if field is defined as an available filter
|
||||||
if available_filters.has_key? field
|
if available_filters.has_key? field
|
||||||
filter_options = available_filters[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 || [''])}
|
filters[field] = {:operator => operator, :values => (values || [''])}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -410,7 +407,7 @@ class Query < ActiveRecord::Base
|
||||||
def add_short_filter(field, expression)
|
def add_short_filter(field, expression)
|
||||||
return unless expression && available_filters.has_key?(field)
|
return unless expression && available_filters.has_key?(field)
|
||||||
field_type = available_filters[field][:type]
|
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)}(.*)$/
|
next unless expression =~ /^#{Regexp.escape(operator)}(.*)$/
|
||||||
add_filter field, operator, $1.present? ? $1.split('|') : ['']
|
add_filter field, operator, $1.present? ? $1.split('|') : ['']
|
||||||
end || add_filter(field, '=', expression.split('|'))
|
end || add_filter(field, '=', expression.split('|'))
|
||||||
|
@ -483,10 +480,6 @@ class Query < ActiveRecord::Base
|
||||||
@available_columns
|
@available_columns
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.available_columns=(v)
|
|
||||||
self.available_columns = (v)
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.add_available_column(column)
|
def self.add_available_column(column)
|
||||||
self.available_columns << (column) if column.is_a?(QueryColumn)
|
self.available_columns << (column) if column.is_a?(QueryColumn)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue