forked from tildetown/town
WIP on accept/reject
parent
b03e4f069e
commit
7e8f8cb0fc
|
@ -13,6 +13,12 @@ import (
|
||||||
"github.com/rivo/tview"
|
"github.com/rivo/tview"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
signupDir = "/town/signups"
|
||||||
|
acceptedDir = "/town/signups/accepted"
|
||||||
|
rejectedDir = "/town/signups/rejected"
|
||||||
|
)
|
||||||
|
|
||||||
func getTitle() string {
|
func getTitle() string {
|
||||||
titles := []string{
|
titles := []string{
|
||||||
"yo bum rush the show",
|
"yo bum rush the show",
|
||||||
|
@ -25,21 +31,37 @@ func getTitle() string {
|
||||||
return titles[rand.Intn(len(titles))]
|
return titles[rand.Intn(len(titles))]
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
|
||||||
signupDir = "/town/signups"
|
|
||||||
acceptedDir = "/town/signups/accepted"
|
|
||||||
rejectedDir = "/town/signups/rejected"
|
|
||||||
)
|
|
||||||
|
|
||||||
type townSignup struct {
|
type townSignup struct {
|
||||||
When time.Time
|
When time.Time
|
||||||
|
DecisionTime time.Time
|
||||||
|
Decision string
|
||||||
|
Filename string
|
||||||
Answers map[string]string
|
Answers map[string]string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a townSignup) Render() string {
|
func (s townSignup) Accept() error {
|
||||||
out := fmt.Sprintf("[-:-:b]submitted:[-:-:-] %s\n", a.When.Format("2006-01-02 15:04"))
|
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 += fmt.Sprintf("[-:-:b]%s[-:-:-]\n", k)
|
||||||
out += strings.TrimSpace(v)
|
out += strings.TrimSpace(v)
|
||||||
out += "\n\n"
|
out += "\n\n"
|
||||||
|
@ -72,6 +94,7 @@ func getSignups() ([]townSignup, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("could not unmarshal signup file '%s': %w", abs, err)
|
return nil, fmt.Errorf("could not unmarshal signup file '%s': %w", abs, err)
|
||||||
}
|
}
|
||||||
|
signup.Filename = entry.Name()
|
||||||
|
|
||||||
out = append(out, signup)
|
out = append(out, signup)
|
||||||
}
|
}
|
||||||
|
@ -95,7 +118,7 @@ func _main() error {
|
||||||
title := tview.NewTextView()
|
title := tview.NewTextView()
|
||||||
title.SetText(getTitle())
|
title.SetText(getTitle())
|
||||||
title.SetTextAlign(tview.AlignCenter)
|
title.SetTextAlign(tview.AlignCenter)
|
||||||
title.SetTextColor(tcell.ColorPink)
|
title.SetTextColor(tcell.ColorPurple)
|
||||||
title.SetBackgroundColor(tcell.ColorBlack)
|
title.SetBackgroundColor(tcell.ColorBlack)
|
||||||
|
|
||||||
appView := tview.NewTextView()
|
appView := tview.NewTextView()
|
||||||
|
@ -107,7 +130,10 @@ func _main() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
legend := tview.NewTextView()
|
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.SetDirection(tview.FlexRow)
|
||||||
mainFlex.AddItem(title, 1, -1, false)
|
mainFlex.AddItem(title, 1, -1, false)
|
||||||
|
@ -120,6 +146,8 @@ func _main() error {
|
||||||
app := tview.NewApplication()
|
app := tview.NewApplication()
|
||||||
app.SetRoot(pages, true)
|
app.SetRoot(pages, true)
|
||||||
|
|
||||||
|
// TODO count of pending signups somewhere
|
||||||
|
|
||||||
app.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
|
app.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
|
||||||
switch event.Rune() {
|
switch event.Rune() {
|
||||||
case 's':
|
case 's':
|
||||||
|
@ -132,9 +160,19 @@ func _main() error {
|
||||||
signupIx = rand.Intn(len(signups))
|
signupIx = rand.Intn(len(signups))
|
||||||
appView.SetText(signups[signupIx].Render())
|
appView.SetText(signups[signupIx].Render())
|
||||||
case 'A':
|
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':
|
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':
|
case 'n':
|
||||||
// TODO notate
|
// TODO notate
|
||||||
case 'Q':
|
case 'Q':
|
||||||
|
|
Loading…
Reference in New Issue