|
|
|
@ -26,19 +26,19 @@ class Report::Operator |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def label |
|
|
|
|
@label ||= self.class.name.to_sym |
|
|
|
|
@label ||= self.class.name |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
# Operators from Redmine |
|
|
|
|
new ">t-", :label => :label_less_than_ago do |
|
|
|
|
new ">t-", :label => I18n.t(:label_less_than_ago) do |
|
|
|
|
include DateRange |
|
|
|
|
def modify(query, field, value) |
|
|
|
|
super query, field, -value.to_i, 0 |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
new "w", :arity => 0, :label => :label_this_week do |
|
|
|
|
new "w", :arity => 0, :label => I18n.t(:label_this_week) do |
|
|
|
|
def modify(query, field, offset = nil) |
|
|
|
|
offset ||= 0 |
|
|
|
|
first_day = begin |
|
|
|
@ -53,16 +53,16 @@ class Report::Operator |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
new "t+", :label => :label_in do |
|
|
|
|
new "t+", :label => I18n.t(:label_in) do |
|
|
|
|
include DateRange |
|
|
|
|
def modify(query, field, *values) |
|
|
|
|
super query, field, values.first.to_i, values.first.to_i |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
new "<=", :label => :label_less_or_equal |
|
|
|
|
new "<=", :label => I18n.t(:label_less_or_equal) |
|
|
|
|
|
|
|
|
|
new "!", :label => :label_not_equals do |
|
|
|
|
new "!", :label => I18n.t(:label_not_equals) do |
|
|
|
|
def modify(query, field, *values) |
|
|
|
|
where_clause = "(#{field} IS NULL" |
|
|
|
|
where_clause += " OR #{field} NOT IN #{collection(*values)}" unless values.compact.empty? |
|
|
|
@ -72,14 +72,14 @@ class Report::Operator |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
new "t-", :label => :label_ago do |
|
|
|
|
new "t-", :label => I18n.t(:label_ago) do |
|
|
|
|
include DateRange |
|
|
|
|
def modify(query, field, *values) |
|
|
|
|
super query, field, -values.first.to_i, -values.first.to_i |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
new "!~", :arity => 1, :label => :label_not_contains do |
|
|
|
|
new "!~", :arity => 1, :label => I18n.t(:label_not_contains) do |
|
|
|
|
def modify(query, field, *values) |
|
|
|
|
value = values.first || '' |
|
|
|
|
query.where "LOWER(#{field}) NOT LIKE '%#{quote_string(value.to_s.downcase)}%'" |
|
|
|
@ -87,7 +87,7 @@ class Report::Operator |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
new "=", :label => :label_equals do |
|
|
|
|
new "=", :label => I18n.t(:label_equals) do |
|
|
|
|
def modify(query, field, *values) |
|
|
|
|
case |
|
|
|
|
when values.size == 1 && values.first.nil? |
|
|
|
@ -101,7 +101,7 @@ class Report::Operator |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
new "~", :arity => 1, :label => :label_contains do |
|
|
|
|
new "~", :arity => 1, :label => I18n.t(:label_contains) do |
|
|
|
|
def modify(query, field, *values) |
|
|
|
|
value = values.first || '' |
|
|
|
|
query.where "LOWER(#{field}) LIKE '%#{quote_string(value.to_s.downcase)}%'" |
|
|
|
@ -109,70 +109,70 @@ class Report::Operator |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
new "<t+", :label => :label_in_less_than do |
|
|
|
|
new "<t+", :label => I18n.t(:label_in_less_than) do |
|
|
|
|
include DateRange |
|
|
|
|
def modify(query, field, value) |
|
|
|
|
super query, field, 0, value.to_i |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
new "t", :label => :label_today do |
|
|
|
|
new "t", :label => I18n.t(:label_today) do |
|
|
|
|
include DateRange |
|
|
|
|
def modify(query, field) |
|
|
|
|
super query, field, 0, 0 |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
new ">=", :label => :label_greater_or_equal |
|
|
|
|
new ">=", :label => I18n.t(:label_greater_or_equal) |
|
|
|
|
|
|
|
|
|
new "!*", :arity => 0, :where_clause => "%s IS NULL", :label => :label_none |
|
|
|
|
new "!*", :arity => 0, :where_clause => "%s IS NULL", :label => I18n.t(:label_none) |
|
|
|
|
|
|
|
|
|
new "<t-", :label => :label_more_than_ago do |
|
|
|
|
new "<t-", :label => I18n.t(:label_more_than_ago) do |
|
|
|
|
include DateRange |
|
|
|
|
def modify(query, field, value) |
|
|
|
|
super query, field, nil, -value.to_i |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
new ">t+", :label => :label_in_more_than do |
|
|
|
|
new ">t+", :label => I18n.t(:label_in_more_than) do |
|
|
|
|
include DateRange |
|
|
|
|
def modify(query, field, value) |
|
|
|
|
super query, field, value.to_i, nil |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
new "*", :arity => 0, :where_clause => "%s IS NOT NULL", :label => :label_all |
|
|
|
|
new "*", :arity => 0, :where_clause => "%s IS NOT NULL", :label => I18n.t(:label_all) |
|
|
|
|
|
|
|
|
|
# Our own operators |
|
|
|
|
new "<", :label => :label_less |
|
|
|
|
new ">", :label => :label_greater |
|
|
|
|
new "<", :label => I18n.t(:label_less) |
|
|
|
|
new ">", :label => I18n.t(:label_greater) |
|
|
|
|
|
|
|
|
|
new "=n", :label => :label_equals do |
|
|
|
|
new "=n", :label => I18n.t(:label_equals) do |
|
|
|
|
def modify(query, field, value) |
|
|
|
|
query.where "#{field} = #{clean_currency(value)}" |
|
|
|
|
query |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
new "0", :label => :label_none, :where_clause => "%s = 0" |
|
|
|
|
new "y", :label => :label_yes, :arity => 0, :where_clause => "%s IS NOT NULL" |
|
|
|
|
new "n", :label => :label_no, :arity => 0, :where_clause => "%s IS NULL" |
|
|
|
|
new "0", :label => I18n.t(:label_none), :where_clause => "%s = 0" |
|
|
|
|
new "y", :label => I18n.t(:label_yes), :arity => 0, :where_clause => "%s IS NOT NULL" |
|
|
|
|
new "n", :label => I18n.t(:label_no), :arity => 0, :where_clause => "%s IS NULL" |
|
|
|
|
|
|
|
|
|
new "<d", :label => :label_less_or_equal, :validate => :dates do |
|
|
|
|
new "<d", :label => I18n.t(:label_less_or_equal), :validate => :dates do |
|
|
|
|
def modify(query, field, value) |
|
|
|
|
return query if value.to_s.empty? |
|
|
|
|
"<=".to_operator.modify query, field, quoted_date(value) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
new ">d", :label => :label_greater_or_equal, :validate => :dates do |
|
|
|
|
new ">d", :label => I18n.t(:label_greater_or_equal), :validate => :dates do |
|
|
|
|
def modify(query, field, value) |
|
|
|
|
return query if value.to_s.empty? |
|
|
|
|
">=".to_operator.modify query, field, quoted_date(value) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
new "<>d", :label => :label_between, :validate => :dates do |
|
|
|
|
new "<>d", :label => I18n.t(:label_between), :validate => :dates do |
|
|
|
|
def modify(query, field, from, to) |
|
|
|
|
return query if from.to_s.empty? || to.to_s.empty? |
|
|
|
|
query.where "#{field} BETWEEN '#{quoted_date from}' AND '#{quoted_date to}'" |
|
|
|
@ -180,14 +180,14 @@ class Report::Operator |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
new "=d", :label => :label_date_on, :validate => :dates do |
|
|
|
|
new "=d", :label => I18n.t(:label_date_on), :validate => :dates do |
|
|
|
|
def modify(query, field, value) |
|
|
|
|
return query if value.to_s.empty? |
|
|
|
|
"=".to_operator.modify query, field, quoted_date(value) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
new ">=d", :label => :label_days_ago, :validate => :integers do |
|
|
|
|
new ">=d", :label => I18n.t(:label_days_ago), :validate => :integers do |
|
|
|
|
force! :integers |
|
|
|
|
|
|
|
|
|
def modify(query, field, value) |
|
|
|
@ -197,7 +197,7 @@ class Report::Operator |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
new "?=", :label => :label_null_or_equal do |
|
|
|
|
new "?=", :label => I18n.t(:label_null_or_equal) do |
|
|
|
|
def modify(query, field, *values) |
|
|
|
|
where_clause = "(#{field} IS NULL" |
|
|
|
|
where_clause += " OR #{field} IN #{collection(*values)}" unless values.compact.empty? |
|
|
|
@ -207,7 +207,7 @@ class Report::Operator |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
new "?!", :label => :label_not_null_and_not_equal do |
|
|
|
|
new "?!", :label => I18n.t(:label_not_null_and_not_equal) do |
|
|
|
|
def modify(query, field, *values) |
|
|
|
|
where_clause = "(#{field} IS NOT NULL" |
|
|
|
|
where_clause += " AND #{field} NOT IN #{collection(*values)}" unless values.compact.empty? |
|
|
|
|