From c178f2e403b0b711d8aa3c0155d1368827f88afd Mon Sep 17 00:00:00 2001 From: Steve Manuel Date: Fri, 28 Oct 2016 12:58:25 -0700 Subject: adding some clean up code and UI toggle for future external vs. internal posted content --- system/admin/handlers.go | 55 +++++++++++++++++++++++++++++++++++++++++++++--- system/db/content.go | 2 -- system/db/init.go | 18 +++++++++++----- 3 files changed, 65 insertions(+), 10 deletions(-) (limited to 'system') diff --git a/system/admin/handlers.go b/system/admin/handlers.go index d508ef2..8cbfe0a 100644 --- a/system/admin/handlers.go +++ b/system/admin/handlers.go @@ -15,6 +15,7 @@ import ( "github.com/bosssauce/ponzu/management/manager" "github.com/bosssauce/ponzu/system/admin/config" "github.com/bosssauce/ponzu/system/admin/user" + "github.com/bosssauce/ponzu/system/api" "github.com/bosssauce/ponzu/system/db" "github.com/nilslice/jwt" @@ -535,7 +536,21 @@ func postsHandler(res http.ResponseWriter, req *http.Request) { posts := db.ContentAll(t + "_sorted") b := &bytes.Buffer{} - p, ok := content.Types[t]().(editor.Editable) + + if _, ok := content.Types[t]; !ok { + res.WriteHeader(http.StatusBadRequest) + errView, err := Error405() + if err != nil { + return + } + + res.Write(errView) + return + } + + pt := content.Types[t]() + + p, ok := pt.(editor.Editable) if !ok { res.WriteHeader(http.StatusInternalServerError) errView, err := Error500() @@ -547,6 +562,12 @@ func postsHandler(res http.ResponseWriter, req *http.Request) { return } + var hasExt bool + ext, ok := pt.(api.Externalable) + if ok { + hasExt = true + } + html := `
@@ -604,8 +625,36 @@ func postsHandler(res http.ResponseWriter, req *http.Request) {
-
-
` + if hasExt { + created := q.Get("created") + switch created { + q.Set("created", "internal") + intURL := strings.TrimPrefix(req.URL.String(), req.URL.Scheme+req.URL.Host) + + q.Set("created", "external") + extURL := strings.TrimPrefix(req.URL.String(), req.URL.Scheme+req.URL.Host) + + case "internal": + + html += `
+ Created by: + Internal +  |  + External +
` + + case "external": + html += `
+ Created by: + Internal +  |  + External +
` + } + + } + html += `