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