diff options
Diffstat (limited to 'system')
-rw-r--r-- | system/admin/admin.go | 14 | ||||
-rw-r--r-- | system/admin/auth.go | 11 | ||||
-rw-r--r-- | system/admin/config.go | 5 | ||||
-rw-r--r-- | system/db/query.go | 30 |
4 files changed, 58 insertions, 2 deletions
diff --git a/system/admin/admin.go b/system/admin/admin.go index bbc34cf..8febbf7 100644 --- a/system/admin/admin.go +++ b/system/admin/admin.go @@ -4,6 +4,7 @@ package admin import ( "bytes" + "fmt" "html/template" "github.com/nilslice/cms/content" @@ -13,6 +14,17 @@ const adminHTML = `<!doctype html> <html> <head> <title>CMS</title> + <style type="text/css"> + label { + display: block; + margin-top: 11px; + } + input { + display: block; + margin-bottom: 11px; + padding: 2px; + } + </style> </head> <body> <h1><a href="/admin">CMS</a></h1> @@ -43,6 +55,8 @@ func Admin(manager []byte) []byte { Subview: template.HTML(manager), } + fmt.Println(a.Types) + buf := &bytes.Buffer{} tmpl := template.Must(template.New("admin").Parse(adminHTML)) tmpl.Execute(buf, a) diff --git a/system/admin/auth.go b/system/admin/auth.go new file mode 100644 index 0000000..153a31a --- /dev/null +++ b/system/admin/auth.go @@ -0,0 +1,11 @@ +package admin + +// Session ... +type Session struct { + User + token string +} + +// User ... +type User struct { +} diff --git a/system/admin/config.go b/system/admin/config.go new file mode 100644 index 0000000..e067299 --- /dev/null +++ b/system/admin/config.go @@ -0,0 +1,5 @@ +package admin + +// Config represents the confirgurable options of the system +type Config struct { +} diff --git a/system/db/query.go b/system/db/query.go index fd526f8..80a3412 100644 --- a/system/db/query.go +++ b/system/db/query.go @@ -12,6 +12,8 @@ import ( "github.com/boltdb/bolt" "github.com/gorilla/schema" "github.com/nilslice/cms/content" + "github.com/nilslice/cms/management/editor" + "github.com/nilslice/cms/management/manager" ) var store *bolt.DB @@ -22,6 +24,19 @@ func init() { if err != nil { log.Fatal(err) } + + // initialize db with all content type buckets + store.Update(func(tx *bolt.Tx) error { + for t := range content.Types { + _, err := tx.CreateBucketIfNotExists([]byte(t)) + if err != nil { + return err + } + } + + return nil + }) + } // Set inserts or updates values in the database. @@ -30,8 +45,13 @@ func Set(target string, data url.Values) (int, error) { t := strings.Split(target, ":") ns, id := t[0], t[1] - // check if content has an id, and if not get new one from target bucket - if len(id) == 0 { + // check if content id == -1 (indicating new post). + // if so, run an insert which will assign the next auto incremented int. + // this is done because boltdb begins its bucket auto increment value at 0, + // which is the zero-value of an int in the Item struct field for ID. + // this is a problem when the original first post (with auto ID = 0) gets + // overwritten by any new post, originally having no ID, defauting to 0. + if id == "-1" { return insert(ns, data) } @@ -125,6 +145,12 @@ func toJSON(ns string, data url.Values) ([]byte, error) { return nil, err } + slug, err := manager.Slug(post.(editor.Editable)) + if err != nil { + return nil, err + } + post.(editor.Editable).SetSlug(slug) + // marshall content struct to json for db storage j, err := json.Marshal(post) if err != nil { |