diff options
-rw-r--r-- | assets/css/gril.css | 9 | ||||
-rw-r--r-- | dashboard.go | 6 | ||||
-rw-r--r-- | frontend/renderer.go | 13 | ||||
-rw-r--r-- | main.go | 6 | ||||
-rw-r--r-- | modules/grils/gril.go | 1 | ||||
-rw-r--r-- | modules/grils/grils.go | 24 | ||||
-rw-r--r-- | modules/lists/lists.go | 68 | ||||
-rw-r--r-- | views/dashboard.html | 10 | ||||
-rw-r--r-- | views/gril.html | 42 | ||||
-rw-r--r-- | views/navbar.html | 3 |
10 files changed, 131 insertions, 51 deletions
diff --git a/assets/css/gril.css b/assets/css/gril.css index 409ef51..5b5bd84 100644 --- a/assets/css/gril.css +++ b/assets/css/gril.css | |||
@@ -1,4 +1,13 @@ | |||
1 | h1 > small { | 1 | h1 > small { |
2 | padding-left: 8px; | 2 | padding-left: 8px; |
3 | font-size: 50%; | 3 | font-size: 50%; |
4 | } | ||
5 | |||
6 | .card-title.big { | ||
7 | font-size: 36px !important; | ||
8 | } | ||
9 | |||
10 | .card-content.center-big { | ||
11 | padding-top: 9px; | ||
12 | padding-bottom: 9px; | ||
4 | } \ No newline at end of file | 13 | } \ No newline at end of file |
diff --git a/dashboard.go b/dashboard.go index 63dcdfc..0ca38ef 100644 --- a/dashboard.go +++ b/dashboard.go | |||
@@ -7,11 +7,7 @@ import ( | |||
7 | ) | 7 | ) |
8 | 8 | ||
9 | func viewDashboard(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { | 9 | func viewDashboard(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { |
10 | user, err := app.Charakterin.GetUserFromRequest(r) | 10 | user, _ := app.Charakterin.GetUserFromRequest(r) |
11 | if err != nil { | ||
12 | http.Redirect(w, r, "/", 302) | ||
13 | return | ||
14 | } | ||
15 | 11 | ||
16 | var categories []grilist.DashboardCategory | 12 | var categories []grilist.DashboardCategory |
17 | 13 | ||
diff --git a/frontend/renderer.go b/frontend/renderer.go index e9b9931..a3aa83d 100644 --- a/frontend/renderer.go +++ b/frontend/renderer.go | |||
@@ -7,8 +7,9 @@ import ( | |||
7 | 7 | ||
8 | // Action ist die Aktion auf einer Card. | 8 | // Action ist die Aktion auf einer Card. |
9 | type Action struct { | 9 | type Action struct { |
10 | Name string | 10 | Name string |
11 | Link string | 11 | Link string |
12 | Disabled bool | ||
12 | } | 13 | } |
13 | 14 | ||
14 | // Card ist eine Karte im Materialize-Design. | 15 | // Card ist eine Karte im Materialize-Design. |
@@ -41,8 +42,14 @@ func (r *Renderer) SetDefaultData(data map[string]interface{}) { | |||
41 | 42 | ||
42 | // New erstellt einen neuen Renderer und sucht alle Templates aus dem gegebenen pfad. | 43 | // New erstellt einen neuen Renderer und sucht alle Templates aus dem gegebenen pfad. |
43 | func New(path string) *Renderer { | 44 | func New(path string) *Renderer { |
45 | // Custom Template Funcs | ||
46 | funcMap := template.FuncMap{ | ||
47 | "html": func(in string) template.HTML { | ||
48 | return template.HTML(in) | ||
49 | }, | ||
50 | } | ||
44 | r := &Renderer{ | 51 | r := &Renderer{ |
45 | template.Must(template.ParseGlob(path + "/*")), | 52 | template.Must(template.ParseGlob(path + "/*")).Funcs(funcMap), |
46 | make(map[string]interface{}), | 53 | make(map[string]interface{}), |
47 | } | 54 | } |
48 | 55 | ||
@@ -19,12 +19,6 @@ import ( | |||
19 | var app *grilist.Grilist | 19 | var app *grilist.Grilist |
20 | 20 | ||
21 | func index(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { | 21 | func index(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { |
22 | _, err := app.Charakterin.GetUserFromRequest(r) | ||
23 | if err != nil { | ||
24 | http.Redirect(w, r, "/login", 302) | ||
25 | return | ||
26 | } | ||
27 | |||
28 | http.Redirect(w, r, "/dashboard", 302) | 22 | http.Redirect(w, r, "/dashboard", 302) |
29 | } | 23 | } |
30 | 24 | ||
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 |
diff --git a/views/dashboard.html b/views/dashboard.html index f2d410d..0551285 100644 --- a/views/dashboard.html +++ b/views/dashboard.html | |||
@@ -16,12 +16,16 @@ | |||
16 | <div class="col s12 m6 l4"> | 16 | <div class="col s12 m6 l4"> |
17 | <div class="card white"> | 17 | <div class="card white"> |
18 | <div class="card-content black-text"> | 18 | <div class="card-content black-text"> |
19 | <span class="card-title">{{ $card.Title }}</span> | 19 | <span class="card-title">{{ $card.Title | html }}</span> |
20 | <p>{{ $card.Description }}</p> | 20 | <p>{{ $card.Description | html }}</p> |
21 | </div> | 21 | </div> |
22 | <div class="card-action"> | 22 | <div class="card-action"> |
23 | {{ range $action := $card.Actions }} | 23 | {{ range $action := $card.Actions }} |
24 | <a href="{{ $action.Link }}">{{ $action.Name }}</a> | 24 | {{ if $action.Disabled }} |
25 | <span>{{ $action.Name | html }}</span> | ||
26 | {{ else }} | ||
27 | <a href="{{ $action.Link }}">{{ $action.Name | html }}</a> | ||
28 | {{ end }} | ||
25 | {{ end }} | 29 | {{ end }} |
26 | </div> | 30 | </div> |
27 | </div> | 31 | </div> |
diff --git a/views/gril.html b/views/gril.html index 3983061..c7ecbdc 100644 --- a/views/gril.html +++ b/views/gril.html | |||
@@ -16,6 +16,48 @@ | |||
16 | {{ $tag }} | 16 | {{ $tag }} |
17 | </div> | 17 | </div> |
18 | {{ end }} | 18 | {{ end }} |
19 | <br /> | ||
20 | <br /> | ||
21 | <div class="row"> | ||
22 | {{ if $gril.Birthday.Valid }} | ||
23 | <div class="col s6 m2 l2"> | ||
24 | <div class="card"> | ||
25 | <div class="card-content purple-text text-lighten-2 center-align"> | ||
26 | <span class="card-title big">{{ $gril.Birthday.Value}}</span> | ||
27 | <p>geburtstag</p> | ||
28 | </div> | ||
29 | </div> | ||
30 | </div> | ||
31 | {{ else if $gril.Age.Valid }} | ||
32 | <div class="col s6 m2 l2"> | ||
33 | <div class="card"> | ||
34 | <div class="card-content purple-text text-lighten-2 center-align"> | ||
35 | <span class="card-title big">{{ $gril.Age.Value }}</span> | ||
36 | <p>jahre alt</p> | ||
37 | </div> | ||
38 | </div> | ||
39 | </div> | ||
40 | {{ end }} | ||
41 | {{ if $gril.Lists }} | ||
42 | <div class="col s6 m2 l2"> | ||
43 | <div class="card"> | ||
44 | <div class="card-content center-big purple-text text-lighten-2 center-align"> | ||
45 | <p>in</p> | ||
46 | <span class="card-title big">{{ len $gril.Lists}}</span> | ||
47 | <p>liste{{ if ne (len $gril.Lists) 1 }}n{{ end }}</p> | ||
48 | </div> | ||
49 | </div> | ||
50 | </div> | ||
51 | {{ end }} | ||
52 | <div class="col s12 m4 l4"> | ||
53 | <div class="card"> | ||
54 | <div class="card-content purple-text text-lighten-2 center-align"> | ||
55 | <span class="card-title big">{{ $gril.UpdatedAt.Format "Jan 02, 2006" }}</span> | ||
56 | <p>aktualisiert</p> | ||
57 | </div> | ||
58 | </div> | ||
59 | </div> | ||
60 | </div> | ||
19 | </div> | 61 | </div> |
20 | </body> | 62 | </body> |
21 | </html> | 63 | </html> |
diff --git a/views/navbar.html b/views/navbar.html index c4bbace..70911e4 100644 --- a/views/navbar.html +++ b/views/navbar.html | |||
@@ -6,6 +6,9 @@ | |||
6 | {{ if .user }} | 6 | {{ if .user }} |
7 | <li><a href="/">{{ .user.Name }}</a></li> | 7 | <li><a href="/">{{ .user.Name }}</a></li> |
8 | <li><a href="/logout">Ausloggen</a></li> | 8 | <li><a href="/logout">Ausloggen</a></li> |
9 | {{ else }} | ||
10 | <li><a href="/login">Einloggen</a></li> | ||
11 | <li><a href="/register">Registrieren</a></li> | ||
9 | {{ end }} | 12 | {{ end }} |
10 | </ul> | 13 | </ul> |
11 | </div> | 14 | </div> |