-
-
Notifications
You must be signed in to change notification settings - Fork 801
/
widget.go
106 lines (84 loc) · 2.41 KB
/
widget.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
package jira
import (
"fmt"
"github.com/rivo/tview"
"github.com/wtfutil/wtf/wtf"
)
type Widget struct {
wtf.KeyboardWidget
wtf.ScrollableWidget
result *SearchResult
settings *Settings
}
func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget {
widget := Widget{
KeyboardWidget: wtf.NewKeyboardWidget(app, pages, settings.common),
ScrollableWidget: wtf.NewScrollableWidget(app, settings.common, true),
settings: settings,
}
widget.SetRenderFunction(widget.Render)
widget.initializeKeyboardControls()
widget.View.SetInputCapture(widget.InputCapture)
widget.KeyboardWidget.SetView(widget.View)
return &widget
}
/* -------------------- Exported Functions -------------------- */
func (widget *Widget) Refresh() {
searchResult, err := widget.IssuesFor(
widget.settings.username,
widget.settings.projects,
widget.settings.jql,
)
if err != nil {
widget.result = nil
widget.Redraw(widget.CommonSettings().Title, err.Error(), true)
return
}
widget.result = searchResult
widget.SetItemCount(len(searchResult.Issues))
widget.Render()
}
func (widget *Widget) Render() {
if widget.result == nil {
return
}
str := fmt.Sprintf("%s- [green]%s[white]", widget.CommonSettings().Title, widget.settings.projects)
widget.Redraw(str, widget.contentFrom(widget.result), false)
}
/* -------------------- Unexported Functions -------------------- */
func (widget *Widget) openItem() {
sel := widget.GetSelected()
if sel >= 0 && widget.result != nil && sel < len(widget.result.Issues) {
issue := &widget.result.Issues[sel]
wtf.OpenFile(widget.settings.domain + "/browse/" + issue.Key)
}
}
func (widget *Widget) contentFrom(searchResult *SearchResult) string {
str := " [red]Assigned Issues[white]\n"
for idx, issue := range searchResult.Issues {
row := fmt.Sprintf(
`[%s] [%s]%-6s[white] [green]%-10s[white] [yellow][%s][white] [%s]%s`,
widget.RowColor(idx),
widget.issueTypeColor(&issue),
issue.IssueFields.IssueType.Name,
issue.Key,
issue.IssueFields.IssueStatus.IName,
widget.RowColor(idx),
issue.IssueFields.Summary,
)
str += wtf.HighlightableHelper(widget.View, row, idx, len(issue.IssueFields.Summary))
}
return str
}
func (widget *Widget) issueTypeColor(issue *Issue) string {
switch issue.IssueFields.IssueType.Name {
case "Bug":
return "red"
case "Story":
return "blue"
case "Task":
return "orange"
default:
return "white"
}
}