Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additional options for what to do with Tasks when copying a Story #1118

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 20 additions & 0 deletions app/views/backlogs/_settings.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,26 @@
<%= check_box_tag("settings[show_priority]", 'enabled',
Backlogs.setting[:show_priority]) %>
</p>

<p>
<%= content_tag(:label, l(:backlogs_copy_tasks_action)) %>
<%= select_tag("settings[copy_tasks_action]",
options_for_select([
[l(:rb_label_copy_tasks_action_copy), 'copy'],
[l(:rb_label_copy_tasks_action_move), 'move']
], Backlogs.setting[:copy_tasks_action])) %>
</p>

<p>
<%= content_tag(:label, l(:backlogs_copy_tasks_default)) %>
<%= select_tag("settings[copy_tasks_default]",
options_for_select([
[l(:rb_label_copy_tasks_open), 'open'],
[l(:rb_label_copy_tasks_closed), 'closed'],
[l(:rb_label_copy_tasks_none), 'none'],
[l(:rb_label_copy_tasks_all), 'all']
], Backlogs.setting[:copy_tasks_default])) %>
</p>
</fieldset>

<fieldset>
Expand Down
6 changes: 6 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ en:
backlogs_sharing_support: "Backlogs sharing"
backlogs_show_in_scrum_stats: "Show project in Scrum statistics"
backlogs_show_priority: "Show task priority on taskboard"
backlogs_copy_tasks_action: "Copy or Move tasks when copying a Story"
backlogs_copy_tasks_default: 'Default selection for "Copy/Move tasks"'
backlogs_show_redmine_std_header: "Show redmine header in backlogs"
backlogs_show_stories_from_subprojects_in_backlog: "Show stories from subprojects in backlog"
backlogs_sprint_card_settings: "Card printing"
Expand Down Expand Up @@ -184,10 +186,14 @@ en:
To support distributed teams, calculations for burndown graphs use a common concept of when a day begins.
Your user timezone is %{user_timezone}, the server timezone is %{server_timezone} and Burndowns use %{burndown_timezone} to calculate the graphs.
Note: Historic data is not affected when changing this option.
rb_label_copy_tasks_action_copy: Copy
rb_label_copy_tasks_action_move: Move
rb_label_copy_tasks: "Copy tasks"
rb_label_move_tasks: "Move tasks"
rb_label_copy_tasks_all: All
rb_label_copy_tasks_none: None
rb_label_copy_tasks_open: Open
rb_label_copy_tasks_closed: Closed
rb_label_link_to_original: "Include link to original story"
rb_label_timelog_disable: Disable
rb_label_timelog_enable: Enable
Expand Down
50 changes: 39 additions & 11 deletions lib/backlogs_hooks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,18 @@ def view_issues_form_details_bottom(context={ })
snippet += "<p><label for='link_to_original'>#{l(:rb_label_link_to_original)}</label>"
snippet += "#{check_box_tag('link_to_original', params[:copy_from], true)}</p>"

snippet += "<p><label>#{l(:rb_label_copy_tasks)}</label>"
snippet += "#{radio_button_tag('copy_tasks', 'open:' + params[:copy_from], true)} #{l(:rb_label_copy_tasks_open)}<br />"
snippet += "#{radio_button_tag('copy_tasks', 'none', false)} #{l(:rb_label_copy_tasks_none)}<br />"
snippet += "#{radio_button_tag('copy_tasks', 'all:' + params[:copy_from], false)} #{l(:rb_label_copy_tasks_all)}</p>"
snippet += "<p><label>#{
if Backlogs.setting[:copy_tasks_action] == 'move'
l(:rb_label_move_tasks)
else
l(:rb_label_copy_tasks)
end
}</label>"

snippet += "#{radio_button_tag('copy_tasks', 'open:' + params[:copy_from], Backlogs.setting[:copy_tasks_default]=='open')} #{l(:rb_label_copy_tasks_open)}<br />"
snippet += "#{radio_button_tag('copy_tasks', 'closed:' + params[:copy_from], Backlogs.setting[:copy_tasks_default]=='closed')} #{l(:rb_label_copy_tasks_closed)}<br />"
snippet += "#{radio_button_tag('copy_tasks', 'none', Backlogs.setting[:copy_tasks_default]=='none')} #{l(:rb_label_copy_tasks_none)}<br />"
snippet += "#{radio_button_tag('copy_tasks', 'all:' + params[:copy_from], Backlogs.setting[:copy_tasks_default]=='all')} #{l(:rb_label_copy_tasks_all)}</p>"
end

if issue.is_task? && !issue.new_record?
Expand Down Expand Up @@ -338,6 +346,8 @@ def controller_issues_new_after_save(context={ })
case action
when 'open'
tasks = story.tasks.select{|t| !t.reload.closed?}
when 'closed'
tasks = story.tasks.reject{|t| !t.reload.closed?}
when 'none'
tasks = []
when 'all'
Expand All @@ -346,13 +356,31 @@ def controller_issues_new_after_save(context={ })
raise "Unexpected value #{params[:copy_tasks]}"
end

tasks.each {|t|
nt = Issue.new
nt.copy_from(t)
nt.parent_issue_id = issue.id
nt.position = nil # will assign a new position
nt.save!
}
if Backlogs.setting[:copy_tasks_action] == 'move'
tasks.each {|t|
#
# Update parent_issue_id as a Task, because it will fail if
# we try to perform the update as an Issue. The consequence
# of this is that it does not create an entry in the Journal.
#
# We also skip validation, otherwise we would get a "parent
# task is invalid" error.
#
t.parent_issue_id = issue.id
t.save(:validate => false)
}
else
tasks.each {|t|
nt = Issue.new
nt.copy_from(t)
nt.parent_issue_id = issue.id
nt.position = nil # will assign a new position
nt.save!
}
end

# In case the new story only has closed tasks, make sure it is closed.
context[:issue].becomes(RbStory).story_follow_task_state
end
end
end
Expand Down