-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathticket_list_page.go
159 lines (143 loc) · 3.62 KB
/
ticket_list_page.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
package jiraui
import (
"fmt"
"regexp"
"gopkg.in/Netflix-Skunkworks/go-jira.v0"
ui "gopkg.in/gizak/termui.v2"
)
type TicketListPage struct {
BaseListPage
CommandBarFragment
StatusBarFragment
ActiveQuery Query
ActiveSort Sort
RankingTicketId string
}
func (p *TicketListPage) Search() {
s := p.ActiveSearch
n := len(p.cachedResults)
if s.command == "" {
return
}
increment := 1
if s.directionUp {
increment = -1
}
// we use modulo here so we can loop through every line.
// adding 'n' means we never have '-1 % n'.
startLine := (p.uiList.Cursor + n + increment) % n
for i := startLine; i != p.uiList.Cursor; i = (i + increment + n) % n {
if s.re.MatchString(p.cachedResults[i]) {
p.uiList.SetCursorLine(i)
p.Update()
break
}
}
}
func (p *TicketListPage) ActiveTicketId() string {
return p.GetSelectedTicketId()
}
func (p *TicketListPage) GetSelectedTicketId() string {
return findTicketIdInString(p.cachedResults[p.uiList.Cursor])
}
func (p *TicketListPage) MarkItemForRanking() {
p.RankingTicketId = p.GetSelectedTicketId()
}
func (p *TicketListPage) PreviousLine(n int) {
if p.RankingTicketId != "" {
p.uiList.MoveUp(n)
} else {
p.uiList.CursorUpLines(n)
}
}
func (p *TicketListPage) NextLine(n int) {
if p.RankingTicketId != "" {
p.uiList.MoveDown(n)
} else {
p.uiList.CursorDownLines(n)
}
}
func (p *TicketListPage) SelectItem() {
if p.RankingTicketId != "" {
log.Debugf("Setting Rank for %s", p.RankingTicketId)
order := jira.RANKAFTER
var targetId string
if p.uiList.Cursor == 0 {
order = jira.RANKBEFORE
targetId = findTicketIdInString(p.cachedResults[p.uiList.Cursor+1])
} else {
targetId = findTicketIdInString(p.cachedResults[p.uiList.Cursor-1])
}
runJiraCmdRank(p.RankingTicketId, targetId, order)
p.RankingTicketId = ""
p.Refresh()
return
}
if len(p.cachedResults) == 0 {
return
}
q := new(TicketShowPage)
q.TicketId = p.GetSelectedTicketId()
previousPages = append(previousPages, currentPage)
currentPage = q
q.Create()
changePage()
}
func (p *TicketListPage) GoBack() {
if len(previousPages) == 0 {
currentPage = ticketQueryPage
} else {
currentPage, previousPages = previousPages[len(previousPages)-1], previousPages[:len(previousPages)-1]
}
changePage()
}
func (p *TicketListPage) EditTicket() {
runJiraCmdEdit(p.GetSelectedTicketId())
}
func (p *TicketListPage) Update() {
ui.Render(p.uiList)
p.statusBar.Update()
p.commandBar.Update()
}
func (p *TicketListPage) Refresh() {
pDeref := &p
q := *pDeref
q.cachedResults = make([]string, 0)
currentPage = q
changePage()
q.Create()
}
func (p *TicketListPage) Create() {
log.Debugf("TicketListPage.Create(): self: %s (%p)", p.Id(), p)
log.Debugf("TicketListPage.Create(): currentPage: %s (%p)", currentPage.Id(), currentPage)
ui.Clear()
if p.uiList == nil {
p.uiList = NewScrollableList()
}
if p.statusBar == nil {
p.statusBar = new(StatusBar)
}
if p.commandBar == nil {
p.commandBar = commandBar
}
query := p.ActiveQuery.JQL
if sort := p.ActiveSort.JQL; sort != "" {
re := regexp.MustCompile(`(?i)\s+ORDER\s+BY.+$`)
query = re.ReplaceAllString(query, ``) + " " + sort
}
if len(p.cachedResults) == 0 {
p.cachedResults = JiraQueryAsStrings(query, p.ActiveQuery.Template)
}
if p.uiList.Cursor >= len(p.cachedResults) {
p.uiList.Cursor = len(p.cachedResults) - 1
}
p.uiList.Items = p.cachedResults
p.uiList.ItemFgColor = ui.ColorYellow
p.uiList.BorderLabel = fmt.Sprintf("%s: %s", p.ActiveQuery.Name, p.ActiveQuery.JQL)
p.uiList.Height = ui.TermHeight() - 2
p.uiList.Width = ui.TermWidth()
p.uiList.Y = 0
p.statusBar.Create()
p.commandBar.Create()
p.Update()
}