Compare commits
No commits in common. "7543c2c4cd9b100dcda0b5509c39c2568c4073f9" and "46ee8932c1ab5b5b45fe5eb1a5f09c466f41fe6d" have entirely different histories.
7543c2c4cd
...
46ee8932c1
|
@ -60,37 +60,24 @@ func (r *reviewer) AddNote(s *models.TownSignup, content string) error {
|
|||
}
|
||||
|
||||
func renderSignup(s models.TownSignup) string {
|
||||
out := ""
|
||||
out := fmt.Sprintf("[-:-:b]submitted:[-:-:-] %s\n", s.Created.Format("2006-01-02 15:04"))
|
||||
|
||||
pairs := [][]string{
|
||||
{"submitted", s.Created.Format("2006-01-02 15:04")},
|
||||
{"e-mail", s.Email},
|
||||
{"how found / referral", s.How},
|
||||
{"why like town / plans", s.Why},
|
||||
{"links", s.Links},
|
||||
pairs := map[string]string{
|
||||
"e-mail": s.Email,
|
||||
"how found / referral": s.How,
|
||||
"why like town / what do": s.Why,
|
||||
"links": s.Links,
|
||||
}
|
||||
|
||||
for _, v := range pairs {
|
||||
out += fmt.Sprintf("[-:-:b]%s[-:-:-]\n", v[0])
|
||||
out += strings.TrimSpace(v[1])
|
||||
for k, v := range pairs {
|
||||
out += fmt.Sprintf("[-:-:b]%s[-:-:-]\n", k)
|
||||
out += strings.TrimSpace(v)
|
||||
out += "\n\n"
|
||||
}
|
||||
|
||||
return out
|
||||
}
|
||||
|
||||
func renderNotes(s models.TownSignup) string {
|
||||
out := ""
|
||||
for _, note := range s.Notes {
|
||||
out += fmt.Sprintf(`%s said on %s:
|
||||
%s`, note.Author, note.Created.Format("2006-01-02 15:04"), note.Content)
|
||||
|
||||
out += "\n\n"
|
||||
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func _main() error {
|
||||
/*
|
||||
TODO will use this for invites
|
||||
|
@ -139,6 +126,11 @@ func _main() error {
|
|||
|
||||
appView := tview.NewTextView()
|
||||
appView.SetDynamicColors(true)
|
||||
if len(signups) == 0 {
|
||||
appView.SetText("no signups found.")
|
||||
} else {
|
||||
appView.SetText(renderSignup(*signups[signupIx]))
|
||||
}
|
||||
|
||||
legend := tview.NewTextView()
|
||||
legend.SetText("s: skip r: random A: approve R: reject N: notate Q: quit")
|
||||
|
@ -149,32 +141,19 @@ func _main() error {
|
|||
count := tview.NewTextView()
|
||||
count.SetDynamicColors(true)
|
||||
updateCount := func() {
|
||||
plural := "s"
|
||||
if len(signups) == 1 {
|
||||
plural = ""
|
||||
}
|
||||
count.SetText(fmt.Sprintf("[-:-:b]%d pending signup%s[-:-:-]", len(signups), plural))
|
||||
count.SetText(fmt.Sprintf("[-:-:b]%d pending signups[-:-:-]", len(signups)))
|
||||
}
|
||||
updateCount()
|
||||
|
||||
notesView := tview.NewTextView()
|
||||
notesView.SetDynamicColors(true)
|
||||
notesView.SetBorder(true).SetBorderColor(tcell.ColorPurple)
|
||||
|
||||
bottomFlex := tview.NewFlex()
|
||||
bottomFlex.SetDirection(tview.FlexColumn)
|
||||
bottomFlex.AddItem(count, 0, 1, false)
|
||||
bottomFlex.AddItem(legend, 0, 10, false)
|
||||
|
||||
innerFlex := tview.NewFlex()
|
||||
innerFlex.SetDirection(tview.FlexColumn)
|
||||
innerFlex.AddItem(appView, 0, 2, true)
|
||||
innerFlex.AddItem(notesView, 0, 1, true)
|
||||
|
||||
mainFlex := tview.NewFlex()
|
||||
mainFlex.SetDirection(tview.FlexRow)
|
||||
mainFlex.AddItem(title, 1, -1, false)
|
||||
mainFlex.AddItem(innerFlex, 0, 1, false)
|
||||
mainFlex.AddItem(appView, 0, 1, true)
|
||||
mainFlex.AddItem(bottomFlex, 1, -1, false)
|
||||
|
||||
pages := tview.NewPages()
|
||||
|
@ -185,24 +164,6 @@ func _main() error {
|
|||
pages.SwitchToPage("main")
|
||||
})
|
||||
|
||||
render := func() {
|
||||
if len(signups) == 0 {
|
||||
appView.SetText("no signups")
|
||||
return
|
||||
}
|
||||
currSignup := signups[signupIx]
|
||||
err := currSignup.RefreshNotes(signupDB)
|
||||
if err != nil {
|
||||
errorModal.SetText(fmt.Sprintf("error! failed to add note: %s", err.Error()))
|
||||
pages.SwitchToPage("error")
|
||||
}
|
||||
|
||||
appView.SetText(renderSignup(*currSignup))
|
||||
notesView.SetText(renderNotes(*currSignup))
|
||||
}
|
||||
|
||||
render()
|
||||
|
||||
notate := tview.NewForm()
|
||||
notate.AddTextArea("note", "", 80, 10, 1000, func(string) {})
|
||||
notate.AddButton("submit", func() {
|
||||
|
@ -214,7 +175,7 @@ func _main() error {
|
|||
return
|
||||
}
|
||||
|
||||
render()
|
||||
// TODO force redraw of current item
|
||||
|
||||
pages.SwitchToPage("main")
|
||||
})
|
||||
|
@ -231,11 +192,15 @@ func _main() error {
|
|||
|
||||
// TODO replace imperative shit with a signupManager
|
||||
advanceSignup := func() {
|
||||
if len(signups) == 0 {
|
||||
appView.SetText("no signups found.")
|
||||
return
|
||||
}
|
||||
signupIx++
|
||||
if signupIx == len(signups) {
|
||||
signupIx = 0
|
||||
}
|
||||
render()
|
||||
appView.SetText(renderSignup(*signups[signupIx]))
|
||||
}
|
||||
|
||||
removeSignup := func(signup *models.TownSignup) {
|
||||
|
@ -251,7 +216,7 @@ func _main() error {
|
|||
signupIx = 0
|
||||
}
|
||||
}
|
||||
render()
|
||||
appView.SetText(renderSignup(*signups[signupIx]))
|
||||
}
|
||||
|
||||
app.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
|
||||
|
@ -265,7 +230,7 @@ func _main() error {
|
|||
case 'r':
|
||||
if len(signups) > 0 {
|
||||
signupIx = rand.Intn(len(signups))
|
||||
render()
|
||||
appView.SetText(renderSignup(*signups[signupIx]))
|
||||
}
|
||||
case 'A':
|
||||
if len(signups) == 0 {
|
||||
|
@ -281,7 +246,6 @@ func _main() error {
|
|||
}
|
||||
removeSignup(signup)
|
||||
updateCount()
|
||||
render()
|
||||
// TODO generate invite token
|
||||
// TODO send invite email
|
||||
case 'R':
|
||||
|
@ -297,7 +261,6 @@ func _main() error {
|
|||
}
|
||||
removeSignup(signup)
|
||||
updateCount()
|
||||
render()
|
||||
case 'N':
|
||||
if len(signups) == 0 {
|
||||
return nil
|
||||
|
|
|
@ -54,6 +54,9 @@ const (
|
|||
SignupRejected SignupDecision = "rejected"
|
||||
)
|
||||
|
||||
// TODO add DecisionTime column to DB
|
||||
// TODO add DecisionBy column to DB
|
||||
// TODO add CleanEmail column to DB
|
||||
type TownSignup struct {
|
||||
ID int64
|
||||
Created time.Time
|
||||
|
@ -96,41 +99,6 @@ func (s *TownSignup) Insert(db *sql.DB) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (s *TownSignup) RefreshNotes(db *sql.DB) error {
|
||||
stmt, err := db.Prepare(`
|
||||
SELECT created, author, content
|
||||
FROM notes
|
||||
WHERE signupid = ?`)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
rows, err := stmt.Query(s.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer stmt.Close()
|
||||
|
||||
s.Notes = []SignupNote{}
|
||||
|
||||
for rows.Next() {
|
||||
note := &SignupNote{}
|
||||
var timestamp int64
|
||||
err = rows.Scan(
|
||||
×tamp,
|
||||
¬e.Author,
|
||||
¬e.Content,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
note.Created = time.Unix(timestamp, 0)
|
||||
s.Notes = append(s.Notes, *note)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *TownSignup) All(db *sql.DB) ([]*TownSignup, error) {
|
||||
// TODO notes; circle back once can author them
|
||||
rows, err := db.Query(`
|
||||
|
@ -158,6 +126,7 @@ func (s *TownSignup) All(db *sql.DB) ([]*TownSignup, error) {
|
|||
|
||||
su.Created = time.Unix(timestamp, 0)
|
||||
|
||||
// TODO fetch notes
|
||||
out = append(out, su)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue