Project

General

Profile

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

Toshi MARUYAMA, 2013-05-18 01:36

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 self.sort_issues!(issues)
680
        issues.sort! { |a, b| gantt_issue_compare(a, b) }
679
        issues.sort! {|a, b| sort_issue_logic(a) <=> sort_issue_logic(b)}
681 680
      end
682 681

  
683
      # TODO: top level issues should be sorted by start date
684
      def self.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
689
        end
682
      def self.sort_issue_logic(issue)
683
        julian_date = Date.new()
684
        ancesters_start_date = []
685
        current_issue = issue
686
        begin
687
          ancesters_start_date.unshift([current_issue.start_date || julian_date, current_issue.id])
688
          current_issue = current_issue.parent
689
        end while (current_issue)
690
        ancesters_start_date
690 691
      end
691 692

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

  
694
      def self.sort_versions!(versions)
695
        versions.sort! {|a, b| sort_version_logic(a) <=> sort_version_logic(b)}
696
      end
697

  
698
      def self.sort_version_logic(version)
699
        [(version.due_date || Date.new()), version.id]
700
      end
701

  
693 702
      def current_limit
694 703
        if @max_rows
695 704
          @max_rows - @number_of_rows
(12-12/13)