-
Notifications
You must be signed in to change notification settings - Fork 0
/
page_kudos.go
50 lines (42 loc) · 1021 Bytes
/
page_kudos.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package main
import (
"fmt"
"net/http"
"strings"
"github.com/julienschmidt/httprouter"
)
// Kudo main kudos
type KudosStats struct {
Member Member
Pts int
Position int
Prc float32
HasCrown bool
}
type kudosView struct {
Item Kudo
Text []string
}
type kudosPageView struct {
Kudos []kudosView
KudosReceived []KudosStats
KudosGave []KudosStats
}
func loadKudosPage(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
pageName := "kudos.tmpl"
tmpl, ok := templates[pageName]
if !ok {
fmt.Errorf("The template %s does not exist.", pageName)
}
var viewKudos []kudosView
for i := 0; i < 9 && i < len(kudos); i++ {
view := kudosView{Item: kudos[i], Text: strings.Split(kudos[i].Text, "\n")}
viewKudos = append(viewKudos, view)
}
pageData := kudosPageView{
Kudos: viewKudos,
KudosReceived: loadKudosReceivedList(),
KudosGave: loadKudosGaveList()}
r.Header.Set("Content-Type", "text/html; charset=utf-8")
tmpl.ExecuteTemplate(w, "base.tmpl", pageData)
}