From a33f0ed31c1527a4ce7dd08e75844da7b477cce4 Mon Sep 17 00:00:00 2001 From: Jason Ernst Date: Sat, 20 Apr 2024 21:11:10 -0700 Subject: [PATCH] Split admin into a couple of sections --- admin/admin.go | 36 +++++++++ admin/admin_test.go | 5 ++ goblog.go | 6 +- templates/admin.html | 10 +++ templates/admin_all_posts.html | 103 ++++++++++++++++++++++++++ templates/admin_dashboard.html | 56 ++++++++++++++ templates/admin_new_post.html | 130 +++++++++++++++++++++++++++++++++ templates/admin_settings.html | 56 ++++++++++++++ 8 files changed, 401 insertions(+), 1 deletion(-) create mode 100644 templates/admin_all_posts.html create mode 100644 templates/admin_dashboard.html create mode 100644 templates/admin_new_post.html create mode 100644 templates/admin_settings.html diff --git a/admin/admin.go b/admin/admin.go index d507d40..d636a12 100644 --- a/admin/admin.go +++ b/admin/admin.go @@ -223,6 +223,42 @@ func (a Admin) Admin(c *gin.Context) { }) } +func (a Admin) AdminDashboard(c *gin.Context) { + c.HTML(http.StatusOK, "admin_dashboard.html", gin.H{ + "posts": a.b.GetPosts(true), + "logged_in": a.auth.IsLoggedIn(c), + "is_admin": a.auth.IsAdmin(c), + "version": a.version, + }) +} + +func (a Admin) AdminPosts(c *gin.Context) { + c.HTML(http.StatusOK, "admin_all_posts.html", gin.H{ + "posts": a.b.GetPosts(true), + "logged_in": a.auth.IsLoggedIn(c), + "is_admin": a.auth.IsAdmin(c), + "version": a.version, + }) +} + +func (a Admin) AdminNewPost(c *gin.Context) { + c.HTML(http.StatusOK, "admin_new_post.html", gin.H{ + "posts": a.b.GetPosts(true), + "logged_in": a.auth.IsLoggedIn(c), + "is_admin": a.auth.IsAdmin(c), + "version": a.version, + }) +} + +func (a Admin) AdminSettings(c *gin.Context) { + c.HTML(http.StatusOK, "admin_settings.html", gin.H{ + "posts": a.b.GetPosts(true), + "logged_in": a.auth.IsLoggedIn(c), + "is_admin": a.auth.IsAdmin(c), + "version": a.version, + }) +} + func (a Admin) Post(c *gin.Context) { if !a.auth.IsAdmin(c) { log.Println("IS ADMIN RETURNED FALSE") diff --git a/admin/admin_test.go b/admin/admin_test.go index fc6be5c..1783ee4 100644 --- a/admin/admin_test.go +++ b/admin/admin_test.go @@ -55,7 +55,12 @@ func TestCreatePost(t *testing.T) { router.PATCH("/api/v1/posts", ad.UpdatePost) router.DELETE("/api/v1/posts", ad.DeletePost) router.POST("/api/v1/upload", ad.UploadFile) + router.GET("/admin", ad.Admin) + router.GET("/admin/dashboard", ad.AdminDashboard) + router.GET("/admin/posts", ad.AdminPosts) + router.GET("/admin/newpost", ad.AdminNewPost) + router.GET("/admin/settings", ad.AdminSettings) //improper content-type testPost := blog.Post{ diff --git a/goblog.go b/goblog.go index 7f1b439..7f5194c 100644 --- a/goblog.go +++ b/goblog.go @@ -70,7 +70,7 @@ func main() { setup_wizard() err := godotenv.Load(".env") if err != nil { - log.Println("Failed to read the .env file after the wizard, can't procced") + log.Println("Failed to read the .env file after the wizard, can't proceed") return } } @@ -174,6 +174,10 @@ func main() { router.Use(static.Serve("/wp-content", static.LocalFile("www", false))) router.GET("/admin", _admin.Admin) + router.GET("/admin/dashboard", _admin.AdminDashboard) + router.GET("/admin/posts", _admin.AdminPosts) + router.GET("/admin/newpost", _admin.AdminNewPost) + router.GET("/admin/settings", _admin.AdminSettings) router.NoRoute(_blog.NoRoute) diff --git a/templates/admin.html b/templates/admin.html index 8ebf704..7cf2ddb 100644 --- a/templates/admin.html +++ b/templates/admin.html @@ -38,6 +38,16 @@
+

All Posts

diff --git a/templates/admin_all_posts.html b/templates/admin_all_posts.html new file mode 100644 index 0000000..6958a8c --- /dev/null +++ b/templates/admin_all_posts.html @@ -0,0 +1,103 @@ +{{ template "header.html" .}} + + +
+ +

All Posts

+ +
+ {{ range .posts }} + + + + + + + + {{ end }} +
{{ .Title }}{{ .CreatedAt.Format "01/02/06" }}{{ range .Tags }} + #{{ .Name }} + {{ end }} +
+ + +
+ + + +{{ template "footer.html" .}} diff --git a/templates/admin_dashboard.html b/templates/admin_dashboard.html new file mode 100644 index 0000000..866a435 --- /dev/null +++ b/templates/admin_dashboard.html @@ -0,0 +1,56 @@ +{{ template "header.html" .}} + + +
+ +

Dashboard

+

Welcome to the admin dashboard.

+ +
+ +{{ template "footer.html" .}} diff --git a/templates/admin_new_post.html b/templates/admin_new_post.html new file mode 100644 index 0000000..f424482 --- /dev/null +++ b/templates/admin_new_post.html @@ -0,0 +1,130 @@ +{{ template "header.html" .}} + + +
+ + +

Create post

+ +
+ + +
+ +
+ + +
+ +
+ +
+ +
+
+
+
+
+ +
+ +
+ +
+
+ +
+

* - required fields

+
+ +
+ + + +
+ +
+ + + +{{ template "footer.html" .}} \ No newline at end of file diff --git a/templates/admin_settings.html b/templates/admin_settings.html new file mode 100644 index 0000000..fae41dd --- /dev/null +++ b/templates/admin_settings.html @@ -0,0 +1,56 @@ +{{ template "header.html" .}} + + +
+ +

Settings

+

TODO

+ +
+ +{{ template "footer.html" .}}