pelican/internal/ui/keymappings.go
Dan Anglin c1bb834a7f
All checks were successful
/ test (pull_request) Successful in 34s
/ lint (pull_request) Successful in 46s
feat(ui): add support for creating status columns
This commit adds support for creating new status columns. When the user
is in the 'board edit' mode, they can press the 'c' key to create a new
column. When a new column is created it automatically assumes the last
position on the board. We will add support later on to allow the user to
re-arrange the columns on the board.

Part of apollo/pelican#22
2024-01-17 17:10:36 +00:00

148 lines
3.2 KiB
Go

package ui
import (
"fmt"
"github.com/gdamore/tcell/v2"
)
func (a *App) inputCapture() func(event *tcell.EventKey) *tcell.EventKey {
return func(event *tcell.EventKey) *tcell.EventKey {
key, character := event.Key(), event.Rune()
switch {
case character == 'h' || key == tcell.KeyLeft:
a.shiftColumnFocus(previous)
case character == 'l' || key == tcell.KeyRight:
a.shiftColumnFocus(next)
case character == 'c':
a.create()
case character == 'm':
a.move()
case character == 'e':
a.edit()
case character == 'b':
a.updateBoardMode(boardEdit)
case key == tcell.KeyCtrlD:
a.delete()
case key == tcell.KeyCtrlQ:
a.quit()
case key == tcell.KeyESC:
a.escape()
case key == tcell.KeyEnter:
a.selected()
}
return event
}
}
func (a *App) create() {
switch a.mode {
case normal:
a.cardForm.mode = create
a.cardForm.updateInputFields("", "")
a.cardForm.frame.SetTitle(" Create Card ")
a.pages.ShowPage(cardFormPage)
a.SetFocus(a.cardForm)
case boardEdit:
a.statusForm.mode = create
a.statusForm.updateInputFields("")
a.statusForm.frame.SetTitle(" Create Status ")
a.pages.ShowPage(statusFormPage)
a.SetFocus(a.statusForm)
}
}
func (a *App) move() {
if a.mode == normal {
a.statusSelection.cardID = a.focusedCardID()
a.statusSelection.currentStatusID = a.focusedStatusID()
a.updateBoardMode(selection)
}
}
func (a *App) edit() {
switch a.mode {
case normal:
a.cardForm.mode = edit
card, ok := a.getFocusedCard()
if !ok {
return
}
a.cardForm.updateInputFields(card.Title, card.Description)
a.cardForm.frame.SetTitle(" Edit Card ")
a.pages.ShowPage(cardFormPage)
a.SetFocus(a.cardForm)
case boardEdit:
a.statusForm.mode = edit
statusName := a.focusedStatusName()
a.statusForm.updateInputFields(statusName)
a.statusForm.frame.SetTitle(" Edit Status Name ")
a.pages.ShowPage(statusFormPage)
a.SetFocus(a.statusForm)
}
}
func (a *App) delete() {
if a.mode == normal {
card, ok := a.getFocusedCard()
if !ok {
return
}
text := fmt.Sprintf("Do you want to delete '%s'?", card.Title)
a.deleteCardModal.SetText(text)
a.pages.ShowPage(deleteCardModalPage)
a.SetFocus(a.deleteCardModal)
}
}
func (a *App) quit() {
if a.mode == normal {
a.pages.ShowPage(quitPage)
a.SetFocus(a.quitModal)
}
}
func (a *App) selected() {
switch a.mode {
case normal:
card, ok := a.getFocusedCard()
if !ok {
break
}
status := a.focusedStatusName()
a.cardView.setText(card.ID, card.Title, status, card.Created, card.Description)
a.pages.ShowPage(viewPage)
a.SetFocus(a.cardView)
case selection:
a.statusSelection.nextStatusID = a.focusedStatusID()
if a.statusSelection.currentStatusID != a.statusSelection.nextStatusID {
if err := a.statusSelection.moveCard(a.board); err != nil {
a.statusbar.displayMessage(
errorLevel,
fmt.Sprintf("Failed to move card: %v", err),
)
} else {
a.statusbar.displayMessage(
infoLevel,
"Card moved successfully.",
)
}
}
a.statusSelection = statusSelection{0, 0, 0}
a.updateBoardMode(normal)
a.refresh(refreshArgs{updateFocusedColumnOnly: false, reinitialiseColumns: false})
}
}
func (a *App) escape() {
if a.mode != normal {
a.updateBoardMode(normal)
}
}