Project

General

Profile

Feature #3110 » query.rb.patch

app/models/query.rb patch file... - Mikko Ruohola, 2009-07-09 10:03

View differences:

app/models/query.rb ke heinä 8 15:44:07 2009
"t+" => :label_in,
"t" => :label_today,
"w" => :label_this_week,
"lm" => :label_last_month,
"tm" => :label_this_month,
">t-" => :label_less_than_ago,
"<t-" => :label_more_than_ago,
"t-" => :label_ago,
......
:list_optional => [ "=", "!", "!*", "*" ],
:list_subprojects => [ "*", "!*", "=" ],
:date => [ "<t+", ">t+", "t+", "t", "w", ">t-", "<t-", "t-" ],
:date_past => [ ">t-", "<t-", "t-", "t", "w" ],
:date_past => [ ">t-", "<t-", "t-", "t", "w", "tm", "lm"],
:string => [ "=", "~", "!", "!~" ],
:text => [ "~", "!~" ],
:integer => [ "=", ">=", "<=", "!*", "*" ] }
......
# filter requires one or more values
(values_for(field) and !values_for(field).first.blank?) or
# filter doesn't require any value
["o", "c", "!*", "*", "t", "w"].include? operator_for(field)
["o", "c", "!*", "*", "t", "w", "tm", "lm"].include? operator_for(field)
end if filters
end
......
# week starts on monday (Rails default)
Time.now.at_beginning_of_week
sql = "#{db_table}.#{db_field} BETWEEN '%s' AND '%s'" % [connection.quoted_date(from), connection.quoted_date(from + 7.days)]
when "lm"
back_month = Time.now - 2592000
from = Time.local(back_month.year,back_month.month,1,0,0,0,0)
to = DateTime.civil(back_month.year,back_month.month,-1,23,59,59).to_time
sql = "#{db_table}.#{db_field} BETWEEN '%s' AND '%s'" % [connection.quoted_date(from), connection.quoted_date(to)]
when "tm"
this_month = Time.now
from = Time.local(this_month.year,this_month.month,1,0,0,0,0)
to = DateTime.civil(this_month.year,this_month.month,-1,23,59,59).to_time
sql = "#{db_table}.#{db_field} BETWEEN '%s' AND '%s'" % [connection.quoted_date(from), connection.quoted_date(to)]
when "~"
sql = "LOWER(#{db_table}.#{db_field}) LIKE '%#{connection.quote_string(value.first.to_s.downcase)}%'"
when "!~"
(2-2/2)