Project

General

Profile

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

Toshi MARUYAMA, 2013-03-31 08:51

View differences:

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
......
675 676
        start_date + (end_date - start_date + 1) * (progress / 100.0)
676 677
      end
677 678

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

  
683
      # TODO: top level issues should be sorted by start date
684 684
      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
689
        end
685
        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]
686
        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]
687
        sort_dates_x <=> sort_dates_y
688
      end
689

  
690
      # Sorts a collection of versions by due_date for gantt rendering
691
      def sort_versions!(versions)
692
        versions.sort! { |a, b| gantt_version_compare(a, b) }
693
      end
694

  
695
      def gantt_version_compare(x, y)
696
        sort_dates_x = [(x.due_date or Date.new()), x.id]
697
        sort_dates_y = [(y.due_date or Date.new()), y.id]
698
        sort_dates_x <=> sort_dates_y
690 699
      end
691 700

  
692 701
      def current_limit
(6-6/13)