diff options
author | Steve Manuel <nilslice@gmail.com> | 2017-05-15 12:18:06 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-15 12:18:06 -0700 |
commit | f176e7d98f0facbf0ccfac08eb4d7aea03c53c8b (patch) | |
tree | f11aa7e399e354d8f613d18ea10f14cc8e405773 /system/admin/handlers.go | |
parent | 0cf8aa550a3da63cb1509678bf5add0d73925546 (diff) | |
parent | 0ee16cc099c4fea518e9e57ff4b5166aba54ee34 (diff) |
Merge pull request #142 from ponzu-cms/ponzu-dev
[core] add CSVFormattable interface to export CSV formatted content
Diffstat (limited to 'system/admin/handlers.go')
-rw-r--r-- | system/admin/handlers.go | 43 |
1 files changed, 39 insertions, 4 deletions
diff --git a/system/admin/handlers.go b/system/admin/handlers.go index 23c7e50..a950633 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,20 @@ 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>` + + if _, ok := pt.(format.CSVFormattable); ok { + btn += `<br/> + <a href="/admin/contents/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>` + } + + html += b.String() + script + btn + `</div></div>` adminView, err := Admin([]byte(html)) if err != nil { @@ -2422,7 +2435,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 +2520,23 @@ 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>` html = html + b.String() + btn + if _, ok := post.(format.CSVFormattable); ok { + btn = `<br/> + <a href="/admin/contents/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>` + html = html + b.String() + btn + } + + html += `</div></div>` + adminView, err := Admin([]byte(html)) if err != nil { log.Println(err) |