aboutsummaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorrtz12 <koenig@fagott.pw>2015-12-29 19:51:43 (UTC)
committerrtz12 <koenig@fagott.pw>2015-12-29 19:51:43 (UTC)
commit989ab00b731d659aa17d6a626efb899f8e400936 (patch)
tree8f31f5987a0ee6232b730dfad3fdd4d75f9ce153 /modules
parentc2498d562d3e30e4795056058fc3d8a5cec4ec11 (diff)
parent1354a3a30c1639c1441e79356df12601151630a6 (diff)
Merge branch 'master' of projekte.fagott.pw:grilist
Diffstat (limited to 'modules')
-rw-r--r--modules/grils/gril.go25
-rw-r--r--modules/grils/grils.go4
-rw-r--r--modules/lists/lists.go25
3 files changed, 39 insertions, 15 deletions
diff --git a/modules/grils/gril.go b/modules/grils/gril.go
index c8c6538..89dd7c4 100644
--- a/modules/grils/gril.go
+++ b/modules/grils/gril.go
@@ -3,6 +3,7 @@ package grils
3import ( 3import (
4 "database/sql" 4 "database/sql"
5 "fmt" 5 "fmt"
6 "os"
6 "strconv" 7 "strconv"
7 "strings" 8 "strings"
8 "time" 9 "time"
@@ -39,3 +40,27 @@ func (g *Gril) Slug() string {
39 g.ID, 40 g.ID,
40 strings.Replace(g.RomajiName, " ", "", -1)) 41 strings.Replace(g.RomajiName, " ", "", -1))
41} 42}
43
44func (g *Gril) ImagePath(prioritizeThumbnail bool) string {
45 var big string
46 exts := []string{"png", "jpg", "gif", "jpeg"}
47 for _, ext := range exts {
48 path := fmt.Sprintf("assets/img/gril/%d/0.%s", g.ID, ext)
49 if _, err := os.Stat(path); err == nil {
50 if prioritizeThumbnail {
51 big = path
52 } else {
53 return path
54 }
55 }
56 }
57
58 for _, ext := range exts {
59 path := fmt.Sprintf("assets/img/gril/%d/1.%s", g.ID, ext)
60 if _, err := os.Stat(path); err == nil {
61 return path
62 }
63 }
64
65 return big
66}
diff --git a/modules/grils/grils.go b/modules/grils/grils.go
index 46d0fb3..0df93a0 100644
--- a/modules/grils/grils.go
+++ b/modules/grils/grils.go
@@ -44,10 +44,6 @@ func (m *GrilsModule) Init(g *grilist.Grilist) {
44 m.g.Router.GET("/gril/:id/*rest", m.viewGril) 44 m.g.Router.GET("/gril/:id/*rest", m.viewGril)
45} 45}
46 46
47func (m *GrilsModule) Interface() interface{} {
48 return m
49}
50
51func (m *GrilsModule) getGrils(whereClause string, params ...interface{}) ([]*Gril, error) { 47func (m *GrilsModule) getGrils(whereClause string, params ...interface{}) ([]*Gril, error) {
52 var grils []*Gril 48 var grils []*Gril
53 49
diff --git a/modules/lists/lists.go b/modules/lists/lists.go
index 47501c2..4c4288f 100644
--- a/modules/lists/lists.go
+++ b/modules/lists/lists.go
@@ -52,7 +52,7 @@ func (m *Module) Init(g *grilist.Grilist) {
52 log.Fatal("lists: grils module not found") 52 log.Fatal("lists: grils module not found")
53 } 53 }
54 54
55 grilsModule, ok := gm.Interface().(*grils.GrilsModule) 55 grilsModule, ok := gm.(*grils.GrilsModule)
56 if !ok { 56 if !ok {
57 log.Fatal("lists: error with grils module") 57 log.Fatal("lists: error with grils module")
58 } 58 }
@@ -60,11 +60,6 @@ func (m *Module) Init(g *grilist.Grilist) {
60 m.g.Router.GET("/list/:id", m.viewList) 60 m.g.Router.GET("/list/:id", m.viewList)
61} 61}
62 62
63// Interface gibt das Modul zurück
64func (m *Module) Interface() interface{} {
65 return m
66}
67
68func (m *Module) getListGrils(list *List) error { 63func (m *Module) getListGrils(list *List) error {
69 rows, err := m.g.DB.Query(`SELECT gril_id, "order" FROM grilist.lists_grils WHERE list_id = $1`, list.ID) 64 rows, err := m.g.DB.Query(`SELECT gril_id, "order" FROM grilist.lists_grils WHERE list_id = $1`, list.ID)
70 if err != nil { 65 if err != nil {
@@ -96,7 +91,7 @@ func (m *Module) getListGrils(list *List) error {
96func (m *Module) getLists(whereClause string, params ...interface{}) ([]*List, error) { 91func (m *Module) getLists(whereClause string, params ...interface{}) ([]*List, error) {
97 var lists []*List 92 var lists []*List
98 93
99 rows, err := m.g.DB.Query(fmt.Sprintf(`SELECT id, name, description, fork_of, updated_at FROM grilist.lists WHERE %s`, whereClause), params...) 94 rows, err := m.g.DB.Query(fmt.Sprintf(`SELECT id, name, description, fork_of, updated_at, user_id FROM grilist.lists WHERE %s`, whereClause), params...)
100 if err != nil { 95 if err != nil {
101 return nil, err 96 return nil, err
102 } 97 }
@@ -104,8 +99,8 @@ func (m *Module) getLists(whereClause string, params ...interface{}) ([]*List, e
104 defer rows.Close() 99 defer rows.Close()
105 for rows.Next() { 100 for rows.Next() {
106 list := &List{} 101 list := &List{}
107 102 var ownerID int
108 if err := rows.Scan(&list.ID, &list.Name, &list.Description, &list.ForkOf, &list.UpdatedAt); err != nil { 103 if err := rows.Scan(&list.ID, &list.Name, &list.Description, &list.ForkOf, &list.UpdatedAt, &ownerID); err != nil {
109 log.Println("error scanning row in getLists:", err) 104 log.Println("error scanning row in getLists:", err)
110 continue 105 continue
111 } 106 }
@@ -115,6 +110,14 @@ func (m *Module) getLists(whereClause string, params ...interface{}) ([]*List, e
115 continue 110 continue
116 } 111 }
117 112
113 // Owner kriegn
114 owner, err := m.g.Charakterin.GetUserByID(ownerID)
115 if err != nil {
116 log.Println("error retreiving owner of list", err)
117 continue
118 }
119 list.Owner = owner
120
118 lists = append(lists, list) 121 lists = append(lists, list)
119 } 122 }
120 123
@@ -161,8 +164,8 @@ func listsToCards(lists []*List) []frontend.Card {
161 Link: fmt.Sprintf("/list/%d", list.ID), 164 Link: fmt.Sprintf("/list/%d", list.ID),
162 }, 165 },
163 frontend.Action{ 166 frontend.Action{
164 Name: fmt.Sprintf(`<span class="chip">%d gril%s</span>`, len(list.Grils), s), 167 Name: fmt.Sprintf(`<span class="chip">%d gril%s</span>`, len(list.Grils), s),
165 Link: "#", 168 Link: "#",
166 Disabled: true, 169 Disabled: true,
167 }, 170 },
168 }, 171 },