Feature #16045 » previous-assignee-v5.patch
app/helpers/application_helper.rb | ||
---|---|---|
672 | 672 |
if collection.include?(User.current) |
673 | 673 |
s << content_tag('option', "<< #{l(:label_me)} >>", :value => User.current.id) |
674 | 674 |
end |
675 |
groups = +'' |
|
675 | ||
676 |
shortcut_users_html = +'' |
|
677 |
# This optgroup is displayed only when editing a single issue |
|
678 |
if @issue.present? |
|
679 |
users = [@issue.author, @issue.prior_assigned_to].uniq.compact |
|
680 |
shortcut_users_html = users.map do |user| |
|
681 |
collection.include?(user) ? content_tag('option', user.name, value: user.id) : nil |
|
682 |
end.join |
|
683 |
end |
|
684 | ||
685 |
users_html = +'' |
|
686 |
groups_html = +'' |
|
676 | 687 |
collection.sort.each do |element| |
677 | 688 |
if option_value_selected?(element, selected) || element.id.to_s == selected |
678 | 689 |
selected_attribute = ' selected="selected"' |
679 | 690 |
end |
680 |
(element.is_a?(Group) ? groups : s) <<
|
|
691 |
(element.is_a?(Group) ? groups_html : users_html) <<
|
|
681 | 692 |
%(<option value="#{element.id}"#{selected_attribute}>#{h element.name}</option>) |
682 | 693 |
end |
683 |
unless groups.empty? |
|
684 |
s << %(<optgroup label="#{h(l(:label_group_plural))}">#{groups}</optgroup>) |
|
694 |
if shortcut_users_html.blank? && groups_html.blank? |
|
695 |
s << users_html |
|
696 |
else |
|
697 |
[ |
|
698 |
[l(:label_author_and_prior_assignee), shortcut_users_html], |
|
699 |
[l(:label_user_plural), users_html], |
|
700 |
[l(:label_group_plural), groups_html] |
|
701 |
].each do |label, options_html| |
|
702 |
s << %(<optgroup label="#{h(label)}">#{options_html}</optgroup>) if options_html.present? |
|
703 |
end |
|
685 | 704 |
end |
686 | 705 |
s.html_safe |
687 | 706 |
end |
app/models/issue.rb | ||
---|---|---|
925 | 925 |
result |
926 | 926 |
end |
927 | 927 | |
928 |
# Returns the assignee immediately prior to the current one from the issue history |
|
929 |
def prior_assigned_to |
|
930 |
prior_assigned_to_id = |
|
931 |
journals.joins(:details) |
|
932 |
.where(details: {prop_key: 'assigned_to_id'}) |
|
933 |
.where.not(details: {old_value: nil}) |
|
934 |
.order(id: :desc) |
|
935 |
.pick(:old_value) |
|
936 | ||
937 |
prior_assigned_to_id && Principal.find_by(id: prior_assigned_to_id) |
|
938 |
end |
|
939 | ||
940 |
# Returns the previous assignee from the issue history |
|
941 |
def previous_assigned_to |
|
942 |
journals.reverse_each do |j| |
|
943 |
previous_assignee_change = j.detail_for_attribute 'assigned_to_id' |
|
944 |
return User.find_by(id: previous_assignee_change.old_value.to_i) if previous_assignee_change && previous_assignee_change.old_value |
|
945 |
end |
|
946 |
nil |
|
947 |
end |
|
948 |
|
|
949 | ||
928 | 950 |
# Returns the initial status of the issue |
929 | 951 |
# Returns nil for a new issue |
930 | 952 |
def status_was |
config/locales/en.yml | ||
---|---|---|
909 | 909 |
label_optional: optional |
910 | 910 |
label_show_completed_versions: Show completed versions |
911 | 911 |
label_me: me |
912 |
label_previous_assignee: "Previous: %{name}" |
|
912 | 913 |
label_board: Forum |
913 | 914 |
label_board_new: New forum |
914 | 915 |
label_board_plural: Forums |
... | ... | |
1145 | 1146 |
label_default_query: Default query |
1146 | 1147 |
label_edited: Edited |
1147 | 1148 |
label_time_by_author: "%{time} by %{author}" |
1149 |
label_author_and_prior_assignee: Author / Prior assignee |
|
1148 | 1150 | |
1149 | 1151 |
button_login: Login |
1150 | 1152 |
button_submit: Submit |
config/locales/ja.yml | ||
---|---|---|
1445 | 1445 |
setting_issue_done_ratio_interval: 進捗率の選択肢の間隔 |
1446 | 1446 |
setting_copy_attachments_on_issue_copy: チケットをコピーするとき添付ファイルもコピー |
1447 | 1447 |
field_thousands_delimiter: 3桁区切り表示 |
1448 |
label_author_and_prior_assignee: 作成者・直前担当者 |
|
1449 |
test/helpers/application_helper_test.rb | ||
---|---|---|
2052 | 2052 |
User.current = nil |
2053 | 2053 |
set_language_if_valid 'en' |
2054 | 2054 |
users = [User.find(2), Group.find(11), User.find(4), Group.find(10)] |
2055 |
assert_equal( |
|
2056 |
%(<option value="2">John Smith</option><option value="4">Robert Hill</option>) + |
|
2057 |
%(<optgroup label="Groups"><option value="10">A Team</option><option value="11">B Team</option></optgroup>), |
|
2058 |
principals_options_for_select(users)) |
|
2055 |
result = principals_options_for_select(users) |
|
2056 | ||
2057 |
assert_select_in result, 'optgroup[label="Users"]' do |
|
2058 |
assert_select 'option[value="2"]', text: 'John Smith' |
|
2059 |
assert_select 'option[value="4"]', text: 'Robert Hill' |
|
2060 |
end |
|
2061 |
assert_select_in result, 'optgroup[label="Groups"]' do |
|
2062 |
assert_select 'option[value="10"]', text: 'A Team' |
|
2063 |
assert_select 'option[value="11"]', text: 'B Team' |
|
2064 |
end |
|
2059 | 2065 |
end |
2060 | 2066 | |
2061 | 2067 |
def test_principals_options_for_select_with_empty_collection |
... | ... | |
2070 | 2076 |
principals_options_for_select(users) |
2071 | 2077 |
end |
2072 | 2078 | |
2079 |
def test_principals_options_for_select_should_include_author_and_prior_assignee |
|
2080 |
set_language_if_valid 'en' |
|
2081 |
users = [User.find(2), User.find(3), User.find(1)] |
|
2082 |
@issue = Issue.generate!(author_id: 1, assigned_to_id: 2) |
|
2083 |
@issue.init_journal(users.first, 'update') |
|
2084 |
@issue.assigned_to_id = 3 |
|
2085 |
@issue.save |
|
2086 | ||
2087 |
result = principals_options_for_select(users) |
|
2088 |
assert_select_in result, 'optgroup[label="Author / Prior assignee"]' do |
|
2089 |
assert_select 'option:nth-of-type(1)', text: 'Redmine Admin' # Author |
|
2090 |
assert_select 'option:nth-of-type(2)', text: 'John Smith' # Prior assignee |
|
2091 |
end |
|
2092 |
end |
|
2093 | ||
2094 | ||
2073 | 2095 |
def test_stylesheet_link_tag_should_pick_the_default_stylesheet |
2074 | 2096 |
assert_match 'href="/assets/styles.css"', stylesheet_link_tag("styles") |
2075 | 2097 |
end |
test/unit/issue_test.rb | ||
---|---|---|
3247 | 3247 |
assert_equal was_closed_on, issue.closed_on |
3248 | 3248 |
end |
3249 | 3249 | |
3250 |
def test_prior_assigned_to |
|
3251 |
issue = Issue.generate!(assigned_to_id: 2) |
|
3252 |
issue.init_journal(User.find(2), 'update') |
|
3253 |
issue.assigned_to_id = 3 |
|
3254 |
issue.save |
|
3255 | ||
3256 |
assert_equal User.find(2), issue.prior_assigned_to |
|
3257 |
end |
|
3258 | ||
3250 | 3259 |
def test_status_was_should_return_nil_for_new_issue |
3251 | 3260 |
issue = Issue.new |
3252 | 3261 |
assert_nil issue.status_was |