restructure admin area
This commit is contained in:
parent
0de18e89fc
commit
7ead1ffe22
|
@ -1,9 +1,25 @@
|
||||||
{{define "title"}}Admin{{end}}
|
{{define "title"}}Admin{{end}}
|
||||||
|
|
||||||
{{define "main"}}
|
{{define "main"}}
|
||||||
|
<h2>Write</h2>
|
||||||
|
|
||||||
<ul>
|
<ul>
|
||||||
{{ range . }}
|
{{range .Types}}
|
||||||
<li><a href="/admin/config/{{.Name}}">{{.Name}}</a></li>
|
<li><a href="/editor/new/{{.}}/">{{.}}</a></li>
|
||||||
{{ end }}
|
{{end}}
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<h2>Configurations</h2>
|
||||||
|
<ul>
|
||||||
|
<li><a href="/site-config">Site Settings</a></li>
|
||||||
|
<li><a href="/site-config/me">Me Links</a></li>
|
||||||
|
<li><a href="/site-config/lists">Lists</a></li>
|
||||||
|
<li><a href="/site-config/menus">Menus</a></li>
|
||||||
|
<li>Modules</li>
|
||||||
|
<ul>
|
||||||
|
{{ range .Configs }}
|
||||||
|
<li><a href="/admin/config/{{.Name}}">{{.Name}}</a></li>
|
||||||
|
{{ end }}
|
||||||
|
</ul>
|
||||||
</ul>
|
</ul>
|
||||||
{{end}}
|
{{end}}
|
|
@ -1,8 +1,8 @@
|
||||||
{{define "title"}}Editor{{end}}
|
{{define "title"}}Configuration{{end}}
|
||||||
|
|
||||||
{{define "main"}}
|
{{define "main"}}
|
||||||
|
|
||||||
<a href="/editor">Back</a>
|
<a href="/admin">Back</a>
|
||||||
<br>
|
<br>
|
||||||
<br>
|
<br>
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
{{define "main"}}
|
{{define "main"}}
|
||||||
|
|
||||||
<a href="/editor">Back</a>
|
<a href="/admin">Back</a>
|
||||||
<br>
|
<br>
|
||||||
<br>
|
<br>
|
||||||
|
|
||||||
|
|
|
@ -1,24 +0,0 @@
|
||||||
{{define "title"}}Editor List{{end}}
|
|
||||||
|
|
||||||
{{define "main"}}
|
|
||||||
|
|
||||||
|
|
||||||
<nav>
|
|
||||||
<ul>
|
|
||||||
<li><a href="/">Home</a></li>
|
|
||||||
<li><a href="/editor">Editor</a></li>
|
|
||||||
<li><a href="/site-config">Site Settings</a></li>
|
|
||||||
<li><a href="/site-config/me">Me Links</a></li>
|
|
||||||
<li><a href="/site-config/lists">Lists</a></li>
|
|
||||||
<li><a href="/site-config/menus">Menus</a></li>
|
|
||||||
</ul>
|
|
||||||
</nav>
|
|
||||||
|
|
||||||
<h1>Editor List</h1>
|
|
||||||
|
|
||||||
<ul>
|
|
||||||
{{range .Types}}
|
|
||||||
<li><a href="/editor/new/{{.}}/">{{.}}</a></li>
|
|
||||||
{{end}}
|
|
||||||
|
|
||||||
{{end}}
|
|
|
@ -2,16 +2,7 @@
|
||||||
|
|
||||||
{{define "main"}}
|
{{define "main"}}
|
||||||
|
|
||||||
<nav>
|
<a href="/admin">Back</a>
|
||||||
<ul>
|
|
||||||
<li><a href="/">Home</a></li>
|
|
||||||
<li><a href="/editor">Editor</a></li>
|
|
||||||
<li><a href="/site-config">Site Settings</a></li>
|
|
||||||
<li><a href="/site-config/me">Me Links</a></li>
|
|
||||||
<li><a href="/site-config/lists">Lists</a></li>
|
|
||||||
<li><a href="/site-config/menus">Menus</a></li>
|
|
||||||
</ul>
|
|
||||||
</nav>
|
|
||||||
|
|
||||||
<h2>Site Settings</h2>
|
<h2>Site Settings</h2>
|
||||||
|
|
||||||
|
|
|
@ -2,16 +2,7 @@
|
||||||
|
|
||||||
{{define "main"}}
|
{{define "main"}}
|
||||||
|
|
||||||
<nav>
|
<a href="/admin">Back</a>
|
||||||
<ul>
|
|
||||||
<li><a href="/">Home</a></li>
|
|
||||||
<li><a href="/editor">Editor</a></li>
|
|
||||||
<li><a href="/site-config">Site Settings</a></li>
|
|
||||||
<li><a href="/site-config/me">Me Links</a></li>
|
|
||||||
<li><a href="/site-config/lists">Lists</a></li>
|
|
||||||
<li><a href="/site-config/menus">Menus</a></li>
|
|
||||||
</ul>
|
|
||||||
</nav>
|
|
||||||
|
|
||||||
<h2>Create a List</h2>
|
<h2>Create a List</h2>
|
||||||
<form action="/site-config/lists/create" method="post" enctype="multipart/form-data">
|
<form action="/site-config/lists/create" method="post" enctype="multipart/form-data">
|
||||||
|
|
|
@ -2,16 +2,7 @@
|
||||||
|
|
||||||
{{define "main"}}
|
{{define "main"}}
|
||||||
|
|
||||||
<nav>
|
<a href="/admin">Back</a>
|
||||||
<ul>
|
|
||||||
<li><a href="/">Home</a></li>
|
|
||||||
<li><a href="/editor">Editor</a></li>
|
|
||||||
<li><a href="/site-config">Site Settings</a></li>
|
|
||||||
<li><a href="/site-config/me">Me Links</a></li>
|
|
||||||
<li><a href="/site-config/lists">Lists</a></li>
|
|
||||||
<li><a href="/site-config/menus">Menus</a></li>
|
|
||||||
</ul>
|
|
||||||
</nav>
|
|
||||||
|
|
||||||
<h2>Create a Me Link</h2>
|
<h2>Create a Me Link</h2>
|
||||||
<form action="/site-config/me/create" method="post" enctype="multipart/form-data">
|
<form action="/site-config/me/create" method="post" enctype="multipart/form-data">
|
||||||
|
|
|
@ -2,16 +2,7 @@
|
||||||
|
|
||||||
{{define "main"}}
|
{{define "main"}}
|
||||||
|
|
||||||
<nav>
|
<a href="/admin">Back</a>
|
||||||
<ul>
|
|
||||||
<li><a href="/">Home</a></li>
|
|
||||||
<li><a href="/editor">Editor</a></li>
|
|
||||||
<li><a href="/site-config">Site Settings</a></li>
|
|
||||||
<li><a href="/site-config/me">Me Links</a></li>
|
|
||||||
<li><a href="/site-config/lists">Lists</a></li>
|
|
||||||
<li><a href="/site-config/menus">Menus</a></li>
|
|
||||||
</ul>
|
|
||||||
</nav>
|
|
||||||
|
|
||||||
<h2>Create a List</h2>
|
<h2>Create a List</h2>
|
||||||
<form action="/site-config/menus/create" method="post" enctype="multipart/form-data">
|
<form action="/site-config/menus/create" method="post" enctype="multipart/form-data">
|
||||||
|
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"owl-blogs/app/repository"
|
"owl-blogs/app/repository"
|
||||||
"owl-blogs/render"
|
"owl-blogs/render"
|
||||||
"owl-blogs/web/forms"
|
"owl-blogs/web/forms"
|
||||||
|
"sort"
|
||||||
|
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
)
|
)
|
||||||
|
@ -12,12 +13,23 @@ import (
|
||||||
type adminHandler struct {
|
type adminHandler struct {
|
||||||
configRepo repository.ConfigRepository
|
configRepo repository.ConfigRepository
|
||||||
configRegister *app.ConfigRegister
|
configRegister *app.ConfigRegister
|
||||||
|
typeRegistry *app.EntryTypeRegistry
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewAdminHandler(configRepo repository.ConfigRepository, configRegister *app.ConfigRegister) *adminHandler {
|
type adminContet struct {
|
||||||
|
Configs []app.RegisteredConfig
|
||||||
|
Types []string
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewAdminHandler(
|
||||||
|
configRepo repository.ConfigRepository,
|
||||||
|
configRegister *app.ConfigRegister,
|
||||||
|
typeRegistry *app.EntryTypeRegistry,
|
||||||
|
) *adminHandler {
|
||||||
return &adminHandler{
|
return &adminHandler{
|
||||||
configRepo: configRepo,
|
configRepo: configRepo,
|
||||||
configRegister: configRegister,
|
configRegister: configRegister,
|
||||||
|
typeRegistry: typeRegistry,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,7 +38,27 @@ func (h *adminHandler) Handle(c *fiber.Ctx) error {
|
||||||
|
|
||||||
siteConfig := getSiteConfig(h.configRepo)
|
siteConfig := getSiteConfig(h.configRepo)
|
||||||
configs := h.configRegister.Configs()
|
configs := h.configRegister.Configs()
|
||||||
return render.RenderTemplateWithBase(c, siteConfig, "views/admin", configs)
|
|
||||||
|
types := h.typeRegistry.Types()
|
||||||
|
typeNames := []string{}
|
||||||
|
|
||||||
|
for _, t := range types {
|
||||||
|
name, _ := h.typeRegistry.TypeName(t)
|
||||||
|
typeNames = append(typeNames, name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// sort names to have a consistent order
|
||||||
|
sort.Slice(typeNames, func(i, j int) bool {
|
||||||
|
return typeNames[i] < typeNames[j]
|
||||||
|
})
|
||||||
|
|
||||||
|
return render.RenderTemplateWithBase(
|
||||||
|
c, siteConfig,
|
||||||
|
"views/admin", &adminContet{
|
||||||
|
Configs: configs,
|
||||||
|
Types: typeNames,
|
||||||
|
},
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *adminHandler) HandleConfigGet(c *fiber.Ctx) error {
|
func (h *adminHandler) HandleConfigGet(c *fiber.Ctx) error {
|
||||||
|
|
|
@ -44,7 +44,6 @@ func NewWebApp(
|
||||||
mediaHandler := NewMediaHandler(binService)
|
mediaHandler := NewMediaHandler(binService)
|
||||||
rssHandler := NewRSSHandler(entryService, configRepo)
|
rssHandler := NewRSSHandler(entryService, configRepo)
|
||||||
loginHandler := NewLoginHandler(authorService, configRepo)
|
loginHandler := NewLoginHandler(authorService, configRepo)
|
||||||
editorListHandler := NewEditorListHandler(typeRegistry, configRepo)
|
|
||||||
editorHandler := NewEditorHandler(entryService, typeRegistry, binService, configRepo)
|
editorHandler := NewEditorHandler(entryService, typeRegistry, binService, configRepo)
|
||||||
|
|
||||||
// Login
|
// Login
|
||||||
|
@ -52,7 +51,7 @@ func NewWebApp(
|
||||||
app.Post("/auth/login", loginHandler.HandlePost)
|
app.Post("/auth/login", loginHandler.HandlePost)
|
||||||
|
|
||||||
// admin
|
// admin
|
||||||
adminHandler := NewAdminHandler(configRepo, configRegister)
|
adminHandler := NewAdminHandler(configRepo, configRegister, typeRegistry)
|
||||||
admin := app.Group("/admin")
|
admin := app.Group("/admin")
|
||||||
admin.Use(middleware.NewAuthMiddleware(authorService).Handle)
|
admin.Use(middleware.NewAuthMiddleware(authorService).Handle)
|
||||||
admin.Get("/", adminHandler.Handle)
|
admin.Get("/", adminHandler.Handle)
|
||||||
|
@ -62,7 +61,6 @@ func NewWebApp(
|
||||||
// Editor
|
// Editor
|
||||||
editor := app.Group("/editor")
|
editor := app.Group("/editor")
|
||||||
editor.Use(middleware.NewAuthMiddleware(authorService).Handle)
|
editor.Use(middleware.NewAuthMiddleware(authorService).Handle)
|
||||||
editor.Get("/", editorListHandler.Handle)
|
|
||||||
editor.Get("/new/:editor/", editorHandler.HandleGetNew)
|
editor.Get("/new/:editor/", editorHandler.HandleGetNew)
|
||||||
editor.Post("/new/:editor/", editorHandler.HandlePostNew)
|
editor.Post("/new/:editor/", editorHandler.HandlePostNew)
|
||||||
editor.Get("/edit/:id/", editorHandler.HandleGetEdit)
|
editor.Get("/edit/:id/", editorHandler.HandleGetEdit)
|
||||||
|
|
|
@ -1,41 +0,0 @@
|
||||||
package web
|
|
||||||
|
|
||||||
import (
|
|
||||||
"owl-blogs/app"
|
|
||||||
"owl-blogs/app/repository"
|
|
||||||
"owl-blogs/render"
|
|
||||||
|
|
||||||
"github.com/gofiber/fiber/v2"
|
|
||||||
)
|
|
||||||
|
|
||||||
type EditorListHandler struct {
|
|
||||||
configRepo repository.ConfigRepository
|
|
||||||
registry *app.EntryTypeRegistry
|
|
||||||
}
|
|
||||||
|
|
||||||
type EditorListContext struct {
|
|
||||||
Types []string
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewEditorListHandler(registry *app.EntryTypeRegistry,
|
|
||||||
configRepo repository.ConfigRepository) *EditorListHandler {
|
|
||||||
return &EditorListHandler{
|
|
||||||
registry: registry,
|
|
||||||
configRepo: configRepo,
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *EditorListHandler) Handle(c *fiber.Ctx) error {
|
|
||||||
c.Set(fiber.HeaderContentType, fiber.MIMETextHTML)
|
|
||||||
|
|
||||||
types := h.registry.Types()
|
|
||||||
typeNames := []string{}
|
|
||||||
|
|
||||||
for _, t := range types {
|
|
||||||
name, _ := h.registry.TypeName(t)
|
|
||||||
typeNames = append(typeNames, name)
|
|
||||||
}
|
|
||||||
|
|
||||||
return render.RenderTemplateWithBase(c, getSiteConfig(h.configRepo), "views/editor_list", &EditorListContext{Types: typeNames})
|
|
||||||
}
|
|
Loading…
Reference in New Issue