aboutsummaryrefslogtreecommitdiff
path: root/modules/lists
diff options
context:
space:
mode:
Diffstat (limited to 'modules/lists')
-rw-r--r--modules/lists/lists.go68
1 files changed, 34 insertions, 34 deletions
diff --git a/modules/lists/lists.go b/modules/lists/lists.go
index a7e822a..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}
@@ -177,30 +175,32 @@ func rowsToCard(rows *sql.Rows) []frontend.Card {
177func (m *Module) ProvideDashboardData(user *charakterin.User) []grilist.DashboardCategory { 175func (m *Module) ProvideDashboardData(user *charakterin.User) []grilist.DashboardCategory {
178 var categories []grilist.DashboardCategory 176 var categories []grilist.DashboardCategory
179 177
180 // Listen des Benutzers 178 // Neue Listen
181 rows, err := m.g.DB.Query(`SELECT id, name, description FROM grilist.lists WHERE user_id = $1`, user.ID) 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 []grilist.DashboardCategory{} 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: "Meine Listen", 186 Title: "Neueste Listen",
190 Cards: rowsToCard(rows), 187 Cards: listsToCards(lists),
191 }) 188 })
192 189
193 // Neue Listen 190 if user == nil {
194 rows, err = m.g.DB.Query(`SELECT id, name, description FROM grilist.lists ORDER BY id DESC LIMIT 5`) 191 return categories
192 }
193
194 // Listen des Benutzers
195 lists, err = m.getLists(`user_id = $1`, user.ID)
195 if err != nil { 196 if err != nil {
196 log.Println(err) 197 log.Println(err)
197 return categories 198 return categories
198 } 199 }
199 defer rows.Close()
200 200
201 categories = append(categories, grilist.DashboardCategory{ 201 categories = append(categories, grilist.DashboardCategory{
202 Title: "Neueste Listen", 202 Title: "Meine Listen",
203 Cards: rowsToCard(rows), 203 Cards: listsToCards(lists),
204 }) 204 })
205 205
206 return categories 206 return categories