Patch #4502 » add-next-range-filters-v2.patch
| app/models/query.rb | ||
|---|---|---|
|
"=!p" => :label_any_issues_not_in_project,
|
||
|
"!p" => :label_no_issues_in_project,
|
||
|
"*o" => :label_any_open_issues,
|
||
|
"!o" => :label_no_open_issues
|
||
|
"!o" => :label_no_open_issues,
|
||
|
"nd" => :label_tomorrow,
|
||
|
"nw" => :label_next_week,
|
||
|
"nm" => :label_next_month
|
||
|
}
|
||
|
class_attribute :operators_by_filter_type
|
||
| ... | ... | |
|
:list_status => [ "o", "=", "!", "c", "*" ],
|
||
|
:list_optional => [ "=", "!", "!*", "*" ],
|
||
|
:list_subprojects => [ "*", "!*", "=", "!" ],
|
||
|
:date => [ "=", ">=", "<=", "><", "<t+", ">t+", "><t+", "t+", "t", "ld", "w", "lw", "l2w", "m", "lm", "y", ">t-", "<t-", "><t-", "t-", "!*", "*" ],
|
||
|
:date => [ "=", ">=", "<=", "><", "<t+", ">t+", "><t+", "t+", "t", "ld", "nd", "w", "lw", "l2w", "nw", "m", "lm", "nm", "y", ">t-", "<t-", "><t-", "t-", "!*", "*" ],
|
||
|
:date_past => [ "=", ">=", "<=", "><", ">t-", "<t-", "><t-", "t-", "t", "ld", "w", "lw", "l2w", "m", "lm", "y", "!*", "*" ],
|
||
|
:string => [ "~", "=", "!~", "!", "!*", "*" ],
|
||
|
:text => [ "~", "!~", "!*", "*" ],
|
||
| ... | ... | |
|
# 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", "ld", "w", "lw", "l2w", "m", "lm", "y", "*o", "!o"].include? operator_for(field)
|
||
|
["o", "c", "!*", "*", "t", "ld", "w", "lw", "l2w", "m", "lm", "y", "*o", "!o", "nd", "nw", "nm"].include? operator_for(field)
|
||
|
end if filters
|
||
|
end
|
||
| ... | ... | |
|
when "ld"
|
||
|
# = yesterday
|
||
|
sql = relative_date_clause(db_table, db_field, -1, -1, is_custom_filter)
|
||
|
when "nd"
|
||
|
# = tomorrow
|
||
|
sql = relative_date_clause(db_table, db_field, 1, 1, is_custom_filter)
|
||
|
when "w"
|
||
|
# = this week
|
||
|
first_day_of_week = l(:general_first_day_of_week).to_i
|
||
| ... | ... | |
|
day_of_week = User.current.today.cwday
|
||
|
days_ago = (day_of_week >= first_day_of_week ? day_of_week - first_day_of_week : day_of_week + 7 - first_day_of_week)
|
||
|
sql = relative_date_clause(db_table, db_field, - days_ago - 14, - days_ago - 1, is_custom_filter)
|
||
|
when "nw"
|
||
|
# = next week
|
||
|
first_day_of_week = l(:general_first_day_of_week).to_i
|
||
|
day_of_week = User.current.today.cwday
|
||
|
from = -(day_of_week >= first_day_of_week ? day_of_week - first_day_of_week : day_of_week + 7 - first_day_of_week) + 7
|
||
|
sql = relative_date_clause(db_table, db_field, from, from + 6, is_custom_filter)
|
||
|
when "m"
|
||
|
# = this month
|
||
|
date = User.current.today
|
||
| ... | ... | |
|
# = last month
|
||
|
date = User.current.today.prev_month
|
||
|
sql = date_clause(db_table, db_field, date.beginning_of_month, date.end_of_month, is_custom_filter)
|
||
|
when "nm"
|
||
|
# = next month
|
||
|
date = User.current.today.next_month
|
||
|
sql = date_clause(db_table, db_field, date.beginning_of_month, date.end_of_month, is_custom_filter)
|
||
|
when "y"
|
||
|
# = this year
|
||
|
date = User.current.today
|
||
| config/locales/en.yml | ||
|---|---|---|
|
label_today: today
|
||
|
label_all_time: all time
|
||
|
label_yesterday: yesterday
|
||
|
label_tomorrow: tomorrow
|
||
|
label_this_week: this week
|
||
|
label_last_week: last week
|
||
|
label_next_week: next week
|
||
|
label_last_n_weeks: "last %{count} weeks"
|
||
|
label_last_n_days: "last %{count} days"
|
||
|
label_this_month: this month
|
||
|
label_last_month: last month
|
||
|
label_next_month: next month
|
||
|
label_this_year: this year
|
||
|
label_date_range: Date range
|
||
|
label_less_than_ago: less than days ago
|
||
| public/javascripts/application.js | ||
|---|---|---|
|
case "c":
|
||
|
case "*o":
|
||
|
case "!o":
|
||
|
case "nd":
|
||
|
case "nw":
|
||
|
case "nm":
|
||
|
enableValues(field, []);
|
||
|
break;
|
||
|
case "><":
|
||
| test/unit/query_test.rb | ||
|---|---|---|
|
issues.each {|issue| assert_equal Date.today, issue.due_date}
|
||
|
end
|
||
|
def test_operator_tomorrow
|
||
|
query = IssueQuery.new(:project => Project.find(1), :name => '_')
|
||
|
query.add_filter('due_date', 'nd', [''])
|
||
|
issues = find_issues_with_query(query)
|
||
|
assert !issues.empty?
|
||
|
issues.each {|issue| assert_equal Date.today.tomorrow, issue.due_date}
|
||
|
end
|
||
|
def test_operator_date_periods
|
||
|
%w(t ld w lw l2w m lm y).each do |operator|
|
||
|
%w(t ld w lw l2w m lm y nd nw nm).each do |operator|
|
||
|
query = IssueQuery.new(:name => '_')
|
||
|
query.add_filter('due_date', operator, [''])
|
||
|
assert query.valid?
|
||
| ... | ... | |
|
query.statement
|
||
|
end
|
||
|
def test_range_for_next_week_with_week_starting_on_monday
|
||
|
I18n.locale = :fr
|
||
|
assert_equal '1', I18n.t(:general_first_day_of_week)
|
||
|
Date.stubs(:today).returns(Date.parse('2011-04-29')) # Friday
|
||
|
query = IssueQuery.new(:project => Project.find(1), :name => '_')
|
||
|
query.add_filter('due_date', 'nw', [''])
|
||
|
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+)?/,
|
||
|
query.statement
|
||
|
I18n.locale = :en
|
||
|
end
|
||
|
def test_range_for_next_week_with_week_starting_on_sunday
|
||
|
I18n.locale = :en
|
||
|
assert_equal '7', I18n.t(:general_first_day_of_week)
|
||
|
Date.stubs(:today).returns(Date.parse('2011-04-29')) # Friday
|
||
|
query = IssueQuery.new(:project => Project.find(1), :name => '_')
|
||
|
query.add_filter('due_date', 'nw', [''])
|
||
|
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+)?/,
|
||
|
query.statement
|
||
|
end
|
||
|
def test_range_for_next_month
|
||
|
Date.stubs(:today).returns(Date.parse('2011-04-29')) # Friday
|
||
|
query = IssueQuery.new(:project => Project.find(1), :name => '_')
|
||
|
query.add_filter('due_date', 'nm', [''])
|
||
|
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+)?/,
|
||
|
query.statement
|
||
|
end
|
||
|
def test_filter_assigned_to_me
|
||
|
user = User.find(2)
|
||
|
group = Group.find(10)
|
||