diff --git a/app/models/issue_status_changer.rb b/app/models/issue_status_changer.rb index d15a880..76b3437 100644 --- a/app/models/issue_status_changer.rb +++ b/app/models/issue_status_changer.rb @@ -9,37 +9,52 @@ def self.get_closed_status IssueStatus.select( :id ).where("is_closed=1").collect {|s| s.id}.join(",") end - def self.get_enabled_trackers + def self.get_enabled_trackers(state = 'open') + state = 'close' if (state != 'close' and state != 'open') settings = Setting['plugin_redmine_issue_status_changer'] || {} - if settings['status_change'] != nil then - settings['status_change'].keys.join(',') + if settings['status_change'][state] != nil then + settings['status_change'][state].keys.join(',') else false end end - def self.get_next_state(tracker_id) + def self.get_next_state(tracker_id, state = 'close') + state = 'close' if (state != 'close' and state != 'open') settings = Setting['plugin_redmine_issue_status_changer'] || {} - settings['new_status'][tracker_id.to_s].to_i + settings['new_status'][state][tracker_id.to_s].to_i end - def self.close_issues_with_all_subtasks_closed + issue_change_state('close') + end + + def self.open_issues_with_open_subtasks + issue_change_state('open') + end + + def self.issue_change_state(state) settings = Setting['plugin_redmine_issue_status_changer'] || {} - status_message = settings['status_message'] + - enabled_trackers = get_enabled_trackers() + enabled_trackers = get_enabled_trackers(state) if enabled_trackers then - open_state = get_open_status() - closed_state = get_closed_status() + if state == 'close' then + change_state = get_open_status() + test = "=" + status_message = settings['status_message_closed'] + elsif state == 'open' then + change_state = get_closed_status() + test = "<" + status_message = settings['status_message_open'] + end - # Get all issues that have a done ratio of 100% (meaning all subtask closed) but the status is not closed - Issue.where("done_ratio=100 AND tracker_id IN (#{enabled_trackers}) AND status_id IN (#{open_state})").each do |issue| + Issue.where("done_ratio#{test}100 AND tracker_id IN (#{enabled_trackers}) AND status_id IN (#{change_state}) AND id IN (SELECT parent_id FROM issues)").each do |issue| i = Issue.find issue.id - new_status = IssueStatus.find get_next_state(i.tracker_id) + new_status = IssueStatus.find get_next_state(i.tracker_id, state) - #puts i.id.to_s + " " + i.subject + ": " + (IssueStatus.find i.status_id).name + " --> " + new_status.name + puts i.id.to_s + " " + i.subject + ": " + (IssueStatus.find i.status_id).name + " --> " + new_status.name i.init_journal(User.anonymous, status_message) i.update_attribute :status, new_status end diff --git a/app/views/settings/_issue_status_change.html.erb b/app/views/settings/_issue_status_change.html.erb index 28755ce..e057119 100755 --- a/app/views/settings/_issue_status_change.html.erb +++ b/app/views/settings/_issue_status_change.html.erb @@ -3,51 +3,85 @@
<%= l(:issue_status_change_rake_task) %>
-<% settings['status_change'] = Hash.new if settings['status_change'] == nil %> -<% settings['new_status'] = Hash.new if settings['new_status'] == nil %> -<% settings['status_message'] = l(:status_message) if settings['status_message'] == nil %> +<% settings['status_change']['close'] = Hash.new if settings['status_change']['close'] == nil %> +<% settings['new_status']['close'] = Hash.new if settings['new_status']['close'] == nil %> + +<% settings['status_change']['open'] = Hash.new if settings['status_change']['open'] == nil %> +<% settings['new_status']['open'] = Hash.new if settings['new_status']['open'] == nil %> + +<% settings['status_message_closed'] = l(:status_message_closed) if settings['status_message_closed'] == nil %> +<% settings['status_message_open'] = l(:status_message_open) if settings['status_message_open'] == nil %>
<%= l(:status_message_legend) %>

- - <%= text_field_tag "settings[status_message]", settings[:status_message] %> + + <%= text_field_tag "settings[status_message_closed]", settings[:status_message_closed] %> +

+

+ + <%= text_field_tag "settings[status_message_open]", settings[:status_message_open] %>

<% Tracker.all.each do |tracker| %> -
<%= tracker.name %>

- - <%= check_box_tag "settings[status_change][#{tracker.id}]", "1", @settings[:status_change][tracker.id.to_s] %> + + <%= check_box_tag "settings[status_change][close][#{tracker.id}]", "1", @settings[:status_change]['close'][tracker.id.to_s] %>

- - <%= select_tag "settings[new_status][#{tracker.id}", options_for_select(IssueStatus.joins(:workflows).where(:workflows => {:tracker_id => tracker.id}, :is_closed => 1).uniq.map {|s| [s.name, s.id]},@settings[:new_status][tracker.id.to_s]) %> + + <%= select_tag "settings[new_status][close][#{tracker.id}", options_for_select(IssueStatus.joins(:workflows).where(:workflows => {:tracker_id => tracker.id}, :is_closed => 1).uniq.map {|s| [s.name, s.id]},@settings[:new_status]['close'][tracker.id.to_s]) %> +

