aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--frontend/renderer.go13
-rw-r--r--modules/lists/lists.go56
-rw-r--r--views/dashboard.html10
3 files changed, 43 insertions, 36 deletions
diff --git a/frontend/renderer.go b/frontend/renderer.go
index e9b9931..a3aa83d 100644
--- a/frontend/renderer.go
+++ b/frontend/renderer.go
@@ -7,8 +7,9 @@ import (
7 7
8// Action ist die Aktion auf einer Card. 8// Action ist die Aktion auf einer Card.
9type Action struct { 9type Action struct {
10 Name string 10 Name string
11 Link string 11 Link string
12 Disabled bool
12} 13}
13 14
14// Card ist eine Karte im Materialize-Design. 15// Card ist eine Karte im Materialize-Design.
@@ -41,8 +42,14 @@ func (r *Renderer) SetDefaultData(data map[string]interface{}) {
41 42
42// New erstellt einen neuen Renderer und sucht alle Templates aus dem gegebenen pfad. 43// New erstellt einen neuen Renderer und sucht alle Templates aus dem gegebenen pfad.
43func New(path string) *Renderer { 44func New(path string) *Renderer {
45 // Custom Template Funcs
46 funcMap := template.FuncMap{
47 "html": func(in string) template.HTML {
48 return template.HTML(in)
49 },
50 }
44 r := &Renderer{ 51 r := &Renderer{
45 template.Must(template.ParseGlob(path + "/*")), 52 template.Must(template.ParseGlob(path + "/*")).Funcs(funcMap),
46 make(map[string]interface{}), 53 make(map[string]interface{}),
47 } 54 }
48 55
diff --git a/modules/lists/lists.go b/modules/lists/lists.go
index 154bf74..47501c2 100644
--- a/modules/lists/lists.go
+++ b/modules/lists/lists.go
@@ -143,32 +143,30 @@ func (m *Module) FromID(id int) (*List, error) {
143 return lists[0], nil 143 return lists[0], nil
144} 144}
145 145
146func mkCard(title, description string, actions ...frontend.Action) frontend.Card { 146func listsToCards(lists []*List) []frontend.Card {
147 card := frontend.Card{
148 Title: title,
149 Description: description,
150 Size: "medium",
151 }
152
153 for _, action := range actions {
154 card.Actions = append(card.Actions, action)
155 }
156
157 return card
158}
159
160func rowsToCard(rows *sql.Rows) []frontend.Card {
161 var cards []frontend.Card 147 var cards []frontend.Card
162 148
163 for rows.Next() { 149 for _, list := range lists {
164 var id int 150 s := "s"
165 var title, description string 151 if len(list.Grils) == 1 {
166 if err := rows.Scan(&id, &title, &description); err != nil { 152 s = ""
167 log.Println("error scanning row", err)
168 continue
169 } 153 }
170 154 cards = append(cards, frontend.Card{
171 cards = append(cards, mkCard(title, description, frontend.Action{"anguckieren", fmt.Sprintf("/list/%d", id)})) 155 Title: list.Name,
156 Description: list.Description,
157 Size: "medium",
158 Actions: []frontend.Action{
159 frontend.Action{
160 Name: "anguckieren",
161 Link: fmt.Sprintf("/list/%d", list.ID),
162 },
163 frontend.Action{
164 Name: fmt.Sprintf(`<span class="chip">%d gril%s</span>`, len(list.Grils), s),
165 Link: "#",
166 Disabled: true,
167 },
168 },
169 })
172 } 170 }
173 return cards 171 return cards
174} 172}
@@ -178,16 +176,15 @@ func (m *Module) ProvideDashboardData(user *charakterin.User) []grilist.Dashboar
178 var categories []grilist.DashboardCategory 176 var categories []grilist.DashboardCategory
179 177
180 // Neue Listen 178 // Neue Listen
181 rows, err := m.g.DB.Query(`SELECT id, name, description FROM grilist.lists ORDER BY id DESC LIMIT 5`) 179 lists, err := m.getLists(`1=1 ORDER BY id DESC LIMIT 5`)
182 if err != nil { 180 if err != nil {
183 log.Println(err) 181 log.Println(err)
184 return categories 182 return categories
185 } 183 }
186 defer rows.Close()
187 184
188 categories = append(categories, grilist.DashboardCategory{ 185 categories = append(categories, grilist.DashboardCategory{
189 Title: "Neueste Listen", 186 Title: "Neueste Listen",
190 Cards: rowsToCard(rows), 187 Cards: listsToCards(lists),
191 }) 188 })
192 189
193 if user == nil { 190 if user == nil {
@@ -195,16 +192,15 @@ func (m *Module) ProvideDashboardData(user *charakterin.User) []grilist.Dashboar
195 } 192 }
196 193
197 // Listen des Benutzers 194 // Listen des Benutzers
198 rows, err = m.g.DB.Query(`SELECT id, name, description FROM grilist.lists WHERE user_id = $1`, user.ID) 195 lists, err = m.getLists(`user_id = $1`, user.ID)
199 if err != nil { 196 if err != nil {
200 log.Println(err) 197 log.Println(err)
201 return []grilist.DashboardCategory{} 198 return categories
202 } 199 }
203 defer rows.Close()
204 200
205 categories = append(categories, grilist.DashboardCategory{ 201 categories = append(categories, grilist.DashboardCategory{
206 Title: "Meine Listen", 202 Title: "Meine Listen",
207 Cards: rowsToCard(rows), 203 Cards: listsToCards(lists),
208 }) 204 })
209 205
210 return categories 206 return categories
diff --git a/views/dashboard.html b/views/dashboard.html
index f2d410d..0551285 100644
--- a/views/dashboard.html
+++ b/views/dashboard.html
@@ -16,12 +16,16 @@
16 <div class="col s12 m6 l4"> 16 <div class="col s12 m6 l4">
17 <div class="card white"> 17 <div class="card white">
18 <div class="card-content black-text"> 18 <div class="card-content black-text">
19 <span class="card-title">{{ $card.Title }}</span> 19 <span class="card-title">{{ $card.Title | html }}</span>
20 <p>{{ $card.Description }}</p> 20 <p>{{ $card.Description | html }}</p>
21 </div> 21 </div>
22 <div class="card-action"> 22 <div class="card-action">
23 {{ range $action := $card.Actions }} 23 {{ range $action := $card.Actions }}
24 <a href="{{ $action.Link }}">{{ $action.Name }}</a> 24 {{ if $action.Disabled }}
25 <span>{{ $action.Name | html }}</span>
26 {{ else }}
27 <a href="{{ $action.Link }}">{{ $action.Name | html }}</a>
28 {{ end }}
25 {{ end }} 29 {{ end }}
26 </div> 30 </div>
27 </div> 31 </div>