Project

General

Profile

Defect #7335 » sort_issues.rb

Felipe Ribeiro, 2011-12-05 20:03

 
1
INFINITY = 1.0/0
2

    
3
#selection sort
4
def sort_issues(issues)
5
  for i in 0...issues.length do
6
    list = issues[i...issues.length]
7
    issue = list.min_by{|issue| issue.start_date ? issue.start_date.to_time.to_i : INFINITY }
8
    if issue.start_date != nil and issue != issues[i]
9
      destiny = issue.left_sibling
10
      issue.move_to_left_of issues[i]
11

    
12
      if destiny != issues[i]
13
        issues[i].move_to_right_of destiny
14
      end
15

    
16
      min_index = issues.index(issue)
17
      issues[i], issues[min_index] = issues[min_index], issues[i]
18
    end
19
    sort_issues issue.children
20
  end
21
end
22

    
23

    
24
def sort_all_issues
25
  Project.all.each do |project|
26
    project.issues.each do |issue|
27
      if issue.root?
28
        sort_issues(issue.children)
29
      end
30
    end
31
  end
32
  nil
33
end
34

    
35
sort_all_issues
(2-2/13)