79 lines
1.4 KiB
Go
79 lines
1.4 KiB
Go
package game
|
|
|
|
import (
|
|
"html/template"
|
|
"io"
|
|
|
|
"git.cliffbreak.de/haveachin/scoreboard/data"
|
|
)
|
|
|
|
type previewGame struct {
|
|
ID string
|
|
Name string
|
|
}
|
|
|
|
type master struct {
|
|
Template template.Template
|
|
Games []previewGame
|
|
}
|
|
|
|
type previewGroup struct {
|
|
ID string
|
|
Name string
|
|
Points int
|
|
}
|
|
|
|
type detail struct {
|
|
Template template.Template
|
|
Game data.Game
|
|
Groups []previewGroup
|
|
}
|
|
|
|
func newMasterPage(t template.Template, games []data.Game) *master {
|
|
previewGames := []previewGame{}
|
|
|
|
for _, game := range games {
|
|
previewGames = append(previewGames, previewGame{
|
|
ID: game.ID.Hex(),
|
|
Name: game.Name,
|
|
})
|
|
}
|
|
|
|
return &master{
|
|
Template: *t.Lookup("gameMaster.html"),
|
|
Games: previewGames,
|
|
}
|
|
}
|
|
|
|
func newDetailPage(t template.Template, game data.Game, groups []data.Group) *detail {
|
|
previewGroups := []previewGroup{}
|
|
|
|
for _, group := range groups {
|
|
points := 0
|
|
for _, score := range group.Scores {
|
|
if score.GameID == game.ID {
|
|
points = score.Points
|
|
break
|
|
}
|
|
}
|
|
previewGroups = append(previewGroups, previewGroup{
|
|
ID: group.ID.Hex(),
|
|
Name: group.Name,
|
|
Points: points,
|
|
})
|
|
}
|
|
|
|
return &detail{
|
|
Template: *t.Lookup("gameDetail.html"),
|
|
Game: game,
|
|
Groups: previewGroups,
|
|
}
|
|
}
|
|
|
|
func (page master) Send(w io.Writer) {
|
|
page.Template.Execute(w, page)
|
|
}
|
|
|
|
func (page detail) Send(w io.Writer) {
|
|
page.Template.Execute(w, page)
|
|
}
|