aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--frontend/renderer.go9
-rw-r--r--modules/tags/tags.go16
-rw-r--r--views/tag.html6
3 files changed, 30 insertions, 1 deletions
diff --git a/frontend/renderer.go b/frontend/renderer.go
index a3aa83d..524c2c8 100644
--- a/frontend/renderer.go
+++ b/frontend/renderer.go
@@ -47,9 +47,16 @@ func New(path string) *Renderer {
47 "html": func(in string) template.HTML { 47 "html": func(in string) template.HTML {
48 return template.HTML(in) 48 return template.HTML(in)
49 }, 49 },
50 "add": func(a, b int) int {
51 return a + b
52 },
53 "sub": func(a, b int) int {
54 return a - b
55 },
50 } 56 }
57
51 r := &Renderer{ 58 r := &Renderer{
52 template.Must(template.ParseGlob(path + "/*")).Funcs(funcMap), 59 template.Must(template.New("").Funcs(funcMap).ParseGlob(path + "/*")),
53 make(map[string]interface{}), 60 make(map[string]interface{}),
54 } 61 }
55 62
diff --git a/modules/tags/tags.go b/modules/tags/tags.go
index aca1b44..527d1d9 100644
--- a/modules/tags/tags.go
+++ b/modules/tags/tags.go
@@ -69,6 +69,20 @@ func (m *Module) viewTagPage(w http.ResponseWriter, r *http.Request, p httproute
69 pageNumber = 1 69 pageNumber = 1
70 } 70 }
71 71
72 // Anzahl an Pages holen
73 var pageNum int
74 err = m.g.DB.QueryRow(`SELECT COUNT(*) FROM grilist.grils_tags WHERE tag_id = $1`, tagID).Scan(&pageNum)
75 if err != nil {
76 log.Println("error getting page count", err)
77 http.Redirect(w, r, "/", 302)
78 return
79 }
80 pageCount := (int)((float64)(pageNum)/12.0 + 0.5)
81
82 if pageNumber > pageCount {
83 pageNumber = pageCount
84 }
85
72 idList := make([]int, 0) 86 idList := make([]int, 0)
73 rows, err := m.g.DB.Query( 87 rows, err := m.g.DB.Query(
74 "SELECT gril_id FROM grilist.grils_tags WHERE tag_id = $1 LIMIT 12 OFFSET $2", 88 "SELECT gril_id FROM grilist.grils_tags WHERE tag_id = $1 LIMIT 12 OFFSET $2",
@@ -108,5 +122,7 @@ func (m *Module) viewTagPage(w http.ResponseWriter, r *http.Request, p httproute
108 data["user"] = user 122 data["user"] = user
109 data["tag"] = tag 123 data["tag"] = tag
110 data["cards"] = cards 124 data["cards"] = cards
125 data["currentPage"] = pageNumber
126 data["pageCount"] = pageCount
111 m.g.Renderer.RenderPage("tag", w, data) 127 m.g.Renderer.RenderPage("tag", w, data)
112} 128}
diff --git a/views/tag.html b/views/tag.html
index 788083f..3e89a7b 100644
--- a/views/tag.html
+++ b/views/tag.html
@@ -3,6 +3,7 @@
3 <head> 3 <head>
4 {{ template "materialize" }} 4 {{ template "materialize" }}
5 <title>grilist</title> 5 <title>grilist</title>
6 <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
6 <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no"> 7 <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
7 </head> 8 </head>
8 <body> 9 <body>
@@ -15,6 +16,11 @@
15 {{ template "card" . }} 16 {{ template "card" . }}
16 {{ end }} 17 {{ end }}
17 </div> 18 </div>
19 <ul class="pagination center-align">
20 <li class="{{ if eq .currentPage 1 }}disabled{{ else }}waves-effect{{ end }}"><a href="/tag/{{ .tag }}/{{ sub .currentPage 1 }}"><i class="material-icons">chevron_left</i></a></li>
21 <li class="active"><a href="#!">{{ .currentPage }}</a></li>
22 <li class="{{ if eq .currentPage .pageCount }}disabled{{ else }}waves-effect{{ end }}"><a href="/tag/{{ .tag }}/{{ add .currentPage 1 }}"><i class="material-icons">chevron_right</i></a></li>
23 </ul>
18 </div> 24 </div>
19 </div> 25 </div>
20 </body> 26 </body>