aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjan <jan@ruken.pw>2015-12-22 18:01:08 (UTC)
committerjan <jan@ruken.pw>2015-12-22 18:01:08 (UTC)
commitf239fc2678f2f4e458cf10a4ab30d54acc5b92c2 (patch)
tree059c8593e91257eeb39a049a7b8e47df8ba4638d
parent50d50d37809fef22b08c0b260302a5e96ad35694 (diff)
mehr cleanup, neue Listen anzeigen auf dem Dashboard
-rw-r--r--dashboard.go18
-rw-r--r--grilist/grilist.go2
-rw-r--r--modules/grils/grils.go10
-rw-r--r--modules/lists/lists.go50
4 files changed, 53 insertions, 27 deletions
diff --git a/dashboard.go b/dashboard.go
index aa6405c..6e81d6b 100644
--- a/dashboard.go
+++ b/dashboard.go
@@ -1,9 +1,9 @@
1package main 1package main
2 2
3import ( 3import (
4 "net/http"
5 "fagott.pw/grilist/grilist" 4 "fagott.pw/grilist/grilist"
6 "github.com/julienschmidt/httprouter" 5 "github.com/julienschmidt/httprouter"
6 "net/http"
7) 7)
8 8
9func viewDashboard(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { 9func viewDashboard(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
@@ -12,18 +12,18 @@ func viewDashboard(w http.ResponseWriter, r *http.Request, _ httprouter.Params)
12 http.Redirect(w, r, "/", 302) 12 http.Redirect(w, r, "/", 302)
13 return 13 return
14 } 14 }
15 15
16 var categories []grilist.DashboardCategory 16 var categories []grilist.DashboardCategory
17 17
18 for _, module := range app.Modules { 18 for _, module := range app.Modules {
19 category := module.ProvideDashboardData(user) 19 for _, category := range module.ProvideDashboardData(user) {
20 20 if len(category.Cards) > 0 {
21 if len(category.Cards) > 0 { 21 categories = append(categories, category)
22 categories = append(categories, category) 22 }
23 } 23 }
24 } 24 }
25 25
26 data := make(map[string]interface{}) 26 data := make(map[string]interface{})
27 data["categories"] = categories 27 data["categories"] = categories
28 app.Renderer.RenderPage("dashboard", w, data) 28 app.Renderer.RenderPage("dashboard", w, data)
29} \ No newline at end of file 29}
diff --git a/grilist/grilist.go b/grilist/grilist.go
index b166966..baff81c 100644
--- a/grilist/grilist.go
+++ b/grilist/grilist.go
@@ -25,7 +25,7 @@ type Module interface {
25 Init(*Grilist) 25 Init(*Grilist)
26 Interface() interface{} 26 Interface() interface{}
27 Name() string 27 Name() string
28 ProvideDashboardData(*charakterin.User) DashboardCategory 28 ProvideDashboardData(*charakterin.User) []DashboardCategory
29} 29}
30 30
31// DashboardCategory ist eine Kategorie mit Karten, die auf dem Dashboard angezeigt werden. 31// DashboardCategory ist eine Kategorie mit Karten, die auf dem Dashboard angezeigt werden.
diff --git a/modules/grils/grils.go b/modules/grils/grils.go
index 6ce7c5e..fa1f21c 100644
--- a/modules/grils/grils.go
+++ b/modules/grils/grils.go
@@ -6,7 +6,7 @@ import (
6) 6)
7 7
8type GrilsModule struct { 8type GrilsModule struct {
9 g *grilist.Grilist 9 g *grilist.Grilist
10 Test []int 10 Test []int
11} 11}
12 12
@@ -16,16 +16,16 @@ func (m *GrilsModule) Name() string {
16 16
17func (m *GrilsModule) Init(g *grilist.Grilist) { 17func (m *GrilsModule) Init(g *grilist.Grilist) {
18 m.g = g 18 m.g = g
19 m.Test = append(m.Test, len(m.Test) + 1) 19 m.Test = append(m.Test, len(m.Test)+1)
20} 20}
21 21
22func (m *GrilsModule) Interface() interface{} { 22func (m *GrilsModule) Interface() interface{} {
23 m.Test = append(m.Test, len(m.Test) + 1) 23 m.Test = append(m.Test, len(m.Test)+1)
24 return m 24 return m
25} 25}
26 26
27func (m *GrilsModule) ProvideDashboardData(user *charakterin.User) grilist.DashboardCategory { 27func (m *GrilsModule) ProvideDashboardData(user *charakterin.User) []grilist.DashboardCategory {
28 return grilist.DashboardCategory{} 28 return []grilist.DashboardCategory{}
29} 29}
30 30
31func New() *GrilsModule { 31func New() *GrilsModule {
diff --git a/modules/lists/lists.go b/modules/lists/lists.go
index 24d774e..343ba62 100644
--- a/modules/lists/lists.go
+++ b/modules/lists/lists.go
@@ -1,6 +1,7 @@
1package lists 1package lists
2 2
3import ( 3import (
4 "database/sql"
4 "fagott.pw/charakterin" 5 "fagott.pw/charakterin"
5 "fagott.pw/grilist/frontend" 6 "fagott.pw/grilist/frontend"
6 "fagott.pw/grilist/grilist" 7 "fagott.pw/grilist/grilist"
@@ -90,17 +91,9 @@ func mkCard(title, description string, actions ...frontend.Action) frontend.Card
90 return card 91 return card
91} 92}
92 93
93func (m *Module) ProvideDashboardData(user *charakterin.User) grilist.DashboardCategory { 94func rowsToCard(rows *sql.Rows) []frontend.Card {
94 data := grilist.DashboardCategory{ 95 var cards []frontend.Card
95 Title: "Meine Listen",
96 }
97
98 rows, err := m.g.DB.Query(`SELECT id, name, description FROM grilist.lists WHERE user_id = $1`, user.ID)
99 if err != nil {
100 return data
101 }
102 96
103 defer rows.Close()
104 for rows.Next() { 97 for rows.Next() {
105 var id int 98 var id int
106 var title, description string 99 var title, description string
@@ -109,12 +102,45 @@ func (m *Module) ProvideDashboardData(user *charakterin.User) grilist.DashboardC
109 continue 102 continue
110 } 103 }
111 104
112 data.Cards = append(data.Cards, mkCard(title, description, frontend.Action{"anguckieren", fmt.Sprintf("/lists/%d", id)})) 105 cards = append(cards, mkCard(title, description, frontend.Action{"anguckieren", fmt.Sprintf("/lists/%d", id)}))
113 } 106 }
107 return cards
108}
109
110// ProvideDashboardData gibt Daten für das Dashboard bezogen auf den Benutzer zurück
111func (m *Module) ProvideDashboardData(user *charakterin.User) []grilist.DashboardCategory {
112 var categories []grilist.DashboardCategory
113
114 // Listen des Benutzers
115 rows, err := m.g.DB.Query(`SELECT id, name, description FROM grilist.lists WHERE user_id = $1`, user.ID)
116 if err != nil {
117 log.Println(err)
118 return []grilist.DashboardCategory{}
119 }
120 defer rows.Close()
121
122 categories = append(categories, grilist.DashboardCategory{
123 Title: "Meine Listen",
124 Cards: rowsToCard(rows),
125 })
126
127 // Neue Listen
128 rows, err = m.g.DB.Query(`SELECT id, name, description FROM grilist.lists ORDER BY id DESC LIMIT 5`)
129 if err != nil {
130 log.Println(err)
131 return categories
132 }
133 defer rows.Close()
134
135 categories = append(categories, grilist.DashboardCategory{
136 Title: "Neueste Listen",
137 Cards: rowsToCard(rows),
138 })
114 139
115 return data 140 return categories
116} 141}
117 142
143// New erstellt eine neue Instanz des Modules
118func New() *Module { 144func New() *Module {
119 return &Module{} 145 return &Module{}
120} 146}