diff options
author | rtz12 <koenig@fagott.pw> | 2015-12-28 18:56:47 (UTC) |
---|---|---|
committer | rtz12 <koenig@fagott.pw> | 2015-12-28 18:56:47 (UTC) |
commit | eb03000339859fc3b5869cb8906f1e4f1022a52e (patch) | |
tree | b238d003268dfb9c93dfa80635ad8263cb67b2b8 /modules | |
parent | 23f73a60a4cf4621dd5951bfe6601a8c154cad07 (diff) | |
parent | 647c105dadfa58af6cfa80d3f359d43cfa5d5cf2 (diff) |
Merge branch 'master' of projekte.fagott.pw:grilist
Diffstat (limited to 'modules')
-rw-r--r-- | modules/grils/gril.go | 1 | ||||
-rw-r--r-- | modules/grils/grils.go | 24 | ||||
-rw-r--r-- | modules/lists/lists.go | 68 |
3 files changed, 59 insertions, 34 deletions
diff --git a/modules/grils/gril.go b/modules/grils/gril.go index 9fd3be5..edf25a9 100644 --- a/modules/grils/gril.go +++ b/modules/grils/gril.go | |||
@@ -23,4 +23,5 @@ type Gril struct { | |||
23 | Tags []string | 23 | Tags []string |
24 | ForeignIDs map[DataSource]int | 24 | ForeignIDs map[DataSource]int |
25 | UpdatedAt time.Time | 25 | UpdatedAt time.Time |
26 | Lists []int | ||
26 | } | 27 | } |
diff --git a/modules/grils/grils.go b/modules/grils/grils.go index e2eb543..a38f41f 100644 --- a/modules/grils/grils.go +++ b/modules/grils/grils.go | |||
@@ -74,6 +74,26 @@ func (m *GrilsModule) getGrils(whereClause string, params ...interface{}) ([]*Gr | |||
74 | return grils, nil | 74 | return grils, nil |
75 | } | 75 | } |
76 | 76 | ||
77 | func (m *GrilsModule) GetListsOfGril(gril *Gril) error { | ||
78 | rows, err := m.g.DB.Query(`SELECT list_id FROM grilist.lists_grils WHERE gril_id = $1`, gril.ID) | ||
79 | if err != nil { | ||
80 | return err | ||
81 | } | ||
82 | |||
83 | defer rows.Close() | ||
84 | for rows.Next() { | ||
85 | var listID int | ||
86 | if err := rows.Scan(&listID); err != nil { | ||
87 | log.Println(err) | ||
88 | continue | ||
89 | } | ||
90 | |||
91 | gril.Lists = append(gril.Lists, listID) | ||
92 | } | ||
93 | |||
94 | return nil | ||
95 | } | ||
96 | |||
77 | func (m *GrilsModule) ProvideDashboardData(user *charakterin.User) []grilist.DashboardCategory { | 97 | func (m *GrilsModule) ProvideDashboardData(user *charakterin.User) []grilist.DashboardCategory { |
78 | var categories []grilist.DashboardCategory | 98 | var categories []grilist.DashboardCategory |
79 | 99 | ||
@@ -137,6 +157,10 @@ func (m *GrilsModule) viewGril(w http.ResponseWriter, r *http.Request, p httprou | |||
137 | return | 157 | return |
138 | } | 158 | } |
139 | 159 | ||
160 | if err := m.GetListsOfGril(gril); err != nil { | ||
161 | log.Println(err) | ||
162 | } | ||
163 | |||
140 | data := m.g.Renderer.DefaultData() | 164 | data := m.g.Renderer.DefaultData() |
141 | data["user"] = user | 165 | data["user"] = user |
142 | data["gril"] = gril | 166 | data["gril"] = gril |
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 | ||
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 | } |
@@ -177,30 +175,32 @@ func rowsToCard(rows *sql.Rows) []frontend.Card { | |||
177 | func (m *Module) ProvideDashboardData(user *charakterin.User) []grilist.DashboardCategory { | 175 | func (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 |