Project

General

Profile

Defect #8371 » short_filters_regexps.patch

Etienne Massip, 2011-05-20 15:23

View differences:

app/models/query.rb (working copy)
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,
"<t+" => :label_in_less_than,
">t+" => :label_in_more_than,
"t+" => :label_in,
"t" => :label_today,
"w" => :label_this_week,
">t-" => :label_less_than_ago,
"<t-" => :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 },
"<t+" => { :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 },
"<t-" => { :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
......
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+
app/helpers/queries_helper.rb (working copy)
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)
(2-2/3)