Make admin menu links dynamic.

This commit is contained in:
mikestefanello 2025-04-19 10:22:40 -04:00
parent 8219b96df7
commit 36bc20b90f
6 changed files with 42 additions and 15 deletions

View file

@ -49,7 +49,6 @@ func (h *Admin) Routes(g *echo.Group) {
// TODO admin user status middleware
entities := g.Group("/admin/content")
// TODO: can we generate something we can loop instead?
for _, n := range h.graph.Nodes {
ng := entities.Group(fmt.Sprintf("/%s", strings.ToLower(n.Name)))
ng.GET("", h.EntityList(n)).
@ -71,7 +70,6 @@ func (h *Admin) Routes(g *echo.Group) {
}
}
// TODO, maybe this can be used outside of admin stuff as well?
func (h *Admin) middlewareEntityLoad(n *gen.Type) echo.MiddlewareFunc {
return func(next echo.HandlerFunc) echo.HandlerFunc {
return func(ctx echo.Context) error {

View file

@ -1,6 +1,7 @@
package layouts
import (
"github.com/mikestefanello/pagoda/ent/admin"
"github.com/mikestefanello/pagoda/pkg/routenames"
"github.com/mikestefanello/pagoda/pkg/ui"
. "github.com/mikestefanello/pagoda/pkg/ui/components"
@ -42,17 +43,22 @@ func Admin(r *ui.Request, content Node) Node {
}
func adminMenu(r *ui.Request) Node {
entityTypeNames := admin.GetEntityTypeNames()
entityTypeLinks := make(Group, len(entityTypeNames))
for _, n := range entityTypeNames {
entityTypeLinks = append(entityTypeLinks, MenuLink(r, n, routenames.AdminEntityList(n)))
}
return Aside(
Class("menu"),
HxBoost(),
P(
Class("menu-label"),
Text("Content"),
Text("Entities"),
),
Ul(
Class("menu-list"),
MenuLink(r, "User", routenames.AdminEntityList("User")),
MenuLink(r, "PasswordToken", routenames.AdminEntityList("PasswordToken")),
entityTypeLinks,
),
P(
Class("menu-label"),