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