2024-01-14 13:46:42 +00:00
|
|
|
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 {
|
2024-01-17 13:43:20 +00:00
|
|
|
key, character := event.Key(), event.Rune()
|
2024-01-14 13:46:42 +00:00
|
|
|
|
|
|
|
switch {
|
2024-01-17 13:43:20 +00:00
|
|
|
case character == 'h' || key == tcell.KeyLeft:
|
2024-01-14 13:46:42 +00:00
|
|
|
a.shiftColumnFocus(previous)
|
2024-01-17 13:43:20 +00:00
|
|
|
case character == 'l' || key == tcell.KeyRight:
|
2024-01-14 13:46:42 +00:00
|
|
|
a.shiftColumnFocus(next)
|
2024-01-17 13:43:20 +00:00
|
|
|
case character == 'c':
|
2024-01-14 13:46:42 +00:00
|
|
|
a.create()
|
2024-01-17 13:43:20 +00:00
|
|
|
case character == 'm':
|
2024-01-14 13:46:42 +00:00
|
|
|
a.move()
|
2024-01-17 13:43:20 +00:00
|
|
|
case character == 'e':
|
2024-01-14 13:46:42 +00:00
|
|
|
a.edit()
|
2024-01-17 13:43:20 +00:00
|
|
|
case character == 'b':
|
|
|
|
a.updateBoardMode(boardEdit)
|
2024-01-14 13:46:42 +00:00
|
|
|
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() {
|
2024-01-17 17:10:36 +00:00
|
|
|
switch a.mode {
|
|
|
|
case normal:
|
2024-01-14 13:46:42 +00:00
|
|
|
a.cardForm.mode = create
|
|
|
|
a.cardForm.updateInputFields("", "")
|
|
|
|
a.cardForm.frame.SetTitle(" Create Card ")
|
|
|
|
a.pages.ShowPage(cardFormPage)
|
|
|
|
a.SetFocus(a.cardForm)
|
2024-01-17 17:10:36 +00:00
|
|
|
case boardEdit:
|
|
|
|
a.statusForm.mode = create
|
|
|
|
a.statusForm.updateInputFields("")
|
|
|
|
a.statusForm.frame.SetTitle(" Create Status ")
|
|
|
|
a.pages.ShowPage(statusFormPage)
|
|
|
|
a.SetFocus(a.statusForm)
|
2024-01-14 13:46:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *App) move() {
|
|
|
|
if a.mode == normal {
|
|
|
|
a.statusSelection.cardID = a.focusedCardID()
|
|
|
|
a.statusSelection.currentStatusID = a.focusedStatusID()
|
2024-01-17 11:12:06 +00:00
|
|
|
a.updateBoardMode(selection)
|
2024-01-14 13:46:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *App) edit() {
|
2024-01-17 13:43:20 +00:00
|
|
|
switch a.mode {
|
|
|
|
case normal:
|
2024-01-14 13:46:42 +00:00
|
|
|
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)
|
2024-01-17 13:43:20 +00:00
|
|
|
case boardEdit:
|
2024-01-17 17:10:36 +00:00
|
|
|
a.statusForm.mode = edit
|
2024-01-17 13:43:20 +00:00
|
|
|
statusName := a.focusedStatusName()
|
|
|
|
a.statusForm.updateInputFields(statusName)
|
|
|
|
a.statusForm.frame.SetTitle(" Edit Status Name ")
|
|
|
|
a.pages.ShowPage(statusFormPage)
|
|
|
|
a.SetFocus(a.statusForm)
|
2024-01-14 13:46:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *App) delete() {
|
2024-01-18 22:36:33 +00:00
|
|
|
switch a.mode {
|
|
|
|
case normal:
|
2024-01-14 13:46:42 +00:00
|
|
|
card, ok := a.getFocusedCard()
|
|
|
|
if !ok {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-01-18 22:36:33 +00:00
|
|
|
text := fmt.Sprintf("Do you want to delete the CARD %q?", card.Title)
|
|
|
|
a.deleteModal.SetText(text)
|
|
|
|
a.pages.ShowPage(deleteModalPage)
|
|
|
|
a.SetFocus(a.deleteModal)
|
|
|
|
case boardEdit:
|
|
|
|
text := fmt.Sprintf("Do you want to delete the STATUS %q?", a.focusedStatusName())
|
|
|
|
a.deleteModal.SetText(text)
|
|
|
|
a.pages.ShowPage(deleteModalPage)
|
|
|
|
a.SetFocus(a.deleteModal)
|
2024-01-14 13:46:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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()
|
2024-01-17 11:12:06 +00:00
|
|
|
a.cardView.setText(card.ID, card.Title, status, card.Created, card.Description)
|
2024-01-14 13:46:42 +00:00
|
|
|
a.pages.ShowPage(viewPage)
|
2024-01-17 11:12:06 +00:00
|
|
|
a.SetFocus(a.cardView)
|
2024-01-14 13:46:42 +00:00
|
|
|
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}
|
2024-01-17 11:12:06 +00:00
|
|
|
a.updateBoardMode(normal)
|
2024-01-17 17:10:36 +00:00
|
|
|
a.refresh(refreshArgs{updateFocusedColumnOnly: false, reinitialiseColumns: false})
|
2024-01-14 13:46:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *App) escape() {
|
|
|
|
if a.mode != normal {
|
2024-01-17 11:12:06 +00:00
|
|
|
a.updateBoardMode(normal)
|
2024-01-14 13:46:42 +00:00
|
|
|
}
|
|
|
|
}
|