@@ -101,48 +101,51 class Query < ActiveRecord::Base | |||
|
101 | 101 | validates_length_of :name, :maximum => 255 |
|
102 | 102 | validate :validate_query_filters |
|
103 | 103 | |
|
104 | @@operators = { "=" => :label_equals, | |
|
105 | "!" => :label_not_equals, | |
|
106 |
|
|
|
107 | "c" => :label_closed_issues, | |
|
108 | "!*" => :label_none, | |
|
109 | "*" => :label_any, | |
|
110 | ">=" => :label_greater_or_equal, | |
|
111 | "<=" => :label_less_or_equal, | |
|
112 |
|
|
|
113 |
|
|
|
114 | ">t+" => :label_in_more_than, | |
|
115 |
|
|
|
116 |
|
|
|
117 | "t" => :label_today, | |
|
118 | "w" => :label_this_week, | |
|
119 | ">t-" => :label_less_than_ago, | |
|
120 | "<t-" => :label_more_than_ago, | |
|
121 | "><t-"=> :label_in_the_past_days, | |
|
122 |
|
|
|
123 | "~" => :label_contains, | |
|
124 | "!~" => :label_not_contains, | |
|
125 | "=p" => :label_any_issues_in_project, | |
|
126 | "=!p" => :label_any_issues_not_in_project, | |
|
127 |
|
|
|
128 | ||
|
129 | cattr_reader :operators | |
|
130 | ||
|
131 | @@operators_by_filter_type = { :list => [ "=", "!" ], | |
|
132 | :list_status => [ "o", "=", "!", "c", "*" ], | |
|
133 | :list_optional => [ "=", "!", "!*", "*" ], | |
|
134 | :list_subprojects => [ "*", "!*", "=" ], | |
|
135 | :date => [ "=", ">=", "<=", "><", "<t+", ">t+", "><t+", "t+", "t", "w", ">t-", "<t-", "><t-", "t-", "!*", "*" ], | |
|
136 | :date_past => [ "=", ">=", "<=", "><", ">t-", "<t-", "><t-", "t-", "t", "w", "!*", "*" ], | |
|
137 | :string => [ "=", "~", "!", "!~", "!*", "*" ], | |
|
138 | :text => [ "~", "!~", "!*", "*" ], | |
|
139 | :integer => [ "=", ">=", "<=", "><", "!*", "*" ], | |
|
140 |
|
|
|
141 | :relation => ["=", "=p", "=!p", "!p", "!*", "*"]} | |
|
142 | ||
|
143 | cattr_reader :operators_by_filter_type | |
|
144 | ||
|
145 | @@available_columns = [ | |
|
104 | class_attribute :operators | |
|
105 | self.operators = { | |
|
106 | "=" => :label_equals, | |
|
107 | "!" => :label_not_equals, | |
|
108 | "o" => :label_open_issues, | |
|
109 | "c" => :label_closed_issues, | |
|
110 | "!*" => :label_none, | |
|
111 | "*" => :label_any, | |
|
112 | ">=" => :label_greater_or_equal, | |
|
113 | "<=" => :label_less_or_equal, | |
|
114 | "><" => :label_between, | |
|
115 | "<t+" => :label_in_less_than, | |
|
116 | ">t+" => :label_in_more_than, | |
|
117 | "><t+"=> :label_in_the_next_days, | |
|
118 | "t+" => :label_in, | |
|
119 | "t" => :label_today, | |
|
120 | "w" => :label_this_week, | |
|
121 | ">t-" => :label_less_than_ago, | |
|
122 | "<t-" => :label_more_than_ago, | |
|
123 | "><t-"=> :label_in_the_past_days, | |
|
124 | "t-" => :label_ago, | |
|
125 | "~" => :label_contains, | |
|
126 | "!~" => :label_not_contains, | |
|
127 | "=p" => :label_any_issues_in_project, | |
|
128 | "=!p" => :label_any_issues_not_in_project, | |
|
129 | "!p" => :label_no_issues_in_project | |
|
130 | } | |
|
131 | ||
|
132 | class_attribute :operators_by_filter_type | |
|
133 | self.operators_by_filter_type = { | |
|
134 | :list => [ "=", "!" ], | |
|
135 | :list_status => [ "o", "=", "!", "c", "*" ], | |
|
136 | :list_optional => [ "=", "!", "!*", "*" ], | |
|
137 | :list_subprojects => [ "*", "!*", "=" ], | |
|
138 | :date => [ "=", ">=", "<=", "><", "<t+", ">t+", "><t+", "t+", "t", "w", ">t-", "<t-", "><t-", "t-", "!*", "*" ], | |
|
139 | :date_past => [ "=", ">=", "<=", "><", ">t-", "<t-", "><t-", "t-", "t", "w", "!*", "*" ], | |
|
140 | :string => [ "=", "~", "!", "!~", "!*", "*" ], | |
|
141 | :text => [ "~", "!~", "!*", "*" ], | |
|
142 | :integer => [ "=", ">=", "<=", "><", "!*", "*" ], | |
|
143 | :float => [ "=", ">=", "<=", "><", "!*", "*" ], | |
|
144 | :relation => ["=", "=p", "=!p", "!p", "!*", "*"] | |
|
145 | } | |
|
146 | ||
|
147 | class_attribute :available_columns | |
|
148 | self.available_columns = [ | |
|
146 | 149 | QueryColumn.new(:project, :sortable => "#{Project.table_name}.name", :groupable => true), |
|
147 | 150 | QueryColumn.new(:tracker, :sortable => "#{Tracker.table_name}.position", :groupable => true), |
|
148 | 151 | 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 | |||
|
162 | 165 | QueryColumn.new(:relations, :caption => :label_related_issues), |
|
163 | 166 | QueryColumn.new(:description, :inline => false) |
|
164 | 167 | ] |
|
165 | cattr_reader :available_columns | |
|
166 | 168 | |
|
167 | 169 | scope :visible, lambda {|*args| |
|
168 | 170 | user = args.shift || User.current |
@@ -398,11 +400,6 class Query < ActiveRecord::Base | |||
|
398 | 400 | # check if field is defined as an available filter |
|
399 | 401 | if available_filters.has_key? field |
|
400 | 402 | filter_options = available_filters[field] |
|
401 | # check if operator is allowed for that filter | |
|
402 | #if @@operators_by_filter_type[filter_options[:type]].include? operator | |
|
403 | # allowed_values = values & ([""] + (filter_options[:values] || []).collect {|val| val[1]}) | |
|
404 | # filters[field] = {:operator => operator, :values => allowed_values } if (allowed_values.first and !allowed_values.first.empty?) or ["o", "c", "!*", "*", "t"].include? operator | |
|
405 | #end | |
|
406 | 403 | filters[field] = {:operator => operator, :values => (values || [''])} |
|
407 | 404 | end |
|
408 | 405 | end |
@@ -410,7 +407,7 class Query < ActiveRecord::Base | |||
|
410 | 407 | def add_short_filter(field, expression) |
|
411 | 408 | return unless expression && available_filters.has_key?(field) |
|
412 | 409 | field_type = available_filters[field][:type] |
|
413 |
|
|
|
410 | operators_by_filter_type[field_type].sort.reverse.detect do |operator| | |
|
414 | 411 | next unless expression =~ /^#{Regexp.escape(operator)}(.*)$/ |
|
415 | 412 | add_filter field, operator, $1.present? ? $1.split('|') : [''] |
|
416 | 413 | end || add_filter(field, '=', expression.split('|')) |
@@ -483,10 +480,6 class Query < ActiveRecord::Base | |||
|
483 | 480 | @available_columns |
|
484 | 481 | end |
|
485 | 482 | |
|
486 | def self.available_columns=(v) | |
|
487 | self.available_columns = (v) | |
|
488 | end | |
|
489 | ||
|
490 | 483 | def self.add_available_column(column) |
|
491 | 484 | self.available_columns << (column) if column.is_a?(QueryColumn) |
|
492 | 485 | end |
General Comments 0
You need to be logged in to leave comments.
Login now