aboutsummaryrefslogtreecommitdiff
path: root/modules/grils
diff options
context:
space:
mode:
authorjan <jan@ruken.pw>2015-12-29 18:56:33 (UTC)
committerjan <jan@ruken.pw>2015-12-29 18:56:33 (UTC)
commitd6d002dda847b9bdeb6f464f7a1fafaab0419a55 (patch)
treed0b64c779c1aab618e82d419c1071944d0b18b3d /modules/grils
parent0189b471cab18ec565bfa5605015d6f994cdde00 (diff)
die grils werden jetzt in einer besseren liste dargestellt. es gibt bereits knöpfe zum umsortieren, muss aber alles noch implementiert werden.
Diffstat (limited to 'modules/grils')
-rw-r--r--modules/grils/gril.go23
-rw-r--r--modules/grils/grils.go23
2 files changed, 23 insertions, 23 deletions
diff --git a/modules/grils/gril.go b/modules/grils/gril.go
index edf25a9..a450647 100644
--- a/modules/grils/gril.go
+++ b/modules/grils/gril.go
@@ -2,7 +2,9 @@ package grils
2 2
3import ( 3import (
4 "database/sql" 4 "database/sql"
5 "fmt"
5 "github.com/lib/pq" 6 "github.com/lib/pq"
7 "os"
6 "time" 8 "time"
7) 9)
8 10
@@ -25,3 +27,24 @@ type Gril struct {
25 UpdatedAt time.Time 27 UpdatedAt time.Time
26 Lists []int 28 Lists []int
27} 29}
30
31func (g *Gril) ImagePath() string {
32 exts := []string{"png", "jpg", "gif", "jpeg"}
33 var imagePath string
34 for _, ext := range exts {
35 path := fmt.Sprintf("assets/img/gril/%d/0.%s", g.ID, ext)
36 if _, err := os.Stat(path); err == nil {
37 return path
38 }
39 }
40
41 if len(imagePath) == 0 {
42 for _, ext := range exts {
43 path := fmt.Sprintf("assets/img/gril/%d/1.%s", g.ID, ext)
44 if _, err := os.Stat(path); err == nil {
45 return path
46 }
47 }
48 }
49 return ""
50}
diff --git a/modules/grils/grils.go b/modules/grils/grils.go
index 9bfd6e6..a1c84c7 100644
--- a/modules/grils/grils.go
+++ b/modules/grils/grils.go
@@ -8,7 +8,6 @@ import (
8 "github.com/julienschmidt/httprouter" 8 "github.com/julienschmidt/httprouter"
9 "log" 9 "log"
10 "net/http" 10 "net/http"
11 "os"
12 "regexp" 11 "regexp"
13 "strconv" 12 "strconv"
14 "strings" 13 "strings"
@@ -174,28 +173,6 @@ func (m *GrilsModule) viewGril(w http.ResponseWriter, r *http.Request, p httprou
174 data["user"] = user 173 data["user"] = user
175 data["gril"] = gril 174 data["gril"] = gril
176 175
177 // get the file ending
178 exts := []string{"png", "jpg", "gif", "jpeg"}
179 var imagePath string
180 for _, ext := range exts {
181 path := fmt.Sprintf("assets/img/gril/%d/0.%s", gril.ID, ext)
182 if _, err := os.Stat(path); err == nil {
183 imagePath = path
184 break
185 }
186 }
187
188 if len(imagePath) == 0 {
189 for _, ext := range exts {
190 path := fmt.Sprintf("assets/img/gril/%d/1.%s", gril.ID, ext)
191 if _, err := os.Stat(path); err == nil {
192 imagePath = path
193 break
194 }
195 }
196 }
197 data["imagePath"] = "/" + imagePath
198
199 m.g.Renderer.RenderPage("gril", w, data) 176 m.g.Renderer.RenderPage("gril", w, data)
200} 177}
201 178