Adds a textual css class for issue priorities (#12216).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10720 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
a679d19709
commit
113f8b5cf2
|
@ -906,7 +906,7 @@ class Issue < ActiveRecord::Base
|
|||
|
||||
# Returns a string of css classes that apply to the issue
|
||||
def css_classes
|
||||
s = "issue status-#{status_id} priority-#{priority_id}"
|
||||
s = "issue status-#{status_id} #{priority.try(:css_classes)}"
|
||||
s << ' closed' if closed?
|
||||
s << ' overdue' if overdue?
|
||||
s << ' child' if child?
|
||||
|
|
|
@ -18,6 +18,9 @@
|
|||
class IssuePriority < Enumeration
|
||||
has_many :issues, :foreign_key => 'priority_id'
|
||||
|
||||
after_destroy {|priority| priority.class.compute_position_names}
|
||||
after_save {|priority| priority.class.compute_position_names if priority.position_changed? && priority.position}
|
||||
|
||||
OptionName = :enumeration_issue_priorities
|
||||
|
||||
def option_name
|
||||
|
@ -31,4 +34,35 @@ class IssuePriority < Enumeration
|
|||
def transfer_relations(to)
|
||||
issues.update_all("priority_id = #{to.id}")
|
||||
end
|
||||
|
||||
def css_classes
|
||||
"priority-#{id} priority-#{position_name}"
|
||||
end
|
||||
|
||||
# Clears position_name for all priorities
|
||||
# Called from migration 20121026003537_populate_enumerations_position_name
|
||||
def self.clear_position_names
|
||||
update_all :position_name => nil
|
||||
end
|
||||
|
||||
# Updates position_name for active priorities
|
||||
# Called from migration 20121026003537_populate_enumerations_position_name
|
||||
def self.compute_position_names
|
||||
priorities = where(:active => true).all.sort_by(&:position)
|
||||
if priorities.any?
|
||||
default = priorities.detect(&:is_default?) || priorities[(priorities.size - 1) / 2]
|
||||
priorities.each_with_index do |priority, index|
|
||||
name = case
|
||||
when priority.position == default.position
|
||||
"default"
|
||||
when priority.position < default.position
|
||||
index == 0 ? "lowest" : "low#{index+1}"
|
||||
else
|
||||
index == (priorities.size - 1) ? "highest" : "high#{priorities.size - index}"
|
||||
end
|
||||
|
||||
update_all({:position_name => name}, :id => priority.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
class AddEnumerationsPositionName < ActiveRecord::Migration
|
||||
def up
|
||||
add_column :enumerations, :position_name, :string, :limit => 30
|
||||
end
|
||||
|
||||
def down
|
||||
remove_column :enumerations, :position_name
|
||||
end
|
||||
end
|
|
@ -0,0 +1,9 @@
|
|||
class PopulateEnumerationsPositionName < ActiveRecord::Migration
|
||||
def up
|
||||
IssuePriority.compute_position_names
|
||||
end
|
||||
|
||||
def down
|
||||
IssuePriority.clear_position_names
|
||||
end
|
||||
end
|
|
@ -23,6 +23,7 @@ enumerations_004:
|
|||
type: IssuePriority
|
||||
active: true
|
||||
position: 1
|
||||
position_name: lowest
|
||||
enumerations_005:
|
||||
name: Normal
|
||||
id: 5
|
||||
|
@ -30,24 +31,28 @@ enumerations_005:
|
|||
is_default: true
|
||||
active: true
|
||||
position: 2
|
||||
position_name: default
|
||||
enumerations_006:
|
||||
name: High
|
||||
id: 6
|
||||
type: IssuePriority
|
||||
active: true
|
||||
position: 3
|
||||
position_name: high3
|
||||
enumerations_007:
|
||||
name: Urgent
|
||||
id: 7
|
||||
type: IssuePriority
|
||||
active: true
|
||||
position: 4
|
||||
position_name: high2
|
||||
enumerations_008:
|
||||
name: Immediate
|
||||
id: 8
|
||||
type: IssuePriority
|
||||
active: true
|
||||
position: 5
|
||||
position_name: highest
|
||||
enumerations_009:
|
||||
name: Design
|
||||
id: 9
|
||||
|
|
|
@ -73,4 +73,34 @@ class IssuePriorityTest < ActiveSupport::TestCase
|
|||
priority.expects(:reset_positions_in_list).once
|
||||
priority.move_to = 'higher'
|
||||
end
|
||||
|
||||
def test_clear_position_names_should_set_position_names_to_nil
|
||||
IssuePriority.clear_position_names
|
||||
assert IssuePriority.all.all? {|priority| priority.position_name.nil?}
|
||||
end
|
||||
|
||||
def test_compute_position_names_with_default_priority
|
||||
IssuePriority.clear_position_names
|
||||
|
||||
IssuePriority.compute_position_names
|
||||
assert_equal %w(lowest default high3 high2 highest), IssuePriority.active.all.sort.map(&:position_name)
|
||||
end
|
||||
|
||||
def test_compute_position_names_without_default_priority_should_split_priorities
|
||||
IssuePriority.clear_position_names
|
||||
IssuePriority.update_all :is_default => false
|
||||
|
||||
IssuePriority.compute_position_names
|
||||
assert_equal %w(lowest low2 default high2 highest), IssuePriority.active.all.sort.map(&:position_name)
|
||||
end
|
||||
|
||||
def test_adding_a_priority_should_update_position_names
|
||||
priority = IssuePriority.create!(:name => 'New')
|
||||
assert_equal %w(lowest default high4 high3 high2 highest), IssuePriority.active.all.sort.map(&:position_name)
|
||||
end
|
||||
|
||||
def test_destroying_a_priority_should_update_position_names
|
||||
IssuePriority.find_by_position_name('highest').destroy
|
||||
assert_equal %w(lowest default high2 highest), IssuePriority.active.all.sort.map(&:position_name)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1821,4 +1821,11 @@ class IssueTest < ActiveSupport::TestCase
|
|||
def test_journals_after_with_blank_arg_should_return_all_journals
|
||||
assert_equal [Journal.find(1), Journal.find(2)], Issue.find(1).journals_after('')
|
||||
end
|
||||
|
||||
def test_css_classes_should_include_priority
|
||||
issue = Issue.new(:priority => IssuePriority.find(8))
|
||||
classes = issue.css_classes.split(' ')
|
||||
assert_include 'priority-8', classes
|
||||
assert_include 'priority-highest', classes
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue