diff options
author | Jan C <jan@ruken.pw> | 2016-03-11 13:16:08 (UTC) |
---|---|---|
committer | Jan C <jan@ruken.pw> | 2016-03-11 13:16:08 (UTC) |
commit | e46a94b715fdbf55ea71dc2e2664883e53955605 (patch) | |
tree | c1ccf1d97e68b4ac7d089cf8a56ebfa1e6c0d364 | |
parent | 848558c3ddcceddc3df6f0ff446a2691c895228d (diff) |
ähnliche grils anzeigen, wenn verfügbar (gril view)
-rw-r--r-- | modules/grils/grils.go | 30 | ||||
-rw-r--r-- | views/includes/card_gril.html | 11 | ||||
-rw-r--r-- | views/pages/gril.html | 11 |
3 files changed, 52 insertions, 0 deletions
diff --git a/modules/grils/grils.go b/modules/grils/grils.go index 5d548e6..e6aaa11 100644 --- a/modules/grils/grils.go +++ b/modules/grils/grils.go | |||
@@ -195,6 +195,36 @@ func (m *GrilsModule) viewGril(w http.ResponseWriter, r *http.Request, p httprou | |||
195 | data := m.g.Renderer.DefaultData() | 195 | data := m.g.Renderer.DefaultData() |
196 | data["user"] = user | 196 | data["user"] = user |
197 | data["gril"] = gril | 197 | data["gril"] = gril |
198 | |||
199 | // ähnliche grils holen | ||
200 | rows, err := m.g.DB.Query(`SELECT gril_id FROM ( | ||
201 | SELECT DISTINCT gril_id FROM gril_appearance WHERE appearance_id IN (SELECT appearance_id FROM gril_appearance WHERE gril_id = $1) | ||
202 | ) as t | ||
203 | ORDER BY RANDOM() | ||
204 | LIMIT 4;`, id) | ||
205 | if err != nil { | ||
206 | log.Println("could not get similar grils:", err) | ||
207 | http.Error(w, "500", http.StatusInternalServerError) | ||
208 | return | ||
209 | } | ||
210 | |||
211 | defer rows.Close() | ||
212 | var similar []*Gril | ||
213 | for rows.Next() { | ||
214 | var id int | ||
215 | if err := rows.Scan(&id); err != nil { | ||
216 | log.Println("error scanning for similar gril:", err) | ||
217 | continue | ||
218 | } | ||
219 | |||
220 | g, err := m.FromID(id) | ||
221 | if err != nil { | ||
222 | log.Println("invalid similar gril:", err) | ||
223 | continue | ||
224 | } | ||
225 | similar = append(similar, g) | ||
226 | } | ||
227 | data["SimilarGrils"] = similar | ||
198 | 228 | ||
199 | m.g.Renderer.RenderPage("gril", w, data) | 229 | m.g.Renderer.RenderPage("gril", w, data) |
200 | } | 230 | } |
diff --git a/views/includes/card_gril.html b/views/includes/card_gril.html new file mode 100644 index 0000000..337c9a9 --- /dev/null +++ b/views/includes/card_gril.html | |||
@@ -0,0 +1,11 @@ | |||
1 | {{ define "card_gril" }} | ||
2 | <div class="card white"> | ||
3 | <div class="center-align"> | ||
4 | <div class="circle gril-img" style="background-image: url(/{{ .ImagePath false }})"> </div> | ||
5 | </div> | ||
6 | <div class="card-content black-text"> | ||
7 | <span class="card-title">{{ .RomajiName }} <small>{{ .KanjiName }}</small></span> | ||
8 | </div> | ||
9 | <div class="card-action"><a href="/gril/{{ .Slug }}">anguckieren</a></div> | ||
10 | </div> | ||
11 | {{ end }} \ No newline at end of file | ||
diff --git a/views/pages/gril.html b/views/pages/gril.html index cd92208..eb66537 100644 --- a/views/pages/gril.html +++ b/views/pages/gril.html | |||
@@ -75,6 +75,17 @@ | |||
75 | </div> | 75 | </div> |
76 | </div> | 76 | </div> |
77 | </div> | 77 | </div> |
78 | |||
79 | {{ if .SimilarGrils }} | ||
80 | <h1>Ähnliche Grils</h1> | ||
81 | <div class="row"> | ||
82 | {{ range .SimilarGrils }} | ||
83 | <div class="col s3"> | ||
84 | {{ template "card_gril" . }} | ||
85 | </div> | ||
86 | {{ end }} | ||
87 | </div> | ||
88 | {{ end }} | ||
78 | </div> | 89 | </div> |
79 | 90 | ||
80 | 91 | ||