Patch #4502 » add-next-range-filters.patch
| app/models/query.rb | ||
|---|---|---|
| 281 | 281 |
"=!p" => :label_any_issues_not_in_project, |
| 282 | 282 |
"!p" => :label_no_issues_in_project, |
| 283 | 283 |
"*o" => :label_any_open_issues, |
| 284 |
"!o" => :label_no_open_issues |
|
| 284 |
"!o" => :label_no_open_issues, |
|
| 285 |
"nd" => :label_tomorrow, |
|
| 286 |
"nw" => :label_next_week, |
|
| 287 |
"nm" => :label_next_month |
|
| 285 | 288 |
} |
| 286 | 289 | |
| 287 | 290 |
class_attribute :operators_by_filter_type |
| ... | ... | |
| 290 | 293 |
:list_status => [ "o", "=", "!", "c", "*" ], |
| 291 | 294 |
:list_optional => [ "=", "!", "!*", "*" ], |
| 292 | 295 |
:list_subprojects => [ "*", "!*", "=", "!" ], |
| 293 |
:date => [ "=", ">=", "<=", "><", "<t+", ">t+", "><t+", "t+", "t", "ld", "w", "lw", "l2w", "m", "lm", "y", ">t-", "<t-", "><t-", "t-", "!*", "*" ],
|
|
| 296 |
:date => [ "=", ">=", "<=", "><", "<t+", ">t+", "><t+", "t+", "t", "ld", "nd", "w", "lw", "l2w", "nw", "m", "lm", "nm", "y", ">t-", "<t-", "><t-", "t-", "!*", "*" ],
|
|
| 294 | 297 |
:date_past => [ "=", ">=", "<=", "><", ">t-", "<t-", "><t-", "t-", "t", "ld", "w", "lw", "l2w", "m", "lm", "y", "!*", "*" ], |
| 295 | 298 |
:string => [ "~", "=", "!~", "!", "!*", "*" ], |
| 296 | 299 |
:text => [ "~", "!~", "!*", "*" ], |
| ... | ... | |
| 453 | 456 |
# filter requires one or more values |
| 454 | 457 |
(values_for(field) and !values_for(field).first.blank?) or |
| 455 | 458 |
# filter doesn't require any value |
| 456 |
["o", "c", "!*", "*", "t", "ld", "w", "lw", "l2w", "m", "lm", "y", "*o", "!o"].include? operator_for(field) |
|
| 459 |
["o", "c", "!*", "*", "t", "ld", "w", "lw", "l2w", "m", "lm", "y", "*o", "!o", "nd", "nw", "nm"].include? operator_for(field)
|
|
| 457 | 460 |
end if filters |
| 458 | 461 |
end |
| 459 | 462 | |
| ... | ... | |
| 1207 | 1210 |
when "ld" |
| 1208 | 1211 |
# = yesterday |
| 1209 | 1212 |
sql = relative_date_clause(db_table, db_field, -1, -1, is_custom_filter) |
| 1213 |
when "nd" |
|
| 1214 |
# = tomorrow |
|
| 1215 |
sql = relative_date_clause(db_table, db_field, 1, 1, is_custom_filter) |
|
| 1210 | 1216 |
when "w" |
| 1211 | 1217 |
# = this week |
| 1212 | 1218 |
first_day_of_week = l(:general_first_day_of_week).to_i |
| ... | ... | |
| 1225 | 1231 |
day_of_week = User.current.today.cwday |
| 1226 | 1232 |
days_ago = (day_of_week >= first_day_of_week ? day_of_week - first_day_of_week : day_of_week + 7 - first_day_of_week) |
| 1227 | 1233 |
sql = relative_date_clause(db_table, db_field, - days_ago - 14, - days_ago - 1, is_custom_filter) |
| 1234 |
when "nw" |
|
| 1235 |
# = next week |
|
| 1236 |
first_day_of_week = l(:general_first_day_of_week).to_i |
|
| 1237 |
day_of_week = User.current.today.cwday |
|
| 1238 |
from = -(day_of_week >= first_day_of_week ? day_of_week - first_day_of_week : day_of_week + 7 - first_day_of_week) + 7 |
|
| 1239 |
sql = relative_date_clause(db_table, db_field, from, from + 6, is_custom_filter) |
|
| 1228 | 1240 |
when "m" |
| 1229 | 1241 |
# = this month |
| 1230 | 1242 |
date = User.current.today |
| ... | ... | |
| 1233 | 1245 |
# = last month |
| 1234 | 1246 |
date = User.current.today.prev_month |
| 1235 | 1247 |
sql = date_clause(db_table, db_field, date.beginning_of_month, date.end_of_month, is_custom_filter) |
| 1248 |
when "nm" |
|
| 1249 |
# = next month |
|
| 1250 |
date = User.current.today.next_month |
|
| 1251 |
sql = date_clause(db_table, db_field, date.beginning_of_month, date.end_of_month, is_custom_filter) |
|
| 1236 | 1252 |
when "y" |
| 1237 | 1253 |
# = this year |
| 1238 | 1254 |
date = User.current.today |
| config/locales/en.yml | ||
|---|---|---|
| 743 | 743 |
label_today: today |
| 744 | 744 |
label_all_time: all time |
| 745 | 745 |
label_yesterday: yesterday |
| 746 |
label_tomorrow: tomorrow |
|
| 746 | 747 |
label_this_week: this week |
| 747 | 748 |
label_last_week: last week |
| 749 |
label_next_week: next week |
|
| 748 | 750 |
label_last_n_weeks: "last %{count} weeks"
|
| 749 | 751 |
label_last_n_days: "last %{count} days"
|
| 750 | 752 |
label_this_month: this month |
| 751 | 753 |
label_last_month: last month |
| 754 |
label_next_month: next month |
|
| 752 | 755 |
label_this_year: this year |
| 753 | 756 |
label_date_range: Date range |
| 754 | 757 |
label_less_than_ago: less than days ago |
| public/javascripts/application.js | ||
|---|---|---|
| 301 | 301 |
case "c": |
| 302 | 302 |
case "*o": |
| 303 | 303 |
case "!o": |
| 304 |
case "nd": |
|
| 305 |
case "nw": |
|
| 306 |
case "nm": |
|
| 304 | 307 |
enableValues(field, []); |
| 305 | 308 |
break; |
| 306 | 309 |
case "><": |
| test/unit/query_test.rb | ||
|---|---|---|
| 638 | 638 |
issues.each {|issue| assert_equal Date.today, issue.due_date}
|
| 639 | 639 |
end |
| 640 | 640 | |
| 641 |
def test_operator_tomorrow |
|
| 642 |
query = IssueQuery.new(:project => Project.find(1), :name => '_') |
|
| 643 |
query.add_filter('due_date', 'nd', [''])
|
|
| 644 |
issues = find_issues_with_query(query) |
|
| 645 |
assert !issues.empty? |
|
| 646 |
issues.each {|issue| assert_equal Date.today.tomorrow, issue.due_date}
|
|
| 647 |
end |
|
| 648 | ||
| 641 | 649 |
def test_operator_date_periods |
| 642 |
%w(t ld w lw l2w m lm y).each do |operator| |
|
| 650 |
%w(t ld w lw l2w m lm y nd nw nm).each do |operator|
|
|
| 643 | 651 |
query = IssueQuery.new(:name => '_') |
| 644 | 652 |
query.add_filter('due_date', operator, [''])
|
| 645 | 653 |
assert query.valid? |
| ... | ... | |
| 648 | 656 |
end |
| 649 | 657 | |
| 650 | 658 |
def test_operator_datetime_periods |
| 651 |
%w(t ld w lw l2w m lm y).each do |operator| |
|
| 659 |
%w(t ld w lw l2w m lm y nd nw nm).each do |operator|
|
|
| 652 | 660 |
query = IssueQuery.new(:name => '_') |
| 653 | 661 |
query.add_filter('created_on', operator, [''])
|
| 654 | 662 |
assert query.valid? |
| ... | ... | |
| 710 | 718 |
query.statement |
| 711 | 719 |
end |
| 712 | 720 | |
| 721 |
def test_range_for_next_week_with_week_starting_on_monday |
|
| 722 |
I18n.locale = :fr |
|
| 723 |
assert_equal '1', I18n.t(:general_first_day_of_week) |
|
| 724 | ||
| 725 |
Date.stubs(:today).returns(Date.parse('2011-04-29')) # Friday
|
|
| 726 | ||
| 727 |
query = IssueQuery.new(:project => Project.find(1), :name => '_') |
|
| 728 |
query.add_filter('due_date', 'nw', [''])
|
|
| 729 |
assert_match /issues\.due_date > '#{quoted_date "2011-05-01"} 23:59:59(\.\d+)?' AND issues\.due_date <= '#{quoted_date "2011-05-08"} 23:59:59(\.\d+)?/,
|
|
| 730 |
query.statement |
|
| 731 |
I18n.locale = :en |
|
| 732 |
end |
|
| 733 | ||
| 734 |
def test_range_for_next_week_with_week_starting_on_sunday |
|
| 735 |
I18n.locale = :en |
|
| 736 |
assert_equal '7', I18n.t(:general_first_day_of_week) |
|
| 737 | ||
| 738 |
Date.stubs(:today).returns(Date.parse('2011-04-29')) # Friday
|
|
| 739 | ||
| 740 |
query = IssueQuery.new(:project => Project.find(1), :name => '_') |
|
| 741 |
query.add_filter('due_date', 'nw', [''])
|
|
| 742 |
assert_match /issues\.due_date > '#{quoted_date "2011-04-30"} 23:59:59(\.\d+)?' AND issues\.due_date <= '#{quoted_date "2011-05-07"} 23:59:59(\.\d+)?/,
|
|
| 743 |
query.statement |
|
| 744 |
end |
|
| 745 | ||
| 746 |
def test_range_for_next_month |
|
| 747 |
Date.stubs(:today).returns(Date.parse('2011-04-29')) # Friday
|
|
| 748 | ||
| 749 |
query = IssueQuery.new(:project => Project.find(1), :name => '_') |
|
| 750 |
query.add_filter('due_date', 'nm', [''])
|
|
| 751 |
assert_match /issues\.due_date > '#{quoted_date "2011-04-30"} 23:59:59(\.\d+)?' AND issues\.due_date <= '#{quoted_date "2011-05-31"} 23:59:59(\.\d+)?/,
|
|
| 752 |
query.statement |
|
| 753 |
end |
|
| 754 | ||
| 713 | 755 |
def test_filter_assigned_to_me |
| 714 | 756 |
user = User.find(2) |
| 715 | 757 |
group = Group.find(10) |