+ +

+ + <%= check_box_tag "settings[status_change][open][#{tracker.id}]", "1", @settings[:status_change]['open'][tracker.id.to_s] %> +

+ + <%= select_tag "settings[new_status][open][#{tracker.id}", options_for_select(IssueStatus.joins(:workflows).where(:workflows => {:tracker_id => tracker.id}, :is_closed => 0).uniq.map {|s| [s.name, s.id]},@settings[:new_status]['open'][tracker.id.to_s]) %>

<% end %> <%= javascript_tag do %> $(document).ready(function() { - $('[id^=settings_status_change_]').click(function() { + $('[id^=settings_status_change_close_]').click(function() { tracker_id = this.id.substring(this.id.lastIndexOf("_")+1); - if ($('#settings_status_change_'+tracker_id).is(':checked')) { - $('#settings_new_status_'+tracker_id).show(); - $('#settings_new_status_'+tracker_id+'_label').show(); + if ($('#settings_status_change_close_'+tracker_id).is(':checked')) { + $('#settings_new_status_close_'+tracker_id).show(); + $('#settings_new_status_close_'+tracker_id+'_label').show(); } else { - $('#settings_new_status_'+tracker_id).hide(); - $('#settings_new_status_'+tracker_id+'_label').hide(); + $('#settings_new_status_close_'+tracker_id).hide(); + $('#settings_new_status_close_'+tracker_id+'_label').hide(); } }); -}); -$('[id^=settings_status_change_]:not(:checked)').each(function(index) { + $('[id^=settings_status_change_open_]').click(function() { tracker_id = this.id.substring(this.id.lastIndexOf("_")+1); - $('#settings_new_status_'+tracker_id).hide(); - $('#settings_new_status_'+tracker_id+'_label').hide(); + if ($('#settings_status_change_open_'+tracker_id).is(':checked')) { + $('#settings_new_status_open_'+tracker_id).show(); + $('#settings_new_status_open_'+tracker_id+'_label').show(); + } + else { + $('#settings_new_status_open_'+tracker_id).hide(); + $('#settings_new_status_open_'+tracker_id+'_label').hide(); + } + }); + + $('[id^=settings_status_change_open_]:not(:checked)').each(function(index) { + tracker_id = this.id.substring(this.id.lastIndexOf("_")+1); + $('#settings_new_status_open_'+tracker_id).hide(); + $('#settings_new_status_open_'+tracker_id+'_label').hide(); + }); + + $('[id^=settings_status_change_close_]:not(:checked)').each(function(index) { + tracker_id = this.id.substring(this.id.lastIndexOf("_")+1); + $('#settings_new_status_close_'+tracker_id).hide(); + $('#settings_new_status_close_'+tracker_id+'_label').hide(); +}); }); <% end %> \ No newline at end of file diff --git a/config/locales/en.yml b/config/locales/en.yml index 7eb816c..9088e9e 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -3,8 +3,11 @@ en: issue_status_change: "Change issue status automatically" issue_status_change_help: "This plugin does not change the status unless you define a cron job that runs a rake task periodically. This task is:" issue_status_change_rake_task: "rake redmine:plugins:issue_status_change:close_issues_with_all_subtasks_closed RAILS_ENV=production" - change_status_label: "Change status when all subtasks are done" - new_status: "Closed status" - status_message: "Automatically changing status because all subtasks are solved" - status_message_label: "Journal message when status is changed" + change_closed_label: "Change status when all subtasks are done" + change_open_label: "Change status when all there are new open subtasks" + new_status: "New status" + status_message_closed: "Automatically changing status because all subtasks are solved" + status_message_label_closed: "Journal message when issue is closed" + status_message_open: "Automatically changing status there are still open subtasks" + status_message_label_open: "Journal message when issue is reopened" status_message_legend: "Journal" \ No newline at end of file diff --git a/init.rb b/init.rb index 93cf95d..519f38a 100644 --- a/init.rb +++ b/init.rb @@ -15,6 +15,10 @@ }, :partial => 'settings/issue_status_change' settings[:default]["change_status"] = Hash.new - settings[:default]["new_status"] = Hash.new + settings[:default]["new_status"]= Hash.new + settings[:default]["change_status"]["close"] = Hash.new + settings[:default]["new_status"]["close"] = Hash.new + settings[:default]["change_status"]["open"] = Hash.new + settings[:default]["new_status"]["open"] = Hash.new end diff --git a/lib/tasks/open_issues_with_open_subtasks.rake b/lib/tasks/open_issues_with_open_subtasks.rake new file mode 100644 index 0000000..97c3756 --- /dev/null +++ b/lib/tasks/open_issues_with_open_subtasks.rake @@ -0,0 +1,14 @@ +namespace :redmine do + namespace :plugins do + namespace :issue_status_change do + desc <<-END_DESC +Bla bla bla + + rake redmine:plugins:issue_status_change:open_issues_with_open_subtasks RAILS_ENV=production + END_DESC + task open_issues_with_open_subtasks: :environment do |_t, _args| + IssueStatusChanger.open_issues_with_open_subtasks + end + end + end +end