aboutsummaryrefslogtreecommitdiff
path: root/modules/grils
diff options
context:
space:
mode:
Diffstat (limited to 'modules/grils')
-rw-r--r--modules/grils/gril.go15
-rw-r--r--modules/grils/grils.go29
2 files changed, 38 insertions, 6 deletions
diff --git a/modules/grils/gril.go b/modules/grils/gril.go
index fe316cd..89dd7c4 100644
--- a/modules/grils/gril.go
+++ b/modules/grils/gril.go
@@ -3,9 +3,12 @@ package grils
3import ( 3import (
4 "database/sql" 4 "database/sql"
5 "fmt" 5 "fmt"
6 "github.com/lib/pq"
7 "os" 6 "os"
7 "strconv"
8 "strings"
8 "time" 9 "time"
10
11 "github.com/lib/pq"
9) 12)
10 13
11type DataSource int 14type DataSource int
@@ -28,6 +31,16 @@ type Gril struct {
28 Lists []int 31 Lists []int
29} 32}
30 33
34func (g *Gril) Slug() string {
35 if g.RomajiName == "" {
36 return strconv.Itoa(g.ID)
37 }
38 return fmt.Sprintf(
39 "%d/%s",
40 g.ID,
41 strings.Replace(g.RomajiName, " ", "", -1))
42}
43
31func (g *Gril) ImagePath(prioritizeThumbnail bool) string { 44func (g *Gril) ImagePath(prioritizeThumbnail bool) string {
32 var big string 45 var big string
33 exts := []string{"png", "jpg", "gif", "jpeg"} 46 exts := []string{"png", "jpg", "gif", "jpeg"}
diff --git a/modules/grils/grils.go b/modules/grils/grils.go
index a1c84c7..0df93a0 100644
--- a/modules/grils/grils.go
+++ b/modules/grils/grils.go
@@ -1,16 +1,18 @@
1package grils 1package grils
2 2
3import ( 3import (
4 "fagott.pw/charakterin"
5 "fagott.pw/grilist/frontend"
6 "fagott.pw/grilist/grilist"
7 "fmt" 4 "fmt"
8 "github.com/julienschmidt/httprouter"
9 "log" 5 "log"
10 "net/http" 6 "net/http"
11 "regexp" 7 "regexp"
12 "strconv" 8 "strconv"
13 "strings" 9 "strings"
10
11 "fagott.pw/charakterin"
12 "fagott.pw/grilist/frontend"
13 "fagott.pw/grilist/grilist"
14
15 "github.com/julienschmidt/httprouter"
14) 16)
15 17
16var ( 18var (
@@ -39,6 +41,7 @@ func (m *GrilsModule) Init(g *grilist.Grilist) {
39 findIdx() 41 findIdx()
40 m.g = g 42 m.g = g
41 m.g.Router.GET("/gril/:id", m.viewGril) 43 m.g.Router.GET("/gril/:id", m.viewGril)
44 m.g.Router.GET("/gril/:id/*rest", m.viewGril)
42} 45}
43 46
44func (m *GrilsModule) getGrils(whereClause string, params ...interface{}) ([]*Gril, error) { 47func (m *GrilsModule) getGrils(whereClause string, params ...interface{}) ([]*Gril, error) {
@@ -124,7 +127,7 @@ func (m *GrilsModule) ProvideDashboardData(user *charakterin.User) []grilist.Das
124 Actions: []frontend.Action{ 127 Actions: []frontend.Action{
125 frontend.Action{ 128 frontend.Action{
126 Name: "anguckieren", 129 Name: "anguckieren",
127 Link: fmt.Sprintf("/gril/%d", gril.ID), 130 Link: "/gril/" + gril.Slug(),
128 }, 131 },
129 }, 132 },
130 }) 133 })
@@ -149,6 +152,22 @@ func (m *GrilsModule) FromID(id int) (*Gril, error) {
149 return gril, nil 152 return gril, nil
150} 153}
151 154
155func (m *GrilsModule) FromIDs(ids []int) ([]*Gril, error) {
156 idList := "("
157 first := true
158 for _, v := range ids {
159 if first {
160 first = false
161 } else {
162 idList += ","
163 }
164 idList += strconv.Itoa(v)
165 }
166 idList += ")"
167 grils, err := m.getGrils("id IN " + idList)
168 return grils, err
169}
170
152func (m *GrilsModule) viewGril(w http.ResponseWriter, r *http.Request, p httprouter.Params) { 171func (m *GrilsModule) viewGril(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
153 user, _ := m.g.Charakterin.GetUserFromRequest(r) 172 user, _ := m.g.Charakterin.GetUserFromRequest(r)
154 sid := p.ByName("id") 173 sid := p.ByName("id")