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
78 78
                  "t+"  => :label_in,
79 79
                  "t"   => :label_today,
80 80
                  "w"   => :label_this_week,
81
		  "lm"  => :label_last_month,
82
                  "tm"  => :label_this_month,
81 83
                  ">t-" => :label_less_than_ago,
82 84
                  "<t-" => :label_more_than_ago,
83 85
                  "t-"  => :label_ago,
......
91 93
                                 :list_optional => [ "=", "!", "!*", "*" ],
92 94
                                 :list_subprojects => [ "*", "!*", "=" ],
93 95
                                 :date => [ "<t+", ">t+", "t+", "t", "w", ">t-", "<t-", "t-" ],
94
                                 :date_past => [ ">t-", "<t-", "t-", "t", "w" ],
96
                                 :date_past => [ ">t-", "<t-", "t-", "t", "w", "tm", "lm"],
95 97
                                 :string => [ "=", "~", "!", "!~" ],
96 98
                                 :text => [  "~", "!~" ],
97 99
                                 :integer => [ "=", ">=", "<=", "!*", "*" ] }
......
133 135
          # filter requires one or more values
134 136
          (values_for(field) and !values_for(field).first.blank?) or 
135 137
          # filter doesn't require any value
136
          ["o", "c", "!*", "*", "t", "w"].include? operator_for(field)
138
          ["o", "c", "!*", "*", "t", "w", "tm", "lm"].include? operator_for(field)
137 139
    end if filters
138 140
  end
139 141
  
......
423 425
        # week starts on monday (Rails default)
424 426
        Time.now.at_beginning_of_week
425 427
      sql = "#{db_table}.#{db_field} BETWEEN '%s' AND '%s'" % [connection.quoted_date(from), connection.quoted_date(from + 7.days)]
428
    when "lm"
429
      back_month = Time.now - 2592000
430
      from = Time.local(back_month.year,back_month.month,1,0,0,0,0)
431
      to = DateTime.civil(back_month.year,back_month.month,-1,23,59,59).to_time
432
      sql = "#{db_table}.#{db_field} BETWEEN '%s' AND '%s'" % [connection.quoted_date(from), connection.quoted_date(to)]
433
    when "tm"
434
      this_month = Time.now
435
      from = Time.local(this_month.year,this_month.month,1,0,0,0,0)
436
      to = DateTime.civil(this_month.year,this_month.month,-1,23,59,59).to_time
437
      sql = "#{db_table}.#{db_field} BETWEEN '%s' AND '%s'" % [connection.quoted_date(from), connection.quoted_date(to)]
426 438
    when "~"
427 439
      sql = "LOWER(#{db_table}.#{db_field}) LIKE '%#{connection.quote_string(value.first.to_s.downcase)}%'"
428 440
    when "!~"
(2-2/2)