diff options
author | Steve Manuel <nilslice@gmail.com> | 2016-11-03 00:54:13 -0700 |
---|---|---|
committer | Steve Manuel <nilslice@gmail.com> | 2016-11-03 00:54:13 -0700 |
commit | 9db0046fadcd703d9903c7abd4159ded0730bf3a (patch) | |
tree | 0ac3592b120e175372e3d78276d2cbf8bbf2bccd /system/admin | |
parent | 607f29fd3e61df0b921178995eb12fdee5049f16 (diff) |
simplifying Editable interface by adding Sluggable and Identifiable interfaces, moving relevant interface methods to be implemented by other types and updating caller code to assert the new interface types as needed
Diffstat (limited to 'system/admin')
-rw-r--r-- | system/admin/config/config.go | 9 | ||||
-rw-r--r-- | system/admin/handlers.go | 20 |
2 files changed, 13 insertions, 16 deletions
diff --git a/system/admin/config/config.go b/system/admin/config/config.go index 66f767d..ba8ffb3 100644 --- a/system/admin/config/config.go +++ b/system/admin/config/config.go @@ -18,18 +18,9 @@ type Config struct { CacheInvalidate []string `json:"-"` } -// SetContentID partially implements editor.Editable -func (c *Config) SetContentID(id int) { c.ID = id } - -// ContentID partially implements editor.Editable -func (c *Config) ContentID() int { return c.ID } - // ContentName partially implements editor.Editable func (c *Config) ContentName() string { return c.Name } -// SetSlug partially implements editor.Editable -func (c *Config) SetSlug(slug string) { c.Slug = slug } - // Editor partially implements editor.Editable func (c *Config) Editor() *editor.Editor { return &c.editor } diff --git a/system/admin/handlers.go b/system/admin/handlers.go index 12750e2..18faec9 100644 --- a/system/admin/handlers.go +++ b/system/admin/handlers.go @@ -752,10 +752,10 @@ func postsHandler(res http.ResponseWriter, req *http.Request) { // adminPostListItem is a helper to create the li containing a post. // p is the asserted post as an Editable, t is the Type of the post. // specifier is passed to append a name to a namespace like _pending -func adminPostListItem(p editor.Editable, t, status string) []byte { - s, ok := p.(editor.Sortable) +func adminPostListItem(e editor.Editable, typeName, status string) []byte { + s, ok := e.(editor.Sortable) if !ok { - log.Println("Content type", t, "doesn't implement editor.Sortable") + log.Println("Content type", typeName, "doesn't implement editor.Sortable") post := `<li class="col s12">Error retreiving data. Your data type doesn't implement necessary interfaces.</li>` return []byte(post) } @@ -766,7 +766,7 @@ func adminPostListItem(p editor.Editable, t, status string) []byte { updatedTime := upTime.Format("01/02/06 03:04 PM") publishTime := tsTime.Format("01/02/06") - cid := fmt.Sprintf("%d", p.ContentID()) + cid := fmt.Sprintf("%d", s.ItemID()) switch status { case "public", "": @@ -777,14 +777,14 @@ func adminPostListItem(p editor.Editable, t, status string) []byte { post := ` <li class="col s12"> - <a href="/admin/edit?type=` + t + `&status=` + strings.TrimPrefix(status, "_") + `&id=` + cid + `">` + p.ContentName() + `</a> + <a href="/admin/edit?type=` + typeName + `&status=` + strings.TrimPrefix(status, "_") + `&id=` + cid + `">` + e.ContentName() + `</a> <span class="post-detail">Updated: ` + updatedTime + `</span> <span class="publish-date right">` + publishTime + `</span> <form enctype="multipart/form-data" class="quick-delete-post __ponzu right" action="/admin/edit/delete" method="post"> <span>Delete</span> <input type="hidden" name="id" value="` + cid + `" /> - <input type="hidden" name="type" value="` + t + status + `" /> + <input type="hidden" name="type" value="` + typeName + status + `" /> </form> </li>` @@ -940,7 +940,13 @@ func editHandler(res http.ResponseWriter, req *http.Request) { return } } else { - post.(editor.Editable).SetContentID(-1) + s, ok := post.(content.Identifiable) + if !ok { + log.Println("Content type", typeName, "doesn't implement editor.Sortable") + return + } + s.SetContentID(-1) + } m, err := manager.Manage(post.(editor.Editable), t) |