filters can now be invalid given certain combinations of values and operators. by default, a filter is valid

git-svn-id: https://dev.finn.de/svn/cockpit/branches/reporting_merge@1831 7926756e-e54e-46e6-9721-ed318f58905e
pull/6827/head
j.wollert 14 years ago
parent 978cf0bf50
commit db407ae997
  1. 28
      app/controllers/cost_reports_controller.rb
  2. 4
      app/models/cost_query/filter/base.rb
  3. 56
      app/models/cost_query/operator.rb
  4. 8
      app/views/cost_reports/index.rhtml

@ -8,15 +8,18 @@ class CostReportsController < ApplicationController
include ReportingHelper
def index
if @query.group_bys.empty?
@table_partial = "cost_entry_table"
elsif @query.depth_of(:column) + @query.depth_of(:row) == 1
@table_partial = "simple_cost_report_table"
else
if @query.depth_of(:column) == 0 || @query.depth_of(:row) == 0
@query.depth_of(:column) == 0 ? @query.column(:singleton_value) : @query.row(:singleton_value)
@valid = valid_query?
if @valid
if @query.group_bys.empty?
@table_partial = "cost_entry_table"
elsif @query.depth_of(:column) + @query.depth_of(:row) == 1
@table_partial = "simple_cost_report_table"
else
if @query.depth_of(:column) == 0 || @query.depth_of(:row) == 0
@query.depth_of(:column) == 0 ? @query.column(:singleton_value) : @query.row(:singleton_value)
end
@table_partial = "cost_report_table"
end
@table_partial = "cost_report_table"
end
respond_to do |format|
format.html { render :layout => !request.xhr? }
@ -140,6 +143,15 @@ class CostReportsController < ApplicationController
@query
end
def valid_query?
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"
end
errornous.empty?
end
##
# FIXME: Split
# This method does three things:

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

@ -15,6 +15,10 @@ 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
@ -165,6 +169,19 @@ class CostQuery::Operator
return query if value.to_s.empty?
"<".to_operator.modify query, field, quoted_date(value)
end
def validate(*values)
values.all? do |vals|
vals = vals.is_a?(Array) ? vals : [vals]
vals.all? do |val|
begin
!!val.to_dateish
rescue ArgumentError
false
end
end
end
end
end
new ">d", :label => :label_greater_or_equal do
@ -172,6 +189,19 @@ class CostQuery::Operator
return query if value.to_s.empty?
">".to_operator.modify query, field, quoted_date(value)
end
def validate(*values)
values.all? do |vals|
vals = vals.is_a?(Array) ? vals : [vals]
vals.all? do |val|
begin
!!val.to_dateish
rescue ArgumentError
false
end
end
end
end
end
new "<>d", :label => :label_between do
@ -180,6 +210,19 @@ class CostQuery::Operator
query.where "#{field} BETWEEN '#{quoted_date from}' AND '#{quoted_date to}'"
query
end
def validate(*values)
values.all? do |vals|
vals = vals.is_a?(Array) ? vals : [vals]
vals.all? do |val|
begin
!!val.to_dateish
rescue ArgumentError
false
end
end
end
end
end
new "=d", :label => :label_date_on do
@ -187,6 +230,19 @@ class CostQuery::Operator
return query if value.to_s.empty?
"=".to_operator.modify query, field, quoted_date(value)
end
def validate(*values)
values.all? do |vals|
vals = vals.is_a?(Array) ? vals : [vals]
vals.all? do |val|
begin
!!val.to_dateish
rescue ArgumentError
false
end
end
end
end
end
end

@ -4,8 +4,10 @@
<%= stylesheet_link_tag 'reporting', :plugin => 'redmine_reporting' %>
<% end %>
<% if @custom_error %>
<div class="flash error"><%= @custom_error %></div>
<% if @custom_error && !@custom_error.empty? %>
<% @custom_error.each do |err| %>
<div class="flash error"><%= err %></div>
<% end %>
<% end %>
<h2><%= l(:label_cost_report) %></h2>
@ -54,7 +56,7 @@
<% end %>
</div>
<% if @query.result.count > 0 %>
<% if @valid and @query.result.count > 0 %>
<%= render :partial => @table_partial, :locals => {:query => @query, :walker => @query.walker} %>
<p class="footnote">
<%= l(:text_costs_are_rounded_note) %>

Loading…
Cancel
Save