aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--dashboard.go1
-rw-r--r--frontend/renderer.go24
-rw-r--r--main.go2
-rw-r--r--modules/grils/grils.go9
-rw-r--r--modules/lists/lists.go9
-rw-r--r--views/dashboard.html4
-rw-r--r--views/gril.html6
-rw-r--r--views/index.html34
-rw-r--r--views/list.html6
-rw-r--r--views/navbar.html13
10 files changed, 47 insertions, 61 deletions
diff --git a/dashboard.go b/dashboard.go
index 6e81d6b..63dcdfc 100644
--- a/dashboard.go
+++ b/dashboard.go
@@ -25,5 +25,6 @@ func viewDashboard(w http.ResponseWriter, r *http.Request, _ httprouter.Params)
25 25
26 data := make(map[string]interface{}) 26 data := make(map[string]interface{})
27 data["categories"] = categories 27 data["categories"] = categories
28 data["user"] = user
28 app.Renderer.RenderPage("dashboard", w, data) 29 app.Renderer.RenderPage("dashboard", w, data)
29} 30}
diff --git a/frontend/renderer.go b/frontend/renderer.go
index 0a2b7e9..e9b9931 100644
--- a/frontend/renderer.go
+++ b/frontend/renderer.go
@@ -21,13 +21,29 @@ type Card struct {
21 21
22// Renderer rendert Seiten. 22// Renderer rendert Seiten.
23type Renderer struct { 23type Renderer struct {
24 templates *template.Template 24 templates *template.Template
25 defaultData map[string]interface{}
26}
27
28// DefaultData gibt die Standard-Daten für die Views zurück. Das ist immer eine Kopie weil Reasons.
29func (r *Renderer) DefaultData() map[string]interface{} {
30 d := make(map[string]interface{})
31 for k, v := range r.defaultData {
32 d[k] = v
33 }
34 return d
35}
36
37// SetDefaultData updated die standarddaten
38func (r *Renderer) SetDefaultData(data map[string]interface{}) {
39 r.defaultData = data
25} 40}
26 41
27// New erstellt einen neuen Renderer und sucht alle Templates aus dem gegebenen pfad. 42// New erstellt einen neuen Renderer und sucht alle Templates aus dem gegebenen pfad.
28func New(path string) *Renderer { 43func New(path string) *Renderer {
29 r := &Renderer{ 44 r := &Renderer{
30 template.Must(template.ParseGlob(path + "/*")), 45 template.Must(template.ParseGlob(path + "/*")),
46 make(map[string]interface{}),
31 } 47 }
32 48
33 return r 49 return r
@@ -35,6 +51,12 @@ func New(path string) *Renderer {
35 51
36// RenderPage rendert eine bestimmte Seite (basierend auf dem Template-Namen) und den gegebenen Daten. 52// RenderPage rendert eine bestimmte Seite (basierend auf dem Template-Namen) und den gegebenen Daten.
37func (r *Renderer) RenderPage(name string, w http.ResponseWriter, data map[string]interface{}) { 53func (r *Renderer) RenderPage(name string, w http.ResponseWriter, data map[string]interface{}) {
54 // default daten einspeisen
55 for k, v := range r.defaultData {
56 if _, ok := data[k]; !ok {
57 data[k] = v
58 }
59 }
38 err := r.templates.ExecuteTemplate(w, name, data) 60 err := r.templates.ExecuteTemplate(w, name, data)
39 if err != nil { 61 if err != nil {
40 http.Error(w, err.Error(), http.StatusInternalServerError) 62 http.Error(w, err.Error(), http.StatusInternalServerError)
diff --git a/main.go b/main.go
index 70763d4..dacdfe1 100644
--- a/main.go
+++ b/main.go
@@ -9,8 +9,8 @@ import (
9 "fagott.pw/charakterin" 9 "fagott.pw/charakterin"
10 "fagott.pw/grilist/frontend" 10 "fagott.pw/grilist/frontend"
11 "fagott.pw/grilist/grilist" 11 "fagott.pw/grilist/grilist"
12 "fagott.pw/grilist/modules/lists"
13 "fagott.pw/grilist/modules/grils" 12 "fagott.pw/grilist/modules/grils"
13 "fagott.pw/grilist/modules/lists"
14 14
15 "github.com/julienschmidt/httprouter" 15 "github.com/julienschmidt/httprouter"
16 _ "github.com/lib/pq" 16 _ "github.com/lib/pq"
diff --git a/modules/grils/grils.go b/modules/grils/grils.go
index fbe57e3..3663c7f 100644
--- a/modules/grils/grils.go
+++ b/modules/grils/grils.go
@@ -73,10 +73,7 @@ func (m *GrilsModule) FromID(id int) (*Gril, error) {
73} 73}
74 74
75func (m *GrilsModule) viewGril(w http.ResponseWriter, r *http.Request, p httprouter.Params) { 75func (m *GrilsModule) viewGril(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
76 loggedIn := false 76 user, _ := m.g.Charakterin.GetUserFromRequest(r)
77 if user, _ := m.g.Charakterin.GetUserFromRequest(r); user != nil {
78 loggedIn = true
79 }
80 sid := p.ByName("id") 77 sid := p.ByName("id")
81 78
82 id, err := strconv.Atoi(sid) 79 id, err := strconv.Atoi(sid)
@@ -91,8 +88,8 @@ func (m *GrilsModule) viewGril(w http.ResponseWriter, r *http.Request, p httprou
91 return 88 return
92 } 89 }
93 90
94 data := make(map[string]interface{}) 91 data := m.g.Renderer.DefaultData()
95 data["loggedIn"] = loggedIn 92 data["user"] = user
96 data["gril"] = gril 93 data["gril"] = gril
97 94
98 m.g.Renderer.RenderPage("gril", w, data) 95 m.g.Renderer.RenderPage("gril", w, data)
diff --git a/modules/lists/lists.go b/modules/lists/lists.go
index 519bb36..970b15b 100644
--- a/modules/lists/lists.go
+++ b/modules/lists/lists.go
@@ -207,10 +207,7 @@ func (m *Module) ProvideDashboardData(user *charakterin.User) []grilist.Dashboar
207} 207}
208 208
209func (m *Module) viewList(w http.ResponseWriter, r *http.Request, p httprouter.Params) { 209func (m *Module) viewList(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
210 loggedIn := false 210 user, _ := m.g.Charakterin.GetUserFromRequest(r)
211 if user, _ := m.g.Charakterin.GetUserFromRequest(r); user != nil {
212 loggedIn = true
213 }
214 sid := p.ByName("id") 211 sid := p.ByName("id")
215 212
216 id, err := strconv.Atoi(sid) 213 id, err := strconv.Atoi(sid)
@@ -225,8 +222,8 @@ func (m *Module) viewList(w http.ResponseWriter, r *http.Request, p httprouter.P
225 return 222 return
226 } 223 }
227 224
228 data := make(map[string]interface{}) 225 data := m.g.Renderer.DefaultData()
229 data["loggedIn"] = loggedIn 226 data["user"] = user
230 data["list"] = list 227 data["list"] = list
231 228
232 m.g.Renderer.RenderPage("list", w, data) 229 m.g.Renderer.RenderPage("list", w, data)
diff --git a/views/dashboard.html b/views/dashboard.html
index a000b57..a9a01d9 100644
--- a/views/dashboard.html
+++ b/views/dashboard.html
@@ -6,10 +6,8 @@
6 <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no"> 6 <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
7 </head> 7 </head>
8 <body> 8 <body>
9 {{ template "navbar" . }}
9 <div class="container"> 10 <div class="container">
10 <div class="row right-align">
11 <a class="waves-effect waves-teal btn-flat large" style="top: 24px; font-size: 18px" href="/logout">Ausloggen</a>
12 </div>
13 <div class="row"> 11 <div class="row">
14 {{ range $category := .categories }} 12 {{ range $category := .categories }}
15 <h2>{{ $category.Title }}</h2> 13 <h2>{{ $category.Title }}</h2>
diff --git a/views/gril.html b/views/gril.html
index d62fc75..d623abf 100644
--- a/views/gril.html
+++ b/views/gril.html
@@ -8,12 +8,8 @@
8 <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no"> 8 <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
9 </head> 9 </head>
10 <body> 10 <body>
11 {{ template "navbar" . }}
11 <div class="container"> 12 <div class="container">
12 {{ if .loggedIn }}
13 <div class="row right-align">
14 <a class="waves-effect waves-teal btn-flat large" style="top: 24px; font-size: 18px" href="/logout">Ausloggen</a>
15 </div>
16 {{ end }}
17 <h1>{{ $gril.RomajiName }}<small>{{ $gril.KanjiName }}</small></h1> 13 <h1>{{ $gril.RomajiName }}<small>{{ $gril.KanjiName }}</small></h1>
18 </div> 14 </div>
19 </body> 15 </body>
diff --git a/views/index.html b/views/index.html
deleted file mode 100644
index 81c801f..0000000
--- a/views/index.html
+++ /dev/null
@@ -1,34 +0,0 @@
1{{ define "index" }}
2<html>
3 <head>
4 {{ template "materialize" }}
5 <title>grilist</title>
6 <style>
7 body {
8 height: 100%;
9 width: 100%;
10 overflow: hidden;
11 }
12
13 h1 {
14 font-size: 100px;
15 }
16
17 h1 >small {
18 margin-top: -50px;
19 font-size: 20%;
20 }
21 </style>
22 <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
23 </head>
24 <body class="valign-wrapper center-align">
25 <div class="container">
26 <div class="center-align">
27 <h1>grilist<small class="blue-grey-text lighten-1">#tamtam</small></h1>
28
29 <a class="btn waves-effect waves-light cyan lighten-3" href="/logout">Ausloggen</a>
30 </div>
31 </div>
32 </body>
33</html>
34{{ end }} \ No newline at end of file
diff --git a/views/list.html b/views/list.html
index 63cfd9c..fb5f7a3 100644
--- a/views/list.html
+++ b/views/list.html
@@ -8,12 +8,8 @@
8 <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no"> 8 <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
9 </head> 9 </head>
10 <body> 10 <body>
11 {{ template "navbar" . }}
11 <div class="container"> 12 <div class="container">
12 {{ if .loggedIn }}
13 <div class="row right-align">
14 <a class="waves-effect waves-teal btn-flat large" style="top: 24px; font-size: 18px" href="/logout">Ausloggen</a>
15 </div>
16 {{ end }}
17 <h1>{{ $list.Name }}<small>von xyz</small></h1><br /> 13 <h1>{{ $list.Name }}<small>von xyz</small></h1><br />
18 <ul> 14 <ul>
19 {{ range $lg := $list.Grils }} 15 {{ range $lg := $list.Grils }}
diff --git a/views/navbar.html b/views/navbar.html
new file mode 100644
index 0000000..c4bbace
--- /dev/null
+++ b/views/navbar.html
@@ -0,0 +1,13 @@
1{{ define "navbar" }}
2 <nav>
3 <div class="nav-wrapper purple lighten-2">
4 <a href="/" class="brand-logo center">grilist</a>
5 <ul id="nav-mobile" class="right hide-on-med-and-down">
6 {{ if .user }}
7 <li><a href="/">{{ .user.Name }}</a></li>
8 <li><a href="/logout">Ausloggen</a></li>
9 {{ end }}
10 </ul>
11 </div>
12 </nav>
13{{ end }} \ No newline at end of file