aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--assets/css/gril.css9
-rw-r--r--main.go2
-rw-r--r--modules/grils/grils.go16
-rw-r--r--modules/tags/tags.go96
-rw-r--r--views/card.html20
-rw-r--r--views/dashboard.html20
-rw-r--r--views/gril.html10
-rw-r--r--views/tag.html22
8 files changed, 174 insertions, 21 deletions
diff --git a/assets/css/gril.css b/assets/css/gril.css
index 63c45ed..b82e2c7 100644
--- a/assets/css/gril.css
+++ b/assets/css/gril.css
@@ -7,6 +7,15 @@
7 margin-bottom: 1rem; 7 margin-bottom: 1rem;
8} 8}
9 9
10.gril-tag {
11 transition: background-color .2s, color .2s;
12}
13
14.gril-tag:hover {
15 background-color: #BA68C8;
16 color: #FFF;
17}
18
10h1 > small { 19h1 > small {
11 padding-left: 8px; 20 padding-left: 8px;
12 font-size: 50%; 21 font-size: 50%;
diff --git a/main.go b/main.go
index 6dec94c..04db8d6 100644
--- a/main.go
+++ b/main.go
@@ -11,6 +11,7 @@ import (
11 "fagott.pw/grilist/grilist" 11 "fagott.pw/grilist/grilist"
12 "fagott.pw/grilist/modules/grils" 12 "fagott.pw/grilist/modules/grils"
13 "fagott.pw/grilist/modules/lists" 13 "fagott.pw/grilist/modules/lists"
14 "fagott.pw/grilist/modules/tags"
14 15
15 "github.com/julienschmidt/httprouter" 16 "github.com/julienschmidt/httprouter"
16 _ "github.com/lib/pq" 17 _ "github.com/lib/pq"
@@ -73,6 +74,7 @@ func main() {
73 // Module laden 74 // Module laden
74 loadModule(grils.New()) 75 loadModule(grils.New())
75 loadModule(lists.New()) 76 loadModule(lists.New())
77 loadModule(tags.New())
76 78
77 log.Fatal(http.ListenAndServe(":8080", nil)) 79 log.Fatal(http.ListenAndServe(":8080", nil))
78} 80}
diff --git a/modules/grils/grils.go b/modules/grils/grils.go
index 7ea5259..46d0fb3 100644
--- a/modules/grils/grils.go
+++ b/modules/grils/grils.go
@@ -156,6 +156,22 @@ func (m *GrilsModule) FromID(id int) (*Gril, error) {
156 return gril, nil 156 return gril, nil
157} 157}
158 158
159func (m *GrilsModule) FromIDs(ids []int) ([]*Gril, error) {
160 idList := "("
161 first := true
162 for _, v := range ids {
163 if first {
164 first = false
165 } else {
166 idList += ","
167 }
168 idList += strconv.Itoa(v)
169 }
170 idList += ")"
171 grils, err := m.getGrils("id IN " + idList)
172 return grils, err
173}
174
159func (m *GrilsModule) viewGril(w http.ResponseWriter, r *http.Request, p httprouter.Params) { 175func (m *GrilsModule) viewGril(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
160 user, _ := m.g.Charakterin.GetUserFromRequest(r) 176 user, _ := m.g.Charakterin.GetUserFromRequest(r)
161 sid := p.ByName("id") 177 sid := p.ByName("id")
diff --git a/modules/tags/tags.go b/modules/tags/tags.go
new file mode 100644
index 0000000..9412e24
--- /dev/null
+++ b/modules/tags/tags.go
@@ -0,0 +1,96 @@
1package tags
2
3import (
4 "log"
5 "net/http"
6
7 "fagott.pw/charakterin"
8 "fagott.pw/grilist/frontend"
9 "fagott.pw/grilist/grilist"
10 "fagott.pw/grilist/modules/grils"
11
12 "github.com/julienschmidt/httprouter"
13)
14
15type Module struct {
16 g *grilist.Grilist
17 grils *grils.GrilsModule
18}
19
20func New() *Module {
21 return &Module{}
22}
23
24func (m *Module) Name() string {
25 return "Tags"
26}
27
28func (m *Module) Init(g *grilist.Grilist) {
29 m.g = g
30 gm, ok := g.Modules["Grils"]
31 if !ok {
32 log.Fatal("tags: grils module not found")
33 }
34 m.grils = gm.(*grils.GrilsModule)
35 m.g.Router.GET("/tag/:tag", m.viewTag)
36}
37
38func (m *Module) Interface() interface{} {
39 return m
40}
41
42func (m *Module) ProvideDashboardData(user *charakterin.User) []grilist.DashboardCategory {
43 return make([]grilist.DashboardCategory, 0)
44}
45
46func (m *Module) viewTag(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
47 user, _ := m.g.Charakterin.GetUserFromRequest(r)
48 tag := p.ByName("tag")
49 var tagID int
50 row := m.g.DB.QueryRow("SELECT id FROM grilist.tags WHERE name = $1;", tag)
51 if err := row.Scan(&tagID); err != nil {
52 log.Println(err)
53 http.Redirect(w, r, "/", 302)
54 return
55 }
56 idList := make([]int, 0)
57 rows, err := m.g.DB.Query(
58 "SELECT gril_id FROM grilist.grils_tags WHERE tag_id = $1",
59 tagID)
60 if err != nil {
61 log.Println(err)
62 http.Redirect(w, r, "/", 302)
63 return
64 }
65 defer rows.Close()
66 for rows.Next() {
67 var grilID int
68 rows.Scan(&grilID)
69 idList = append(idList, grilID)
70 }
71 grils, err := m.grils.FromIDs(idList)
72 if err != nil {
73 log.Println(err)
74 http.Redirect(w, r, "/", 302)
75 return
76 }
77 cards := make([]frontend.Card, 0)
78 for _, v := range grils {
79 cards = append(cards, frontend.Card{
80 Title: v.RomajiName,
81 Description: v.KanjiName,
82 Size: "medium",
83 Actions: []frontend.Action{
84 frontend.Action{
85 Name: "anguckieren",
86 Link: "/gril/" + v.Slug(),
87 },
88 },
89 })
90 }
91 data := m.g.Renderer.DefaultData()
92 data["user"] = user
93 data["tag"] = tag
94 data["cards"] = cards
95 m.g.Renderer.RenderPage("tag", w, data)
96}
diff --git a/views/card.html b/views/card.html
new file mode 100644
index 0000000..be28272
--- /dev/null
+++ b/views/card.html
@@ -0,0 +1,20 @@
1{{ define "card" }}
2{{ $card := . }}
3<div class="col s12 m6 l4">
4 <div class="card white">
5 <div class="card-content black-text">
6 <span class="card-title">{{ $card.Title | html }}</span>
7 <p>{{ $card.Description | html }}</p>
8 </div>
9 <div class="card-action">
10 {{ range $action := $card.Actions }}
11 {{ if $action.Disabled }}
12 <span>{{ $action.Name | html }}</span>
13 {{ else }}
14 <a href="{{ $action.Link }}">{{ $action.Name | html }}</a>
15 {{ end }}
16 {{ end }}
17 </div>
18 </div>
19</div>
20{{ end }}
diff --git a/views/dashboard.html b/views/dashboard.html
index 0551285..56be42b 100644
--- a/views/dashboard.html
+++ b/views/dashboard.html
@@ -13,23 +13,7 @@
13 <h2>{{ $category.Title }}</h2> 13 <h2>{{ $category.Title }}</h2>
14 <div class="row"> 14 <div class="row">
15 {{ range $card := $category.Cards }} 15 {{ range $card := $category.Cards }}
16 <div class="col s12 m6 l4"> 16 {{ template "card" $card }}
17 <div class="card white">
18 <div class="card-content black-text">
19 <span class="card-title">{{ $card.Title | html }}</span>
20 <p>{{ $card.Description | html }}</p>
21 </div>
22 <div class="card-action">
23 {{ range $action := $card.Actions }}
24 {{ if $action.Disabled }}
25 <span>{{ $action.Name | html }}</span>
26 {{ else }}
27 <a href="{{ $action.Link }}">{{ $action.Name | html }}</a>
28 {{ end }}
29 {{ end }}
30 </div>
31 </div>
32 </div>
33 {{ end }} 17 {{ end }}
34 </div> 18 </div>
35 {{ end }} 19 {{ end }}
@@ -37,4 +21,4 @@
37 </div> 21 </div>
38 </body> 22 </body>
39</html> 23</html>
40{{ end }} \ No newline at end of file 24{{ end }}
diff --git a/views/gril.html b/views/gril.html
index 9768778..803cdde 100644
--- a/views/gril.html
+++ b/views/gril.html
@@ -18,9 +18,13 @@
18 </p> 18 </p>
19 {{ end }} 19 {{ end }}
20 {{ range $tag := $gril.Tags }} 20 {{ range $tag := $gril.Tags }}
21 <div class="chip"> 21 <a href="/tag/{{ $tag }}"
22 {{ $tag }} 22 alt="Mit &quot;{{ $tag }}&quot; getaggte Grils einsehen"
23 </div> 23 title="Mit &quot;{{ $tag }}&quot; getaggte Grils einsehen">
24 <div class="chip gril-tag">
25 {{ $tag }}
26 </div>
27 </a>
24 {{ end }} 28 {{ end }}
25 <br /> 29 <br />
26 <br /> 30 <br />
diff --git a/views/tag.html b/views/tag.html
new file mode 100644
index 0000000..788083f
--- /dev/null
+++ b/views/tag.html
@@ -0,0 +1,22 @@
1{{ define "tag" }}
2<html>
3 <head>
4 {{ template "materialize" }}
5 <title>grilist</title>
6 <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
7 </head>
8 <body>
9 {{ template "navbar" . }}
10 <div class="container">
11 <div class="row">
12 <h2>Grils mit dem Tag &quot;{{ .tag }}&quot;:</h2>
13 <div class="row">
14 {{ range .cards }}
15 {{ template "card" . }}
16 {{ end }}
17 </div>
18 </div>
19 </div>
20 </body>
21</html>
22{{ end }}