diff options
author | Steve Manuel <nilslice@gmail.com> | 2017-05-15 03:49:49 -0700 |
---|---|---|
committer | Steve Manuel <nilslice@gmail.com> | 2017-05-15 03:49:49 -0700 |
commit | 8f12938f28c0637a9261c7fcb4b0e311b8ba3b40 (patch) | |
tree | a0f521025b809979085164c8e8e843b650c55c6f /system/admin/handlers.go | |
parent | 0cf8aa550a3da63cb1509678bf5add0d73925546 (diff) |
adding csv format interface and handler impl
Diffstat (limited to 'system/admin/handlers.go')
-rw-r--r-- | system/admin/handlers.go | 49 |
1 files changed, 45 insertions, 4 deletions
diff --git a/system/admin/handlers.go b/system/admin/handlers.go index 23c7e50..2a76e58 100644 --- a/system/admin/handlers.go +++ b/system/admin/handlers.go @@ -13,6 +13,7 @@ import ( "time" "github.com/ponzu-cms/ponzu/management/editor" + "github.com/ponzu-cms/ponzu/management/format" "github.com/ponzu-cms/ponzu/management/manager" "github.com/ponzu-cms/ponzu/system/addon" "github.com/ponzu-cms/ponzu/system/admin/config" @@ -1492,8 +1493,24 @@ func contentsHandler(res http.ResponseWriter, req *http.Request) { </script> ` - btn := `<div class="col s3"><a href="/admin/edit?type=` + t + `" class="btn new-post waves-effect waves-light">New ` + t + `</a></div></div>` - html = html + b.String() + script + btn + btn := `<div class="col s3"> + <a href="/admin/edit?type=` + t + `" class="btn new-post waves-effect waves-light"> + New ` + t + ` + </a> + </div>` + html = html + b.String() + btn + + if _, ok := pt.(format.CSVFormattable); ok { + btn = `<div class="col s3"> + <a href="/admin/edit/export?type=` + t + `&format=csv" class="green darken-4 btn export-post waves-effect waves-light"> + <i class="material-icons left">system_update_alt</i> + .CSV + </a> + </div>` + html = html + b.String() + btn + } + + html += `</div>` + script adminView, err := Admin([]byte(html)) if err != nil { @@ -2422,7 +2439,15 @@ func searchHandler(res http.ResponseWriter, req *http.Request) { posts := db.ContentAll(t + specifier) b := &bytes.Buffer{} - p := item.Types[t]().(editor.Editable) + pt, ok := item.Types[t] + if !ok { + res.WriteHeader(http.StatusBadRequest) + return + } + + post := pt() + + p := post.(editor.Editable) html := `<div class="col s9 card"> <div class="card-content"> @@ -2499,9 +2524,25 @@ func searchHandler(res http.ResponseWriter, req *http.Request) { return } - btn := `<div class="col s3"><a href="/admin/edit?type=` + t + `" class="btn new-post waves-effect waves-light">New ` + t + `</a></div></div>` + btn := `<div class="col s3"> + <a href="/admin/edit?type=` + t + `" class="btn new-post waves-effect waves-light"> + New ` + t + ` + </a> + </div>` html = html + b.String() + btn + if _, ok := post.(format.CSVFormattable); ok { + btn = `<div class="col s3"> + <a href="/admin/edit/export?type=` + t + `&format=csv" class="green darken-4 btn export-post waves-effect waves-light"> + <i class="material-icons left">system_update_alt</i> + .CSV + </a> + </div>` + html = html + b.String() + btn + } + + html += `</div>` + adminView, err := Admin([]byte(html)) if err != nil { log.Println(err) |