mirror of
https://github.com/meineerde/redmine.git
synced 2025-12-19 15:01:14 +00:00
New date filter operators: tomorrow, next week, next month (#4502).
Patch by Mizuki ISHIKAWA. git-svn-id: http://svn.redmine.org/redmine/trunk@17811 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
a8d24ab4b8
commit
04ac58b3c5
@ -263,11 +263,14 @@ class Query < ActiveRecord::Base
|
|||||||
">t+" => :label_in_more_than,
|
">t+" => :label_in_more_than,
|
||||||
"><t+"=> :label_in_the_next_days,
|
"><t+"=> :label_in_the_next_days,
|
||||||
"t+" => :label_in,
|
"t+" => :label_in,
|
||||||
|
"nd" => :label_tomorrow,
|
||||||
"t" => :label_today,
|
"t" => :label_today,
|
||||||
"ld" => :label_yesterday,
|
"ld" => :label_yesterday,
|
||||||
|
"nw" => :label_next_week,
|
||||||
"w" => :label_this_week,
|
"w" => :label_this_week,
|
||||||
"lw" => :label_last_week,
|
"lw" => :label_last_week,
|
||||||
"l2w" => [:label_last_n_weeks, {:count => 2}],
|
"l2w" => [:label_last_n_weeks, {:count => 2}],
|
||||||
|
"nm" => :label_next_month,
|
||||||
"m" => :label_this_month,
|
"m" => :label_this_month,
|
||||||
"lm" => :label_last_month,
|
"lm" => :label_last_month,
|
||||||
"y" => :label_this_year,
|
"y" => :label_this_year,
|
||||||
@ -281,7 +284,7 @@ class Query < ActiveRecord::Base
|
|||||||
"=!p" => :label_any_issues_not_in_project,
|
"=!p" => :label_any_issues_not_in_project,
|
||||||
"!p" => :label_no_issues_in_project,
|
"!p" => :label_no_issues_in_project,
|
||||||
"*o" => :label_any_open_issues,
|
"*o" => :label_any_open_issues,
|
||||||
"!o" => :label_no_open_issues
|
"!o" => :label_no_open_issues,
|
||||||
}
|
}
|
||||||
|
|
||||||
class_attribute :operators_by_filter_type
|
class_attribute :operators_by_filter_type
|
||||||
@ -290,7 +293,7 @@ class Query < ActiveRecord::Base
|
|||||||
:list_status => [ "o", "=", "!", "c", "*" ],
|
:list_status => [ "o", "=", "!", "c", "*" ],
|
||||||
:list_optional => [ "=", "!", "!*", "*" ],
|
:list_optional => [ "=", "!", "!*", "*" ],
|
||||||
:list_subprojects => [ "*", "!*", "=", "!" ],
|
:list_subprojects => [ "*", "!*", "=", "!" ],
|
||||||
:date => [ "=", ">=", "<=", "><", "<t+", ">t+", "><t+", "t+", "t", "ld", "w", "lw", "l2w", "m", "lm", "y", ">t-", "<t-", "><t-", "t-", "!*", "*" ],
|
:date => [ "=", ">=", "<=", "><", "<t+", ">t+", "><t+", "t+", "nd", "t", "ld", "nw", "w", "lw", "l2w", "nm", "m", "lm", "y", ">t-", "<t-", "><t-", "t-", "!*", "*" ],
|
||||||
:date_past => [ "=", ">=", "<=", "><", ">t-", "<t-", "><t-", "t-", "t", "ld", "w", "lw", "l2w", "m", "lm", "y", "!*", "*" ],
|
:date_past => [ "=", ">=", "<=", "><", ">t-", "<t-", "><t-", "t-", "t", "ld", "w", "lw", "l2w", "m", "lm", "y", "!*", "*" ],
|
||||||
:string => [ "~", "=", "!~", "!", "!*", "*" ],
|
:string => [ "~", "=", "!~", "!", "!*", "*" ],
|
||||||
:text => [ "~", "!~", "!*", "*" ],
|
:text => [ "~", "!~", "!*", "*" ],
|
||||||
@ -453,7 +456,7 @@ class Query < ActiveRecord::Base
|
|||||||
# filter requires one or more values
|
# filter requires one or more values
|
||||||
(values_for(field) and !values_for(field).first.blank?) or
|
(values_for(field) and !values_for(field).first.blank?) or
|
||||||
# filter doesn't require any value
|
# filter doesn't require any value
|
||||||
["o", "c", "!*", "*", "t", "ld", "w", "lw", "l2w", "m", "lm", "y", "*o", "!o"].include? operator_for(field)
|
["o", "c", "!*", "*", "nd", "t", "ld", "nw", "w", "lw", "l2w", "nm", "m", "lm", "y", "*o", "!o"].include? operator_for(field)
|
||||||
end if filters
|
end if filters
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -1207,6 +1210,9 @@ class Query < ActiveRecord::Base
|
|||||||
when "ld"
|
when "ld"
|
||||||
# = yesterday
|
# = yesterday
|
||||||
sql = relative_date_clause(db_table, db_field, -1, -1, is_custom_filter)
|
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"
|
when "w"
|
||||||
# = this week
|
# = this week
|
||||||
first_day_of_week = l(:general_first_day_of_week).to_i
|
first_day_of_week = l(:general_first_day_of_week).to_i
|
||||||
@ -1225,6 +1231,12 @@ class Query < ActiveRecord::Base
|
|||||||
day_of_week = User.current.today.cwday
|
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)
|
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)
|
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"
|
when "m"
|
||||||
# = this month
|
# = this month
|
||||||
date = User.current.today
|
date = User.current.today
|
||||||
@ -1233,6 +1245,10 @@ class Query < ActiveRecord::Base
|
|||||||
# = last month
|
# = last month
|
||||||
date = User.current.today.prev_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)
|
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"
|
when "y"
|
||||||
# = this year
|
# = this year
|
||||||
date = User.current.today
|
date = User.current.today
|
||||||
|
|||||||
@ -743,12 +743,15 @@ en:
|
|||||||
label_today: today
|
label_today: today
|
||||||
label_all_time: all time
|
label_all_time: all time
|
||||||
label_yesterday: yesterday
|
label_yesterday: yesterday
|
||||||
|
label_tomorrow: tomorrow
|
||||||
label_this_week: this week
|
label_this_week: this week
|
||||||
label_last_week: last week
|
label_last_week: last week
|
||||||
|
label_next_week: next week
|
||||||
label_last_n_weeks: "last %{count} weeks"
|
label_last_n_weeks: "last %{count} weeks"
|
||||||
label_last_n_days: "last %{count} days"
|
label_last_n_days: "last %{count} days"
|
||||||
label_this_month: this month
|
label_this_month: this month
|
||||||
label_last_month: last month
|
label_last_month: last month
|
||||||
|
label_next_month: next month
|
||||||
label_this_year: this year
|
label_this_year: this year
|
||||||
label_date_range: Date range
|
label_date_range: Date range
|
||||||
label_less_than_ago: less than days ago
|
label_less_than_ago: less than days ago
|
||||||
|
|||||||
@ -635,11 +635,14 @@ ja:
|
|||||||
label_today: 今日
|
label_today: 今日
|
||||||
label_all_time: 全期間
|
label_all_time: 全期間
|
||||||
label_yesterday: 昨日
|
label_yesterday: 昨日
|
||||||
|
label_tomorrow: 明日
|
||||||
label_this_week: 今週
|
label_this_week: 今週
|
||||||
label_last_week: 先週
|
label_last_week: 先週
|
||||||
|
label_next_week: 来週
|
||||||
label_last_n_days: "直近%{count}日間"
|
label_last_n_days: "直近%{count}日間"
|
||||||
label_this_month: 今月
|
label_this_month: 今月
|
||||||
label_last_month: 先月
|
label_last_month: 先月
|
||||||
|
label_next_month: 来月
|
||||||
label_this_year: 今年
|
label_this_year: 今年
|
||||||
label_date_range: 期間
|
label_date_range: 期間
|
||||||
label_less_than_ago: N日前以降
|
label_less_than_ago: N日前以降
|
||||||
|
|||||||
@ -289,11 +289,14 @@ function toggleOperator(field) {
|
|||||||
switch (operator.val()) {
|
switch (operator.val()) {
|
||||||
case "!*":
|
case "!*":
|
||||||
case "*":
|
case "*":
|
||||||
|
case "nd":
|
||||||
case "t":
|
case "t":
|
||||||
case "ld":
|
case "ld":
|
||||||
|
case "nw":
|
||||||
case "w":
|
case "w":
|
||||||
case "lw":
|
case "lw":
|
||||||
case "l2w":
|
case "l2w":
|
||||||
|
case "nm":
|
||||||
case "m":
|
case "m":
|
||||||
case "lm":
|
case "lm":
|
||||||
case "y":
|
case "y":
|
||||||
|
|||||||
@ -638,8 +638,16 @@ class QueryTest < ActiveSupport::TestCase
|
|||||||
issues.each {|issue| assert_equal Date.today, issue.due_date}
|
issues.each {|issue| assert_equal Date.today, issue.due_date}
|
||||||
end
|
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
|
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 = IssueQuery.new(:name => '_')
|
||||||
query.add_filter('due_date', operator, [''])
|
query.add_filter('due_date', operator, [''])
|
||||||
assert query.valid?
|
assert query.valid?
|
||||||
@ -710,6 +718,40 @@ class QueryTest < ActiveSupport::TestCase
|
|||||||
query.statement
|
query.statement
|
||||||
end
|
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
|
def test_filter_assigned_to_me
|
||||||
user = User.find(2)
|
user = User.find(2)
|
||||||
group = Group.find(10)
|
group = Group.find(10)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user