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 committed by jwollert
parent 0dfa835a23
commit 0f6017f4c4
  1. 12
      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,6 +8,8 @@ class CostReportsController < ApplicationController
include ReportingHelper
def index
@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
@ -18,6 +20,7 @@ class CostReportsController < ApplicationController
end
@table_partial = "cost_report_table"
end
end
respond_to do |format|
format.html { render :layout => !request.xhr? }
end
@ -141,6 +144,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>
@ -53,7 +55,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