diff options
author | Go MAEDA <maeda@farend.jp> | 2020-01-21 04:08:29 +0000 |
---|---|---|
committer | Go MAEDA <maeda@farend.jp> | 2020-01-21 04:08:29 +0000 |
commit | 006b686499a469fcafbf34bd910332f246c75b48 (patch) | |
tree | f84517e8e169e31b0c8a0663625afdf0accc05d8 /app | |
parent | 758a08fad9c9da5a8378bcde2cd29608b6127741 (diff) | |
download | redmine-006b686499a469fcafbf34bd910332f246c75b48.tar.gz redmine-006b686499a469fcafbf34bd910332f246c75b48.zip |
Extract finding the default or "middle" issue priority into its own class method (#32628).
Patch by Jan Schulz-Hofen.
git-svn-id: http://svn.redmine.org/redmine/trunk@19447 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app')
-rw-r--r-- | app/models/issue_priority.rb | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/app/models/issue_priority.rb b/app/models/issue_priority.rb index 05be79dd1..8326b8ffa 100644 --- a/app/models/issue_priority.rb +++ b/app/models/issue_priority.rb @@ -47,18 +47,25 @@ class IssuePriority < Enumeration update_all :position_name => nil end + def self.default_or_middle + default || begin + priorities = active + priorities[(priorities.size - 1) / 2] + end + end + # Updates position_name for active priorities # Called from migration 20121026003537_populate_enumerations_position_name def self.compute_position_names priorities = active if priorities.any? - default = priorities.detect(&:is_default?) || priorities[(priorities.size - 1) / 2] + default_position = default_or_middle.position priorities.each_with_index do |priority, index| name = case - when priority.position == default.position + when priority.position == default_position "default" - when priority.position < default.position + when priority.position < default_position index == 0 ? "lowest" : "low#{index+1}" else index == (priorities.size - 1) ? "highest" : "high#{priorities.size - index}" |