diff options
-rw-r--r-- | modules/lists/lists.go | 37 | ||||
-rw-r--r-- | views/create_list.html | 47 | ||||
-rw-r--r-- | views/navbar.html | 1 |
3 files changed, 85 insertions, 0 deletions
diff --git a/modules/lists/lists.go b/modules/lists/lists.go index 2b1ced3..ae1ec65 100644 --- a/modules/lists/lists.go +++ b/modules/lists/lists.go | |||
@@ -61,6 +61,8 @@ func (m *Module) Init(g *grilist.Grilist) { | |||
61 | m.grils = grilsModule | 61 | m.grils = grilsModule |
62 | m.g.Router.GET("/list/:id", m.viewList) | 62 | m.g.Router.GET("/list/:id", m.viewList) |
63 | m.g.Router.POST("/list/:id", m.addGrilToList) | 63 | m.g.Router.POST("/list/:id", m.addGrilToList) |
64 | m.g.Router.GET("/new/list", m.displayCreateList) | ||
65 | m.g.Router.POST("/new/list", m.createList) | ||
64 | } | 66 | } |
65 | 67 | ||
66 | func (m *Module) getListGrils(list *List) error { | 68 | func (m *Module) getListGrils(list *List) error { |
@@ -260,6 +262,41 @@ func (m *Module) addGrilToList(w http.ResponseWriter, r *http.Request, p httprou | |||
260 | http.Error(w, "not implemented", 500) | 262 | http.Error(w, "not implemented", 500) |
261 | } | 263 | } |
262 | 264 | ||
265 | func (m *Module) displayCreateList(w http.ResponseWriter, r *http.Request, p httprouter.Params) { | ||
266 | user, _ := m.g.Charakterin.GetUserFromRequest(r) | ||
267 | |||
268 | data := m.g.Renderer.DefaultData() | ||
269 | data["user"] = user | ||
270 | |||
271 | m.g.Renderer.RenderPage("create_list", w, data) | ||
272 | } | ||
273 | |||
274 | func (m *Module) createList(w http.ResponseWriter, r *http.Request, p httprouter.Params) { | ||
275 | user, err := m.g.Charakterin.GetUserFromRequest(r) | ||
276 | if err != nil { | ||
277 | log.Println(err) | ||
278 | http.Error(w, "500", http.StatusInternalServerError) | ||
279 | return | ||
280 | } | ||
281 | |||
282 | values, err := readBody(r) | ||
283 | if err != nil { | ||
284 | log.Println(err) | ||
285 | http.Error(w, "500", http.StatusInternalServerError) | ||
286 | return | ||
287 | } | ||
288 | |||
289 | var id int | ||
290 | err = m.g.DB.QueryRow(`INSERT INTO grilist.lists(user_id, name, description) VALUES($1, $2, $3) RETURNING id`, user.ID, values.Get("name"), values.Get("description")).Scan(&id) | ||
291 | if err != nil { | ||
292 | log.Println(err) | ||
293 | http.Error(w, "500", http.StatusInternalServerError) | ||
294 | return | ||
295 | } | ||
296 | |||
297 | http.Redirect(w, r, fmt.Sprintf("/list/%d", id), 302) | ||
298 | } | ||
299 | |||
263 | // New erstellt eine neue Instanz des Modules | 300 | // New erstellt eine neue Instanz des Modules |
264 | func New() *Module { | 301 | func New() *Module { |
265 | return &Module{} | 302 | return &Module{} |
diff --git a/views/create_list.html b/views/create_list.html new file mode 100644 index 0000000..375dddd --- /dev/null +++ b/views/create_list.html | |||
@@ -0,0 +1,47 @@ | |||
1 | {{ define "create_list" }} | ||
2 | <html> | ||
3 | <head> | ||
4 | {{ template "materialize" }} | ||
5 | <title>grilist</title> | ||
6 | <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet"> | ||
7 | <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no"> | ||
8 | </head> | ||
9 | <body> | ||
10 | {{ template "navbar" . }} | ||
11 | <div class="container"> | ||
12 | <div class="row"> | ||
13 | <div class="col s12 m8 offset-m2 l6 offset-l3"> | ||
14 | {{ if .error }} | ||
15 | <div class="col s12 m8 offset-m2"> | ||
16 | <div class="card red lighten-2"> | ||
17 | <div class="card-content white-text"> | ||
18 | <span class="card-title">Fehler</span> | ||
19 | <p>Es gab einen Fehler: {{ .error }}</p> | ||
20 | </div> | ||
21 | </div> | ||
22 | </div> | ||
23 | {{ end }} | ||
24 | |||
25 | <form method="POST" name="create-list" action=""> | ||
26 | <div class="input-field col s12"> | ||
27 | <i class="material-icons prefix">list</i> | ||
28 | <input name="name" type="text" placeholder="Name" class="validate"/> | ||
29 | </div> | ||
30 | <div class="input-field col s12"> | ||
31 | <textarea id="description" name="description" class="materialize-textarea" style="padding-top: 32px"></textarea> | ||
32 | <label for="description">Beschreibung</label> | ||
33 | </div> | ||
34 | <div class="row col s12"> | ||
35 | <div class="right-align"> | ||
36 | <button class="btn waves-effect waves-light purple lighten-2" type="submit" name="action"> | ||
37 | Erstellen <i class="material-icons right">send</i> | ||
38 | </button> | ||
39 | </div> | ||
40 | </div> | ||
41 | </form> | ||
42 | </div> | ||
43 | </div> | ||
44 | </div> | ||
45 | </body> | ||
46 | </html> | ||
47 | {{ end }} | ||
diff --git a/views/navbar.html b/views/navbar.html index 8905a1d..c456112 100644 --- a/views/navbar.html +++ b/views/navbar.html | |||
@@ -4,6 +4,7 @@ | |||
4 | <a href="/" class="brand-logo center">grilist</a> | 4 | <a href="/" class="brand-logo center">grilist</a> |
5 | <ul id="nav-mobile" class="right hide-on-med-and-down"> | 5 | <ul id="nav-mobile" class="right hide-on-med-and-down"> |
6 | {{ if .user }} | 6 | {{ if .user }} |
7 | <li><a href="/new/list">Liste erstellen</a></li> | ||
7 | <li><a href="/">{{ .user.GetName }}</a></li> | 8 | <li><a href="/">{{ .user.GetName }}</a></li> |
8 | <li><a href="/logout">Ausloggen</a></li> | 9 | <li><a href="/logout">Ausloggen</a></li> |
9 | {{ else }} | 10 | {{ else }} |