From 92da069ce4b704f28dd97457d1b025b31c5cd43e Mon Sep 17 00:00:00 2001 From: Matt Baer Date: Fri, 14 Feb 2020 13:55:24 -0500 Subject: [PATCH] Move admin dashboard sections into subpages This moves app config to a "Settings" page and the application monitor to a "Monitor" page. It also reworks the admin navigation bar a bit and adds some instance stats on the dashboard. Ref T694 --- admin.go | 51 ++++++++- less/admin.less | 8 +- routes.go | 2 + templates/user/admin.tmpl | 146 ++----------------------- templates/user/admin/app-settings.tmpl | 85 ++++++++++++++ templates/user/admin/monitor.tmpl | 105 ++++++++++++++++++ templates/user/include/header.tmpl | 4 +- 7 files changed, 259 insertions(+), 142 deletions(-) create mode 100644 templates/user/admin/app-settings.tmpl create mode 100644 templates/user/admin/monitor.tmpl diff --git a/admin.go b/admin.go index 5f7d244..33445ac 100644 --- a/admin.go +++ b/admin.go @@ -1,5 +1,5 @@ /* - * Copyright © 2018-2019 A Bunch Tell LLC. + * Copyright © 2018-2020 A Bunch Tell LLC. * * This file is part of WriteFreely. * @@ -100,6 +100,33 @@ func (c instanceContent) UpdatedFriendly() string { } func handleViewAdminDash(app *App, u *User, w http.ResponseWriter, r *http.Request) error { + p := struct { + *UserPage + Message string + + UsersCount, CollectionsCount, PostsCount int64 + }{ + UserPage: NewUserPage(app, r, u, "Admin", nil), + Message: r.FormValue("m"), + } + + // Get user stats + p.UsersCount = app.db.GetAllUsersCount() + var err error + p.CollectionsCount, err = app.db.GetTotalCollections() + if err != nil { + return err + } + p.PostsCount, err = app.db.GetTotalPosts() + if err != nil { + return err + } + + showUserPage(w, "admin", p) + return nil +} + +func handleViewAdminMonitor(app *App, u *User, w http.ResponseWriter, r *http.Request) error { updateAppStats() p := struct { *UserPage @@ -116,7 +143,25 @@ func handleViewAdminDash(app *App, u *User, w http.ResponseWriter, r *http.Reque ConfigMessage: r.FormValue("cm"), } - showUserPage(w, "admin", p) + showUserPage(w, "monitor", p) + return nil +} + +func handleViewAdminSettings(app *App, u *User, w http.ResponseWriter, r *http.Request) error { + p := struct { + *UserPage + Config config.AppCfg + + Message, ConfigMessage string + }{ + UserPage: NewUserPage(app, r, u, "Admin", nil), + Config: app.cfg.App, + + Message: r.FormValue("m"), + ConfigMessage: r.FormValue("cm"), + } + + showUserPage(w, "app-settings", p) return nil } @@ -475,7 +520,7 @@ func handleAdminUpdateConfig(apper Apper, u *User, w http.ResponseWriter, r *htt if err != nil { m = "?cm=" + err.Error() } - return impart.HTTPError{http.StatusFound, "/admin" + m + "#config"} + return impart.HTTPError{http.StatusFound, "/admin/settings" + m + "#config"} } func updateAppStats() { diff --git a/less/admin.less b/less/admin.less index 9c4a7c2..3cbf30b 100644 --- a/less/admin.less +++ b/less/admin.less @@ -13,11 +13,11 @@ nav#admin { display: block; margin: 0.5em 0; a { - color: @primary; - &:first-child { - margin-left: 0; - } + margin-left: 0; + .rounded(.25em); + border: 0; &.selected { + background: #dedede; font-weight: bold; } } diff --git a/routes.go b/routes.go index fcd00ec..e606fbc 100644 --- a/routes.go +++ b/routes.go @@ -152,6 +152,8 @@ func InitRoutes(apper Apper, r *mux.Router) *mux.Router { write.HandleFunc("/auth/login", handler.Web(webLogin, UserLevelNoneRequired)).Methods("POST") write.HandleFunc("/admin", handler.Admin(handleViewAdminDash)).Methods("GET") + write.HandleFunc("/admin/monitor", handler.Admin(handleViewAdminMonitor)).Methods("GET") + write.HandleFunc("/admin/settings", handler.Admin(handleViewAdminSettings)).Methods("GET") write.HandleFunc("/admin/users", handler.Admin(handleViewAdminUsers)).Methods("GET") write.HandleFunc("/admin/user/{username}", handler.Admin(handleViewAdminUser)).Methods("GET") write.HandleFunc("/admin/user/{username}/status", handler.Admin(handleAdminToggleUserStatus)).Methods("POST") diff --git a/templates/user/admin.tmpl b/templates/user/admin.tmpl index 3cb81be..1a0e6b4 100644 --- a/templates/user/admin.tmpl +++ b/templates/user/admin.tmpl @@ -35,6 +35,14 @@ form dt { p.docs { font-size: 0.86em; } +.stats { + font-size: 1.2em; + margin: 1em 0; +} +.num { + font-weight: bold; + font-size: 1.5em; +}
@@ -42,142 +50,12 @@ p.docs { {{if .Message}}

{{.Message}}

{{end}} -

On this page

- - -

Resources

- - -
- -

App Configuration

-

Read more in the configuration docs.

- - {{if .ConfigMessage}}

{{.ConfigMessage}}

{{end}} - -
-
-
-
- +
+
{{largeNumFmt .UsersCount}} {{pluralize "user" "users" .UsersCount}}
+
{{largeNumFmt .CollectionsCount}} {{pluralize "blog" "blogs" .CollectionsCount}}
+
{{largeNumFmt .PostsCount}} {{pluralize "post" "posts" .PostsCount}}
- -
- -

Application

- -
-
-
WriteFreely
-
{{.Version}}
-
Server Uptime
-
{{.SysStatus.Uptime}}
-
Current Goroutines
-
{{.SysStatus.NumGoroutine}}
-
-
Current memory usage
-
{{.SysStatus.MemAllocated}}
-
Total mem allocated
-
{{.SysStatus.MemTotal}}
-
Memory obtained
-
{{.SysStatus.MemSys}}
-
Pointer lookup times
-
{{.SysStatus.Lookups}}
-
Memory allocate times
-
{{.SysStatus.MemMallocs}}
-
Memory free times
-
{{.SysStatus.MemFrees}}
-
-
Current heap usage
-
{{.SysStatus.HeapAlloc}}
-
Heap memory obtained
-
{{.SysStatus.HeapSys}}
-
Heap memory idle
-
{{.SysStatus.HeapIdle}}
-
Heap memory in use
-
{{.SysStatus.HeapInuse}}
-
Heap memory released
-
{{.SysStatus.HeapReleased}}
-
Heap objects
-
{{.SysStatus.HeapObjects}}
-
-
Bootstrap stack usage
-
{{.SysStatus.StackInuse}}
-
Stack memory obtained
-
{{.SysStatus.StackSys}}
-
MSpan structures in use
-
{{.SysStatus.MSpanInuse}}
-
MSpan structures obtained
-
{{.SysStatus.HeapSys}}
-
MCache structures in use
-
{{.SysStatus.MCacheInuse}}
-
MCache structures obtained
-
{{.SysStatus.MCacheSys}}
-
Profiling bucket hash table obtained
-
{{.SysStatus.BuckHashSys}}
-
GC metadata obtained
-
{{.SysStatus.GCSys}}
-
Other system allocation obtained
-
{{.SysStatus.OtherSys}}
-
-
Next GC recycle
-
{{.SysStatus.NextGC}}
-
Since last GC
-
{{.SysStatus.LastGC}}
-
Total GC pause
-
{{.SysStatus.PauseTotalNs}}
-
Last GC pause
-
{{.SysStatus.PauseNs}}
-
GC times
-
{{.SysStatus.NumGC}}
-
-
+ +{{template "footer" .}} + +{{template "body-end" .}} +{{end}} diff --git a/templates/user/admin/monitor.tmpl b/templates/user/admin/monitor.tmpl new file mode 100644 index 0000000..e803dd3 --- /dev/null +++ b/templates/user/admin/monitor.tmpl @@ -0,0 +1,105 @@ +{{define "monitor"}} +{{template "header" .}} + + + +
+ {{template "admin-header" .}} + + {{if .Message}}

{{.Message}}

{{end}} + +

Application Monitor

+ +
+
+
WriteFreely
+
{{.Version}}
+
Server Uptime
+
{{.SysStatus.Uptime}}
+
Current Goroutines
+
{{.SysStatus.NumGoroutine}}
+
+
Current memory usage
+
{{.SysStatus.MemAllocated}}
+
Total mem allocated
+
{{.SysStatus.MemTotal}}
+
Memory obtained
+
{{.SysStatus.MemSys}}
+
Pointer lookup times
+
{{.SysStatus.Lookups}}
+
Memory allocate times
+
{{.SysStatus.MemMallocs}}
+
Memory free times
+
{{.SysStatus.MemFrees}}
+
+
Current heap usage
+
{{.SysStatus.HeapAlloc}}
+
Heap memory obtained
+
{{.SysStatus.HeapSys}}
+
Heap memory idle
+
{{.SysStatus.HeapIdle}}
+
Heap memory in use
+
{{.SysStatus.HeapInuse}}
+
Heap memory released
+
{{.SysStatus.HeapReleased}}
+
Heap objects
+
{{.SysStatus.HeapObjects}}
+
+
Bootstrap stack usage
+
{{.SysStatus.StackInuse}}
+
Stack memory obtained
+
{{.SysStatus.StackSys}}
+
MSpan structures in use
+
{{.SysStatus.MSpanInuse}}
+
MSpan structures obtained
+
{{.SysStatus.HeapSys}}
+
MCache structures in use
+
{{.SysStatus.MCacheInuse}}
+
MCache structures obtained
+
{{.SysStatus.MCacheSys}}
+
Profiling bucket hash table obtained
+
{{.SysStatus.BuckHashSys}}
+
GC metadata obtained
+
{{.SysStatus.GCSys}}
+
Other system allocation obtained
+
{{.SysStatus.OtherSys}}
+
+
Next GC recycle
+
{{.SysStatus.NextGC}}
+
Since last GC
+
{{.SysStatus.LastGC}}
+
Total GC pause
+
{{.SysStatus.PauseTotalNs}}
+
Last GC pause
+
{{.SysStatus.PauseNs}}
+
GC times
+
{{.SysStatus.NumGC}}
+
+
+
+ +{{template "footer" .}} + +{{template "body-end" .}} +{{end}} diff --git a/templates/user/include/header.tmpl b/templates/user/include/header.tmpl index 0704854..f7c06ef 100644 --- a/templates/user/include/header.tmpl +++ b/templates/user/include/header.tmpl @@ -97,12 +97,14 @@ {{define "admin-header"}}

Admin

-
{{end}}