Skip to content

Commit f206d97

Browse files
author
Mike Pountney
committed
Add edit support, with caveat - need to exit after
'E' edits the current ticket on both List and Show pages (basically where we have an obvious ticketId available) This fixes #2, but opens #8 - CmdEdit() requires that we close down termui, as it needs control of the keyboard (fine). However, I've not yet found a way of implementing this so that we can subsequently re-enter the termui control. Meh. Hence #8. Same problemw will happen with all editor based operations, #8 covers them.
1 parent 66ef3c7 commit f206d97

6 files changed

+34
-2
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ This should be all that's needed to get going.
3030
<enter> - select item
3131
q - go back / quit
3232
L - Label view (query results page only)
33+
E - Edit ticket
3334

3435
### Configuration
3536

jira-ui.go

+4
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ type ItemSelecter interface {
2828
SelectItem()
2929
}
3030

31+
type TicketEditer interface {
32+
EditTicket()
33+
}
34+
3135
type PagePager interface {
3236
NextLine(int)
3337
PreviousLine(int)

ticket_list_page.go

+4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ func (p *TicketListPage) GoBack() {
2626
changePage()
2727
}
2828

29+
func (p *TicketListPage) EditTicket() {
30+
runJiraCmdEdit(p.GetSelectedTicketId())
31+
}
32+
2933
func (p *TicketListPage) Create(opts ...interface{}) {
3034
ui.Clear()
3135
var label string

ticket_show_page.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66

77
type TicketShowPage struct {
88
BaseListPage
9+
TicketId string
910
}
1011

1112
func (p *TicketShowPage) PreviousPage() {
@@ -22,6 +23,10 @@ func (p *TicketShowPage) GoBack() {
2223
changePage()
2324
}
2425

26+
func (p *TicketShowPage) EditTicket() {
27+
runJiraCmdEdit(p.TicketId)
28+
}
29+
2530
func (p *TicketShowPage) lastDisplayedLine() int {
2631
return lastLineDisplayed(p.uiList, p.firstDisplayLine, 5)
2732
}
@@ -32,8 +37,8 @@ func (p *TicketShowPage) Create(opts ...interface{}) {
3237
p.uiList = ls
3338
p.selectedLine = 0
3439
p.firstDisplayLine = 0
35-
ticketId := ticketListPage.GetSelectedTicketId()
36-
p.cachedResults = JiraTicketAsStrings(ticketId)
40+
p.TicketId = ticketListPage.GetSelectedTicketId()
41+
p.cachedResults = JiraTicketAsStrings(p.TicketId)
3742
p.displayLines = make([]string, len(p.cachedResults))
3843
ls.ItemFgColor = ui.ColorYellow
3944
ls.Height = ui.TermHeight()

ui_controls.go

+9
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ func registerKeyboardHandlers() {
3535
ui.Handle("/sys/kbd/C-b", func(ui.Event) {
3636
handlePageUpKey()
3737
})
38+
ui.Handle("/sys/kbd/E", func(ui.Event) {
39+
handleEditKey()
40+
})
3841
ui.Handle("/sys/wnd/resize", func(ui.Event) {
3942
handleResize()
4043
})
@@ -49,6 +52,12 @@ func handleLabelViewKey() {
4952
changePage()
5053
}
5154

55+
func handleEditKey() {
56+
if obj, ok := currentPage.(TicketEditer); ok {
57+
obj.EditTicket()
58+
}
59+
}
60+
5261
func handleBackKey() {
5362
if obj, ok := currentPage.(GoBacker); ok {
5463
obj.GoBack()

utils.go

+9
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,15 @@ func countLabelsFromQuery(query string) map[string]int {
2525
return counts
2626
}
2727

28+
func runJiraCmdEdit(ticketId string) {
29+
opts := getJiraOpts()
30+
c := jira.New(opts)
31+
ui.Close()
32+
c.CmdEdit(ticketId)
33+
log.Notice("Regrettably, need to exit after edit. See https://github.com/mikepea/go-jira-ui/issues/8")
34+
os.Exit(0)
35+
}
36+
2837
func runJiraQuery(query string) (interface{}, error) {
2938
opts := getJiraOpts()
3039
opts["query"] = query

0 commit comments

Comments
 (0)