# HG changeset patch # User Toshi MARUYAMA # Parent 79ff96a8ae8096ab626d6944cecc4909c9391616 qnew diff --git a/lib/redmine/helpers/gantt.rb b/lib/redmine/helpers/gantt.rb --- a/lib/redmine/helpers/gantt.rb +++ b/lib/redmine/helpers/gantt.rb @@ -220,6 +220,7 @@ module Redmine return if abort? end versions = project_versions(project) + sort_versions!(versions) versions.each do |version| render_version(project, version, options) end @@ -675,18 +676,26 @@ module Redmine start_date + (end_date - start_date + 1) * (progress / 100.0) end - # Sorts a collection of issues by start_date, due_date, id for gantt rendering + # Sorts a collection of issues by start_date for gantt rendering def sort_issues!(issues) issues.sort! { |a, b| gantt_issue_compare(a, b) } end - # TODO: top level issues should be sorted by start date def gantt_issue_compare(x, y) - if x.root_id == y.root_id - x.lft <=> y.lft - else - x.root_id <=> y.root_id - end + sort_dates_x = [(x.root.start_date or x.start_date or Date.new()), x.root_id, (x.start_date or Date.new()), x.lft] + sort_dates_y = [(y.root.start_date or y.start_date or Date.new()), y.root_id, (y.start_date or Date.new()), y.lft] + sort_dates_x <=> sort_dates_y + end + + # Sorts a collection of versions by due_date for gantt rendering + def sort_versions!(versions) + versions.sort! { |a, b| gantt_version_compare(a, b) } + end + + def gantt_version_compare(x, y) + sort_dates_x = [(x.due_date or Date.new()), x.id] + sort_dates_y = [(y.due_date or Date.new()), y.id] + sort_dates_x <=> sort_dates_y end def current_limit