Show responses on admin page
This commit is contained in:
@ -357,7 +357,7 @@ func (h *handler) handleAdmin(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
responses, err := h.store.GetEventResponseSummary(context.Background(), back.GetEventResponseSummaryQuery{
|
||||
summary, err := h.store.GetEventResponseSummary(context.Background(), back.GetEventResponseSummaryQuery{
|
||||
EventID: eventID,
|
||||
})
|
||||
if err != nil {
|
||||
@ -365,6 +365,33 @@ func (h *handler) handleAdmin(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
// Build the counts table
|
||||
dateSpan := metadata.Latest.Sub(metadata.Earliest)
|
||||
var dates []date.Date
|
||||
for offset := date.PeriodOfDays(0); offset <= dateSpan; offset++ {
|
||||
dates = append(dates, metadata.Earliest.Add(offset))
|
||||
}
|
||||
var ths = hm.Terms{e.Th()()}
|
||||
for _, date := range dates {
|
||||
ths = append(ths, e.Th()(hm.Text(date.Format("Jan 2"))))
|
||||
}
|
||||
var rows = hm.Terms{e.Thead()(ths)}
|
||||
for hour := 0; hour < 24; hour++ {
|
||||
var row = hm.Terms{
|
||||
e.Td()(hm.Text(timeLabels[hour])),
|
||||
}
|
||||
for _, day := range dates {
|
||||
hourCounts := summary.PerHourCounts[day]
|
||||
var count int
|
||||
if hourCounts != nil {
|
||||
count = hourCounts[hour]
|
||||
}
|
||||
row = append(row, e.Td()(hm.Text(strconv.Itoa(count))))
|
||||
}
|
||||
rows = append(rows, e.Tr()(row))
|
||||
}
|
||||
countsTable := e.Table()(rows)
|
||||
|
||||
body := hm.Terms{
|
||||
e.Form()(
|
||||
e.Label(a.For(fieldNameEventName))(hm.Text("Event name")),
|
||||
@ -400,7 +427,8 @@ func (h *handler) handleAdmin(w http.ResponseWriter, r *http.Request) {
|
||||
),
|
||||
),
|
||||
e.H3()(hm.Text("Responses")),
|
||||
e.P()(hm.Text(strconv.Itoa(responses.TotalResponses))),
|
||||
e.P()(hm.Text(strconv.Itoa(summary.TotalResponses))),
|
||||
countsTable,
|
||||
}
|
||||
_ = h.writePage(w, "Edit your event", body)
|
||||
}
|
||||
|
Reference in New Issue
Block a user