aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjan <jan@ruken.pw>2015-12-21 22:29:10 (UTC)
committerjan <jan@ruken.pw>2015-12-21 22:29:10 (UTC)
commit4254929eea29a42896fd57185d6f52fdc3efdca4 (patch)
tree9e8dc1f456ef20c4308d193be5db4114e976577a
parentc3e905c2698f6eb44e291eeb6b180b13755b7705 (diff)
dashboard. FUCKING DASHBOARD!
-rw-r--r--dashboard.go28
-rw-r--r--grilist/grilist.go1
-rw-r--r--main.go11
-rw-r--r--modules/grils/grils.go33
-rw-r--r--modules/lists/lists.go63
-rw-r--r--views/dashboard.html35
6 files changed, 159 insertions, 12 deletions
diff --git a/dashboard.go b/dashboard.go
index 221e923..aa6405c 100644
--- a/dashboard.go
+++ b/dashboard.go
@@ -1,3 +1,29 @@
1package main 1package main
2 2
3import () 3import (
4 "net/http"
5 "fagott.pw/grilist/grilist"
6 "github.com/julienschmidt/httprouter"
7)
8
9func viewDashboard(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
10 user, err := app.Charakterin.GetUserFromRequest(r)
11 if err != nil {
12 http.Redirect(w, r, "/", 302)
13 return
14 }
15
16 var categories []grilist.DashboardCategory
17
18 for _, module := range app.Modules {
19 category := module.ProvideDashboardData(user)
20
21 if len(category.Cards) > 0 {
22 categories = append(categories, category)
23 }
24 }
25
26 data := make(map[string]interface{})
27 data["categories"] = categories
28 app.Renderer.RenderPage("dashboard", w, data)
29} \ No newline at end of file
diff --git a/grilist/grilist.go b/grilist/grilist.go
index c672dec..b166966 100644
--- a/grilist/grilist.go
+++ b/grilist/grilist.go
@@ -23,6 +23,7 @@ type Grilist struct {
23// Module ist ein Modul für Grilist. 23// Module ist ein Modul für Grilist.
24type Module interface { 24type Module interface {
25 Init(*Grilist) 25 Init(*Grilist)
26 Interface() interface{}
26 Name() string 27 Name() string
27 ProvideDashboardData(*charakterin.User) DashboardCategory 28 ProvideDashboardData(*charakterin.User) DashboardCategory
28} 29}
diff --git a/main.go b/main.go
index e106a80..70763d4 100644
--- a/main.go
+++ b/main.go
@@ -10,6 +10,7 @@ import (
10 "fagott.pw/grilist/frontend" 10 "fagott.pw/grilist/frontend"
11 "fagott.pw/grilist/grilist" 11 "fagott.pw/grilist/grilist"
12 "fagott.pw/grilist/modules/lists" 12 "fagott.pw/grilist/modules/lists"
13 "fagott.pw/grilist/modules/grils"
13 14
14 "github.com/julienschmidt/httprouter" 15 "github.com/julienschmidt/httprouter"
15 _ "github.com/lib/pq" 16 _ "github.com/lib/pq"
@@ -18,16 +19,13 @@ import (
18var app *grilist.Grilist 19var app *grilist.Grilist
19 20
20func index(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { 21func index(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
21 user, err := app.Charakterin.GetUserFromRequest(r) 22 _, err := app.Charakterin.GetUserFromRequest(r)
22 if err != nil { 23 if err != nil {
23 http.Redirect(w, r, "/login", 302) 24 http.Redirect(w, r, "/login", 302)
24 return 25 return
25 } 26 }
26 27
27 data := make(map[string]interface{}) 28 http.Redirect(w, r, "/dashboard", 302)
28
29 data["username"] = user.GetName()
30 app.Renderer.RenderPage("index", w, data)
31} 29}
32 30
33func loadModule(mod grilist.Module) error { 31func loadModule(mod grilist.Module) error {
@@ -35,6 +33,7 @@ func loadModule(mod grilist.Module) error {
35 return fmt.Errorf("module with name %s already exists", mod.Name()) 33 return fmt.Errorf("module with name %s already exists", mod.Name())
36 } 34 }
37 app.Modules[mod.Name()] = mod 35 app.Modules[mod.Name()] = mod
36 mod.Init(app)
38 return nil 37 return nil
39} 38}
40 39
@@ -71,12 +70,14 @@ func main() {
71 router.HandlerFunc("GET", "/register", login.DisplayRegistration) 70 router.HandlerFunc("GET", "/register", login.DisplayRegistration)
72 router.HandlerFunc("POST", "/register", login.Register) 71 router.HandlerFunc("POST", "/register", login.Register)
73 router.GET("/", index) 72 router.GET("/", index)
73 router.GET("/dashboard", viewDashboard)
74 74
75 fs := http.FileServer(http.Dir("assets")) 75 fs := http.FileServer(http.Dir("assets"))
76 http.Handle("/assets/", http.StripPrefix("/assets/", fs)) 76 http.Handle("/assets/", http.StripPrefix("/assets/", fs))
77 http.Handle("/", router) 77 http.Handle("/", router)
78 78
79 // Module laden 79 // Module laden
80 loadModule(grils.New())
80 loadModule(lists.New()) 81 loadModule(lists.New())
81 82
82 log.Fatal(http.ListenAndServe(":8080", nil)) 83 log.Fatal(http.ListenAndServe(":8080", nil))
diff --git a/modules/grils/grils.go b/modules/grils/grils.go
new file mode 100644
index 0000000..6ce7c5e
--- /dev/null
+++ b/modules/grils/grils.go
@@ -0,0 +1,33 @@
1package grils
2
3import (
4 "fagott.pw/charakterin"
5 "fagott.pw/grilist/grilist"
6)
7
8type GrilsModule struct {
9 g *grilist.Grilist
10 Test []int
11}
12
13func (m *GrilsModule) Name() string {
14 return "Grils"
15}
16
17func (m *GrilsModule) Init(g *grilist.Grilist) {
18 m.g = g
19 m.Test = append(m.Test, len(m.Test) + 1)
20}
21
22func (m *GrilsModule) Interface() interface{} {
23 m.Test = append(m.Test, len(m.Test) + 1)
24 return m
25}
26
27func (m *GrilsModule) ProvideDashboardData(user *charakterin.User) grilist.DashboardCategory {
28 return grilist.DashboardCategory{}
29}
30
31func New() *GrilsModule {
32 return &GrilsModule{}
33}
diff --git a/modules/lists/lists.go b/modules/lists/lists.go
index f8f13bb..4e0036a 100644
--- a/modules/lists/lists.go
+++ b/modules/lists/lists.go
@@ -2,23 +2,74 @@ package lists
2 2
3import ( 3import (
4 "fagott.pw/charakterin" 4 "fagott.pw/charakterin"
5 "fagott.pw/grilist/frontend"
5 "fagott.pw/grilist/grilist" 6 "fagott.pw/grilist/grilist"
7 "fagott.pw/grilist/modules/grils"
8 "log"
6) 9)
7 10
8type ListsModule struct { 11type ListsModule struct {
9 g *grilist.Grilist 12 g *grilist.Grilist
13 grils *grils.GrilsModule
10} 14}
11 15
12func (d *ListsModule) Name() string { 16type List struct {
13 return "ListsModule" 17 ID int
18 Name string
19 Description string
20 Owner *charakterin.User
14} 21}
15 22
16func (d *ListsModule) Init(g *grilist.Grilist) { 23func (m *ListsModule) Name() string {
17 d.g = g 24 return "Lists"
18} 25}
19 26
20func (d *ListsModule) ProvideDashboardData(user *charakterin.User) grilist.DashboardCategory { 27func (m *ListsModule) Init(g *grilist.Grilist) {
21 return grilist.DashboardCategory{} 28 m.g = g
29
30 gm, ok := g.Modules["Grils"]
31 if !ok {
32 log.Fatal("lists: grils module not found")
33 }
34
35 grilsModule, ok := gm.Interface().(*grils.GrilsModule)
36 if !ok {
37 log.Fatal("lists: error with grils module")
38 }
39 m.grils = grilsModule
40}
41
42func (m *ListsModule) Interface() interface{} {
43 return m
44}
45
46func (m *ListsModule) ProvideDashboardData(user *charakterin.User) grilist.DashboardCategory {
47 data := grilist.DashboardCategory{
48 Title: "Meine Listen",
49 }
50
51 rows, err := m.g.DB.Query(`SELECT id, name, description FROM grilist.lists WHERE user_id = $1`, user.ID)
52 if err != nil {
53 return data
54 }
55
56 defer rows.Close()
57 for rows.Next() {
58 card := frontend.Card{}
59 view := frontend.Action{
60 Name: "anguckieren",
61 }
62 var id int
63 if err := rows.Scan(&id, &card.Title, &card.Description); err != nil {
64 log.Println("error scanning row",err)
65 continue
66 }
67
68 card.Actions = []frontend.Action{view}
69 data.Cards = append(data.Cards, card)
70 }
71
72 return data
22} 73}
23 74
24func New() *ListsModule { 75func New() *ListsModule {
diff --git a/views/dashboard.html b/views/dashboard.html
new file mode 100644
index 0000000..67fb005
--- /dev/null
+++ b/views/dashboard.html
@@ -0,0 +1,35 @@
1{{ define "dashboard" }}
2<html>
3 <head>
4 {{ template "materialize" }}
5 <title>grilist</title>
6 <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
7 </head>
8 <body>
9 <div class="container">
10 <div class="row">
11 {{ range $category := .categories }}
12 <h2>{{ $category.Title }}</h2>
13 {{ range $card := $category.Cards }}
14 <div class="row">
15 <div class="col s12 m6 l4">
16 <div class="card white">
17 <div class="card-content black-text">
18 <span class="card-title">{{ $card.Title }}</span>
19 <p>{{ $card.Description }}</p>
20 </div>
21 <div class="card-action">
22 {{ range $action := $card.Actions }}
23 <a href="{{ $action.Link }}">{{ $action.Name }}</a>
24 {{ end }}
25 </div>
26 </div>
27 </div>
28 </div>
29 {{ end }}
30 {{ end }}
31 </div>
32 </div>
33 </body>
34</html>
35{{ end }} \ No newline at end of file