diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2009-12-18 15:41:32 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2009-12-18 15:41:32 +0000 |
commit | 6bf0723d0654e58bc6c8fc19759ff8fb6502a18f (patch) | |
tree | a90c2bb695ca772be91cab3fb07d79f7ea2de30d | |
parent | 6a369f28ddab41673f51c1b7a640ad6054d8e258 (diff) | |
download | redmine-6bf0723d0654e58bc6c8fc19759ff8fb6502a18f.tar.gz redmine-6bf0723d0654e58bc6c8fc19759ff8fb6502a18f.zip |
By default, only show statuses that are used by the tracker on the workflow edit view.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3188 e93f8b46-1217-0410-a6f0-8f06a7374b81
40 files changed, 114 insertions, 9 deletions
diff --git a/app/controllers/workflows_controller.rb b/app/controllers/workflows_controller.rb index 6e7c58e26..fd2876769 100644 --- a/app/controllers/workflows_controller.rb +++ b/app/controllers/workflows_controller.rb @@ -42,7 +42,12 @@ class WorkflowsController < ApplicationController end @roles = Role.find(:all, :order => 'builtin, position') @trackers = Tracker.find(:all, :order => 'position') - @statuses = IssueStatus.find(:all, :order => 'position') + + @used_statuses_only = (params[:used_statuses_only] == '0' ? false : true) + if @tracker && @used_statuses_only && @tracker.issue_statuses.any? + @statuses = @tracker.issue_statuses + end + @statuses ||= IssueStatus.find(:all, :order => 'position') end def copy diff --git a/app/models/tracker.rb b/app/models/tracker.rb index 8f7a98c39..9ee045ce1 100644 --- a/app/models/tracker.rb +++ b/app/models/tracker.rb @@ -43,6 +43,23 @@ class Tracker < ActiveRecord::Base find(:all, :order => 'position') end + # Returns an array of IssueStatus that are used + # in the tracker's workflows + def issue_statuses + if @issue_statuses + return @issue_statuses + elsif new_record? + return [] + end + + ids = Workflow. + connection.select_rows("SELECT DISTINCT old_status_id, new_status_id FROM #{Workflow.table_name} WHERE tracker_id = #{id}"). + flatten. + uniq + + @issue_statuses = IssueStatus.find_all_by_id(ids).sort + end + private def check_integrity raise "Can't delete tracker" if Issue.find(:first, :conditions => ["tracker_id=?", self.id]) diff --git a/app/views/workflows/edit.rhtml b/app/views/workflows/edit.rhtml index 4feaf3a7c..d7343fa2b 100644 --- a/app/views/workflows/edit.rhtml +++ b/app/views/workflows/edit.rhtml @@ -11,8 +11,12 @@ <label><%=l(:label_tracker)%>:</label> <%= select_tag 'tracker_id', options_from_collection_for_select(@trackers, "id", "name", @tracker && @tracker.id) %> - - <%= submit_tag l(:button_edit), :name => nil %> + + <%= hidden_field_tag 'used_statuses_only', '0' %> + <label><%= check_box_tag 'used_statuses_only', '1', @used_statuses_only %> <%= l(:label_display_used_statuses_only) %></label> +</p> +<p> +<%= submit_tag l(:button_edit), :name => nil %> </p> <% end %> diff --git a/config/locales/bg.yml b/config/locales/bg.yml index 300bd3868..4302542ce 100644 --- a/config/locales/bg.yml +++ b/config/locales/bg.yml @@ -855,3 +855,4 @@ bg: label_update_issue_done_ratios: Update issue done ratios setting_start_of_week: Start calendars on permission_view_issues: View Issues + label_display_used_statuses_only: Only display statuses that are used by this tracker diff --git a/config/locales/bs.yml b/config/locales/bs.yml index d2bd1800f..5e33bb8ad 100644 --- a/config/locales/bs.yml +++ b/config/locales/bs.yml @@ -879,3 +879,4 @@ bs: label_update_issue_done_ratios: Update issue done ratios setting_start_of_week: Start calendars on permission_view_issues: View Issues + label_display_used_statuses_only: Only display statuses that are used by this tracker diff --git a/config/locales/ca.yml b/config/locales/ca.yml index 0019a5f37..c5120180d 100644 --- a/config/locales/ca.yml +++ b/config/locales/ca.yml @@ -858,3 +858,4 @@ ca: label_update_issue_done_ratios: Update issue done ratios setting_start_of_week: Start calendars on permission_view_issues: View Issues + label_display_used_statuses_only: Only display statuses that are used by this tracker diff --git a/config/locales/cs.yml b/config/locales/cs.yml index 03d6d90b5..4ad8ad62a 100644 --- a/config/locales/cs.yml +++ b/config/locales/cs.yml @@ -861,3 +861,4 @@ cs: label_update_issue_done_ratios: Update issue done ratios setting_start_of_week: Start calendars on permission_view_issues: View Issues + label_display_used_statuses_only: Only display statuses that are used by this tracker diff --git a/config/locales/da.yml b/config/locales/da.yml index c627f7353..246855811 100644 --- a/config/locales/da.yml +++ b/config/locales/da.yml @@ -881,3 +881,4 @@ da: label_update_issue_done_ratios: Update issue done ratios setting_start_of_week: Start calendars on permission_view_issues: View Issues + label_display_used_statuses_only: Only display statuses that are used by this tracker diff --git a/config/locales/de.yml b/config/locales/de.yml index e936faf87..e11ffb525 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -881,3 +881,4 @@ de: label_update_issue_done_ratios: Update issue done ratios setting_start_of_week: Start calendars on permission_view_issues: View Issues + label_display_used_statuses_only: Only display statuses that are used by this tracker diff --git a/config/locales/el.yml b/config/locales/el.yml index 76825d896..13f8f37c7 100644 --- a/config/locales/el.yml +++ b/config/locales/el.yml @@ -861,3 +861,4 @@ el: label_update_issue_done_ratios: Update issue done ratios setting_start_of_week: Start calendars on permission_view_issues: View Issues + label_display_used_statuses_only: Only display statuses that are used by this tracker diff --git a/config/locales/en.yml b/config/locales/en.yml index 1be78ebcd..3eee529d1 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -727,6 +727,7 @@ en: label_copy_source: Source label_copy_target: Target label_copy_same_as_target: Same as target + label_display_used_statuses_only: Only display statuses that are used by this tracker button_login: Login button_submit: Submit diff --git a/config/locales/es.yml b/config/locales/es.yml index 7a22b7384..c0aa91dba 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -902,3 +902,4 @@ es: label_update_issue_done_ratios: Update issue done ratios setting_start_of_week: Start calendars on permission_view_issues: View Issues + label_display_used_statuses_only: Only display statuses that are used by this tracker diff --git a/config/locales/fi.yml b/config/locales/fi.yml index 7b2e754ef..93d354dc4 100644 --- a/config/locales/fi.yml +++ b/config/locales/fi.yml @@ -891,3 +891,4 @@ fi: label_update_issue_done_ratios: Update issue done ratios setting_start_of_week: Start calendars on permission_view_issues: View Issues + label_display_used_statuses_only: Only display statuses that are used by this tracker diff --git a/config/locales/fr.yml b/config/locales/fr.yml index fd32c6b69..aa7fdafa9 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -742,6 +742,7 @@ fr: label_copy_target: Cible label_copy_same_as_target: Comme la cible label_update_issue_done_ratios: Mettre à jour l'avancement des demandes + label_display_used_statuses_only: N'afficher que les statuts utilisés dans ce tracker button_login: Connexion button_submit: Soumettre diff --git a/config/locales/gl.yml b/config/locales/gl.yml index 77698bd2e..363a54ef3 100644 --- a/config/locales/gl.yml +++ b/config/locales/gl.yml @@ -881,3 +881,4 @@ gl: label_update_issue_done_ratios: Update issue done ratios setting_start_of_week: Start calendars on permission_view_issues: View Issues + label_display_used_statuses_only: Only display statuses that are used by this tracker diff --git a/config/locales/he.yml b/config/locales/he.yml index b7df4fbd3..bc1723826 100644 --- a/config/locales/he.yml +++ b/config/locales/he.yml @@ -865,3 +865,4 @@ he: label_update_issue_done_ratios: Update issue done ratios setting_start_of_week: Start calendars on permission_view_issues: View Issues + label_display_used_statuses_only: Only display statuses that are used by this tracker diff --git a/config/locales/hu.yml b/config/locales/hu.yml index 71023e703..8c9f289f9 100644 --- a/config/locales/hu.yml +++ b/config/locales/hu.yml @@ -886,3 +886,4 @@ label_update_issue_done_ratios: Update issue done ratios setting_start_of_week: Start calendars on permission_view_issues: View Issues + label_display_used_statuses_only: Only display statuses that are used by this tracker diff --git a/config/locales/it.yml b/config/locales/it.yml index 6ec67fee3..627daf347 100644 --- a/config/locales/it.yml +++ b/config/locales/it.yml @@ -868,3 +868,4 @@ it: label_update_issue_done_ratios: Update issue done ratios setting_start_of_week: Start calendars on permission_view_issues: View Issues + label_display_used_statuses_only: Only display statuses that are used by this tracker diff --git a/config/locales/ja.yml b/config/locales/ja.yml index 24127d8e5..1257db260 100644 --- a/config/locales/ja.yml +++ b/config/locales/ja.yml @@ -890,3 +890,4 @@ ja: label_update_issue_done_ratios: Update issue done ratios setting_start_of_week: Start calendars on permission_view_issues: View Issues + label_display_used_statuses_only: Only display statuses that are used by this tracker diff --git a/config/locales/ko.yml b/config/locales/ko.yml index 5402fc191..081c3acd4 100644 --- a/config/locales/ko.yml +++ b/config/locales/ko.yml @@ -921,3 +921,4 @@ ko: label_update_issue_done_ratios: Update issue done ratios setting_start_of_week: Start calendars on permission_view_issues: View Issues + label_display_used_statuses_only: Only display statuses that are used by this tracker diff --git a/config/locales/lt.yml b/config/locales/lt.yml index b7d6eece3..b21fb5c31 100644 --- a/config/locales/lt.yml +++ b/config/locales/lt.yml @@ -929,3 +929,4 @@ lt: error_workflow_copy_source: Please select a source tracker or role label_update_issue_done_ratios: Update issue done ratios permission_view_issues: View Issues + label_display_used_statuses_only: Only display statuses that are used by this tracker diff --git a/config/locales/nl.yml b/config/locales/nl.yml index 2b50fd838..3acefe89f 100644 --- a/config/locales/nl.yml +++ b/config/locales/nl.yml @@ -843,3 +843,4 @@ nl: label_update_issue_done_ratios: Update issue done ratios setting_start_of_week: Start calendars on permission_view_issues: View Issues + label_display_used_statuses_only: Only display statuses that are used by this tracker diff --git a/config/locales/no.yml b/config/locales/no.yml index 6eda0fa71..a8b064c0e 100644 --- a/config/locales/no.yml +++ b/config/locales/no.yml @@ -856,3 +856,4 @@ label_update_issue_done_ratios: Update issue done ratios setting_start_of_week: Start calendars on permission_view_issues: View Issues + label_display_used_statuses_only: Only display statuses that are used by this tracker diff --git a/config/locales/pl.yml b/config/locales/pl.yml index 1eb0c0ee9..d3e502196 100644 --- a/config/locales/pl.yml +++ b/config/locales/pl.yml @@ -884,3 +884,4 @@ pl: label_update_issue_done_ratios: Update issue done ratios setting_start_of_week: Start calendars on permission_view_issues: View Issues + label_display_used_statuses_only: Only display statuses that are used by this tracker diff --git a/config/locales/pt-BR.yml b/config/locales/pt-BR.yml index 98fcf1d26..6491b0c54 100644 --- a/config/locales/pt-BR.yml +++ b/config/locales/pt-BR.yml @@ -889,3 +889,4 @@ pt-BR: field_watcher: Observador permission_view_issues: View Issues + label_display_used_statuses_only: Only display statuses that are used by this tracker diff --git a/config/locales/pt.yml b/config/locales/pt.yml index 2a6140580..24c24190c 100644 --- a/config/locales/pt.yml +++ b/config/locales/pt.yml @@ -873,3 +873,4 @@ pt: label_update_issue_done_ratios: Update issue done ratios setting_start_of_week: Start calendars on permission_view_issues: View Issues + label_display_used_statuses_only: Only display statuses that are used by this tracker diff --git a/config/locales/ro.yml b/config/locales/ro.yml index 4f098e8d6..9a089118a 100644 --- a/config/locales/ro.yml +++ b/config/locales/ro.yml @@ -858,3 +858,4 @@ ro: label_update_issue_done_ratios: Update issue done ratios setting_start_of_week: Start calendars on permission_view_issues: View Issues + label_display_used_statuses_only: Only display statuses that are used by this tracker diff --git a/config/locales/ru.yml b/config/locales/ru.yml index 08141371d..c01e52a64 100644 --- a/config/locales/ru.yml +++ b/config/locales/ru.yml @@ -969,3 +969,4 @@ ru: label_update_issue_done_ratios: Update issue done ratios setting_start_of_week: Start calendars on permission_view_issues: View Issues + label_display_used_statuses_only: Only display statuses that are used by this tracker diff --git a/config/locales/sk.yml b/config/locales/sk.yml index 5798a48d6..a20630837 100644 --- a/config/locales/sk.yml +++ b/config/locales/sk.yml @@ -860,3 +860,4 @@ sk: label_update_issue_done_ratios: Update issue done ratios setting_start_of_week: Start calendars on permission_view_issues: View Issues + label_display_used_statuses_only: Only display statuses that are used by this tracker diff --git a/config/locales/sl.yml b/config/locales/sl.yml index 30c2e3777..61f84ad8b 100644 --- a/config/locales/sl.yml +++ b/config/locales/sl.yml @@ -857,3 +857,4 @@ sl: label_update_issue_done_ratios: Update issue done ratios setting_start_of_week: Start calendars on permission_view_issues: View Issues + label_display_used_statuses_only: Only display statuses that are used by this tracker diff --git a/config/locales/sr.yml b/config/locales/sr.yml index f7af3d4a4..b58df8c60 100644 --- a/config/locales/sr.yml +++ b/config/locales/sr.yml @@ -876,3 +876,4 @@ label_update_issue_done_ratios: Update issue done ratios setting_start_of_week: Start calendars on permission_view_issues: View Issues + label_display_used_statuses_only: Only display statuses that are used by this tracker diff --git a/config/locales/sv.yml b/config/locales/sv.yml index 7a188009b..c73a75688 100644 --- a/config/locales/sv.yml +++ b/config/locales/sv.yml @@ -910,3 +910,4 @@ sv: label_update_issue_done_ratios: Update issue done ratios setting_start_of_week: Start calendars on permission_view_issues: View Issues + label_display_used_statuses_only: Only display statuses that are used by this tracker diff --git a/config/locales/th.yml b/config/locales/th.yml index 1e88942b1..8ad86d00a 100644 --- a/config/locales/th.yml +++ b/config/locales/th.yml @@ -858,3 +858,4 @@ th: label_update_issue_done_ratios: Update issue done ratios setting_start_of_week: Start calendars on permission_view_issues: View Issues + label_display_used_statuses_only: Only display statuses that are used by this tracker diff --git a/config/locales/tr.yml b/config/locales/tr.yml index 1135fc378..e98b53f02 100644 --- a/config/locales/tr.yml +++ b/config/locales/tr.yml @@ -888,3 +888,4 @@ tr: label_update_issue_done_ratios: Update issue done ratios setting_start_of_week: Start calendars on permission_view_issues: View Issues + label_display_used_statuses_only: Only display statuses that are used by this tracker diff --git a/config/locales/uk.yml b/config/locales/uk.yml index f6288f668..55dc50c56 100644 --- a/config/locales/uk.yml +++ b/config/locales/uk.yml @@ -857,3 +857,4 @@ uk: label_update_issue_done_ratios: Update issue done ratios setting_start_of_week: Start calendars on permission_view_issues: View Issues + label_display_used_statuses_only: Only display statuses that are used by this tracker diff --git a/config/locales/vi.yml b/config/locales/vi.yml index 76e28e8b6..d498cb53c 100644 --- a/config/locales/vi.yml +++ b/config/locales/vi.yml @@ -920,3 +920,4 @@ vi: label_update_issue_done_ratios: Update issue done ratios setting_start_of_week: Start calendars on permission_view_issues: View Issues + label_display_used_statuses_only: Only display statuses that are used by this tracker diff --git a/config/locales/zh-TW.yml b/config/locales/zh-TW.yml index f026719c3..b315d370a 100644 --- a/config/locales/zh-TW.yml +++ b/config/locales/zh-TW.yml @@ -954,3 +954,4 @@ error_workflow_copy_source: Please select a source tracker or role label_update_issue_done_ratios: Update issue done ratios permission_view_issues: View Issues + label_display_used_statuses_only: Only display statuses that are used by this tracker diff --git a/config/locales/zh.yml b/config/locales/zh.yml index 389ec4a0d..e34c5c3f3 100644 --- a/config/locales/zh.yml +++ b/config/locales/zh.yml @@ -885,3 +885,4 @@ zh: label_update_issue_done_ratios: Update issue done ratios setting_start_of_week: Start calendars on permission_view_issues: View Issues + label_display_used_statuses_only: Only display statuses that are used by this tracker diff --git a/test/functional/workflows_controller_test.rb b/test/functional/workflows_controller_test.rb index 2b5216f55..802d10d6c 100644 --- a/test/functional/workflows_controller_test.rb +++ b/test/functional/workflows_controller_test.rb @@ -22,7 +22,7 @@ require 'workflows_controller' class WorkflowsController; def rescue_action(e) raise e end; end class WorkflowsControllerTest < ActionController::TestCase - fixtures :roles, :trackers, :workflows, :users + fixtures :roles, :trackers, :workflows, :users, :issue_statuses def setup @controller = WorkflowsController.new @@ -51,18 +51,46 @@ class WorkflowsControllerTest < ActionController::TestCase end def test_get_edit_with_role_and_tracker + Workflow.delete_all + Workflow.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 2, :new_status_id => 3) + Workflow.create!(:role_id => 2, :tracker_id => 1, :old_status_id => 3, :new_status_id => 5) + get :edit, :role_id => 2, :tracker_id => 1 assert_response :success assert_template 'edit' + + # used status only + assert_not_nil assigns(:statuses) + assert_equal [2, 3, 5], assigns(:statuses).collect(&:id) + # allowed transitions assert_tag :tag => 'input', :attributes => { :type => 'checkbox', - :name => 'issue_status[2][]', - :value => '1', + :name => 'issue_status[3][]', + :value => '5', :checked => 'checked' } # not allowed assert_tag :tag => 'input', :attributes => { :type => 'checkbox', - :name => 'issue_status[2][]', - :value => '3', + :name => 'issue_status[3][]', + :value => '2', + :checked => nil } + # unused + assert_no_tag :tag => 'input', :attributes => { :type => 'checkbox', + :name => 'issue_status[4][]' } + end + + def test_get_edit_with_role_and_tracker_and_all_statuses + Workflow.delete_all + + get :edit, :role_id => 2, :tracker_id => 1, :used_statuses_only => '0' + assert_response :success + assert_template 'edit' + + assert_not_nil assigns(:statuses) + assert_equal IssueStatus.count, assigns(:statuses).size + + assert_tag :tag => 'input', :attributes => { :type => 'checkbox', + :name => 'issue_status[1][]', + :value => '1', :checked => nil } end diff --git a/test/unit/tracker_test.rb b/test/unit/tracker_test.rb index efc2aa7ed..f27550aa6 100644 --- a/test/unit/tracker_test.rb +++ b/test/unit/tracker_test.rb @@ -18,7 +18,7 @@ require File.dirname(__FILE__) + '/../test_helper' class TrackerTest < ActiveSupport::TestCase - fixtures :trackers, :workflows + fixtures :trackers, :workflows, :issue_statuses, :roles def test_copy_workflows source = Tracker.find(1) @@ -30,4 +30,20 @@ class TrackerTest < ActiveSupport::TestCase target.reload assert_equal 89, target.workflows.size end + + def test_issue_statuses + tracker = Tracker.find(1) + Workflow.delete_all + Workflow.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 2, :new_status_id => 3) + Workflow.create!(:role_id => 2, :tracker_id => 1, :old_status_id => 3, :new_status_id => 5) + + assert_kind_of Array, tracker.issue_statuses + assert_kind_of IssueStatus, tracker.issue_statuses.first + assert_equal [2, 3, 5], Tracker.find(1).issue_statuses.collect(&:id) + end + + def test_issue_statuses_empty + Workflow.delete_all("tracker_id = 1") + assert_equal [], Tracker.find(1).issue_statuses + end end |