Show total responses on admin page
This commit is contained in:
@ -6,6 +6,7 @@ import (
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
hm "gitlab.codemonkeysoftware.net/b/hatmill"
|
||||
@ -122,7 +123,7 @@ func voteForm(disabled bool, st voteState) hm.Term {
|
||||
|
||||
func (h *handler) handleVote(w http.ResponseWriter, r *http.Request) {
|
||||
query := r.URL.Query()
|
||||
event, err := h.store.GetEvent(context.Background(), back.GetEventQuery{
|
||||
event, err := h.store.GetEventMetadata(context.Background(), back.GetEventMetadataQuery{
|
||||
AlphaID: query.Get(keyEventID),
|
||||
})
|
||||
// TODO return 404 if event not found
|
||||
@ -254,9 +255,10 @@ func (h *handler) handleDoCreate(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
func (h *handler) handleAdmin(w http.ResponseWriter, r *http.Request) {
|
||||
query := r.URL.Query()
|
||||
eventID := query.Get(keyEventID)
|
||||
// TODO authenticate with admin code
|
||||
event, err := h.store.GetEvent(context.Background(), back.GetEventQuery{
|
||||
AlphaID: query.Get(keyEventID),
|
||||
metadata, err := h.store.GetEventMetadata(context.Background(), back.GetEventMetadataQuery{
|
||||
AlphaID: eventID,
|
||||
})
|
||||
// TODO return 404 if event not found
|
||||
if err != nil {
|
||||
@ -264,24 +266,33 @@ func (h *handler) handleAdmin(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
responses, err := h.store.GetEventResponses(context.Background(), back.GetEventResponsesQuery{
|
||||
AlphaID: eventID,
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Fprint(w, err)
|
||||
return
|
||||
}
|
||||
|
||||
// TODO show results (number of responses, grid)
|
||||
body := hm.Terms{
|
||||
e.Form()(
|
||||
e.Label(a.For(fieldNameEventName))(hm.Text("Event name")),
|
||||
e.Input(
|
||||
a.Name(fieldNameEventName),
|
||||
a.Value(event.Name),
|
||||
a.Value(metadata.Name),
|
||||
),
|
||||
e.Br(),
|
||||
|
||||
e.Label(a.For(fieldNameDescription))(hm.Text("Description")),
|
||||
e.Textarea(a.Name(fieldNameDescription))(hm.Text(event.Description)),
|
||||
e.Textarea(a.Name(fieldNameDescription))(hm.Text(metadata.Description)),
|
||||
e.Br(),
|
||||
|
||||
e.Label(a.For(fieldNameEarliest))(hm.Text("Earliest date")),
|
||||
e.Input(
|
||||
a.Name(fieldNameEarliest),
|
||||
a.Type("date"),
|
||||
a.Value(event.EarliestDate.Format(formDateLayout)),
|
||||
a.Value(metadata.EarliestDate.Format(formDateLayout)),
|
||||
),
|
||||
e.Br(),
|
||||
|
||||
@ -289,12 +300,14 @@ func (h *handler) handleAdmin(w http.ResponseWriter, r *http.Request) {
|
||||
e.Input(
|
||||
a.Name(fieldNameLatest),
|
||||
a.Type("date"),
|
||||
a.Value(event.LatestDate.Format(formDateLayout)),
|
||||
a.Value(metadata.LatestDate.Format(formDateLayout)),
|
||||
),
|
||||
e.Br(),
|
||||
|
||||
e.Input(a.Type("submit")),
|
||||
),
|
||||
e.H3()(hm.Text("Responses")),
|
||||
e.P()(hm.Text(strconv.Itoa(responses.TotalResponses))),
|
||||
}
|
||||
_ = h.writePage(w, "Edit your event", body)
|
||||
}
|
||||
|
Reference in New Issue
Block a user