From 6148ddb2473f00fb74b135e00127bbadd2062861 Mon Sep 17 00:00:00 2001 From: Steve Manuel Date: Thu, 13 Oct 2016 12:14:53 -0700 Subject: fixing style and layout for delete button --- system/admin/static/dashboard/css/admin.css | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'system') diff --git a/system/admin/static/dashboard/css/admin.css b/system/admin/static/dashboard/css/admin.css index 888dbf1..7da4154 100644 --- a/system/admin/static/dashboard/css/admin.css +++ b/system/admin/static/dashboard/css/admin.css @@ -154,6 +154,10 @@ footer p { color: #9e9e9e; } +.post-controls .save-post { + margin-left: 10px; +} + /* OVERRIDE Bootstrap + Materialize conflicts */ .iso-texteditor.input-field label { -- cgit v1.2.3 From 8d569ebc74b932fab0e1a725febddf92d43d2892 Mon Sep 17 00:00:00 2001 From: Steve Manuel Date: Thu, 13 Oct 2016 12:45:33 -0700 Subject: adding admin server handler for deleting content --- system/admin/handlers.go | 25 +++++++++++++++++++++++++ system/admin/server.go | 1 + system/db/content.go | 18 ++++++++++++++++++ 3 files changed, 44 insertions(+) (limited to 'system') diff --git a/system/admin/handlers.go b/system/admin/handlers.go index 2be8d8e..f7c3cca 100644 --- a/system/admin/handlers.go +++ b/system/admin/handlers.go @@ -513,6 +513,31 @@ func editHandler(res http.ResponseWriter, req *http.Request) { } } +func deleteHandler(res http.ResponseWriter, req *http.Request) { + if req.Method != http.MethodPost { + res.WriteHeader(http.StatusMethodNotAllowed) + return + } + + q := req.URL.Query() + id := q.Get("id") + t := q.Get("type") + + if id == "" || t == "" { + res.WriteHeader(http.StatusBadRequest) + return + } + + err := db.DeleteContent(t + ":" + i) + if err != nil { + res.WriteHeader(http.StatusInternalServerError) + return + } + + redir := strings.TrimSuffix(req.URL.Scheme+req.URL.Host+req.URL.Path, "/delete") + http.Redirect(res, req, redir, http.StatusFound) +} + func editUploadHandler(res http.ResponseWriter, req *http.Request) { if req.Method != http.MethodPost { res.WriteHeader(http.StatusMethodNotAllowed) diff --git a/system/admin/server.go b/system/admin/server.go index 6f4a96e..b3b128d 100644 --- a/system/admin/server.go +++ b/system/admin/server.go @@ -25,6 +25,7 @@ func Run() { http.HandleFunc("/admin/posts/search", user.Auth(searchHandler)) http.HandleFunc("/admin/edit", user.Auth(editHandler)) + http.HandleFunc("/admin/edit/delete", user.Auth(deleteHandler)) http.HandleFunc("/admin/edit/upload", user.Auth(editUploadHandler)) pwd, err := os.Getwd() diff --git a/system/db/content.go b/system/db/content.go index d637085..1e5b95a 100644 --- a/system/db/content.go +++ b/system/db/content.go @@ -137,6 +137,24 @@ func postToJSON(ns string, data url.Values) ([]byte, error) { return j, nil } +// DeleteContent removes an item from the database. Deleting a non-existent item +// will return a nil error. +func DeleteContent(target string) error { + t := strings.Split(target, ":") + ns, id := t[0], t[1] + + err := store.Update(func(tx *bolt.Tx) error { + tx.Bucket([]byte(ns)).Delete([]byte(id)) + return nil + }) + + if err != nil { + return err + } + + return nil +} + // Content retrives one item from the database. Non-existent values will return an empty []byte // The `target` argument is a string made up of namespace:id (string:int) func Content(target string) ([]byte, error) { -- cgit v1.2.3 From 76040e1c5cd9b00db383cefeb488af7004c0df02 Mon Sep 17 00:00:00 2001 From: Steve Manuel Date: Thu, 13 Oct 2016 12:46:35 -0700 Subject: fixing typo --- system/admin/handlers.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/admin/handlers.go b/system/admin/handlers.go index f7c3cca..8b09e3d 100644 --- a/system/admin/handlers.go +++ b/system/admin/handlers.go @@ -528,7 +528,7 @@ func deleteHandler(res http.ResponseWriter, req *http.Request) { return } - err := db.DeleteContent(t + ":" + i) + err := db.DeleteContent(t + ":" + id) if err != nil { res.WriteHeader(http.StatusInternalServerError) return -- cgit v1.2.3 From 29d36cd2242637236c9473d110dfaf39b8595bb3 Mon Sep 17 00:00:00 2001 From: Steve Manuel Date: Thu, 13 Oct 2016 12:51:21 -0700 Subject: modify to read multipart form post --- system/admin/handlers.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'system') diff --git a/system/admin/handlers.go b/system/admin/handlers.go index 8b09e3d..b7d6ba0 100644 --- a/system/admin/handlers.go +++ b/system/admin/handlers.go @@ -519,16 +519,21 @@ func deleteHandler(res http.ResponseWriter, req *http.Request) { return } - q := req.URL.Query() - id := q.Get("id") - t := q.Get("type") + err := req.ParseMultipartForm(1024 * 1024 * 4) // maxMemory 4MB + if err != nil { + res.WriteHeader(http.StatusInternalServerError) + return + } + + id := req.FormValue("id") + t := req.FormValue("type") if id == "" || t == "" { res.WriteHeader(http.StatusBadRequest) return } - err := db.DeleteContent(t + ":" + id) + err = db.DeleteContent(t + ":" + id) if err != nil { res.WriteHeader(http.StatusInternalServerError) return -- cgit v1.2.3 From fd8aa373e6f408a30897e414cf98289b1e247d42 Mon Sep 17 00:00:00 2001 From: Steve Manuel Date: Thu, 13 Oct 2016 12:54:53 -0700 Subject: updating URL redirect after delete --- system/admin/handlers.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'system') diff --git a/system/admin/handlers.go b/system/admin/handlers.go index b7d6ba0..0dfeaa4 100644 --- a/system/admin/handlers.go +++ b/system/admin/handlers.go @@ -539,7 +539,8 @@ func deleteHandler(res http.ResponseWriter, req *http.Request) { return } - redir := strings.TrimSuffix(req.URL.Scheme+req.URL.Host+req.URL.Path, "/delete") + redir := strings.TrimSuffix(req.URL.Scheme+req.URL.Host+req.URL.Path, "/edit/delete") + redir = redir + "posts?type=" + t http.Redirect(res, req, redir, http.StatusFound) } -- cgit v1.2.3 From 468d9fb3355bd7771af3592becb201b6e9b1e68b Mon Sep 17 00:00:00 2001 From: Steve Manuel Date: Thu, 13 Oct 2016 12:57:40 -0700 Subject: fixing url --- system/admin/handlers.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/admin/handlers.go b/system/admin/handlers.go index 0dfeaa4..d492335 100644 --- a/system/admin/handlers.go +++ b/system/admin/handlers.go @@ -540,7 +540,7 @@ func deleteHandler(res http.ResponseWriter, req *http.Request) { } redir := strings.TrimSuffix(req.URL.Scheme+req.URL.Host+req.URL.Path, "/edit/delete") - redir = redir + "posts?type=" + t + redir = redir + "/posts?type=" + t http.Redirect(res, req, redir, http.StatusFound) } -- cgit v1.2.3