@@ -1,68 +1,68 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2015 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2015 Jean-Philippe Lang | |
3 | # |
|
3 | # | |
4 | # This program is free software; you can redistribute it and/or |
|
4 | # This program is free software; you can redistribute it and/or | |
5 | # modify it under the terms of the GNU General Public License |
|
5 | # modify it under the terms of the GNU General Public License | |
6 | # as published by the Free Software Foundation; either version 2 |
|
6 | # as published by the Free Software Foundation; either version 2 | |
7 | # of the License, or (at your option) any later version. |
|
7 | # of the License, or (at your option) any later version. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU General Public License |
|
14 | # You should have received a copy of the GNU General Public License | |
15 | # along with this program; if not, write to the Free Software |
|
15 | # along with this program; if not, write to the Free Software | |
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 |
|
17 | |||
18 | class IssuePriority < Enumeration |
|
18 | class IssuePriority < Enumeration | |
19 | has_many :issues, :foreign_key => 'priority_id' |
|
19 | has_many :issues, :foreign_key => 'priority_id' | |
20 |
|
20 | |||
21 | after_destroy {|priority| priority.class.compute_position_names} |
|
21 | after_destroy {|priority| priority.class.compute_position_names} | |
22 | after_save {|priority| priority.class.compute_position_names if priority.position_changed? && priority.position} |
|
22 | after_save {|priority| priority.class.compute_position_names if (priority.position_changed? && priority.position) || priority.active_changed?} | |
23 |
|
23 | |||
24 | OptionName = :enumeration_issue_priorities |
|
24 | OptionName = :enumeration_issue_priorities | |
25 |
|
25 | |||
26 | def option_name |
|
26 | def option_name | |
27 | OptionName |
|
27 | OptionName | |
28 | end |
|
28 | end | |
29 |
|
29 | |||
30 | def objects_count |
|
30 | def objects_count | |
31 | issues.count |
|
31 | issues.count | |
32 | end |
|
32 | end | |
33 |
|
33 | |||
34 | def transfer_relations(to) |
|
34 | def transfer_relations(to) | |
35 | issues.update_all(:priority_id => to.id) |
|
35 | issues.update_all(:priority_id => to.id) | |
36 | end |
|
36 | end | |
37 |
|
37 | |||
38 | def css_classes |
|
38 | def css_classes | |
39 | "priority-#{id} priority-#{position_name}" |
|
39 | "priority-#{id} priority-#{position_name}" | |
40 | end |
|
40 | end | |
41 |
|
41 | |||
42 | # Clears position_name for all priorities |
|
42 | # Clears position_name for all priorities | |
43 | # Called from migration 20121026003537_populate_enumerations_position_name |
|
43 | # Called from migration 20121026003537_populate_enumerations_position_name | |
44 | def self.clear_position_names |
|
44 | def self.clear_position_names | |
45 | update_all :position_name => nil |
|
45 | update_all :position_name => nil | |
46 | end |
|
46 | end | |
47 |
|
47 | |||
48 | # Updates position_name for active priorities |
|
48 | # Updates position_name for active priorities | |
49 | # Called from migration 20121026003537_populate_enumerations_position_name |
|
49 | # Called from migration 20121026003537_populate_enumerations_position_name | |
50 | def self.compute_position_names |
|
50 | def self.compute_position_names | |
51 | priorities = where(:active => true).sort_by(&:position) |
|
51 | priorities = where(:active => true).sort_by(&:position) | |
52 | if priorities.any? |
|
52 | if priorities.any? | |
53 | default = priorities.detect(&:is_default?) || priorities[(priorities.size - 1) / 2] |
|
53 | default = priorities.detect(&:is_default?) || priorities[(priorities.size - 1) / 2] | |
54 | priorities.each_with_index do |priority, index| |
|
54 | priorities.each_with_index do |priority, index| | |
55 | name = case |
|
55 | name = case | |
56 | when priority.position == default.position |
|
56 | when priority.position == default.position | |
57 | "default" |
|
57 | "default" | |
58 | when priority.position < default.position |
|
58 | when priority.position < default.position | |
59 | index == 0 ? "lowest" : "low#{index+1}" |
|
59 | index == 0 ? "lowest" : "low#{index+1}" | |
60 | else |
|
60 | else | |
61 | index == (priorities.size - 1) ? "highest" : "high#{priorities.size - index}" |
|
61 | index == (priorities.size - 1) ? "highest" : "high#{priorities.size - index}" | |
62 | end |
|
62 | end | |
63 |
|
63 | |||
64 | where(:id => priority.id).update_all({:position_name => name}) |
|
64 | where(:id => priority.id).update_all({:position_name => name}) | |
65 | end |
|
65 | end | |
66 | end |
|
66 | end | |
67 | end |
|
67 | end | |
68 | end |
|
68 | end |
General Comments 0
You need to be logged in to leave comments.
Login now