diff options
author | jan <jan@ruken.pw> | 2015-12-28 10:36:00 (UTC) |
---|---|---|
committer | jan <jan@ruken.pw> | 2015-12-28 10:36:00 (UTC) |
commit | 0891a94767cafc13307482cd0c4f76db3bcc3b5e (patch) | |
tree | 5be18b1644751bf1365a7b185cab2eaaa6a5f6a6 /modules | |
parent | 0746d945a61ca3dc7588a1f7a2c320ca8a06e198 (diff) |
'html' template func zum rendern von HTML in templates. wird im dashboard verwendet für mehr dynamik.
Diffstat (limited to 'modules')
-rw-r--r-- | modules/lists/lists.go | 56 |
1 files changed, 26 insertions, 30 deletions
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 | ||
146 | func mkCard(title, description string, actions ...frontend.Action) frontend.Card { | 146 | func 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 | |||
160 | func 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 |