Project

General

Profile

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

Toshi MARUYAMA, 2013-04-23 17:44

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
      # 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
687 687
        julian_date = Date.new()
688 688
        ancesters_start_date = []
689 689
        while (parent = issue.parent)
690
          ancesters_start_date.unshift(issue.start_date || julian_date)
690
          ancesters_start_date.unshift([issue.start_date || julian_date, issue.id])
691 691
          issue = parent
692 692
        end
693 693
        ancesters_start_date.unshift(issue.id)
lib/redmine/helpers/gantt.rb
686 686
      def get_compare_params(issue)
687 687
        julian_date = Date.new()
688 688
        ancesters_start_date = []
689
        while (parent = issue.parent)
690
          ancesters_start_date.unshift([issue.start_date || julian_date, issue.id])
691
          issue = parent
692
        end
693
        ancesters_start_date.unshift(issue.id)
689
        current_issue = issue
690
        begin
691
          ancesters_start_date.unshift([current_issue.start_date || julian_date, current_issue.id])
692
          current_issue = current_issue.parent
693
        end while (current_issue)
694 694
        ancesters_start_date
695 695
      end
696 696

  
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
(11-11/13)