diff --git a/README.md b/README.md index 58b84c3..f9131da 100644 --- a/README.md +++ b/README.md @@ -7,8 +7,9 @@ Subtasks Inherited Fields is a plugin that allows to choose which fields are inh * Config which fields you want to inherit in the plugin administration page * Allows to select the default subtask tracker +* Fast Create or Create and Continue subtask creation * Support for custom fields -* Tested on Redmine 2.4.6 and Redmine 2.5.1 +* Works on Redmine 2.4.x, 2.5.x and 2.6.x (For Redmine 4.0.x and 3.x.x check out branch master) ## Install @@ -57,6 +58,14 @@ Additional RSpec tests can also be run by entering the following command: rspec plugins/redmine_subtasks_inherited_fields/spec ``` +## Sponsors + +Thanks to [Luis Blasco](http://www.luisblasco.com) for his contribution to support this plugin and implement the Create and Continue feature. + ## Contact If you have any doubt please raise an Github Issue. Comments are Welcome! + +## License + +This plugin is open source and released under the terms of the [GNU General Public License v2 (GPL)](http://www.gnu.org/licenses/old-licenses/gpl-2.0.html). diff --git a/init.rb b/init.rb index 6f57823..88bb64e 100644 --- a/init.rb +++ b/init.rb @@ -2,11 +2,12 @@ name 'Redmine Subtasks Inherited Fields plugin' author 'Edosoft Factory' description 'This is a plugin for Redmine to allow choosing which fields are inherited when you create a subtask' - version '0.0.3' + version '1.1.0' url 'http://www.edosoftfactory.com' author_url 'mailto:david.verdu@edosoftfactory.com' - requires_redmine :version_or_higher => '2.0.0' + #requires_redmine :version_or_higher => '2.0.0' + requires_redmine :version => '2.0'..'2.6' settings :default => { :inherit_fixed_version_id => true, @@ -24,4 +25,6 @@ end +require 'subtasks_inherited_fields' require 'issues_helper_patch' +require 'issues_controller_patch' diff --git a/lib/issues_controller_patch.rb b/lib/issues_controller_patch.rb new file mode 100644 index 0000000..f443ecc --- /dev/null +++ b/lib/issues_controller_patch.rb @@ -0,0 +1,68 @@ + +module SubtasksInheritedFields + module IssuesControllerPatch + module InstanceMethods + + #redefine create method to call our redirect_after_create + def create_plugin + call_hook(:controller_issues_new_before_save, { :params => params, :issue => @issue }) + @issue.save_attachments(params[:attachments] || (params[:issue] && params[:issue][:uploads])) + if @issue.save + call_hook(:controller_issues_new_after_save, { :params => params, :issue => @issue}) + respond_to do |format| + format.html { + render_attachment_warning_if_needed(@issue) + flash[:notice] = l(:notice_issue_successful_create, :id => view_context.link_to("##{@issue.id}", issue_path(@issue), :title => @issue.subject)) + redirect_after_create #redirect after create inheriting subtask fields + } + format.api { render :action => 'show', :status => :created, :location => issue_url(@issue) } + end + return + else + respond_to do |format| + format.html { render :action => 'new' } + format.api { render_validation_errors(@issue) } + end + end + end + + # Redirects user after a successful issue creation with inheritance + def redirect_after_create + if params[:continue] + + attrs = {:tracker_id => @issue.tracker, :parent_issue_id => @issue.parent_issue_id}.reject {|k,v| v.nil?} + + #inherit fields on create subtask and continue + if @issue.parent_issue_id + parent_issue = Issue.find(@issue.parent_issue_id) + attrs = SubtasksInheritedFields::Helpers.inherit_attrs(parent_issue) + end + + if params[:project_id] + redirect_to new_project_issue_path(@issue.project, :issue => attrs) + else + attrs.merge! :project_id => @issue.project_id + redirect_to new_issue_path(:issue => attrs) + end + else + redirect_to issue_path(@issue) + end + end + end + + def self.included(receiver) + receiver.send :include, InstanceMethods + + receiver.class_eval do + unloadable + alias_method :create, :create_plugin + end + end + end +end + +unless IssuesController.included_modules.include?(SubtasksInheritedFields::IssuesControllerPatch) + #puts "Including module into IssuesController" + IssuesController.send(:include, SubtasksInheritedFields::IssuesControllerPatch) +end + diff --git a/lib/issues_helper_patch.rb b/lib/issues_helper_patch.rb index 69e4ffe..7544f63 100644 --- a/lib/issues_helper_patch.rb +++ b/lib/issues_helper_patch.rb @@ -5,41 +5,7 @@ module InstanceMethods # Returns a link for adding a new subtask to the given issue def link_to_new_subtask_plugin(issue) - settings = Setting.find_by_name("plugin_redmine_subtasks_inherited_fields") || {} - settings = settings.value if settings.respond_to? :value - settings = {} if settings == "" - attrs = { - #:tracker_id => issue.tracker, - :parent_issue_id => issue - } - if settings[:inherit_tracker_id] #inherit tracker - attrs[:tracker_id] = issue.tracker - else #use default subtask tracker - default_tracker = Tracker.find_by_id(settings[:default_tracker_id] || 0) || issue.tracker - default_tracker = issue.tracker unless @project.trackers.include? default_tracker - attrs[:tracker_id] = default_tracker - end - attrs[:fixed_version_id] = issue.fixed_version_id if settings[:inherit_fixed_version_id] - attrs[:category_id] = issue.category_id if settings[:inherit_category_id] - attrs[:assigned_to_id] = issue.assigned_to_id if settings[:inherit_assigned_to_id] - attrs[:priority_id] = issue.priority_id if settings[:inherit_priority_id] - attrs[:start_date] = issue.start_date if settings[:inherit_start_date] - attrs[:due_date] = issue.due_date if settings[:inherit_due_date] - attrs[:description] = issue.description if settings[:inherit_description] - attrs[:is_private] = issue.is_private if settings[:inherit_is_private] - attrs[:status_id] = issue.status_id if settings[:inherit_status_id] - - #inherit custom fields - inherit_custom_fields = settings[:inherit_custom_fields] || {} - unless inherit_custom_fields.empty? - custom_field_values = {} - issue.custom_field_values.each do |v| - custom_field_values[v.custom_field_id] = v.value if inherit_custom_fields[v.custom_field_id.to_s] - end - - attrs[:custom_field_values] = custom_field_values unless custom_field_values.empty? - end - + attrs = SubtasksInheritedFields::Helpers.inherit_attrs(issue) link_to(l(:button_add), new_project_issue_path(issue.project, :issue => attrs)) end end diff --git a/lib/subtasks_inherited_fields.rb b/lib/subtasks_inherited_fields.rb new file mode 100644 index 0000000..a8825af --- /dev/null +++ b/lib/subtasks_inherited_fields.rb @@ -0,0 +1,41 @@ + +module SubtasksInheritedFields + module Helpers + def self.inherit_attrs(parent_issue) + attrs = {:parent_issue_id => parent_issue.id} + settings = Setting.find_by_name("plugin_redmine_subtasks_inherited_fields") || {} + settings = settings.value if settings.respond_to? :value + settings = {} if settings == "" + if settings[:inherit_tracker_id] #inherit tracker + attrs[:tracker_id] = parent_issue.tracker + else #use default subtask tracker + default_tracker = Tracker.find_by_id(settings[:default_tracker_id] || 0) || parent_issue.tracker + project = parent_issue.project + default_tracker = parent_issue.tracker unless project.trackers.include? default_tracker + attrs[:tracker_id] = default_tracker + end + attrs[:fixed_version_id] = parent_issue.fixed_version_id if settings[:inherit_fixed_version_id] + attrs[:category_id] = parent_issue.category_id if settings[:inherit_category_id] + attrs[:assigned_to_id] = parent_issue.assigned_to_id if settings[:inherit_assigned_to_id] + attrs[:priority_id] = parent_issue.priority_id if settings[:inherit_priority_id] + attrs[:start_date] = parent_issue.start_date if settings[:inherit_start_date] + attrs[:due_date] = parent_issue.due_date if settings[:inherit_due_date] + attrs[:description] = parent_issue.description if settings[:inherit_description] + attrs[:is_private] = parent_issue.is_private if settings[:inherit_is_private] + attrs[:status_id] = parent_issue.status_id if settings[:inherit_status_id] + + #inherit custom fields + inherit_custom_fields = settings[:inherit_custom_fields] || {} + unless inherit_custom_fields.empty? + custom_field_values = {} + parent_issue.custom_field_values.each do |v| + custom_field_values[v.custom_field_id] = v.value if inherit_custom_fields[v.custom_field_id.to_s] + end + + attrs[:custom_field_values] = custom_field_values unless custom_field_values.empty? + end + + return attrs + end + end +end