Index: app/models/query.rb =================================================================== --- app/models/query.rb (revision 5822) +++ app/models/query.rb (working copy) @@ -93,24 +93,24 @@ validates_presence_of :name, :on => :save validates_length_of :name, :maximum => 255 - @@operators = { "=" => :label_equals, - "!" => :label_not_equals, - "o" => :label_open_issues, - "c" => :label_closed_issues, - "!*" => :label_none, - "*" => :label_all, - ">=" => :label_greater_or_equal, - "<=" => :label_less_or_equal, - " :label_in_less_than, - ">t+" => :label_in_more_than, - "t+" => :label_in, - "t" => :label_today, - "w" => :label_this_week, - ">t-" => :label_less_than_ago, - " :label_more_than_ago, - "t-" => :label_ago, - "~" => :label_contains, - "!~" => :label_not_contains } + @@operators = { "=" => { :label => :label_equals, :operands_count => 1 }, + "!" => { :label => :label_not_equals, :operands_count => 1 }, + "o" => { :label => :label_open_issues, :operands_count => 0 }, + "c" => { :label => :label_closed_issues, :operands_count => 0 }, + "!*" => { :label => :label_none, :operands_count => 0 }, + "*" => { :label => :label_all, :operands_count => 0 }, + ">=" => { :label => :label_greater_or_equal, :operands_count => 1 }, + "<=" => { :label => :label_less_or_equal, :operands_count => 1 }, + " { :label => :label_in_less_than, :operands_count => 1 }, + ">t+" => { :label => :label_in_more_than, :operands_count => 1 }, + "t+" => { :label => :label_in, :operands_count => 2 }, + "t" => { :label => :label_today, :operands_count => 0 }, + "w" => { :label => :label_this_week, :operands_count => 0 }, + ">t-" => { :label => :label_less_than_ago, :operands_count => 1 }, + " { :label => :label_more_than_ago, :operands_count => 1 }, + "t-" => { :label => :label_ago, :operands_count => 1 }, + "~" => { :label => :label_contains, :operands_count => 1 }, + "!~" => { :label => :label_not_contains, :operands_count => 1} } cattr_reader :operators @@ -266,9 +266,27 @@ end def add_short_filter(field, expression) - return unless expression - parms = expression.scan(/^(o|c|!\*|!|\*)?(.*)$/).first - add_filter field, (parms[0] || "="), [parms[1] || ""] + return unless expression && available_filters.has_key?(field) + m = nil + short_filter_res(field).detect { |re| m = re.match(expression) } + if m + add_filter field, m[1], (m.size > 2 ? m[2..-1] : ['']) + else + add_filter field, '=', [expression] + end + end + + def short_filter_res(field) + @fields_short_filter_res = {} if @fields_short_filter_res.nil? + @fields_short_filter_res_by_type = {} if @fields_short_filter_res_by_type.nil? + + @fields_short_filter_res[field] ||= begin + + field_type = available_filters[field][:type] + @fields_short_filter_res_by_type[field_type] ||= @@operators_by_filter_type[field_type].collect do |operator| + /^#{'(' + Regexp.escape(operator) + ')' + (['(.+)'] * @@operators[operator][:operands_count]).join(',')}$/i + end + end end # Add multiple filters using +add_filter+ Index: app/helpers/queries_helper.rb =================================================================== --- app/helpers/queries_helper.rb (revision 5858) +++ app/helpers/queries_helper.rb (working copy) @@ -18,7 +18,7 @@ module QueriesHelper def operators_for_select(filter_type) - Query.operators_by_filter_type[filter_type].collect {|o| [l(Query.operators[o]), o]} + Query.operators_by_filter_type[filter_type].collect {|o| [l(Query.operators[o][:label]), o]} end def column_header(column)