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 {
|
func renderSignup(s models.TownSignup) string {
|
||||||
out := ""
|
out := fmt.Sprintf("[-:-:b]submitted:[-:-:-] %s\n", s.Created.Format("2006-01-02 15:04"))
|
||||||
|
|
||||||
pairs := [][]string{
|
pairs := map[string]string{
|
||||||
{"submitted", s.Created.Format("2006-01-02 15:04")},
|
"e-mail": s.Email,
|
||||||
{"e-mail", s.Email},
|
"how found / referral": s.How,
|
||||||
{"how found / referral", s.How},
|
"why like town / what do": s.Why,
|
||||||
{"why like town / plans", s.Why},
|
"links": s.Links,
|
||||||
{"links", s.Links},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, v := range pairs {
|
for k, v := range pairs {
|
||||||
out += fmt.Sprintf("[-:-:b]%s[-:-:-]\n", v[0])
|
out += fmt.Sprintf("[-:-:b]%s[-:-:-]\n", k)
|
||||||
out += strings.TrimSpace(v[1])
|
out += strings.TrimSpace(v)
|
||||||
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
|
||||||
|
@ -139,6 +126,11 @@ 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")
|
||||||
|
@ -149,32 +141,19 @@ func _main() error {
|
||||||
count := tview.NewTextView()
|
count := tview.NewTextView()
|
||||||
count.SetDynamicColors(true)
|
count.SetDynamicColors(true)
|
||||||
updateCount := func() {
|
updateCount := func() {
|
||||||
plural := "s"
|
count.SetText(fmt.Sprintf("[-:-:b]%d pending signups[-:-:-]", len(signups)))
|
||||||
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(innerFlex, 0, 1, false)
|
mainFlex.AddItem(appView, 0, 1, true)
|
||||||
mainFlex.AddItem(bottomFlex, 1, -1, false)
|
mainFlex.AddItem(bottomFlex, 1, -1, false)
|
||||||
|
|
||||||
pages := tview.NewPages()
|
pages := tview.NewPages()
|
||||||
|
@ -185,24 +164,6 @@ 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() {
|
||||||
|
@ -214,7 +175,7 @@ func _main() error {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
render()
|
// TODO force redraw of current item
|
||||||
|
|
||||||
pages.SwitchToPage("main")
|
pages.SwitchToPage("main")
|
||||||
})
|
})
|
||||||
|
@ -231,11 +192,15 @@ 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
|
||||||
}
|
}
|
||||||
render()
|
appView.SetText(renderSignup(*signups[signupIx]))
|
||||||
}
|
}
|
||||||
|
|
||||||
removeSignup := func(signup *models.TownSignup) {
|
removeSignup := func(signup *models.TownSignup) {
|
||||||
|
@ -251,7 +216,7 @@ func _main() error {
|
||||||
signupIx = 0
|
signupIx = 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
render()
|
appView.SetText(renderSignup(*signups[signupIx]))
|
||||||
}
|
}
|
||||||
|
|
||||||
app.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
|
app.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
|
||||||
|
@ -265,7 +230,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))
|
||||||
render()
|
appView.SetText(renderSignup(*signups[signupIx]))
|
||||||
}
|
}
|
||||||
case 'A':
|
case 'A':
|
||||||
if len(signups) == 0 {
|
if len(signups) == 0 {
|
||||||
|
@ -281,7 +246,6 @@ 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':
|
||||||
|
@ -297,7 +261,6 @@ 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,6 +54,9 @@ 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
|
||||||
|
@ -96,41 +99,6 @@ 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(`
|
||||||
|
@ -158,6 +126,7 @@ 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