aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrtz12 <koenig@fagott.pw>2016-10-11 19:02:59 (UTC)
committerrtz12 <koenig@fagott.pw>2016-10-11 19:02:59 (UTC)
commitce5973c4024f22a8f8c63818109a2ca4f3be7bc4 (patch)
treee7b6b5d5c6e73451b489e97f90206a96bf9ed2df
parentfbd746aef8c78067593f901afb0f255574392499 (diff)
parentb5051d2358e12f877e5c52053dcf1a16959e4ded (diff)
Merge branch 'master' of projekte.fagott.pw:grilist
-rw-r--r--.gitignore1
-rw-r--r--Makefile24
-rw-r--r--grilist/health.go16
-rw-r--r--main.go3
-rw-r--r--models/gril.go (renamed from modules/grils/gril.go)14
-rw-r--r--modules/grils/grils.go28
-rw-r--r--modules/lists/lists.go3
-rw-r--r--modules/search/search.go5
-rw-r--r--modules/series/module.go44
-rw-r--r--views/pages/gril.html2
10 files changed, 106 insertions, 34 deletions
diff --git a/.gitignore b/.gitignore
index 5d77737..1216dc4 100644
--- a/.gitignore
+++ b/.gitignore
@@ -13,3 +13,4 @@ assets/css/*
13 13
14#Binaries 14#Binaries
15/importer 15/importer
16bin/grilist
diff --git a/Makefile b/Makefile
index 452e1d5..754b1e4 100644
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,7 @@
1include config.mk 1include config.mk
2 2
3BINARY_PATH = ./bin
4TARGET = $(BINARY_PATH)/$(NAME)
3IMPORTER_FILES = $(shell find tools/importer/ -type f -name '*.go') 5IMPORTER_FILES = $(shell find tools/importer/ -type f -name '*.go')
4 6
5CSS_FILES = $(patsubst assets_src/%, assets/%, $(shell find assets_src/css/ -type f -name '*.css')) 7CSS_FILES = $(patsubst assets_src/%, assets/%, $(shell find assets_src/css/ -type f -name '*.css'))
@@ -12,7 +14,7 @@ LESSC := ./node_modules/less/bin/lessc
12 14
13-include $(DEPFILES) 15-include $(DEPFILES)
14 16
15all: $(CSS_FILES) $(LESS_FILES) $(JS_FILES) eventlogging/events.go 17all: assets $(TARGET) $(IMPORTER)
16 18
17print_info: 19print_info:
18 @echo $(CSS_FILES) 20 @echo $(CSS_FILES)
@@ -20,6 +22,11 @@ print_info:
20 @echo $(JS_FILES) 22 @echo $(JS_FILES)
21 @echo $(DEPFILES) 23 @echo $(DEPFILES)
22 24
25$(NAME): $(TARGET)
26
27$(TARGET): eventlogging/events.go
28 go build -o $@
29
23.npm_update: package.json 30.npm_update: package.json
24 touch $@ 31 touch $@
25 npm install 32 npm install
@@ -27,7 +34,9 @@ print_info:
27package.json: package.json.tpl config.mk 34package.json: package.json.tpl config.mk
28 export NAME=$(NAME) &&\ 35 export NAME=$(NAME) &&\
29 export VERSION=$(VERSION) &&\ 36 export VERSION=$(VERSION) &&\
30 ./bin/template.awk < $< | sh > $@ 37 $(BINARY_PATH)/template.awk < $< | sh > $@
38
39assets: $(CSS_FILES) $(LESS_FILES) $(JS_FILES)
31 40
32assets/css/%.css: assets_src/css/%.css 41assets/css/%.css: assets_src/css/%.css
33 @mkdir -p $(@D) 42 @mkdir -p $(@D)
@@ -39,16 +48,17 @@ assets/css/%.css: assets_src/css/%.less .npm_update
39 @$(LESSC) $< > $@ 48 @$(LESSC) $< > $@
40 49
41assets_src/js/%.d: assets_src/js/%.js 50assets_src/js/%.d: assets_src/js/%.js
42 @./bin/generate-dependencies $(patsubst assets_src/%, assets/%, $<) $< $@ 51 @$(BINARY_PATH)/generate-dependencies $(patsubst assets_src/%, assets/%, $<) $< $@
43 52
44assets/js/%.js: assets_src/js/%.js assets_src/js/%.d .babelrc .npm_update 53assets/js/%.js: assets_src/js/%.js assets_src/js/%.d .babelrc .npm_update
45 @echo browserify $< -o $@ 54 @echo browserify $< -o $@
46 @$(BROWSERIFY) --debug $< -o $@ -t babelify 55 @$(BROWSERIFY) --debug $< -o $@ -t babelify
47 56
48eventlogging/events.go: eventlogging/events.txt 57eventlogging/events.go: eventlogging/events.txt
49 @./bin/generate-events < $< > $@ 58 ./bin/generate-events < $< > $@
50 59
51clean: 60clean:
61 -rm -- $(BINARY_PATH)/$(NAME)
52 -rm -- $(CSS_FILES) 62 -rm -- $(CSS_FILES)
53 -rm -- $(LESS_FILES) 63 -rm -- $(LESS_FILES)
54 -rm -- $(JS_FILES) 64 -rm -- $(JS_FILES)
@@ -63,11 +73,11 @@ superclean: clean
63ultraclean: superclean 73ultraclean: superclean
64 -rm -r -- node_modules 74 -rm -r -- node_modules
65 75
66run: all 76run: assets $(TARGET)
67 go run *.go 77 $(TARGET)
68 78
69importer: $(IMPORTER_FILES) 79importer: $(IMPORTER_FILES)
70 go build -o importer tools/importer/*.go 80 go build -o importer tools/importer/*.go
71 81
72.PHONY: all print_info clean superclean ultraclean run 82.PHONY: all assets $(NAME) $(TARGET) print_info clean superclean ultraclean run
73 83
diff --git a/grilist/health.go b/grilist/health.go
new file mode 100644
index 0000000..15697ea
--- /dev/null
+++ b/grilist/health.go
@@ -0,0 +1,16 @@
1package grilist
2
3import (
4 "fmt"
5 "net/http"
6 "runtime"
7
8 "github.com/julienschmidt/httprouter"
9)
10
11func (g *Grilist) HealthCheck(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
12 var mem runtime.MemStats
13 runtime.ReadMemStats(&mem)
14
15 w.Write([]byte(fmt.Sprintf("mem in use: %d\nopen g.DB connections: %d", mem.Alloc, g.DB.Stats().OpenConnections)))
16}
diff --git a/main.go b/main.go
index e1c06e6..75eee68 100644
--- a/main.go
+++ b/main.go
@@ -14,6 +14,7 @@ import (
14 "fagott.pw/grilist/modules/grils" 14 "fagott.pw/grilist/modules/grils"
15 "fagott.pw/grilist/modules/lists" 15 "fagott.pw/grilist/modules/lists"
16 "fagott.pw/grilist/modules/search" 16 "fagott.pw/grilist/modules/search"
17 "fagott.pw/grilist/modules/series"
17 "fagott.pw/grilist/modules/tags" 18 "fagott.pw/grilist/modules/tags"
18 "fagott.pw/grilist/modules/user" 19 "fagott.pw/grilist/modules/user"
19 "fagott.pw/nsa" 20 "fagott.pw/nsa"
@@ -76,6 +77,7 @@ func main() {
76 } 77 }
77 78
78 router.GET("/", index) 79 router.GET("/", index)
80 router.GET("/health", app.HealthCheck)
79 router.HandlerFunc("GET", "/login", login.DisplayLogin) 81 router.HandlerFunc("GET", "/login", login.DisplayLogin)
80 router.HandlerFunc("POST", "/login", login.Login) 82 router.HandlerFunc("POST", "/login", login.Login)
81 router.HandlerFunc("GET", "/settings", login.DisplayUserSettings) 83 router.HandlerFunc("GET", "/settings", login.DisplayUserSettings)
@@ -94,6 +96,7 @@ func main() {
94 loadModule(tags.New()) 96 loadModule(tags.New())
95 loadModule(search.New()) 97 loadModule(search.New())
96 loadModule(user.New()) 98 loadModule(user.New())
99 loadModule(series.New())
97 router.GET("/dashboard", viewDashboard) 100 router.GET("/dashboard", viewDashboard)
98 101
99 log.Fatal(http.ListenAndServe(":8080", nil)) 102 log.Fatal(http.ListenAndServe(":8080", nil))
diff --git a/modules/grils/gril.go b/models/gril.go
index 7b54ab1..f0b8f8f 100644
--- a/modules/grils/gril.go
+++ b/models/gril.go
@@ -1,4 +1,4 @@
1package grils 1package models
2 2
3import ( 3import (
4 "database/sql" 4 "database/sql"
@@ -41,6 +41,7 @@ type Gril struct {
41 Series []series.Series 41 Series []series.Series
42} 42}
43 43
44// Der kram hier sollte eigentlich auch eher wo anders hin als ins Model, oder?!
44func (g *Gril) Slug() string { 45func (g *Gril) Slug() string {
45 if g.RomajiName == "" { 46 if g.RomajiName == "" {
46 return strconv.Itoa(g.ID) 47 return strconv.Itoa(g.ID)
@@ -51,13 +52,10 @@ func (g *Gril) Slug() string {
51 strings.Replace(g.RomajiName, " ", "", -1)) 52 strings.Replace(g.RomajiName, " ", "", -1))
52} 53}
53 54
54func ImagePath(id int, useThumbnail bool) string { 55// Das hier sollte auch irgendwo anders hin.
56func (g *Gril) ImagePath(useThumbnail bool) string {
55 if useThumbnail { 57 if useThumbnail {
56 return fmt.Sprintf("http://img.grilist.moe/gril/thumb/%d.jpg", id) 58 return fmt.Sprintf("http://img.grilist.moe/gril/thumb/%d.jpg", g.ID)
57 } 59 }
58 return fmt.Sprintf("http://img.grilist.moe/gril/full/%d.jpg", id) 60 return fmt.Sprintf("http://img.grilist.moe/gril/full/%d.jpg", g.ID)
59}
60
61func (g *Gril) ImagePath(prioritizeThumbnail bool) string {
62 return ImagePath(g.ID, prioritizeThumbnail)
63} 61}
diff --git a/modules/grils/grils.go b/modules/grils/grils.go
index debb77b..4a9990f 100644
--- a/modules/grils/grils.go
+++ b/modules/grils/grils.go
@@ -14,15 +14,11 @@ import (
14 "fagott.pw/grilist/eventlogging" 14 "fagott.pw/grilist/eventlogging"
15 "fagott.pw/grilist/frontend" 15 "fagott.pw/grilist/frontend"
16 "fagott.pw/grilist/grilist" 16 "fagott.pw/grilist/grilist"
17 "fagott.pw/grilist/models"
17 18
18 "github.com/julienschmidt/httprouter" 19 "github.com/julienschmidt/httprouter"
19) 20)
20 21
21type CachedGril struct {
22 Created time.Time
23 Gril *Gril
24}
25
26var ( 22var (
27 pgArrayReg = regexp.MustCompile(`(((?P<value>(([^",\\{}\s(NULL)])+|"([^"\\]|\\"|\\\\)*")))(,)?)`) 23 pgArrayReg = regexp.MustCompile(`(((?P<value>(([^",\\{}\s(NULL)])+|"([^"\\]|\\"|\\\\)*")))(,)?)`)
28 pgValueIdx int 24 pgValueIdx int
@@ -55,8 +51,8 @@ func (m *GrilsModule) Init(g *grilist.Grilist) {
55 m.c = cache.New() 51 m.c = cache.New()
56} 52}
57 53
58func (m *GrilsModule) getGrils(whereClause string, params ...interface{}) ([]*Gril, error) { 54func (m *GrilsModule) getGrils(whereClause string, params ...interface{}) ([]*models.Gril, error) {
59 var grils []*Gril 55 var grils []*models.Gril
60 56
61 rows, err := m.g.DB.Query(fmt.Sprintf(`SELECT id, kanji_name, romaji_name, other_names, updated_at, age, birthday, tags FROM grilist.grils_flattened WHERE %s`, whereClause), params...) 57 rows, err := m.g.DB.Query(fmt.Sprintf(`SELECT id, kanji_name, romaji_name, other_names, updated_at, age, birthday, tags FROM grilist.grils_flattened WHERE %s`, whereClause), params...)
62 if err != nil { 58 if err != nil {
@@ -65,7 +61,7 @@ func (m *GrilsModule) getGrils(whereClause string, params ...interface{}) ([]*Gr
65 61
66 defer rows.Close() 62 defer rows.Close()
67 for rows.Next() { 63 for rows.Next() {
68 gril := &Gril{} 64 gril := &models.Gril{}
69 var tags []byte 65 var tags []byte
70 var otherNames []byte 66 var otherNames []byte
71 err = rows.Scan(&gril.ID, &gril.KanjiName, &gril.RomajiName, &otherNames, &gril.UpdatedAt, &gril.Age, &gril.Birthday, &tags) 67 err = rows.Scan(&gril.ID, &gril.KanjiName, &gril.RomajiName, &otherNames, &gril.UpdatedAt, &gril.Age, &gril.Birthday, &tags)
@@ -84,7 +80,7 @@ func (m *GrilsModule) getGrils(whereClause string, params ...interface{}) ([]*Gr
84 return grils, nil 80 return grils, nil
85} 81}
86 82
87func (m *GrilsModule) GetListsOfGril(gril *Gril) error { 83func (m *GrilsModule) GetListsOfGril(gril *models.Gril) error {
88 rows, err := m.g.DB.Query(`SELECT list_id FROM grilist.lists_grils WHERE gril_id = $1`, gril.ID) 84 rows, err := m.g.DB.Query(`SELECT list_id FROM grilist.lists_grils WHERE gril_id = $1`, gril.ID)
89 if err != nil { 85 if err != nil {
90 return err 86 return err
@@ -121,7 +117,7 @@ func (m *GrilsModule) ProvideDashboardData(user *charakterin.User) []grilist.Das
121 } 117 }
122 118
123 for rows.Next() { 119 for rows.Next() {
124 var g Gril 120 var g models.Gril
125 if err := rows.Scan(&g.ID, &g.RomajiName, &g.KanjiName); err != nil { 121 if err := rows.Scan(&g.ID, &g.RomajiName, &g.KanjiName); err != nil {
126 log.Println(err) 122 log.Println(err)
127 continue 123 continue
@@ -144,12 +140,12 @@ func (m *GrilsModule) ProvideDashboardData(user *charakterin.User) []grilist.Das
144 return categories 140 return categories
145} 141}
146 142
147func (m *GrilsModule) FromID(id int) (*Gril, error) { 143func (m *GrilsModule) FromID(id int) (*models.Gril, error) {
148 if g, ok := m.c.Get(id); ok { 144 if g, ok := m.c.Get(id); ok {
149 return g.(*Gril), nil 145 return g.(*models.Gril), nil
150 } 146 }
151 147
152 gril := &Gril{ 148 gril := &models.Gril{
153 ID: id, 149 ID: id,
154 } 150 }
155 t1 := time.Now() 151 t1 := time.Now()
@@ -220,9 +216,9 @@ func (m *GrilsModule) FromID(id int) (*Gril, error) {
220 return gril, nil 216 return gril, nil
221} 217}
222 218
223func (m *GrilsModule) FromIDs(ids []int) ([]*Gril, error) { 219func (m *GrilsModule) FromIDs(ids []int) ([]*models.Gril, error) {
224 if len(ids) == 0 { 220 if len(ids) == 0 {
225 return make([]*Gril, 0), nil 221 return make([]*models.Gril, 0), nil
226 } 222 }
227 223
228 idList := "(" 224 idList := "("
@@ -276,7 +272,7 @@ func (m *GrilsModule) viewGril(w http.ResponseWriter, r *http.Request, p httprou
276 } 272 }
277 273
278 defer rows.Close() 274 defer rows.Close()
279 var similar []*Gril 275 var similar []*models.Gril
280 for rows.Next() { 276 for rows.Next() {
281 var id int 277 var id int
282 if err := rows.Scan(&id); err != nil { 278 if err := rows.Scan(&id); err != nil {
diff --git a/modules/lists/lists.go b/modules/lists/lists.go
index 9c9eaf4..65e969f 100644
--- a/modules/lists/lists.go
+++ b/modules/lists/lists.go
@@ -17,6 +17,7 @@ import (
17 "fagott.pw/grilist/eventlogging" 17 "fagott.pw/grilist/eventlogging"
18 "fagott.pw/grilist/frontend" 18 "fagott.pw/grilist/frontend"
19 "fagott.pw/grilist/grilist" 19 "fagott.pw/grilist/grilist"
20 "fagott.pw/grilist/models"
20 "fagott.pw/grilist/modules/grils" 21 "fagott.pw/grilist/modules/grils"
21 "github.com/julienschmidt/httprouter" 22 "github.com/julienschmidt/httprouter"
22 "github.com/lib/pq" 23 "github.com/lib/pq"
@@ -42,7 +43,7 @@ type List struct {
42 43
43// ListGril ist ein geranktes Gril 44// ListGril ist ein geranktes Gril
44type ListGril struct { 45type ListGril struct {
45 Gril *grils.Gril 46 Gril *models.Gril
46 Order int 47 Order int
47} 48}
48 49
diff --git a/modules/search/search.go b/modules/search/search.go
index a614c08..4048dbe 100644
--- a/modules/search/search.go
+++ b/modules/search/search.go
@@ -1,6 +1,7 @@
1package search 1package search
2 2
3import ( 3import (
4 "fmt"
4 "log" 5 "log"
5 "net/http" 6 "net/http"
6 7
@@ -72,7 +73,9 @@ func (m *Module) instantSearchGril(w http.ResponseWriter, r *http.Request, p htt
72 continue 73 continue
73 } 74 }
74 75
75 result.ImagePath = grils.ImagePath(result.ID, true) 76 // Jan: Das ist hier irgendwie scheisse, aber wir bauen ja grad irgendwie den kram auf Models um. Wir brauchen da
77 // irgendwas besseres.
78 result.ImagePath = fmt.Sprintf("http://img.grilist.moe/gril/thumb/%d.jpg", result.ID)
76 results = append(results, result) 79 results = append(results, result)
77 } 80 }
78 81
diff --git a/modules/series/module.go b/modules/series/module.go
new file mode 100644
index 0000000..295e16b
--- /dev/null
+++ b/modules/series/module.go
@@ -0,0 +1,44 @@
1package series
2
3import (
4 "net/http"
5 "strconv"
6
7 "fagott.pw/charakterin"
8 "fagott.pw/grilist/grilist"
9 "github.com/julienschmidt/httprouter"
10)
11
12type Module struct {
13 g *grilist.Grilist
14}
15
16func New() *Module {
17 return &Module{}
18}
19
20func (m *Module) Name() string {
21 return "Series"
22}
23
24func (m *Module) Init(g *grilist.Grilist) {
25 m.g = g
26
27 m.g.Router.GET("/series/:id", m.viewSeries)
28}
29
30func (m *Module) ProvideDashboardData(user *charakterin.User) []grilist.DashboardCategory {
31 return make([]grilist.DashboardCategory, 0)
32}
33
34func (m *Module) viewSeries(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
35 _, _ = m.g.Charakterin.GetUserFromRequest(r)
36
37 _, err := strconv.Atoi(p.ByName("id"))
38 if err != nil {
39 http.Redirect(w, r, "/", 302)
40 return
41 }
42
43 http.Error(w, "not implemented", 500)
44}
diff --git a/views/pages/gril.html b/views/pages/gril.html
index 69d7fcd..b2a00a6 100644
--- a/views/pages/gril.html
+++ b/views/pages/gril.html
@@ -78,7 +78,7 @@
78 <h1>Ähnliche Grils</h1> 78 <h1>Ähnliche Grils</h1>
79 <div class="row"> 79 <div class="row">
80 {{ range .SimilarGrils }} 80 {{ range .SimilarGrils }}
81 <div class="col s3"> 81 <div class="col s6 m4 l3">
82 {{ template "card_gril" . }} 82 {{ template "card_gril" . }}
83 </div> 83 </div>
84 {{ end }} 84 {{ end }}