From 7b55b66d905398d2521e881c28db72c01bd93dbf Mon Sep 17 00:00:00 2001 From: Steve Manuel Date: Thu, 1 Dec 2016 11:44:55 -0800 Subject: adding example html for admin content pagination --- system/admin/handlers.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'system') diff --git a/system/admin/handlers.go b/system/admin/handlers.go index 7b8bfae..c462625 100644 --- a/system/admin/handlers.go +++ b/system/admin/handlers.go @@ -911,7 +911,21 @@ func postsHandler(res http.ResponseWriter, req *http.Request) { html += ``)) + b.Write([]byte(``)) + + pagination := ` + + ` + + b.Write([]byte(pagination + ``)) script := ` `, prevStatus, prevURL, start, end, total, nextStatus, nextURL) b.Write([]byte(pagination + ``)) -- cgit v1.2.3 From 3f07c202373d4d31d74c5430fd83bbac6d07fdde Mon Sep 17 00:00:00 2001 From: Steve Manuel Date: Mon, 5 Dec 2016 11:15:33 -0800 Subject: switch count and total in reassignment --- system/admin/handlers.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/admin/handlers.go b/system/admin/handlers.go index c505914..765ea6f 100644 --- a/system/admin/handlers.go +++ b/system/admin/handlers.go @@ -971,7 +971,7 @@ func postsHandler(res http.ResponseWriter, req *http.Request) { start := 1 + count*offset end := start + count - 1 if total < count { - total = count + count = total } pagination := fmt.Sprintf(` -- cgit v1.2.3 From 4439971245ee470fca74f2e0c07d2f049290fce9 Mon Sep 17 00:00:00 2001 From: Steve Manuel Date: Mon, 5 Dec 2016 11:17:18 -0800 Subject: evaluating and reassigning count earlier to cascade to lower calcs which depend on the value --- system/admin/handlers.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/admin/handlers.go b/system/admin/handlers.go index 765ea6f..fb4d555 100644 --- a/system/admin/handlers.go +++ b/system/admin/handlers.go @@ -968,11 +968,12 @@ func postsHandler(res http.ResponseWriter, req *http.Request) { urlFmt := req.URL.Path + "?count=%d&offset=%d&status=%s&type=%s" prevURL := fmt.Sprintf(urlFmt, count, offset-1, status, t) nextURL := fmt.Sprintf(urlFmt, count, offset+1, status, t) - start := 1 + count*offset - end := start + count - 1 + // total may be less than 10 (default count), so reset count to match total if total < count { count = total } + start := 1 + count*offset + end := start + count - 1 pagination := fmt.Sprintf(`
    -- cgit v1.2.3 From 0113eb3f35c7a5e9edf12815736d1e1233b4388b Mon Sep 17 00:00:00 2001 From: Steve Manuel Date: Mon, 5 Dec 2016 11:21:42 -0800 Subject: moving script to pre-defined script element, moving total & count comparison higher again to be evaluated earlier --- system/admin/handlers.go | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'system') diff --git a/system/admin/handlers.go b/system/admin/handlers.go index fb4d555..81b8723 100644 --- a/system/admin/handlers.go +++ b/system/admin/handlers.go @@ -956,10 +956,15 @@ func postsHandler(res http.ResponseWriter, req *http.Request) { statusDisabled := "disabled" prevStatus := "" nextStatus := "" + // total may be less than 10 (default count), so reset count to match total + if total < count { + count = total + } + // nothing previous to current list if offset == 0 { prevStatus = statusDisabled } - + // nothing after current list if offset*count >= total { nextStatus = statusDisabled } @@ -968,10 +973,6 @@ func postsHandler(res http.ResponseWriter, req *http.Request) { urlFmt := req.URL.Path + "?count=%d&offset=%d&status=%s&type=%s" prevURL := fmt.Sprintf(urlFmt, count, offset-1, status, t) nextURL := fmt.Sprintf(urlFmt, count, offset+1, status, t) - // total may be less than 10 (default count), so reset count to match total - if total < count { - count = total - } start := 1 + count*offset end := start + count - 1 @@ -981,14 +982,6 @@ func postsHandler(res http.ResponseWriter, req *http.Request) {
  • %d to %d of %d
  • chevron_right
- `, prevStatus, prevURL, start, end, total, nextStatus, nextURL) b.Write([]byte(pagination + ``)) @@ -1003,6 +996,13 @@ func postsHandler(res http.ResponseWriter, req *http.Request) { } }); }); + + // disable link from being clicked if parent is 'disabled' + $(function() { + $('ul.pagination li.disabled a').on('click', function(e) { + e.preventDefault(); + }); + }); ` -- cgit v1.2.3 From 579cc9259a7761610a9997f2e0f390716b98e454 Mon Sep 17 00:00:00 2001 From: Steve Manuel Date: Mon, 5 Dec 2016 11:41:12 -0800 Subject: updating offset math to include +1 as it is comparing the next set, html updates --- system/admin/handlers.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'system') diff --git a/system/admin/handlers.go b/system/admin/handlers.go index 81b8723..25de560 100644 --- a/system/admin/handlers.go +++ b/system/admin/handlers.go @@ -965,7 +965,7 @@ func postsHandler(res http.ResponseWriter, req *http.Request) { prevStatus = statusDisabled } // nothing after current list - if offset*count >= total { + if (offset+1)*count >= total { nextStatus = statusDisabled } @@ -978,9 +978,9 @@ func postsHandler(res http.ResponseWriter, req *http.Request) { pagination := fmt.Sprintf(` `, prevStatus, prevURL, start, end, total, nextStatus, nextURL) -- cgit v1.2.3 From f8b0d0f4c2b756b148130c60b868596c7c0cfa67 Mon Sep 17 00:00:00 2001 From: Steve Manuel Date: Mon, 5 Dec 2016 11:43:53 -0800 Subject: fixing pagination html --- system/admin/handlers.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/admin/handlers.go b/system/admin/handlers.go index 25de560..699e503 100644 --- a/system/admin/handlers.go +++ b/system/admin/handlers.go @@ -978,9 +978,9 @@ func postsHandler(res http.ResponseWriter, req *http.Request) { pagination := fmt.Sprintf(` `, prevStatus, prevURL, start, end, total, nextStatus, nextURL) -- cgit v1.2.3 From 24cfc1511d160850a6fc5c93be067c6704892440 Mon Sep 17 00:00:00 2001 From: Steve Manuel Date: Mon, 5 Dec 2016 12:09:37 -0800 Subject: changing Add -> Set for values where it could have been problematic --- system/admin/handlers.go | 4 ++-- system/api/external.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'system') diff --git a/system/admin/handlers.go b/system/admin/handlers.go index 699e503..6293974 100644 --- a/system/admin/handlers.go +++ b/system/admin/handlers.go @@ -871,7 +871,7 @@ func postsHandler(res http.ResponseWriter, req *http.Request) { ` if hasExt { if status == "" { - q.Add("status", "public") + q.Set("status", "public") } // always start from top of results when changing public/pending @@ -1355,7 +1355,7 @@ func editHandler(res http.ResponseWriter, req *http.Request) { } for name, urlPath := range urlPaths { - req.PostForm.Add(name, urlPath) + req.PostForm.Set(name, urlPath) } // check for any multi-value fields (ex. checkbox fields) diff --git a/system/api/external.go b/system/api/external.go index 0c2423b..52510c0 100644 --- a/system/api/external.go +++ b/system/api/external.go @@ -72,7 +72,7 @@ func externalPostHandler(res http.ResponseWriter, req *http.Request) { } for name, urlPath := range urlPaths { - req.PostForm.Add(name, urlPath) + req.PostForm.Set(name, urlPath) } // check for any multi-value fields (ex. checkbox fields) -- cgit v1.2.3 From a53aec78899dad3d9ccdac86677d0b3918a4c876 Mon Sep 17 00:00:00 2001 From: Steve Manuel Date: Tue, 6 Dec 2016 01:47:04 -0800 Subject: adding disabled zero-content pagination and minor fixes --- system/admin/handlers.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'system') diff --git a/system/admin/handlers.go b/system/admin/handlers.go index 6293974..6b5de26 100644 --- a/system/admin/handlers.go +++ b/system/admin/handlers.go @@ -976,6 +976,10 @@ func postsHandler(res http.ResponseWriter, req *http.Request) { start := 1 + count*offset end := start + count - 1 + if total < end { + end = total + } + pagination := fmt.Sprintf(`
  • chevron_left
  • @@ -984,6 +988,18 @@ func postsHandler(res http.ResponseWriter, req *http.Request) {
`, prevStatus, prevURL, start, end, total, nextStatus, nextURL) + // show indicator that a collection of items will be listed implicitly, but + // that none are created yet + if total < 1 { + pagination = ` + + ` + } + b.Write([]byte(pagination + ``)) script := ` -- cgit v1.2.3 From d28d2b6a44bea1f269feadc2b773253a95649f52 Mon Sep 17 00:00:00 2001 From: Steve Manuel Date: Tue, 6 Dec 2016 01:55:24 -0800 Subject: adding test for sorting persisted in pagination --- system/admin/handlers.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'system') diff --git a/system/admin/handlers.go b/system/admin/handlers.go index 6b5de26..247cca7 100644 --- a/system/admin/handlers.go +++ b/system/admin/handlers.go @@ -970,9 +970,9 @@ func postsHandler(res http.ResponseWriter, req *http.Request) { } // set up pagination values - urlFmt := req.URL.Path + "?count=%d&offset=%d&status=%s&type=%s" - prevURL := fmt.Sprintf(urlFmt, count, offset-1, status, t) - nextURL := fmt.Sprintf(urlFmt, count, offset+1, status, t) + urlFmt := req.URL.Path + "?count=%d&offset=%d&&order=%s&status=%s&type=%s" + prevURL := fmt.Sprintf(urlFmt, count, offset-1, order, status, t) + nextURL := fmt.Sprintf(urlFmt, count, offset+1, order, status, t) start := 1 + count*offset end := start + count - 1 -- cgit v1.2.3 From 4e5f54cf8f64b849bf2fbdd610012ebeb7786091 Mon Sep 17 00:00:00 2001 From: Steve Manuel Date: Tue, 6 Dec 2016 09:54:14 -0800 Subject: removing ContentName() from editor.Editble and adding String() to content.Identifiable so embedded Items can manage display names by default, but easily overridden --- system/admin/config/config.go | 4 ++-- system/admin/handlers.go | 2 +- system/db/content.go | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'system') diff --git a/system/admin/config/config.go b/system/admin/config/config.go index 0a7103e..b898b49 100644 --- a/system/admin/config/config.go +++ b/system/admin/config/config.go @@ -18,8 +18,8 @@ type Config struct { CacheInvalidate []string `json:"cache"` } -// ContentName partially implements editor.Editable -func (c *Config) ContentName() string { return c.Name } +// String partially implements content.Identifiable and overrides Item's String() +func (c *Config) String() string { return c.Name } // 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 247cca7..7ea018c 100644 --- a/system/admin/handlers.go +++ b/system/admin/handlers.go @@ -1071,7 +1071,7 @@ func adminPostListItem(e editor.Editable, typeName, status string) []byte { post := `
  • - ` + e.ContentName() + ` + ` + i.String() + ` Updated: ` + updatedTime + ` ` + publishTime + ` diff --git a/system/db/content.go b/system/db/content.go index 76d95c5..b2ba87a 100644 --- a/system/db/content.go +++ b/system/db/content.go @@ -418,7 +418,7 @@ func postToJSON(ns string, data url.Values) ([]byte, error) { return nil, err } - slug, err := manager.Slug(post.(editor.Editable)) + slug, err := manager.Slug(post.(content.Identifiable)) if err != nil { return nil, err } -- cgit v1.2.3 From f2d8a3d846b9322dd4e3d7312a41be575d9b74e1 Mon Sep 17 00:00:00 2001 From: Steve Manuel Date: Tue, 6 Dec 2016 12:49:18 -0800 Subject: removing old unnecessary text processing code --- system/db/content.go | 1 - 1 file changed, 1 deletion(-) (limited to 'system') diff --git a/system/db/content.go b/system/db/content.go index b2ba87a..94d2bad 100644 --- a/system/db/content.go +++ b/system/db/content.go @@ -403,7 +403,6 @@ func (s sortablePosts) Swap(i, j int) { func postToJSON(ns string, data url.Values) ([]byte, error) { // find the content type and decode values into it - ns = strings.TrimSuffix(ns, "_external") t, ok := content.Types[ns] if !ok { return nil, fmt.Errorf(content.ErrTypeNotRegistered, ns) -- cgit v1.2.3 From 115b19e06a81543d7d5ff340f9f054e0692b6d1e Mon Sep 17 00:00:00 2001 From: Steve Manuel Date: Tue, 6 Dec 2016 12:51:57 -0800 Subject: adding content search for both public and pending specifiers --- system/admin/handlers.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'system') diff --git a/system/admin/handlers.go b/system/admin/handlers.go index 7ea018c..b25457a 100644 --- a/system/admin/handlers.go +++ b/system/admin/handlers.go @@ -866,6 +866,7 @@ func postsHandler(res http.ResponseWriter, req *http.Request) { search + ` @@ -1627,13 +1628,19 @@ func searchHandler(res http.ResponseWriter, req *http.Request) { q := req.URL.Query() t := q.Get("type") search := q.Get("q") + status := q.Get("status") + var specifier string if t == "" || search == "" { http.Redirect(res, req, req.URL.Scheme+req.URL.Host+"/admin", http.StatusFound) return } - posts := db.ContentAll(t) + if status == "pending" { + specifier = "_" + status + } + + posts := db.ContentAll(t + specifier) b := &bytes.Buffer{} p := content.Types[t]().(editor.Editable) @@ -1641,11 +1648,13 @@ func searchHandler(res http.ResponseWriter, req *http.Request) {
    ` + t + ` Results
    -
    +
    + search - + +
    -- cgit v1.2.3 From 9bcd849014d8986e72220dc9d8d02888c3dd7103 Mon Sep 17 00:00:00 2001 From: Steve Manuel Date: Tue, 6 Dec 2016 13:08:31 -0800 Subject: fixing code change from previous feature --- system/admin/handlers.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/admin/handlers.go b/system/admin/handlers.go index b25457a..06e43d5 100644 --- a/system/admin/handlers.go +++ b/system/admin/handlers.go @@ -1677,7 +1677,7 @@ func searchHandler(res http.ResponseWriter, req *http.Request) { continue } - post := adminPostListItem(p, t, "") + post := adminPostListItem(p, t, status) b.Write([]byte(post)) } -- cgit v1.2.3 From 4d46c0631703483c62c90f084aa559f85705ad61 Mon Sep 17 00:00:00 2001 From: Steve Manuel Date: Tue, 6 Dec 2016 14:19:56 -0800 Subject: /*post?s*/ => /*content?s*/ substitution --- system/admin/admin.go | 2 +- system/admin/handlers.go | 10 +++++----- system/admin/server.go | 6 +++--- system/api/external.go | 2 +- system/api/handlers.go | 4 ++-- system/api/server.go | 6 +++--- system/db/content.go | 8 ++++---- 7 files changed, 19 insertions(+), 19 deletions(-) (limited to 'system') diff --git a/system/admin/admin.go b/system/admin/admin.go index fdd3e6c..9ddff84 100644 --- a/system/admin/admin.go +++ b/system/admin/admin.go @@ -57,7 +57,7 @@ var mainAdminHTML = ` {{ range $t, $f := .Types }}
    -
  • playlist_add{{ $t }}
  • +
  • playlist_add{{ $t }}
  • {{ end }} diff --git a/system/admin/handlers.go b/system/admin/handlers.go index 06e43d5..87e5fda 100644 --- a/system/admin/handlers.go +++ b/system/admin/handlers.go @@ -733,7 +733,7 @@ func recoveryEditHandler(res http.ResponseWriter, req *http.Request) { } -func postsHandler(res http.ResponseWriter, req *http.Request) { +func contentsHandler(res http.ResponseWriter, req *http.Request) { q := req.URL.Query() t := q.Get("type") if t == "" { @@ -860,7 +860,7 @@ func postsHandler(res http.ResponseWriter, req *http.Request) { -
    +
    search @@ -1086,7 +1086,7 @@ func adminPostListItem(e editor.Editable, typeName, status string) []byte { return []byte(post) } -func approvePostHandler(res http.ResponseWriter, req *http.Request) { +func approveContentHandler(res http.ResponseWriter, req *http.Request) { if req.Method != http.MethodPost { res.WriteHeader(http.StatusMethodNotAllowed) errView, err := Error405() @@ -1603,7 +1603,7 @@ func deleteHandler(res http.ResponseWriter, req *http.Request) { } redir := strings.TrimSuffix(req.URL.Scheme+req.URL.Host+req.URL.Path, "/edit/delete") - redir = redir + "/posts?type=" + ct + redir = redir + "/contents?type=" + ct http.Redirect(res, req, redir, http.StatusFound) } @@ -1648,7 +1648,7 @@ func searchHandler(res http.ResponseWriter, req *http.Request) {
    ` + t + ` Results
    - +
    search diff --git a/system/admin/server.go b/system/admin/server.go index 75b48f6..f80a750 100644 --- a/system/admin/server.go +++ b/system/admin/server.go @@ -27,12 +27,12 @@ func Run() { http.HandleFunc("/admin/configure/users/edit", user.Auth(configUsersEditHandler)) http.HandleFunc("/admin/configure/users/delete", user.Auth(configUsersDeleteHandler)) - http.HandleFunc("/admin/posts", user.Auth(postsHandler)) - http.HandleFunc("/admin/posts/search", user.Auth(searchHandler)) + http.HandleFunc("/admin/contents", user.Auth(contentsHandler)) + http.HandleFunc("/admin/contents/search", user.Auth(searchHandler)) http.HandleFunc("/admin/edit", user.Auth(editHandler)) http.HandleFunc("/admin/edit/delete", user.Auth(deleteHandler)) - http.HandleFunc("/admin/edit/approve", user.Auth(approvePostHandler)) + http.HandleFunc("/admin/edit/approve", user.Auth(approveContentHandler)) http.HandleFunc("/admin/edit/upload", user.Auth(editUploadHandler)) pwd, err := os.Getwd() diff --git a/system/api/external.go b/system/api/external.go index 52510c0..2e9597e 100644 --- a/system/api/external.go +++ b/system/api/external.go @@ -25,7 +25,7 @@ type Trustable interface { AutoApprove(req *http.Request) error } -func externalPostHandler(res http.ResponseWriter, req *http.Request) { +func externalContentHandler(res http.ResponseWriter, req *http.Request) { if req.Method != http.MethodPost { res.WriteHeader(http.StatusMethodNotAllowed) return diff --git a/system/api/handlers.go b/system/api/handlers.go index 1d7dc8f..f31a1eb 100644 --- a/system/api/handlers.go +++ b/system/api/handlers.go @@ -28,7 +28,7 @@ func typesHandler(res http.ResponseWriter, req *http.Request) { sendData(res, j, http.StatusOK) } -func postsHandler(res http.ResponseWriter, req *http.Request) { +func contentsHandler(res http.ResponseWriter, req *http.Request) { q := req.URL.Query() t := q.Get("type") if t == "" { @@ -87,7 +87,7 @@ func postsHandler(res http.ResponseWriter, req *http.Request) { sendData(res, j, http.StatusOK) } -func postHandler(res http.ResponseWriter, req *http.Request) { +func contentHandler(res http.ResponseWriter, req *http.Request) { q := req.URL.Query() id := q.Get("id") t := q.Get("type") diff --git a/system/api/server.go b/system/api/server.go index 70add10..823ec16 100644 --- a/system/api/server.go +++ b/system/api/server.go @@ -8,9 +8,9 @@ import ( func Run() { http.HandleFunc("/api/types", CORS(Record(typesHandler))) - http.HandleFunc("/api/contents", CORS(Record(postsHandler))) + http.HandleFunc("/api/contents", CORS(Record(contentsHandler))) - http.HandleFunc("/api/content", CORS(Record(postHandler))) + http.HandleFunc("/api/content", CORS(Record(contentHandler))) - http.HandleFunc("/api/content/external", CORS(Record(externalPostHandler))) + http.HandleFunc("/api/content/external", CORS(Record(externalContentHandler))) } diff --git a/system/db/content.go b/system/db/content.go index 94d2bad..f313543 100644 --- a/system/db/content.go +++ b/system/db/content.go @@ -387,17 +387,17 @@ func SortContent(namespace string) { } -type sortablePosts []editor.Sortable +type sortableContents []editor.Sortable -func (s sortablePosts) Len() int { +func (s sortableContents) Len() int { return len(s) } -func (s sortablePosts) Less(i, j int) bool { +func (s sortableContents) Less(i, j int) bool { return s[i].Time() > s[j].Time() } -func (s sortablePosts) Swap(i, j int) { +func (s sortableContents) Swap(i, j int) { s[i], s[j] = s[j], s[i] } -- cgit v1.2.3 From 054f01662788fb3bb7fd2808980e59c3a918e9e3 Mon Sep 17 00:00:00 2001 From: Steve Manuel Date: Tue, 6 Dec 2016 14:21:16 -0800 Subject: /*post?s*/ => /*content?s*/ substitution --- system/db/content.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'system') diff --git a/system/db/content.go b/system/db/content.go index f313543..ef74091 100644 --- a/system/db/content.go +++ b/system/db/content.go @@ -334,7 +334,7 @@ func SortContent(namespace string) { all := ContentAll(namespace) - var posts sortablePosts + var posts sortableContent // decode each (json) into type to then sort for i := range all { j := all[i] @@ -387,17 +387,17 @@ func SortContent(namespace string) { } -type sortableContents []editor.Sortable +type sortableContent []editor.Sortable -func (s sortableContents) Len() int { +func (s sortableContent) Len() int { return len(s) } -func (s sortableContents) Less(i, j int) bool { +func (s sortableContent) Less(i, j int) bool { return s[i].Time() > s[j].Time() } -func (s sortableContents) Swap(i, j int) { +func (s sortableContent) Swap(i, j int) { s[i], s[j] = s[j], s[i] } -- cgit v1.2.3 From 650b67e118c6672c65f1b0fab684695284127e9b Mon Sep 17 00:00:00 2001 From: Steve Manuel Date: Tue, 6 Dec 2016 15:08:22 -0800 Subject: substituting "_{specifier}" => "__{specifier}" so users can add their own types with "_" as a separator and not face conflicts --- system/admin/handlers.go | 28 ++++++++++++++-------------- system/api/analytics/init.go | 2 +- system/api/external.go | 2 +- system/api/handlers.go | 2 +- system/db/config.go | 4 ++-- system/db/content.go | 20 ++++++++++---------- system/db/init.go | 8 ++++---- system/db/user.go | 14 +++++++------- 8 files changed, 40 insertions(+), 40 deletions(-) (limited to 'system') diff --git a/system/admin/handlers.go b/system/admin/handlers.go index 87e5fda..c91db79 100644 --- a/system/admin/handlers.go +++ b/system/admin/handlers.go @@ -823,7 +823,7 @@ func contentsHandler(res http.ResponseWriter, req *http.Request) { Order: order, } - total, posts := db.Query(t+"_sorted", opts) + total, posts := db.Query(t+"__sorted", opts) b := &bytes.Buffer{} html := `
    @@ -909,8 +909,8 @@ func contentsHandler(res http.ResponseWriter, req *http.Request) { } case "pending": - // get _pending posts of type t from the db - _, posts = db.Query(t+"_pending", opts) + // get __pending posts of type t from the db + _, posts = db.Query(t+"__pending", opts) html += `
    Status: @@ -1039,7 +1039,7 @@ func contentsHandler(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 +// specifier is passed to append a name to a namespace like __pending func adminPostListItem(e editor.Editable, typeName, status string) []byte { s, ok := e.(editor.Sortable) if !ok { @@ -1067,12 +1067,12 @@ func adminPostListItem(e editor.Editable, typeName, status string) []byte { case "public", "": status = "" default: - status = "_" + status + status = "__" + status } post := `
  • - ` + i.String() + ` + ` + i.String() + ` Updated: ` + updatedTime + ` ` + publishTime + ` @@ -1111,8 +1111,8 @@ func approveContentHandler(res http.ResponseWriter, req *http.Request) { } t := req.FormValue("type") - if strings.Contains(t, "_") { - t = strings.Split(t, "_")[0] + if strings.Contains(t, "__") { + t = strings.Split(t, "__")[0] } post := content.Types[t]() @@ -1257,7 +1257,7 @@ func editHandler(res http.ResponseWriter, req *http.Request) { if i != "" { if status == "pending" { - t = t + "_pending" + t = t + "__pending" } data, err := db.Content(t + ":" + i) @@ -1396,8 +1396,8 @@ func editHandler(res http.ResponseWriter, req *http.Request) { req.PostForm.Del(discardKey) } - if strings.Contains(t, "_") { - t = strings.Split(t, "_")[0] + if strings.Contains(t, "__") { + t = strings.Split(t, "__")[0] } p, ok := content.Types[t] @@ -1506,8 +1506,8 @@ func deleteHandler(res http.ResponseWriter, req *http.Request) { } // catch specifier suffix from delete form value - if strings.Contains(t, "_") { - spec := strings.Split(t, "_") + if strings.Contains(t, "__") { + spec := strings.Split(t, "__") ct = spec[0] } @@ -1637,7 +1637,7 @@ func searchHandler(res http.ResponseWriter, req *http.Request) { } if status == "pending" { - specifier = "_" + status + specifier = "__" + status } posts := db.ContentAll(t + specifier) diff --git a/system/api/analytics/init.go b/system/api/analytics/init.go index 41c24c7..7cb35af 100644 --- a/system/api/analytics/init.go +++ b/system/api/analytics/init.go @@ -66,7 +66,7 @@ func Init() { } err = store.Update(func(tx *bolt.Tx) error { - _, err := tx.CreateBucketIfNotExists([]byte("requests")) + _, err := tx.CreateBucketIfNotExists([]byte("__requests")) if err != nil { return err } diff --git a/system/api/external.go b/system/api/external.go index 2e9597e..0d1ea03 100644 --- a/system/api/external.go +++ b/system/api/external.go @@ -132,7 +132,7 @@ func externalContentHandler(res http.ResponseWriter, req *http.Request) { return } } else { - spec = "_pending" + spec = "__pending" } _, err = db.SetContent(t+spec+":-1", req.PostForm) diff --git a/system/api/handlers.go b/system/api/handlers.go index f31a1eb..8a1517b 100644 --- a/system/api/handlers.go +++ b/system/api/handlers.go @@ -72,7 +72,7 @@ func contentsHandler(res http.ResponseWriter, req *http.Request) { Order: order, } - _, bb := db.Query(t+"_sorted", opts) + _, bb := db.Query(t+"__sorted", opts) var result = []json.RawMessage{} for i := range bb { result = append(result, bb[i]) diff --git a/system/db/config.go b/system/db/config.go index 6855081..ab1c720 100644 --- a/system/db/config.go +++ b/system/db/config.go @@ -24,7 +24,7 @@ func init() { // SetConfig sets key:value pairs in the db for configuration settings func SetConfig(data url.Values) error { err := store.Update(func(tx *bolt.Tx) error { - b := tx.Bucket([]byte("_config")) + b := tx.Bucket([]byte("__config")) // check for any multi-value fields (ex. checkbox fields) // and correctly format for db storage. Essentially, we need @@ -108,7 +108,7 @@ func Config(key string) ([]byte, error) { func ConfigAll() ([]byte, error) { val := &bytes.Buffer{} err := store.View(func(tx *bolt.Tx) error { - b := tx.Bucket([]byte("_config")) + b := tx.Bucket([]byte("__config")) val.Write(b.Get([]byte("settings"))) return nil diff --git a/system/db/content.go b/system/db/content.go index ef74091..74a77ec 100644 --- a/system/db/content.go +++ b/system/db/content.go @@ -39,11 +39,11 @@ func SetContent(target string, data url.Values) (int, error) { } func update(ns, id string, data url.Values) (int, error) { - var specifier string // i.e. _pending, _sorted, etc. - if strings.Contains(ns, "_") { - spec := strings.Split(ns, "_") + var specifier string // i.e. __pending, __sorted, etc. + if strings.Contains(ns, "__") { + spec := strings.Split(ns, "__") ns = spec[0] - specifier = "_" + spec[1] + specifier = "__" + spec[1] } cid, err := strconv.Atoi(id) @@ -82,11 +82,11 @@ func update(ns, id string, data url.Values) (int, error) { func insert(ns string, data url.Values) (int, error) { var effectedID int - var specifier string // i.e. _pending, _sorted, etc. - if strings.Contains(ns, "_") { - spec := strings.Split(ns, "_") + var specifier string // i.e. __pending, __sorted, etc. + if strings.Contains(ns, "__") { + spec := strings.Split(ns, "__") ns = spec[0] - specifier = "_" + spec[1] + specifier = "__" + spec[1] } err := store.Update(func(tx *bolt.Tx) error { @@ -328,7 +328,7 @@ func Query(namespace string, opts QueryOptions) (int, [][]byte) { // Should be called from a goroutine after SetContent is successful func SortContent(namespace string) { // only sort main content types i.e. Post - if strings.Contains(namespace, "_") { + if strings.Contains(namespace, "__") { return } @@ -354,7 +354,7 @@ func SortContent(namespace string) { // store in _sorted bucket, first delete existing err := store.Update(func(tx *bolt.Tx) error { - bname := []byte(namespace + "_sorted") + bname := []byte(namespace + "__sorted") err := tx.DeleteBucket(bname) if err != nil { return err diff --git a/system/db/init.go b/system/db/init.go index 63804e1..967eed1 100644 --- a/system/db/init.go +++ b/system/db/init.go @@ -38,14 +38,14 @@ func Init() { return err } - _, err = tx.CreateBucketIfNotExists([]byte(t + "_sorted")) + _, err = tx.CreateBucketIfNotExists([]byte(t + "__sorted")) if err != nil { return err } } // init db with other buckets as needed - buckets := []string{"_config", "_users"} + buckets := []string{"__config", "__users"} for _, name := range buckets { _, err := tx.CreateBucketIfNotExists([]byte(name)) if err != nil { @@ -54,7 +54,7 @@ func Init() { } // seed db with configs structure if not present - b := tx.Bucket([]byte("_config")) + b := tx.Bucket([]byte("__config")) if b.Get([]byte("settings")) == nil { j, err := json.Marshal(&config.Config{}) if err != nil { @@ -93,7 +93,7 @@ func SystemInitComplete() bool { complete := false err := store.View(func(tx *bolt.Tx) error { - users := tx.Bucket([]byte("_users")) + users := tx.Bucket([]byte("__users")) err := users.ForEach(func(k, v []byte) error { complete = true diff --git a/system/db/user.go b/system/db/user.go index a133890..b92a62a 100644 --- a/system/db/user.go +++ b/system/db/user.go @@ -24,7 +24,7 @@ var ErrNoUserExists = errors.New("Error. No user exists.") func SetUser(usr *user.User) (int, error) { err := store.Update(func(tx *bolt.Tx) error { email := []byte(usr.Email) - users := tx.Bucket([]byte("_users")) + users := tx.Bucket([]byte("__users")) // check if user is found by email, fail if nil exists := users.Get(email) @@ -67,7 +67,7 @@ func UpdateUser(usr, updatedUsr *user.User) error { } err := store.Update(func(tx *bolt.Tx) error { - users := tx.Bucket([]byte("_users")) + users := tx.Bucket([]byte("__users")) // check if user is found by email, fail if nil exists := users.Get([]byte(usr.Email)) @@ -108,7 +108,7 @@ func UpdateUser(usr, updatedUsr *user.User) error { // DeleteUser deletes a user from the db by email func DeleteUser(email string) error { err := store.Update(func(tx *bolt.Tx) error { - b := tx.Bucket([]byte("_users")) + b := tx.Bucket([]byte("__users")) err := b.Delete([]byte(email)) if err != nil { return err @@ -127,7 +127,7 @@ func DeleteUser(email string) error { func User(email string) ([]byte, error) { val := &bytes.Buffer{} err := store.View(func(tx *bolt.Tx) error { - b := tx.Bucket([]byte("_users")) + b := tx.Bucket([]byte("__users")) usr := b.Get([]byte(email)) _, err := val.Write(usr) @@ -152,7 +152,7 @@ func User(email string) ([]byte, error) { func UserAll() ([][]byte, error) { var users [][]byte err := store.View(func(tx *bolt.Tx) error { - b := tx.Bucket([]byte("_users")) + b := tx.Bucket([]byte("__users")) err := b.ForEach(func(k, v []byte) error { users = append(users, v) return nil @@ -201,7 +201,7 @@ func SetRecoveryKey(email string) (string, error) { key := fmt.Sprintf("%d", rand.Int63()) err := store.Update(func(tx *bolt.Tx) error { - b, err := tx.CreateBucketIfNotExists([]byte("_recoveryKeys")) + b, err := tx.CreateBucketIfNotExists([]byte("__recoveryKeys")) if err != nil { return err } @@ -226,7 +226,7 @@ func RecoveryKey(email string) (string, error) { key := &bytes.Buffer{} err := store.View(func(tx *bolt.Tx) error { - b := tx.Bucket([]byte("_recoveryKeys")) + b := tx.Bucket([]byte("__recoveryKeys")) if b == nil { return errors.New("No database found for checking keys.") } -- cgit v1.2.3 From 64050ef8065bccdef0aab1748040995c637fe9ed Mon Sep 17 00:00:00 2001 From: Steve Manuel Date: Tue, 6 Dec 2016 15:11:11 -0800 Subject: missed a rename --- system/api/analytics/init.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/api/analytics/init.go b/system/api/analytics/init.go index 7cb35af..6558adf 100644 --- a/system/api/analytics/init.go +++ b/system/api/analytics/init.go @@ -138,7 +138,7 @@ func ChartData() (map[string]interface{}, error) { // get api request analytics from db var requests = []apiRequest{} err := store.View(func(tx *bolt.Tx) error { - b := tx.Bucket([]byte("requests")) + b := tx.Bucket([]byte("__requests")) err := b.ForEach(func(k, v []byte) error { var r apiRequest -- cgit v1.2.3