This commit is contained in:
Brian Buller 2017-07-05 08:10:08 -05:00
parent 96a53b6090
commit 7162c8c34d
4 changed files with 9 additions and 5 deletions

View File

@ -11,10 +11,6 @@ func handleAdminVotes(w http.ResponseWriter, req *http.Request, page *pageData)
page.SubTitle = "Votes" page.SubTitle = "Votes"
switch vars["function"] { switch vars["function"] {
default: default:
type votesPageData struct {
Votes []Vote
}
page.TemplateData = votesPageData{Votes: dbGetAllVotes()}
page.show("admin-votes.html", w) page.show("admin-votes.html", w)
} }
} }

View File

@ -32,6 +32,8 @@ type siteData struct {
DevMode bool DevMode bool
CurrentJam string CurrentJam string
AllVotes []Vote
} }
// pageData is stuff that changes per request // pageData is stuff that changes per request
@ -199,6 +201,9 @@ func initialize() {
} else { } else {
fmt.Println(err.Error()) fmt.Println(err.Error())
} }
// Load all votes into memory
site.AllVotes = dbGetAllVotes()
} }
func loggingHandler(h http.Handler) http.Handler { func loggingHandler(h http.Handler) http.Handler {

View File

@ -57,5 +57,8 @@ func handlePublicSaveVote(w http.ResponseWriter, req *http.Request) {
if err := dbSaveVote(page.ClientId, timestamp, voteSlice); err != nil { if err := dbSaveVote(page.ClientId, timestamp, voteSlice); err != nil {
page.session.setFlashMessage("Error Saving Vote: "+err.Error(), "error") page.session.setFlashMessage("Error Saving Vote: "+err.Error(), "error")
} }
if newVote, err := dbGetVote(page.ClientId, timestamp); err == nil {
site.AllVotes = append(site.AllVotes, *newVote)
}
redirect("/", w, req) redirect("/", w, req)
} }

View File

@ -5,7 +5,7 @@
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{{ range $i, $v, := .TemplateData.Votes }} {{ range $i, $v, := .Site.AllVotes }}
<tr> <tr>
<td>{{ $v.Timestamp }}</td> <td>{{ $v.Timestamp }}</td>
</tr> </tr>