diff options
-rw-r--r-- | assets_src/css/list.css | 12 | ||||
-rw-r--r-- | assets_src/js/gril.js | 84 | ||||
-rw-r--r-- | assets_src/js/list.js | 70 | ||||
-rw-r--r-- | cache/cache.go | 54 | ||||
-rw-r--r-- | dashboard.go | 5 | ||||
-rw-r--r-- | main.go | 11 | ||||
-rw-r--r-- | modules/grils/grils.go | 152 | ||||
-rw-r--r-- | modules/lists/lists.go | 15 | ||||
-rw-r--r-- | views/includes/card_gril.html | 16 | ||||
-rw-r--r-- | views/includes/navbar.html | 32 |
10 files changed, 225 insertions, 226 deletions
diff --git a/assets_src/css/list.css b/assets_src/css/list.css index 7e6dde9..51b2514 100644 --- a/assets_src/css/list.css +++ b/assets_src/css/list.css | |||
@@ -19,9 +19,9 @@ | |||
19 | } | 19 | } |
20 | 20 | ||
21 | .gril-img { | 21 | .gril-img { |
22 | background-repeat: no-repeat; | 22 | background-repeat: no-repeat; |
23 | background-position: center center; | 23 | background-position: center center; |
24 | background-size: cover; | 24 | background-size: cover; |
25 | width: 64px; | 25 | width: 64px; |
26 | height: 64px; | 26 | height: 64px; |
27 | } \ No newline at end of file | 27 | } |
diff --git a/assets_src/js/gril.js b/assets_src/js/gril.js index 561c221..7d92b5a 100644 --- a/assets_src/js/gril.js +++ b/assets_src/js/gril.js | |||
@@ -3,45 +3,45 @@ import * as dom from './lib/dom'; | |||
3 | import * as ajax from './lib/ajax'; | 3 | import * as ajax from './lib/ajax'; |
4 | 4 | ||
5 | dom.ready(() => { | 5 | dom.ready(() => { |
6 | $('.modal-trigger').leanModal({ | 6 | $('.modal-trigger').leanModal({ |
7 | async ready() { | 7 | async ready() { |
8 | const el = document.getElementById('modal-add-gril-content'); | 8 | const el = document.getElementById('modal-add-gril-content'); |
9 | 9 | ||
10 | el.innerHTML = ` | 10 | el.innerHTML = ` |
11 | <div class="progress"> | 11 | <div class="progress"> |
12 | <div class="indeterminate"></div> | 12 | <div class="indeterminate"></div> |
13 | </div>`; | 13 | </div>`; |
14 | 14 | ||
15 | let data = {}; | 15 | let data = {}; |
16 | try { | 16 | try { |
17 | data = JSON.parse(await ajax.get('/api/lists/user')); | 17 | data = JSON.parse(await ajax.get('/api/lists/user')); |
18 | } catch(e) { | 18 | } catch(e) { |
19 | console.error(e); | 19 | console.error(e); |
20 | } | 20 | } |
21 | 21 | ||
22 | el.innerHTML = ''; | 22 | el.innerHTML = ''; |
23 | 23 | ||
24 | data.forEach(d => { | 24 | data.forEach(d => { |
25 | const element = document.createElement('a'); | 25 | const element = document.createElement('a'); |
26 | element.innerHTML = d.Name; | 26 | element.innerHTML = d.Name; |
27 | element.className = 'collection-item purple-text text-lighten-2'; | 27 | element.className = 'collection-item purple-text text-lighten-2'; |
28 | element.addEventListener('click', async () => { | 28 | element.addEventListener('click', async () => { |
29 | try { | 29 | try { |
30 | await ajax.post( | 30 | await ajax.post( |
31 | `/list/${d.ID}`, | 31 | `/list/${d.ID}`, |
32 | 'id=' + window.location.href.match(/\/gril\/([0-9]{1,})\//)[1], | 32 | 'id=' + window.location.href.match(/\/gril\/([0-9]{1,})\//)[1], |
33 | { headers: { | 33 | { headers: { |
34 | 'Content-type': 'application/x-www-form-urlencoded' | 34 | 'Content-type': 'application/x-www-form-urlencoded' |
35 | } }); | 35 | } }); |
36 | $('#modal_add_gril').closeModal(); | 36 | $('#modal_add_gril').closeModal(); |
37 | } catch(e) { | 37 | } catch(e) { |
38 | console.error(e); | 38 | console.error(e); |
39 | } | 39 | } |
40 | 40 | ||
41 | return true; | 41 | return true; |
42 | }); | 42 | }); |
43 | el.appendChild(element); | 43 | el.appendChild(element); |
44 | }); | 44 | }); |
45 | }, | 45 | }, |
46 | }); | 46 | }); |
47 | }); \ No newline at end of file | 47 | }); |
diff --git a/assets_src/js/list.js b/assets_src/js/list.js index 7a4f69e..7af7444 100644 --- a/assets_src/js/list.js +++ b/assets_src/js/list.js | |||
@@ -20,24 +20,26 @@ async function resultClicked(grilId) { | |||
20 | } | 20 | } |
21 | 21 | ||
22 | async function updateGrilOrder(gril, pos) { | 22 | async function updateGrilOrder(gril, pos) { |
23 | return await ajax.post( | 23 | return await ajax.post( |
24 | `${window.location}/order`, | 24 | `${window.location}/order`, |
25 | `gril=${gril}&pos=${pos}`, | 25 | `gril=${gril}&pos=${pos}`, |
26 | { headers: { | 26 | { |
27 | 'Content-Type': 'application/x-www-form-urlencoded', | 27 | headers: { |
28 | } }); | 28 | 'Content-Type': 'application/x-www-form-urlencoded', |
29 | } | ||
30 | }); | ||
29 | } | 31 | } |
30 | 32 | ||
31 | function getCurrentOrder(gril) { | 33 | function getCurrentOrder(gril) { |
32 | const els = document.querySelectorAll('#gril-list > li') | 34 | const els = document.querySelectorAll('#gril-list > li') |
33 | 35 | ||
34 | for (let i = 0; i < els.length; i++) { | 36 | for (let i = 0; i < els.length; i++) { |
35 | if (els[i].id === gril) { | 37 | if (els[i].id === gril) { |
36 | console.log(i); | 38 | console.log(i); |
37 | return i; | 39 | return i; |
38 | } | 40 | } |
39 | } | 41 | } |
40 | return -1; | 42 | return -1; |
41 | } | 43 | } |
42 | 44 | ||
43 | async function listButtonHandler(e) { | 45 | async function listButtonHandler(e) { |
@@ -47,20 +49,20 @@ async function listButtonHandler(e) { | |||
47 | nItem = dom.next(dom.next(item, liFilter), liFilter); | 49 | nItem = dom.next(dom.next(item, liFilter), liFilter); |
48 | switch (e.target.classList[0]) { | 50 | switch (e.target.classList[0]) { |
49 | case 'gril-sort-up': | 51 | case 'gril-sort-up': |
50 | try { | 52 | try { |
51 | await updateGrilOrder(item.id, getCurrentOrder(item.id) - 1); | 53 | await updateGrilOrder(item.id, getCurrentOrder(item.id) - 1); |
52 | } catch(e) { | 54 | } catch(e) { |
53 | alert(e.message); | 55 | alert(e.message); |
54 | } | 56 | } |
55 | item.parentNode.insertBefore(item, pItem); | 57 | item.parentNode.insertBefore(item, pItem); |
56 | break; | 58 | break; |
57 | case 'gril-sort-down': | 59 | case 'gril-sort-down': |
58 | try { | 60 | try { |
59 | await updateGrilOrder(item.id, getCurrentOrder(item.id) + 1); | 61 | await updateGrilOrder(item.id, getCurrentOrder(item.id) + 1); |
60 | } catch(e) { | 62 | } catch(e) { |
61 | alert(e.message); | 63 | alert(e.message); |
62 | } | 64 | } |
63 | 65 | ||
64 | if (nItem) { | 66 | if (nItem) { |
65 | item.parentNode.insertBefore(item, nItem); | 67 | item.parentNode.insertBefore(item, nItem); |
66 | } else { | 68 | } else { |
@@ -68,16 +70,18 @@ async function listButtonHandler(e) { | |||
68 | } | 70 | } |
69 | break; | 71 | break; |
70 | case 'gril-delete': | 72 | case 'gril-delete': |
71 | let liFilter = x => x.tagName && x.tagName.toLowerCase() === 'li'; | 73 | let liFilter = x => x.tagName && x.tagName.toLowerCase() === 'li'; |
72 | let item = dom.closest(e.target, liFilter); | 74 | let item = dom.closest(e.target, liFilter); |
73 | try { | 75 | try { |
74 | await ajax.del( | 76 | await ajax.del( |
75 | `${window.location}/order`, | 77 | `${window.location}/order`, |
76 | `gril=${item.id}`, | 78 | `gril=${item.id}`, |
77 | { headers: { | 79 | { |
78 | 'Content-Type': 'application/x-www-form-urlencoded', | 80 | headers: { |
79 | } }); | 81 | 'Content-Type': 'application/x-www-form-urlencoded', |
80 | item.parentNode.removeChild(item); | 82 | } |
83 | }); | ||
84 | item.parentNode.removeChild(item); | ||
81 | } catch(e) { | 85 | } catch(e) { |
82 | alert(e.message); | 86 | alert(e.message); |
83 | } | 87 | } |
diff --git a/cache/cache.go b/cache/cache.go index f6e5661..9647836 100644 --- a/cache/cache.go +++ b/cache/cache.go | |||
@@ -1,56 +1,56 @@ | |||
1 | package cache | 1 | package cache |
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | "time" | 4 | "log" |
5 | "log" | 5 | "time" |
6 | ) | 6 | ) |
7 | 7 | ||
8 | type CacheItem struct { | 8 | type CacheItem struct { |
9 | Expires time.Time | 9 | Expires time.Time |
10 | Value interface{} | 10 | Value interface{} |
11 | } | 11 | } |
12 | type Cache struct { | 12 | type Cache struct { |
13 | items map[int]CacheItem | 13 | items map[int]CacheItem |
14 | } | 14 | } |
15 | 15 | ||
16 | func New() *Cache { | 16 | func New() *Cache { |
17 | c := &Cache{ make(map[int]CacheItem) } | 17 | c := &Cache{make(map[int]CacheItem)} |
18 | go c.ticker() | 18 | go c.ticker() |
19 | return c | 19 | return c |
20 | } | 20 | } |
21 | 21 | ||
22 | func (c *Cache) ticker() { | 22 | func (c *Cache) ticker() { |
23 | for _ = range time.NewTicker(time.Second * 1).C { | 23 | for _ = range time.NewTicker(time.Second * 1).C { |
24 | t := time.Now() | 24 | t := time.Now() |
25 | for key, item := range c.items { | 25 | for key, item := range c.items { |
26 | if t.Sub(item.Expires) > 0 { | 26 | if t.Sub(item.Expires) > 0 { |
27 | log.Println("cache delete", key) | 27 | log.Println("cache delete", key) |
28 | delete(c.items, key) | 28 | delete(c.items, key) |
29 | } | 29 | } |
30 | } | 30 | } |
31 | } | 31 | } |
32 | } | 32 | } |
33 | 33 | ||
34 | func (c *Cache) Insert(key int, item interface{}) { | 34 | func (c *Cache) Insert(key int, item interface{}) { |
35 | c.items[key] = CacheItem{ time.Now().Add(time.Minute * 15), item } | 35 | c.items[key] = CacheItem{time.Now().Add(time.Minute * 15), item} |
36 | } | 36 | } |
37 | 37 | ||
38 | func (c *Cache) Remove(key int) { | 38 | func (c *Cache) Remove(key int) { |
39 | delete(c.items, key) | 39 | delete(c.items, key) |
40 | } | 40 | } |
41 | 41 | ||
42 | func (c *Cache) Clear() { | 42 | func (c *Cache) Clear() { |
43 | c.items = make(map[int]CacheItem) | 43 | c.items = make(map[int]CacheItem) |
44 | } | 44 | } |
45 | 45 | ||
46 | func (c *Cache) Get(key int) (interface{}, bool) { | 46 | func (c *Cache) Get(key int) (interface{}, bool) { |
47 | if ci, ok := c.items[key]; ok { | 47 | if ci, ok := c.items[key]; ok { |
48 | return ci.Value, true | 48 | return ci.Value, true |
49 | } | 49 | } |
50 | return nil, false | 50 | return nil, false |
51 | } | 51 | } |
52 | 52 | ||
53 | func (c *Cache) Has(key int) bool { | 53 | func (c *Cache) Has(key int) bool { |
54 | _, ok := c.items[key] | 54 | _, ok := c.items[key] |
55 | return ok | 55 | return ok |
56 | } \ No newline at end of file | 56 | } |
diff --git a/dashboard.go b/dashboard.go index ad3c565..64a0240 100644 --- a/dashboard.go +++ b/dashboard.go | |||
@@ -1,12 +1,13 @@ | |||
1 | package main | 1 | package main |
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | "fagott.pw/grilist/grilist" | ||
5 | "github.com/julienschmidt/httprouter" | ||
6 | "log" | 4 | "log" |
7 | "net/http" | 5 | "net/http" |
8 | "sync" | 6 | "sync" |
9 | "time" | 7 | "time" |
8 | |||
9 | "fagott.pw/grilist/grilist" | ||
10 | "github.com/julienschmidt/httprouter" | ||
10 | ) | 11 | ) |
11 | 12 | ||
12 | func viewDashboard(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { | 13 | func viewDashboard(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { |
@@ -15,18 +15,19 @@ import ( | |||
15 | "fagott.pw/grilist/modules/tags" | 15 | "fagott.pw/grilist/modules/tags" |
16 | "fagott.pw/grilist/modules/user" | 16 | "fagott.pw/grilist/modules/user" |
17 | 17 | ||
18 | "strings" | ||
19 | |||
18 | "github.com/julienschmidt/httprouter" | 20 | "github.com/julienschmidt/httprouter" |
19 | _ "github.com/lib/pq" | 21 | _ "github.com/lib/pq" |
20 | "strings" | ||
21 | ) | 22 | ) |
22 | 23 | ||
23 | var app *grilist.Grilist | 24 | var app *grilist.Grilist |
24 | 25 | ||
25 | func index(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { | 26 | func index(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { |
26 | if strings.Index(r.Referer(), "127.0.0.1") != -1 { | 27 | if strings.Index(r.Referer(), "127.0.0.1") != -1 { |
27 | w.WriteHeader(200) | 28 | w.WriteHeader(200) |
28 | return | 29 | return |
29 | } | 30 | } |
30 | http.Redirect(w, r, "/dashboard", 301) | 31 | http.Redirect(w, r, "/dashboard", 301) |
31 | } | 32 | } |
32 | 33 | ||
diff --git a/modules/grils/grils.go b/modules/grils/grils.go index 116b689..135398d 100644 --- a/modules/grils/grils.go +++ b/modules/grils/grils.go | |||
@@ -6,20 +6,20 @@ import ( | |||
6 | "net/http" | 6 | "net/http" |
7 | "regexp" | 7 | "regexp" |
8 | "strconv" | 8 | "strconv" |
9 | "time" | ||
10 | "strings" | 9 | "strings" |
10 | "time" | ||
11 | 11 | ||
12 | "fagott.pw/charakterin" | 12 | "fagott.pw/charakterin" |
13 | "fagott.pw/grilist/cache" | ||
13 | "fagott.pw/grilist/frontend" | 14 | "fagott.pw/grilist/frontend" |
14 | "fagott.pw/grilist/grilist" | 15 | "fagott.pw/grilist/grilist" |
15 | "fagott.pw/grilist/cache" | ||
16 | 16 | ||
17 | "github.com/julienschmidt/httprouter" | 17 | "github.com/julienschmidt/httprouter" |
18 | ) | 18 | ) |
19 | 19 | ||
20 | type CachedGril struct { | 20 | type CachedGril struct { |
21 | Created time.Time | 21 | Created time.Time |
22 | Gril *Gril | 22 | Gril *Gril |
23 | } | 23 | } |
24 | 24 | ||
25 | var ( | 25 | var ( |
@@ -38,7 +38,7 @@ func findIdx() { | |||
38 | 38 | ||
39 | type GrilsModule struct { | 39 | type GrilsModule struct { |
40 | g *grilist.Grilist | 40 | g *grilist.Grilist |
41 | c *cache.Cache | 41 | c *cache.Cache |
42 | } | 42 | } |
43 | 43 | ||
44 | func (m *GrilsModule) Name() string { | 44 | func (m *GrilsModule) Name() string { |
@@ -50,8 +50,8 @@ func (m *GrilsModule) Init(g *grilist.Grilist) { | |||
50 | m.g = g | 50 | m.g = g |
51 | m.g.Router.GET("/gril/:id", m.viewGril) | 51 | m.g.Router.GET("/gril/:id", m.viewGril) |
52 | m.g.Router.GET("/gril/:id/*rest", m.viewGril) | 52 | m.g.Router.GET("/gril/:id/*rest", m.viewGril) |
53 | 53 | ||
54 | m.c = cache.New() | 54 | m.c = cache.New() |
55 | } | 55 | } |
56 | 56 | ||
57 | func (m *GrilsModule) getGrils(whereClause string, params ...interface{}) ([]*Gril, error) { | 57 | func (m *GrilsModule) getGrils(whereClause string, params ...interface{}) ([]*Gril, error) { |
@@ -105,43 +105,35 @@ func (m *GrilsModule) GetListsOfGril(gril *Gril) error { | |||
105 | 105 | ||
106 | func (m *GrilsModule) ProvideDashboardData(user *charakterin.User) []grilist.DashboardCategory { | 106 | func (m *GrilsModule) ProvideDashboardData(user *charakterin.User) []grilist.DashboardCategory { |
107 | var categories []grilist.DashboardCategory | 107 | var categories []grilist.DashboardCategory |
108 | |||
109 | t1 := time.Now() | 108 | t1 := time.Now() |
110 | rows, err := m.g.DB.Query(`SELECT id FROM grilist.grils ORDER BY updated_at DESC LIMIT 5`) | 109 | |
110 | rows, err := m.g.DB.Query( | ||
111 | `SELECT id, romaji_name, kanji_name FROM grilist.get_recently_updated_grils();`) | ||
111 | if err != nil { | 112 | if err != nil { |
112 | log.Println(err) | 113 | log.Println(err) |
113 | return categories | 114 | return categories |
114 | } | 115 | } |
115 | defer rows.Close() | 116 | defer rows.Close() |
116 | log.Printf("get_newest_grils: %dms", time.Since(t1).Nanoseconds()/1000000) | ||
117 | 117 | ||
118 | cat := grilist.DashboardCategory{ | 118 | cat := grilist.DashboardCategory{ |
119 | Title: "Neue Grils", | 119 | Title: "Neue Grils", |
120 | } | 120 | } |
121 | 121 | ||
122 | for rows.Next() { | 122 | for rows.Next() { |
123 | var id int | 123 | var g Gril |
124 | if err := rows.Scan(&id); err != nil { | 124 | if err := rows.Scan(&g.ID, &g.RomajiName, &g.KanjiName); err != nil { |
125 | log.Println(err) | ||
126 | continue | ||
127 | } | ||
128 | |||
129 | t2 := time.Now() | ||
130 | gril, err := m.FromID(id) | ||
131 | if err != nil { | ||
132 | log.Println(err) | 125 | log.Println(err) |
133 | continue | 126 | continue |
134 | } | 127 | } |
135 | log.Printf("get_gril_from_id_in_newest_grils: %dms", time.Since(t2).Nanoseconds()/1000000) | ||
136 | 128 | ||
137 | cat.Cards = append(cat.Cards, frontend.Card{ | 129 | cat.Cards = append(cat.Cards, frontend.Card{ |
138 | Title: gril.RomajiName, | 130 | Title: g.RomajiName, |
139 | Description: gril.KanjiName, | 131 | Description: g.KanjiName, |
140 | Size: "medium", | 132 | Size: "medium", |
141 | Actions: []frontend.Action{ | 133 | Actions: []frontend.Action{ |
142 | frontend.Action{ | 134 | frontend.Action{ |
143 | Name: "anguckieren", | 135 | Name: "anguckieren", |
144 | Link: "/gril/" + gril.Slug(), | 136 | Link: "/gril/" + g.Slug(), |
145 | }, | 137 | }, |
146 | }, | 138 | }, |
147 | }) | 139 | }) |
@@ -152,77 +144,77 @@ func (m *GrilsModule) ProvideDashboardData(user *charakterin.User) []grilist.Das | |||
152 | } | 144 | } |
153 | 145 | ||
154 | func (m *GrilsModule) FromID(id int) (*Gril, error) { | 146 | func (m *GrilsModule) FromID(id int) (*Gril, error) { |
155 | if g, ok := m.c.Get(id); ok { | 147 | if g, ok := m.c.Get(id); ok { |
156 | return g.(*Gril), nil | 148 | return g.(*Gril), nil |
157 | } | 149 | } |
158 | 150 | ||
159 | gril := &Gril{ | 151 | gril := &Gril{ |
160 | ID: id, | 152 | ID: id, |
161 | } | 153 | } |
162 | t1 := time.Now() | 154 | t1 := time.Now() |
163 | err := m.g.DB.QueryRow(`SELECT updated_at, age, birthday FROM grilist.grils WHERE id = $1`, id).Scan(&gril.UpdatedAt, &gril.Age, &gril.Birthday) | 155 | err := m.g.DB.QueryRow(`SELECT updated_at, age, birthday FROM grilist.grils WHERE id = $1`, id).Scan(&gril.UpdatedAt, &gril.Age, &gril.Birthday) |
164 | log.Printf("get_gril_from_id_raw: %dms", time.Since(t1).Nanoseconds()/1000000) | 156 | log.Printf("get_gril_from_id_raw: %dms", time.Since(t1).Nanoseconds()/1000000) |
165 | 157 | ||
166 | if err != nil { | 158 | if err != nil { |
167 | return nil, err | 159 | return nil, err |
168 | } | 160 | } |
169 | 161 | ||
170 | // Namen rausholen | 162 | // Namen rausholen |
171 | rows, err := m.g.DB.Query(`SELECT name, name_type FROM grilist.gril_names WHERE gril_id = $1`, id) | 163 | rows, err := m.g.DB.Query(`SELECT name, name_type FROM grilist.gril_names WHERE gril_id = $1`, id) |
172 | if err != nil { | 164 | if err != nil { |
173 | return nil, err | 165 | return nil, err |
174 | } | 166 | } |
175 | log.Printf("get_gril_from_id_names: %dms", time.Since(t1).Nanoseconds()/1000000) | 167 | log.Printf("get_gril_from_id_names: %dms", time.Since(t1).Nanoseconds()/1000000) |
176 | defer rows.Close() | 168 | defer rows.Close() |
177 | 169 | ||
178 | for rows.Next() { | 170 | for rows.Next() { |
179 | var name string | 171 | var name string |
180 | var name_type int | 172 | var name_type int |
181 | if err := rows.Scan(&name, &name_type); err != nil { | 173 | if err := rows.Scan(&name, &name_type); err != nil { |
182 | return nil, err | 174 | return nil, err |
183 | } | 175 | } |
184 | 176 | ||
185 | switch name_type { | 177 | switch name_type { |
186 | case 0: | 178 | case 0: |
187 | gril.KanjiName = name | 179 | gril.KanjiName = name |
188 | break | 180 | break |
189 | case 1: | 181 | case 1: |
190 | gril.RomajiName = name | 182 | gril.RomajiName = name |
191 | default: | 183 | default: |
192 | gril.OtherNames = append(gril.OtherNames, name) | 184 | gril.OtherNames = append(gril.OtherNames, name) |
193 | } | 185 | } |
194 | } | ||
195 | /*rows, err := m.g.DB.Query(`SELECT name FROM grilist.gril_names WHERE gril_id = $1 AND name_type > 1`, id) | ||
196 | if err != nil { | ||
197 | return nil, err | ||
198 | } | ||
199 | defer rows.Close() | ||
200 | |||
201 | for rows.Next() { | ||
202 | var name string | ||
203 | if err := rows.Scan(&name); err != nil { | ||
204 | return nil, err | ||
205 | } | ||
206 | gril.OtherNames = append(gril.OtherNames, name) | ||
207 | } | ||
208 | rows.Close() | ||
209 | |||
210 | // Tags holen | ||
211 | rows, err := m.g.DB.Query(`SELECT name FROM grilist.tags WHERE id IN (SELECT tag_id FROM grilist.grils_tags WHERE gril_id = $1)`, id) | ||
212 | if err != nil { | ||
213 | return nil, err | ||
214 | } | 186 | } |
215 | defer rows.Close() | 187 | /*rows, err := m.g.DB.Query(`SELECT name FROM grilist.gril_names WHERE gril_id = $1 AND name_type > 1`, id) |
216 | 188 | if err != nil { | |
217 | for rows.Next() { | 189 | return nil, err |
218 | var name string | 190 | } |
219 | if err := rows.Scan(&name); err != nil { | 191 | defer rows.Close() |
220 | return nil, err | 192 | |
221 | } | 193 | for rows.Next() { |
222 | gril.Tags = append(gril.Tags, name) | 194 | var name string |
223 | }*/ | 195 | if err := rows.Scan(&name); err != nil { |
224 | 196 | return nil, err | |
225 | m.c.Insert(id, gril) | 197 | } |
198 | gril.OtherNames = append(gril.OtherNames, name) | ||
199 | } | ||
200 | rows.Close() | ||
201 | |||
202 | // Tags holen | ||
203 | rows, err := m.g.DB.Query(`SELECT name FROM grilist.tags WHERE id IN (SELECT tag_id FROM grilist.grils_tags WHERE gril_id = $1)`, id) | ||
204 | if err != nil { | ||
205 | return nil, err | ||
206 | } | ||
207 | defer rows.Close() | ||
208 | |||
209 | for rows.Next() { | ||
210 | var name string | ||
211 | if err := rows.Scan(&name); err != nil { | ||
212 | return nil, err | ||
213 | } | ||
214 | gril.Tags = append(gril.Tags, name) | ||
215 | }*/ | ||
216 | |||
217 | m.c.Insert(id, gril) | ||
226 | log.Printf("get_gril_from_id: %dms", time.Since(t1).Nanoseconds()/1000000) | 218 | log.Printf("get_gril_from_id: %dms", time.Since(t1).Nanoseconds()/1000000) |
227 | return gril, nil | 219 | return gril, nil |
228 | } | 220 | } |
diff --git a/modules/lists/lists.go b/modules/lists/lists.go index 90de18c..67856fe 100644 --- a/modules/lists/lists.go +++ b/modules/lists/lists.go | |||
@@ -4,20 +4,21 @@ import ( | |||
4 | "database/sql" | 4 | "database/sql" |
5 | "encoding/json" | 5 | "encoding/json" |
6 | "errors" | 6 | "errors" |
7 | "fagott.pw/charakterin" | ||
8 | "fagott.pw/grilist/cache" | ||
9 | "fagott.pw/grilist/frontend" | ||
10 | "fagott.pw/grilist/grilist" | ||
11 | "fagott.pw/grilist/modules/grils" | ||
12 | "fmt" | 7 | "fmt" |
13 | "github.com/julienschmidt/httprouter" | ||
14 | "github.com/lib/pq" | ||
15 | "io/ioutil" | 8 | "io/ioutil" |
16 | "log" | 9 | "log" |
17 | "net/http" | 10 | "net/http" |
18 | "net/url" | 11 | "net/url" |
19 | "sort" | 12 | "sort" |
20 | "strconv" | 13 | "strconv" |
14 | |||
15 | "fagott.pw/charakterin" | ||
16 | "fagott.pw/grilist/cache" | ||
17 | "fagott.pw/grilist/frontend" | ||
18 | "fagott.pw/grilist/grilist" | ||
19 | "fagott.pw/grilist/modules/grils" | ||
20 | "github.com/julienschmidt/httprouter" | ||
21 | "github.com/lib/pq" | ||
21 | ) | 22 | ) |
22 | 23 | ||
23 | // Module und so. | 24 | // Module und so. |
diff --git a/views/includes/card_gril.html b/views/includes/card_gril.html index 1cd45fa..4166c9a 100644 --- a/views/includes/card_gril.html +++ b/views/includes/card_gril.html | |||
@@ -1,11 +1,11 @@ | |||
1 | {{ define "card_gril" }} | 1 | {{ define "card_gril" }} |
2 | <div class="card white"> | 2 | <div class="card white"> |
3 | <div class="center-align" style="padding-top: 8px"> | 3 | <div class="center-align" style="padding-top: 8px"> |
4 | <img class="circle responsive-img" src="/{{ .ImagePath false }}" /> | 4 | <img class="circle responsive-img" src="/{{ .ImagePath false }}" /> |
5 | </div> | 5 | </div> |
6 | <div class="card-content black-text"> | 6 | <div class="card-content black-text"> |
7 | <span class="card-title">{{ .RomajiName }} <small class="grey-text">{{ .KanjiName }}</small></span> | 7 | <span class="card-title">{{ .RomajiName }} <small class="grey-text">{{ .KanjiName }}</small></span> |
8 | </div> | 8 | </div> |
9 | <div class="card-action"><a href="/gril/{{ .Slug }}">anguckieren</a></div> | 9 | <div class="card-action"><a href="/gril/{{ .Slug }}">anguckieren</a></div> |
10 | </div> | 10 | </div> |
11 | {{ end }} \ No newline at end of file | 11 | {{ end }} |
diff --git a/views/includes/navbar.html b/views/includes/navbar.html index a0db664..23514f8 100644 --- a/views/includes/navbar.html +++ b/views/includes/navbar.html | |||
@@ -1,17 +1,17 @@ | |||
1 | {{ define "navbar" }} | 1 | {{ define "navbar" }} |
2 | <nav> | 2 | <nav> |
3 | <div class="nav-wrapper purple lighten-2"> | 3 | <div class="nav-wrapper purple lighten-2"> |
4 | <a href="/" class="brand-logo center">grilist</a> | 4 | <a href="/" class="brand-logo center">grilist</a> |
5 | <ul id="nav-mobile" class="right hide-on-med-and-down"> | 5 | <ul id="nav-mobile" class="right hide-on-med-and-down"> |
6 | {{ if .user }} | 6 | {{ if .user }} |
7 | <li><a href="/new/list">Liste erstellen</a></li> | 7 | <li><a href="/new/list">Liste erstellen</a></li> |
8 | <li><a href="/user/{{ .user.ID }}/{{ .user.GetName }}">{{ .user.GetName }}</a></li> | 8 | <li><a href="/user/{{ .user.ID }}/{{ .user.GetName }}">{{ .user.GetName }}</a></li> |
9 | <li><a href="/logout">Ausloggen</a></li> | 9 | <li><a href="/logout">Ausloggen</a></li> |
10 | {{ else }} | 10 | {{ else }} |
11 | <li><a href="/login">Einloggen</a></li> | 11 | <li><a href="/login">Einloggen</a></li> |
12 | <li><a href="/register">Registrieren</a></li> | 12 | <li><a href="/register">Registrieren</a></li> |
13 | {{ end }} | 13 | {{ end }} |
14 | </ul> | 14 | </ul> |
15 | </div> | 15 | </div> |
16 | </nav> | 16 | </nav> |
17 | {{ end }} \ No newline at end of file | 17 | {{ end }} |