some methods to indicate the assumed input of an operator

pull/6827/head
jwollert 14 years ago
parent 93ad19d395
commit 58fa770c02
  1. 22
      lib/report/operator.rb
  2. 1
      lib/widget/filters/operators.rb

@ -1,6 +1,7 @@
class Report::Operator
include Report::QueryUtils
include Report::Validation
extend Forwardable
#############################################################################################
# Wrapped so we can place this at the top of the file.
@ -8,6 +9,9 @@ class Report::Operator
# Defaults
defaults do
def_delegators :'singleton_class', :enforced?, :enforce!, :enforced
def sql_operator
name
end
@ -183,10 +187,12 @@ class Report::Operator
end
end
new ">=d", :label => :label_between_now_and_date, :validate => :dates do
new ">=d", :label => :label_days_ago, :validate => :integers do
enforce! :integers
def modify(query, field, value)
now = Time.now
from = value.to_dateish
from = (now - value.to_i.days).beginning_of_day
'<>d'.to_operator.modify query, field, from, now
end
end
@ -212,6 +218,18 @@ class Report::Operator
end
end
def self.enforce!(type)
@enforced = type
end
def self.enforced?
!!@enforced
end
def self.enforced
@enforced
end
def self.new(name, values = {}, &block)
all[name.to_s] ||= super
end

@ -12,6 +12,7 @@ class Widget::Filters::Operators < Widget::Filters::Base
select_box = content_tag :select, options do
filter_class.available_operators.collect do |o|
opts = {:value => h(o.to_s), :"data-arity" => o.arity}
opts.reverse_merge! :"data-enforced" => o.enforced if o.enforced?
opts[:selected] = "selected" if filter.operator.to_s == o.to_s
content_tag(:option, opts) { h(l(o.label)) }
end.join.html_safe

Loading…
Cancel
Save