set votes on homepage

This commit is contained in:
Matthieu Lamalle 2019-11-27 14:42:08 +01:00
parent 1af50c36ae
commit 62a91653c3
3 changed files with 28 additions and 13 deletions

BIN
server

Binary file not shown.

View File

@ -47,7 +47,6 @@ func main() {
if err := http.ListenAndServe(conf.HTTP.Address, r); err != nil {
panic(errors.Wrapf(err, "error while listening on '%s'", conf.HTTP.Address))
}
}
// ServerHTTP is the entry point to all requests
@ -104,12 +103,18 @@ func LogInPage(w http.ResponseWriter, r *http.Request) {
// HomePage is the homepage of the app
func HomePage(w http.ResponseWriter, r *http.Request) {
foods := foodlist.GetFoodOfTheDay()
type HomeData struct {
Foods foodlist.FoodOfTheDay
Votes vote.VotesOfTheDay
}
datas := HomeData{foodlist.GetFoodOfTheDay(), vote.GetVotesOfTheDay()}
paths := []string{
"./templates/index.tmpl",
}
t := template.Must(template.New("index.tmpl").ParseFiles(paths...))
err := t.Execute(w, foods)
err := t.Execute(w, datas)
if err != nil {
log.Printf("\nExecute error: %v", err)
return

View File

@ -7,27 +7,37 @@
<script src="https://code.jquery.com/jquery-3.1.1.min.js" integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.2.13/semantic.min.js"></script>
<style type="text/css"> h2 { margin: 2em 0em; } .ui.container { padding-top: 5em; padding-bottom: 5em; } </style>
<script type="text/javascript">function vote(option){$.post( "/", {option}, ( data ) => { $('.mini.modal').modal('show');});}</script>
<script type="text/javascript">
function vote(option){$.post( "/", {option}, ( data ) => { $('.modal').modal('show');});}
function reload(){document.location.reload(true);}
</script>
</head>
<body>
<div class="ui container">
<h1 class="ui header">Foodoles - {{.Date}}</h1><br/>
<h1 class="ui header">Foodoles - {{.Foods.Date}}</h1><br/>
<h2 class="ui header">Pick Your Preferred Lunch's Food For Today</h2><br/>
<div class="ui four column grid link cards">
{{ range .Foods }}
<div onclick="vote('{{ .Title }}')">
<div class="ui massive label"> {{ .Icon }}</div>
</div>
<div class="ui compact menu">
{{ range .Foods.Foods }}
<a onclick="vote('{{ .Title }}')" class="ui item label massive">
{{$cur := .Title}}
{{ .Icon }}
{{ range $.Votes.Votes }}
{{ if eq .Food $cur }}
<div class="floating ui blue left label">{{ .Voices }}</div>
{{end}}
{{end}}
</a>
{{ end }}
</div>
</div>
<div class="ui modal mini">
<div class="ui modal">
<div class="header">Foodoles</div>
<div class="content">
<p>Vote sent <strong>successfully</strong>, <a href="/results"> check results !</a></p>
<p>Vote sent <strong>successfully</strong></p>
</div>
<div class="actions">
<div class="ui cancel button blue">Close</div>
<div class="ui cancel button blue" onclick="reload()">Close</div>
</div>
</div>
</body>