Project

General

Profile

Defect #7335 » gantt-sort-trunk-r11723.diff

Toshi MARUYAMA, 2013-04-19 07:02

View differences:

lib/redmine/helpers/gantt.rb
675 675
        start_date + (end_date - start_date + 1) * (progress / 100.0)
676 676
      end
677 677

  
678
      # Sorts a collection of issues by start_date, due_date, id for gantt rendering
678
      # TODO: Sorts a collection of issues by start_date, due_date, id for gantt rendering
679 679
      def sort_issues!(issues)
680 680
        issues.sort! { |a, b| gantt_issue_compare(a, b) }
681 681
      end
lib/redmine/helpers/gantt.rb
675 675
        start_date + (end_date - start_date + 1) * (progress / 100.0)
676 676
      end
677 677

  
678
      # TODO: Sorts a collection of issues by start_date, due_date, id for gantt rendering
679 678
      def sort_issues!(issues)
680 679
        issues.sort! { |a, b| gantt_issue_compare(a, b) }
681 680
      end
682 681

  
683
      # TODO: top level issues should be sorted by start date
684 682
      def gantt_issue_compare(x, y)
685
        if x.root_id == y.root_id
686
          x.lft <=> y.lft
687
        else
688
          x.root_id <=> y.root_id
683
        get_compare_params(x) <=> get_compare_params(y)
684
      end
685

  
686
      def get_compare_params(issue)
687
        julian_date = Date.new()
688
        ancesters_start_date = []
689
        while (parent = issue.parent)
690
          ancesters_start_date.unshift(issue.start_date || julian_date)
691
          issue = parent
689 692
        end
693
        ancesters_start_date.unshift(issue.id)
694
        ancesters_start_date
690 695
      end
691 696

  
692 697
      def current_limit
lib/redmine/helpers/gantt.rb
220 220
          return if abort?
221 221
        end
222 222
        versions = project_versions(project)
223
        sort_versions!(versions)
223 224
        versions.each do |version|
224 225
          render_version(project, version, options)
225 226
        end
......
694 695
        ancesters_start_date
695 696
      end
696 697

  
698
      def sort_versions!(versions)
699
        versions.sort! {|a, b| gantt_version_compare(a, b)}
700
      end
701

  
702
      def gantt_version_compare(x, y)
703
        sort_dates_x = [(x.due_date or Date.new()), x.id]
704
        sort_dates_y = [(y.due_date or Date.new()), y.id]
705
        sort_dates_x <=> sort_dates_y
706
      end
707

  
697 708
      def current_limit
698 709
        if @max_rows
699 710
          @max_rows - @number_of_rows
(8-8/13)