gantt: sort versions by start date (#7335)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@11898 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
8ea4e79964
commit
f085508121
|
@ -220,6 +220,7 @@ module Redmine
|
||||||
return if abort?
|
return if abort?
|
||||||
end
|
end
|
||||||
versions = project_versions(project)
|
versions = project_versions(project)
|
||||||
|
self.class.sort_versions!(versions)
|
||||||
versions.each do |version|
|
versions.each do |version|
|
||||||
render_version(project, version, options)
|
render_version(project, version, options)
|
||||||
end
|
end
|
||||||
|
@ -690,6 +691,14 @@ module Redmine
|
||||||
ancesters_start_date
|
ancesters_start_date
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.sort_versions!(versions)
|
||||||
|
versions.sort! {|a, b| sort_version_logic(a) <=> sort_version_logic(b)}
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.sort_version_logic(version)
|
||||||
|
[(version.start_date || Date.new()), version.id]
|
||||||
|
end
|
||||||
|
|
||||||
def current_limit
|
def current_limit
|
||||||
if @max_rows
|
if @max_rows
|
||||||
@max_rows - @number_of_rows
|
@max_rows - @number_of_rows
|
||||||
|
|
|
@ -828,4 +828,29 @@ class Redmine::Helpers::GanttHelperTest < ActionView::TestCase
|
||||||
issue1_child1_child2.id, issue1_child1_child1.id, issue2.id],
|
issue1_child1_child2.id, issue1_child1_child1.id, issue2.id],
|
||||||
issues.map{|v| v.id}
|
issues.map{|v| v.id}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_sort_versions
|
||||||
|
project = Project.generate!
|
||||||
|
version1 = Version.create!(:project => project, :name => 'test1')
|
||||||
|
version2 = Version.create!(:project => project, :name => 'test2')
|
||||||
|
version3 = Version.create!(:project => project, :name => 'test3')
|
||||||
|
version4 = Version.create!(:project => project, :name => 'test4')
|
||||||
|
issue1 = Issue.generate!(:subject => "test", :project => project,
|
||||||
|
:fixed_version => version1)
|
||||||
|
issue2 = Issue.generate!(:subject => "test", :project => project,
|
||||||
|
:fixed_version => version2)
|
||||||
|
issue3 = Issue.generate!(:subject => "test", :project => project,
|
||||||
|
:fixed_version => version3, :start_date => (today - 1))
|
||||||
|
issue4 = Issue.generate!(:subject => "test", :project => project,
|
||||||
|
:fixed_version => version4, :start_date => (today - 2))
|
||||||
|
assert_nil version1.start_date
|
||||||
|
assert_nil version2.start_date
|
||||||
|
assert version1.id < version2.id
|
||||||
|
assert_equal today - 1, version3.start_date
|
||||||
|
assert_equal today - 2, version4.start_date
|
||||||
|
versions = [version4, version3, version2, version1]
|
||||||
|
Redmine::Helpers::Gantt.sort_versions!(versions)
|
||||||
|
assert_equal [version1.id, version2.id, version4.id, version3.id],
|
||||||
|
versions.map{|v| v.id}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue