Project

General

Profile

Feature #16045 » previous-assignee-v5.patch

Go MAEDA, 2024-09-03 11:27

View differences:

app/helpers/application_helper.rb
if collection.include?(User.current)
s << content_tag('option', "<< #{l(:label_me)} >>", :value => User.current.id)
end
groups = +''
shortcut_users_html = +''
# This optgroup is displayed only when editing a single issue
if @issue.present?
users = [@issue.author, @issue.prior_assigned_to].uniq.compact
shortcut_users_html = users.map do |user|
collection.include?(user) ? content_tag('option', user.name, value: user.id) : nil
end.join
end
users_html = +''
groups_html = +''
collection.sort.each do |element|
if option_value_selected?(element, selected) || element.id.to_s == selected
selected_attribute = ' selected="selected"'
end
(element.is_a?(Group) ? groups : s) <<
(element.is_a?(Group) ? groups_html : users_html) <<
%(<option value="#{element.id}"#{selected_attribute}>#{h element.name}</option>)
end
unless groups.empty?
s << %(<optgroup label="#{h(l(:label_group_plural))}">#{groups}</optgroup>)
if shortcut_users_html.blank? && groups_html.blank?
s << users_html
else
[
[l(:label_author_and_prior_assignee), shortcut_users_html],
[l(:label_user_plural), users_html],
[l(:label_group_plural), groups_html]
].each do |label, options_html|
s << %(<optgroup label="#{h(label)}">#{options_html}</optgroup>) if options_html.present?
end
end
s.html_safe
end
app/models/issue.rb
result
end
# Returns the assignee immediately prior to the current one from the issue history
def prior_assigned_to
prior_assigned_to_id =
journals.joins(:details)
.where(details: {prop_key: 'assigned_to_id'})
.where.not(details: {old_value: nil})
.order(id: :desc)
.pick(:old_value)
prior_assigned_to_id && Principal.find_by(id: prior_assigned_to_id)
end
# Returns the previous assignee from the issue history
def previous_assigned_to
journals.reverse_each do |j|
previous_assignee_change = j.detail_for_attribute 'assigned_to_id'
return User.find_by(id: previous_assignee_change.old_value.to_i) if previous_assignee_change && previous_assignee_change.old_value
end
nil
end
# Returns the initial status of the issue
# Returns nil for a new issue
def status_was
config/locales/en.yml
label_optional: optional
label_show_completed_versions: Show completed versions
label_me: me
label_previous_assignee: "Previous: %{name}"
label_board: Forum
label_board_new: New forum
label_board_plural: Forums
......
label_default_query: Default query
label_edited: Edited
label_time_by_author: "%{time} by %{author}"
label_author_and_prior_assignee: Author / Prior assignee
button_login: Login
button_submit: Submit
config/locales/ja.yml
setting_issue_done_ratio_interval: 進捗率の選択肢の間隔
setting_copy_attachments_on_issue_copy: チケットをコピーするとき添付ファイルもコピー
field_thousands_delimiter: 3桁区切り表示
label_author_and_prior_assignee: 作成者・直前担当者
test/helpers/application_helper_test.rb
User.current = nil
set_language_if_valid 'en'
users = [User.find(2), Group.find(11), User.find(4), Group.find(10)]
assert_equal(
%(<option value="2">John Smith</option><option value="4">Robert Hill</option>) +
%(<optgroup label="Groups"><option value="10">A Team</option><option value="11">B Team</option></optgroup>),
principals_options_for_select(users))
result = principals_options_for_select(users)
assert_select_in result, 'optgroup[label="Users"]' do
assert_select 'option[value="2"]', text: 'John Smith'
assert_select 'option[value="4"]', text: 'Robert Hill'
end
assert_select_in result, 'optgroup[label="Groups"]' do
assert_select 'option[value="10"]', text: 'A Team'
assert_select 'option[value="11"]', text: 'B Team'
end
end
def test_principals_options_for_select_with_empty_collection
......
principals_options_for_select(users)
end
def test_principals_options_for_select_should_include_author_and_prior_assignee
set_language_if_valid 'en'
users = [User.find(2), User.find(3), User.find(1)]
@issue = Issue.generate!(author_id: 1, assigned_to_id: 2)
@issue.init_journal(users.first, 'update')
@issue.assigned_to_id = 3
@issue.save
result = principals_options_for_select(users)
assert_select_in result, 'optgroup[label="Author / Prior assignee"]' do
assert_select 'option:nth-of-type(1)', text: 'Redmine Admin' # Author
assert_select 'option:nth-of-type(2)', text: 'John Smith' # Prior assignee
end
end
def test_stylesheet_link_tag_should_pick_the_default_stylesheet
assert_match 'href="/assets/styles.css"', stylesheet_link_tag("styles")
end
test/unit/issue_test.rb
assert_equal was_closed_on, issue.closed_on
end
def test_prior_assigned_to
issue = Issue.generate!(assigned_to_id: 2)
issue.init_journal(User.find(2), 'update')
issue.assigned_to_id = 3
issue.save
assert_equal User.find(2), issue.prior_assigned_to
end
def test_status_was_should_return_nil_for_new_issue
issue = Issue.new
assert_nil issue.status_was
(9-9/16)