WIP on accept/reject

pull/1/head
vilmibm 2023-02-16 05:48:26 +00:00
parent b03e4f069e
commit 7e8f8cb0fc
1 changed files with 53 additions and 15 deletions

View File

@ -13,6 +13,12 @@ import (
"github.com/rivo/tview"
)
const (
signupDir = "/town/signups"
acceptedDir = "/town/signups/accepted"
rejectedDir = "/town/signups/rejected"
)
func getTitle() string {
titles := []string{
"yo bum rush the show",
@ -25,21 +31,37 @@ func getTitle() string {
return titles[rand.Intn(len(titles))]
}
const (
signupDir = "/town/signups"
acceptedDir = "/town/signups/accepted"
rejectedDir = "/town/signups/rejected"
)
type townSignup struct {
When time.Time
Answers map[string]string
When time.Time
DecisionTime time.Time
Decision string
Filename string
Answers map[string]string
}
func (a townSignup) Render() string {
out := fmt.Sprintf("[-:-:b]submitted:[-:-:-] %s\n", a.When.Format("2006-01-02 15:04"))
func (s townSignup) Accept() error {
return s.review("accept")
}
for k, v := range a.Answers {
func (s townSignup) Reject() error {
return s.review("reject")
}
func (s townSignup) review(decision string) error {
s.DecisionTime = time.Now()
s.Decision = "decision"
oldpath := path.Join(signupDir, s.Filename)
newpath := path.Join(acceptedDir, s.Filename)
if decision == "reject" {
newpath = path.Join(rejectedDir, s.Filename)
}
return os.Rename(oldpath, newpath)
}
func (s townSignup) Render() string {
out := fmt.Sprintf("[-:-:b]submitted:[-:-:-] %s\n", s.When.Format("2006-01-02 15:04"))
for k, v := range s.Answers {
out += fmt.Sprintf("[-:-:b]%s[-:-:-]\n", k)
out += strings.TrimSpace(v)
out += "\n\n"
@ -72,6 +94,7 @@ func getSignups() ([]townSignup, error) {
if err != nil {
return nil, fmt.Errorf("could not unmarshal signup file '%s': %w", abs, err)
}
signup.Filename = entry.Name()
out = append(out, signup)
}
@ -95,7 +118,7 @@ func _main() error {
title := tview.NewTextView()
title.SetText(getTitle())
title.SetTextAlign(tview.AlignCenter)
title.SetTextColor(tcell.ColorPink)
title.SetTextColor(tcell.ColorPurple)
title.SetBackgroundColor(tcell.ColorBlack)
appView := tview.NewTextView()
@ -107,7 +130,10 @@ func _main() error {
}
legend := tview.NewTextView()
legend.SetText("TODO actions legend")
legend.SetText("s: skip r: random A: approve R: reject N: notate Q: quit")
legend.SetTextColor(tcell.ColorPurple)
legend.SetTextAlign(tview.AlignCenter)
legend.SetBackgroundColor(tcell.ColorBlack)
mainFlex.SetDirection(tview.FlexRow)
mainFlex.AddItem(title, 1, -1, false)
@ -120,6 +146,8 @@ func _main() error {
app := tview.NewApplication()
app.SetRoot(pages, true)
// TODO count of pending signups somewhere
app.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
switch event.Rune() {
case 's':
@ -132,9 +160,19 @@ func _main() error {
signupIx = rand.Intn(len(signups))
appView.SetText(signups[signupIx].Render())
case 'A':
// TODO approve
err := signups[signupIx].Accept()
if err != nil {
// TODO report in app
panic(fmt.Errorf("failed to approve '%s': %w", signups[signupIx].Filename, err))
}
// TODO remove from signups list
case 'R':
// TODO reject
err = signups[signupIx].Reject()
if err != nil {
// TODO report in app
panic(fmt.Errorf("failed to rejec t'%s': %w", signups[signupIx].Filename, err))
}
// TODO remove from signups list
case 'n':
// TODO notate
case 'Q':