This repository has been archived on 2019-07-11. You can view files and clone it, but cannot push or open issues or pull requests.
scoreboard/features/group/page.go

63 lines
1.1 KiB
Go
Raw Permalink Normal View History

2019-05-27 21:46:09 +00:00
package group
import (
"html/template"
"io"
"git.cliffbreak.de/haveachin/scoreboard/data"
)
type previewGroup struct {
ID string
Name string
PointSum int
}
type master struct {
Template template.Template
Groups []previewGroup
}
type detail struct {
Template template.Template
Group data.Group
Games []data.Game
}
func newMasterPage(t template.Template, groups []data.Group) *master {
previewGroups := []previewGroup{}
for _, group := range groups {
sum := 0
for _, score := range group.Scores {
sum += score.Points
}
previewGroups = append(previewGroups, previewGroup{
ID: group.ID.Hex(),
Name: group.Name,
PointSum: sum,
})
}
return &master{
Template: *t.Lookup("groupMaster.html"),
Groups: previewGroups,
}
}
func newDetailPage(t template.Template, group data.Group, games []data.Game) *detail {
return &detail{
Template: *t.Lookup("groupDetail.html"),
Group: group,
Games: games,
}
}
func (page master) Send(w io.Writer) {
page.Template.Execute(w, page)
}
func (page detail) Send(w io.Writer) {
page.Template.Execute(w, page)
}