blob: eeeb315c2e4b4af760feb3d7f6ea1e94e3b38dbd (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
package cache
import "sort"
type OrderBy int
const (
_ OrderBy = iota
OrderById
OrderByCreation
OrderByEdit
)
type OrderDirection int
const (
_ OrderDirection = iota
OrderAscending
OrderDescending
)
func (c *RepoCache) AllBugsId(order OrderBy, direction OrderDirection) []string {
if order == OrderById {
return c.orderIds(direction)
}
excerpts := c.allExcerpt()
var sorter sort.Interface
switch order {
case OrderByCreation:
sorter = BugsByCreationTime(excerpts)
case OrderByEdit:
sorter = BugsByEditTime(excerpts)
default:
panic("missing sort type")
}
if direction == OrderDescending {
sorter = sort.Reverse(sorter)
}
sort.Sort(sorter)
result := make([]string, len(excerpts))
for i, val := range excerpts {
result[i] = val.Id
}
return result
}
func (c *RepoCache) orderIds(direction OrderDirection) []string {
result := make([]string, len(c.excerpts))
i := 0
for key := range c.excerpts {
result[i] = key
i++
}
var sorter sort.Interface = sort.StringSlice(result)
if direction == OrderDescending {
sorter = sort.Reverse(sorter)
}
sort.Sort(sorter)
return result
}
|