Project

General

Profile

Defect #8366 ยป Change-Gantt-default-sorting-to-start_date-instead-of-id.patch

Patch to change default sorting in Gantt diagram - Tobias Droste, 2013-01-05 09:25

View differences:

lib/redmine/helpers/gantt.rb
200 200
          return if abort?
201 201
        end
202 202
        versions = project_versions(project)
203
        sort_versions!(versions)
203 204
        versions.each do |version|
204 205
          render_version(project, version, options)
205 206
        end
......
638 639
        coords
639 640
      end
640 641

  
641
      # Sorts a collection of issues by start_date, due_date, id for gantt rendering
642
      # Sorts a collection of issues by start_date for gantt rendering
642 643
      def sort_issues!(issues)
643 644
        issues.sort! { |a, b| gantt_issue_compare(a, b) }
644 645
      end
645 646

  
646
      # TODO: top level issues should be sorted by start date
647 647
      def gantt_issue_compare(x, y)
648
        if x.root_id == y.root_id
649
          x.lft <=> y.lft
650
        else
651
          x.root_id <=> y.root_id
652
        end
648
        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]
649
        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]
650
        sort_dates_x <=> sort_dates_y
651
      end
652

  
653
      # Sorts a collection of versions by due_date for gantt rendering
654
      def sort_versions!(versions)
655
        versions.sort! { |a, b| gantt_version_compare(a, b) }
656
      end
657

  
658
      def gantt_version_compare(x, y)
659
        sort_dates_x = [(x.due_date or Date.new()), x.id]
660
        sort_dates_y = [(y.due_date or Date.new()), y.id]
661
        sort_dates_x <=> sort_dates_y
653 662
      end
654 663

  
655 664
      def current_limit
    (1-1/1)