##// END OF EJS Templates
Changes how relative date filters work and adds specific filters for filtering dates in past/next n days (#11426)....
Jean-Philippe Lang -
r10546:d62ef6b9b1dc
parent child
Show More
@@ -106,11 +106,13 class Query < ActiveRecord::Base
106 "><" => :label_between,
106 "><" => :label_between,
107 "<t+" => :label_in_less_than,
107 "<t+" => :label_in_less_than,
108 ">t+" => :label_in_more_than,
108 ">t+" => :label_in_more_than,
109 "><t+"=> :label_in_the_next_days,
109 "t+" => :label_in,
110 "t+" => :label_in,
110 "t" => :label_today,
111 "t" => :label_today,
111 "w" => :label_this_week,
112 "w" => :label_this_week,
112 ">t-" => :label_less_than_ago,
113 ">t-" => :label_less_than_ago,
113 "<t-" => :label_more_than_ago,
114 "<t-" => :label_more_than_ago,
115 "><t-"=> :label_in_the_past_days,
114 "t-" => :label_ago,
116 "t-" => :label_ago,
115 "~" => :label_contains,
117 "~" => :label_contains,
116 "!~" => :label_not_contains,
118 "!~" => :label_not_contains,
@@ -124,8 +126,8 class Query < ActiveRecord::Base
124 :list_status => [ "o", "=", "!", "c", "*" ],
126 :list_status => [ "o", "=", "!", "c", "*" ],
125 :list_optional => [ "=", "!", "!*", "*" ],
127 :list_optional => [ "=", "!", "!*", "*" ],
126 :list_subprojects => [ "*", "!*", "=" ],
128 :list_subprojects => [ "*", "!*", "=" ],
127 :date => [ "=", ">=", "<=", "><", "<t+", ">t+", "t+", "t", "w", ">t-", "<t-", "t-", "!*", "*" ],
129 :date => [ "=", ">=", "<=", "><", "<t+", ">t+", "><t+", "t+", "t", "w", ">t-", "<t-", "><t-", "t-", "!*", "*" ],
128 :date_past => [ "=", ">=", "<=", "><", ">t-", "<t-", "t-", "t", "w", "!*", "*" ],
130 :date_past => [ "=", ">=", "<=", "><", ">t-", "<t-", "><t-", "t-", "t", "w", "!*", "*" ],
129 :string => [ "=", "~", "!", "!~", "!*", "*" ],
131 :string => [ "=", "~", "!", "!~", "!*", "*" ],
130 :text => [ "~", "!~", "!*", "*" ],
132 :text => [ "~", "!~", "!*", "*" ],
131 :integer => [ "=", ">=", "<=", "><", "!*", "*" ],
133 :integer => [ "=", ">=", "<=", "><", "!*", "*" ],
@@ -183,7 +185,7 class Query < ActiveRecord::Base
183 case operator_for(field)
185 case operator_for(field)
184 when "=", ">=", "<=", "><"
186 when "=", ">=", "<=", "><"
185 add_filter_error(field, :invalid) if values_for(field).detect {|v| v.present? && (!v.match(/^\d{4}-\d{2}-\d{2}$/) || (Date.parse(v) rescue nil).nil?) }
187 add_filter_error(field, :invalid) if values_for(field).detect {|v| v.present? && (!v.match(/^\d{4}-\d{2}-\d{2}$/) || (Date.parse(v) rescue nil).nil?) }
186 when ">t-", "<t-", "t-", ">t+", "<t+", "t+"
188 when ">t-", "<t-", "t-", ">t+", "<t+", "t+", "><t+", "><t-"
187 add_filter_error(field, :invalid) if values_for(field).detect {|v| v.present? && !v.match(/^\d+$/) }
189 add_filter_error(field, :invalid) if values_for(field).detect {|v| v.present? && !v.match(/^\d+$/) }
188 end
190 end
189 end
191 end
@@ -936,21 +938,35 class Query < ActiveRecord::Base
936 sql = "#{Issue.table_name}.status_id IN (SELECT id FROM #{IssueStatus.table_name} WHERE is_closed=#{connection.quoted_false})" if field == "status_id"
938 sql = "#{Issue.table_name}.status_id IN (SELECT id FROM #{IssueStatus.table_name} WHERE is_closed=#{connection.quoted_false})" if field == "status_id"
937 when "c"
939 when "c"
938 sql = "#{Issue.table_name}.status_id IN (SELECT id FROM #{IssueStatus.table_name} WHERE is_closed=#{connection.quoted_true})" if field == "status_id"
940 sql = "#{Issue.table_name}.status_id IN (SELECT id FROM #{IssueStatus.table_name} WHERE is_closed=#{connection.quoted_true})" if field == "status_id"
939 when ">t-"
941 when "><t-"
942 # between today - n days and today
940 sql = relative_date_clause(db_table, db_field, - value.first.to_i, 0)
943 sql = relative_date_clause(db_table, db_field, - value.first.to_i, 0)
944 when ">t-"
945 # >= today - n days
946 sql = relative_date_clause(db_table, db_field, - value.first.to_i, nil)
941 when "<t-"
947 when "<t-"
948 # <= today - n days
942 sql = relative_date_clause(db_table, db_field, nil, - value.first.to_i)
949 sql = relative_date_clause(db_table, db_field, nil, - value.first.to_i)
943 when "t-"
950 when "t-"
951 # = n days in past
944 sql = relative_date_clause(db_table, db_field, - value.first.to_i, - value.first.to_i)
952 sql = relative_date_clause(db_table, db_field, - value.first.to_i, - value.first.to_i)
953 when "><t+"
954 # between today and today + n days
955 sql = relative_date_clause(db_table, db_field, 0, value.first.to_i)
945 when ">t+"
956 when ">t+"
957 # >= today + n days
946 sql = relative_date_clause(db_table, db_field, value.first.to_i, nil)
958 sql = relative_date_clause(db_table, db_field, value.first.to_i, nil)
947 when "<t+"
959 when "<t+"
948 sql = relative_date_clause(db_table, db_field, 0, value.first.to_i)
960 # <= today + n days
961 sql = relative_date_clause(db_table, db_field, nil, value.first.to_i)
949 when "t+"
962 when "t+"
963 # = today + n days
950 sql = relative_date_clause(db_table, db_field, value.first.to_i, value.first.to_i)
964 sql = relative_date_clause(db_table, db_field, value.first.to_i, value.first.to_i)
951 when "t"
965 when "t"
966 # = today
952 sql = relative_date_clause(db_table, db_field, 0, 0)
967 sql = relative_date_clause(db_table, db_field, 0, 0)
953 when "w"
968 when "w"
969 # = this week
954 first_day_of_week = l(:general_first_day_of_week).to_i
970 first_day_of_week = l(:general_first_day_of_week).to_i
955 day_of_week = Date.today.cwday
971 day_of_week = Date.today.cwday
956 days_ago = (day_of_week >= first_day_of_week ? day_of_week - first_day_of_week : day_of_week + 7 - first_day_of_week)
972 days_ago = (day_of_week >= first_day_of_week ? day_of_week - first_day_of_week : day_of_week + 7 - first_day_of_week)
@@ -656,6 +656,8 en:
656 label_not_equals: is not
656 label_not_equals: is not
657 label_in_less_than: in less than
657 label_in_less_than: in less than
658 label_in_more_than: in more than
658 label_in_more_than: in more than
659 label_in_the_next_days: in the next
660 label_in_the_past_days: in the past
659 label_greater_or_equal: '>='
661 label_greater_or_equal: '>='
660 label_less_or_equal: '<='
662 label_less_or_equal: '<='
661 label_between: between
663 label_between: between
@@ -649,6 +649,8 fr:
649 label_not_equals: diffΓ©rent
649 label_not_equals: diffΓ©rent
650 label_in_less_than: dans moins de
650 label_in_less_than: dans moins de
651 label_in_more_than: dans plus de
651 label_in_more_than: dans plus de
652 label_in_the_next_days: dans les prochains jours
653 label_in_the_past_days: dans les derniers jours
652 label_in: dans
654 label_in: dans
653 label_today: aujourd'hui
655 label_today: aujourd'hui
654 label_all_time: toute la pΓ©riode
656 label_all_time: toute la pΓ©riode
@@ -252,9 +252,11 function toggleOperator(field) {
252 break;
252 break;
253 case "<t+":
253 case "<t+":
254 case ">t+":
254 case ">t+":
255 case "><t+":
255 case "t+":
256 case "t+":
256 case ">t-":
257 case ">t-":
257 case "<t-":
258 case "<t-":
259 case "><t-":
258 case "t-":
260 case "t-":
259 enableValues(field, [2]);
261 enableValues(field, [2]);
260 break;
262 break;
@@ -413,6 +413,14 class QueryTest < ActiveSupport::TestCase
413 query.add_filter('due_date', '<t+', ['15'])
413 query.add_filter('due_date', '<t+', ['15'])
414 issues = find_issues_with_query(query)
414 issues = find_issues_with_query(query)
415 assert !issues.empty?
415 assert !issues.empty?
416 issues.each {|issue| assert(issue.due_date <= (Date.today + 15))}
417 end
418
419 def test_operator_in_the_next_days
420 query = Query.new(:project => Project.find(1), :name => '_')
421 query.add_filter('due_date', '><t+', ['15'])
422 issues = find_issues_with_query(query)
423 assert !issues.empty?
416 issues.each {|issue| assert(issue.due_date >= Date.today && issue.due_date <= (Date.today + 15))}
424 issues.each {|issue| assert(issue.due_date >= Date.today && issue.due_date <= (Date.today + 15))}
417 end
425 end
418
426
@@ -422,6 +430,15 class QueryTest < ActiveSupport::TestCase
422 query.add_filter('due_date', '>t-', ['3'])
430 query.add_filter('due_date', '>t-', ['3'])
423 issues = find_issues_with_query(query)
431 issues = find_issues_with_query(query)
424 assert !issues.empty?
432 assert !issues.empty?
433 issues.each {|issue| assert(issue.due_date >= (Date.today - 3))}
434 end
435
436 def test_operator_in_the_past_days
437 Issue.find(7).update_attribute(:due_date, (Date.today - 3))
438 query = Query.new(:project => Project.find(1), :name => '_')
439 query.add_filter('due_date', '><t-', ['3'])
440 issues = find_issues_with_query(query)
441 assert !issues.empty?
425 issues.each {|issue| assert(issue.due_date >= (Date.today - 3) && issue.due_date <= Date.today)}
442 issues.each {|issue| assert(issue.due_date >= (Date.today - 3) && issue.due_date <= Date.today)}
426 end
443 end
427
444
General Comments 0
You need to be logged in to leave comments. Login now