Skip to content

Commit

Permalink
Add edit support, with caveat - need to exit after
Browse files Browse the repository at this point in the history
'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.
  • Loading branch information
Mike Pountney committed Jan 6, 2016
1 parent 66ef3c7 commit f206d97
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ This should be all that's needed to get going.
<enter> - select item
q - go back / quit
L - Label view (query results page only)
E - Edit ticket

### Configuration

Expand Down
4 changes: 4 additions & 0 deletions jira-ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ type ItemSelecter interface {
SelectItem()
}

type TicketEditer interface {
EditTicket()
}

type PagePager interface {
NextLine(int)
PreviousLine(int)
Expand Down
4 changes: 4 additions & 0 deletions ticket_list_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ func (p *TicketListPage) GoBack() {
changePage()
}

func (p *TicketListPage) EditTicket() {
runJiraCmdEdit(p.GetSelectedTicketId())
}

func (p *TicketListPage) Create(opts ...interface{}) {
ui.Clear()
var label string
Expand Down
9 changes: 7 additions & 2 deletions ticket_show_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

type TicketShowPage struct {
BaseListPage
TicketId string
}

func (p *TicketShowPage) PreviousPage() {
Expand All @@ -22,6 +23,10 @@ func (p *TicketShowPage) GoBack() {
changePage()
}

func (p *TicketShowPage) EditTicket() {
runJiraCmdEdit(p.TicketId)
}

func (p *TicketShowPage) lastDisplayedLine() int {
return lastLineDisplayed(p.uiList, p.firstDisplayLine, 5)
}
Expand All @@ -32,8 +37,8 @@ func (p *TicketShowPage) Create(opts ...interface{}) {
p.uiList = ls
p.selectedLine = 0
p.firstDisplayLine = 0
ticketId := ticketListPage.GetSelectedTicketId()
p.cachedResults = JiraTicketAsStrings(ticketId)
p.TicketId = ticketListPage.GetSelectedTicketId()
p.cachedResults = JiraTicketAsStrings(p.TicketId)
p.displayLines = make([]string, len(p.cachedResults))
ls.ItemFgColor = ui.ColorYellow
ls.Height = ui.TermHeight()
Expand Down
9 changes: 9 additions & 0 deletions ui_controls.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ func registerKeyboardHandlers() {
ui.Handle("/sys/kbd/C-b", func(ui.Event) {
handlePageUpKey()
})
ui.Handle("/sys/kbd/E", func(ui.Event) {
handleEditKey()
})
ui.Handle("/sys/wnd/resize", func(ui.Event) {
handleResize()
})
Expand All @@ -49,6 +52,12 @@ func handleLabelViewKey() {
changePage()
}

func handleEditKey() {
if obj, ok := currentPage.(TicketEditer); ok {
obj.EditTicket()
}
}

func handleBackKey() {
if obj, ok := currentPage.(GoBacker); ok {
obj.GoBack()
Expand Down
9 changes: 9 additions & 0 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ func countLabelsFromQuery(query string) map[string]int {
return counts
}

func runJiraCmdEdit(ticketId string) {
opts := getJiraOpts()
c := jira.New(opts)
ui.Close()
c.CmdEdit(ticketId)
log.Notice("Regrettably, need to exit after edit. See https://github.com/mikepea/go-jira-ui/issues/8")
os.Exit(0)
}

func runJiraQuery(query string) (interface{}, error) {
opts := getJiraOpts()
opts["query"] = query
Expand Down

0 comments on commit f206d97

Please sign in to comment.