gantt: sort issues by start date (#7335)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@11897 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
596366b062
commit
8ea4e79964
|
@ -675,18 +675,19 @@ module Redmine
|
||||||
start_date + (end_date - start_date + 1) * (progress / 100.0)
|
start_date + (end_date - start_date + 1) * (progress / 100.0)
|
||||||
end
|
end
|
||||||
|
|
||||||
# TODO: Sorts a collection of issues by start_date, due_date, id for gantt rendering
|
|
||||||
def self.sort_issues!(issues)
|
def self.sort_issues!(issues)
|
||||||
issues.sort! { |a, b| gantt_issue_compare(a, b) }
|
issues.sort! {|a, b| sort_issue_logic(a) <=> sort_issue_logic(b)}
|
||||||
end
|
end
|
||||||
|
|
||||||
# TODO: top level issues should be sorted by start date
|
def self.sort_issue_logic(issue)
|
||||||
def self.gantt_issue_compare(x, y)
|
julian_date = Date.new()
|
||||||
if x.root_id == y.root_id
|
ancesters_start_date = []
|
||||||
x.lft <=> y.lft
|
current_issue = issue
|
||||||
else
|
begin
|
||||||
x.root_id <=> y.root_id
|
ancesters_start_date.unshift([current_issue.start_date || julian_date, current_issue.id])
|
||||||
end
|
current_issue = current_issue.parent
|
||||||
|
end while (current_issue)
|
||||||
|
ancesters_start_date
|
||||||
end
|
end
|
||||||
|
|
||||||
def current_limit
|
def current_limit
|
||||||
|
|
|
@ -781,4 +781,51 @@ class Redmine::Helpers::GanttHelperTest < ActionView::TestCase
|
||||||
assert_equal [issue1.id, child1.id, child3.id, child2.id, issue2.id],
|
assert_equal [issue1.id, child1.id, child3.id, child2.id, issue2.id],
|
||||||
issues.map{|v| v.id}
|
issues.map{|v| v.id}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_sort_issues_root_only
|
||||||
|
project = Project.generate!
|
||||||
|
issue1 = Issue.generate!(:subject => "test", :project => project)
|
||||||
|
issue2 = Issue.generate!(:subject => "test", :project => project)
|
||||||
|
issue3 = Issue.generate!(:subject => "test", :project => project,
|
||||||
|
:start_date => (today - 1))
|
||||||
|
issue4 = Issue.generate!(:subject => "test", :project => project,
|
||||||
|
:start_date => (today - 2))
|
||||||
|
issues = [issue4, issue3, issue2, issue1]
|
||||||
|
Redmine::Helpers::Gantt.sort_issues!(issues)
|
||||||
|
assert_equal [issue1.id, issue2.id, issue4.id, issue3.id],
|
||||||
|
issues.map{|v| v.id}
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_sort_issues_tree
|
||||||
|
project = Project.generate!
|
||||||
|
issue1 = Issue.generate!(:subject => "test", :project => project)
|
||||||
|
issue2 = Issue.generate!(:subject => "test", :project => project,
|
||||||
|
:start_date => (today - 2))
|
||||||
|
issue1_child1 =
|
||||||
|
Issue.generate!(:parent_issue_id => issue1.id, :subject => 'child',
|
||||||
|
:project => project)
|
||||||
|
issue1_child2 =
|
||||||
|
Issue.generate!(:parent_issue_id => issue1.id, :subject => 'child',
|
||||||
|
:project => project, :start_date => (today - 10))
|
||||||
|
issue1_child1_child1 =
|
||||||
|
Issue.generate!(:parent_issue_id => issue1_child1.id, :subject => 'child',
|
||||||
|
:project => project, :start_date => (today - 8))
|
||||||
|
issue1_child1_child2 =
|
||||||
|
Issue.generate!(:parent_issue_id => issue1_child1.id, :subject => 'child',
|
||||||
|
:project => project, :start_date => (today - 9))
|
||||||
|
issue1_child1_child1_logic = Redmine::Helpers::Gantt.sort_issue_logic(issue1_child1_child1)
|
||||||
|
assert_equal [[today - 10, issue1.id], [today - 9, issue1_child1.id],
|
||||||
|
[today - 8, issue1_child1_child1.id]],
|
||||||
|
issue1_child1_child1_logic
|
||||||
|
issue1_child1_child2_logic = Redmine::Helpers::Gantt.sort_issue_logic(issue1_child1_child2)
|
||||||
|
assert_equal [[today - 10, issue1.id], [today - 9, issue1_child1.id],
|
||||||
|
[today - 9, issue1_child1_child2.id]],
|
||||||
|
issue1_child1_child2_logic
|
||||||
|
issues = [issue1_child1_child2, issue1_child1_child1, issue1_child2,
|
||||||
|
issue1_child1, issue2, issue1]
|
||||||
|
Redmine::Helpers::Gantt.sort_issues!(issues)
|
||||||
|
assert_equal [issue1.id, issue1_child1.id, issue1_child2.id,
|
||||||
|
issue1_child1_child2.id, issue1_child1_child1.id, issue2.id],
|
||||||
|
issues.map{|v| v.id}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue