validation error messages are now generated by the filters operator

git-svn-id: https://dev.finn.de/svn/cockpit/branches/reporting_merge@1832 7926756e-e54e-46e6-9721-ed318f58905e
pull/6827/head
j.wollert 14 years ago
parent db407ae997
commit 8ed6198511
  1. 2
      app/controllers/cost_reports_controller.rb
  2. 4
      app/models/cost_query/filter/base.rb
  3. 18
      app/models/cost_query/operator.rb

@ -147,7 +147,7 @@ class CostReportsController < ApplicationController
return true unless @query
errornous = @query.filters ? @query.filters.select { |f| !f.valid? } : []
@custom_error = errornous.map do |err|
"Filter #{l(err.label)} with value(s) #{err.values.reject{|val| val.empty?}.join(', ')} seems to be invalid"
"Filter #{l(err.label)}: #{err.errors.join(", ")}"
end
errornous.empty?
end

@ -67,6 +67,10 @@ module CostQuery::Filter
@operator ? @operator.validate(values) : true
end
def errors
@operator ? @operator.errors : []
end
def group_by_fields
[]
end

@ -15,10 +15,6 @@ class CostQuery::Operator
"%s %s '%s'"
end
def validate(*values)
true
end
def modify(query, field, *values)
query.where [where_clause, field, sql_operator, *values]
query
@ -171,12 +167,14 @@ class CostQuery::Operator
end
def validate(*values)
@errors.clear
values.all? do |vals|
vals = vals.is_a?(Array) ? vals : [vals]
vals.all? do |val|
begin
!!val.to_dateish
rescue ArgumentError
@errors << "\'#{val}\' is not a valid date!"
false
end
end
@ -191,12 +189,14 @@ class CostQuery::Operator
end
def validate(*values)
@errors.clear
values.all? do |vals|
vals = vals.is_a?(Array) ? vals : [vals]
vals.all? do |val|
begin
!!val.to_dateish
rescue ArgumentError
@errors << "\'#{val}\' is not a valid date!"
false
end
end
@ -212,12 +212,14 @@ class CostQuery::Operator
end
def validate(*values)
@errors.clear
values.all? do |vals|
vals = vals.is_a?(Array) ? vals : [vals]
vals.all? do |val|
begin
!!val.to_dateish
rescue ArgumentError
@errors << "\'#{val}\' is not a valid date!"
false
end
end
@ -232,12 +234,14 @@ class CostQuery::Operator
end
def validate(*values)
@errors.clear
values.all? do |vals|
vals = vals.is_a?(Array) ? vals : [vals]
vals.all? do |val|
begin
!!val.to_dateish
rescue ArgumentError
@errors << "\'#{val}\' is not a valid date!"
false
end
end
@ -304,15 +308,21 @@ class CostQuery::Operator
end
attr_reader :name
attr_reader :errors
def initialize(name, values = {}, &block)
@name = name.to_s
@errors = []
values.each do |key, value|
metaclass.class_eval { define_method(key) { value } }
end
metaclass.class_eval(&block) if block
end
def validate(*values)
true
end
def to_operator
self
end

Loading…
Cancel
Save