/
sort.go
102 lines (98 loc) · 2.6 KB
/
sort.go
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package issuebrowser
import (
"sort"
"github.com/google/go-github/github"
"github.com/jroimartin/gocui"
)
//typeCasting Issues so that each has a different sort method, allowing issues to be sorted by any heading
type byNumber []*github.Issue
type byTitle []*github.Issue
type byBody []*github.Issue
type byUser []*github.Issue
type byAssignee []*github.Issue
type byComments []*github.Issue
type byClosedAt []*github.Issue
type byCreatedAt []*github.Issue
type byUpdatedAt []*github.Issue
type byMilestone []*github.Issue
//sortIssues sorts the list of issues depending on the sortChoice variable and then refreshes the display
func sortIssues(g *gocui.Gui, v *gocui.View) error {
switch {
case sortChoice == "Number":
if orderChoice == "Ascending" {
sort.Sort(byNumber(issueList))
} else {
sort.Sort(sort.Reverse(byNumber(issueList)))
}
case sortChoice == "Title":
if orderChoice == "Ascending" {
sort.Sort(byTitle(issueList))
} else {
sort.Sort(sort.Reverse(byTitle(issueList)))
}
case sortChoice == "Body":
if orderChoice == "Ascending" {
sort.Sort(byBody(issueList))
} else {
sort.Sort(sort.Reverse(byBody(issueList)))
}
case sortChoice == "User":
if orderChoice == "Ascending" {
sort.Sort(byUser(issueList))
} else {
sort.Sort(sort.Reverse(byUser(issueList)))
}
case sortChoice == "Assignee":
if orderChoice == "Ascending" {
sort.Sort(byAssignee(issueList))
} else {
sort.Sort(sort.Reverse(byAssignee(issueList)))
}
case sortChoice == "Comments":
if orderChoice == "Ascending" {
sort.Sort(byComments(issueList))
} else {
sort.Sort(sort.Reverse(byComments(issueList)))
}
case sortChoice == "Date Closed":
if orderChoice == "Ascending" {
sort.Sort(byClosedAt(issueList))
} else {
sort.Sort(sort.Reverse(byClosedAt(issueList)))
}
case sortChoice == "Date Created":
if orderChoice == "Ascending" {
sort.Sort(byCreatedAt(issueList))
} else {
sort.Sort(sort.Reverse(byCreatedAt(issueList)))
}
case sortChoice == "Date Updated":
if orderChoice == "Ascending" {
sort.Sort(byUpdatedAt(issueList))
} else {
sort.Sort(sort.Reverse(byUpdatedAt(issueList)))
}
case sortChoice == "Milestone Title":
if orderChoice == "Ascending" {
sort.Sort(byMilestone(issueList))
} else {
sort.Sort(sort.Reverse(byMilestone(issueList)))
}
case sortChoice == "":
sort.Sort(byNumber(issueList))
}
if err := showIssues(g); err != nil {
return err
}
if err := cancel(g, v); err != nil {
return err
}
browser, err := g.View("browser")
if err != nil {
return err
}
if err := getLine(g, browser); err != nil {
return err
}
return nil
}