Move admin pages to primary layout.
This commit is contained in:
parent
2c9cf2a21a
commit
db09b1db97
4 changed files with 28 additions and 75 deletions
|
|
@ -1,72 +0,0 @@
|
||||||
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"
|
|
||||||
|
|
||||||
. "maragu.dev/gomponents"
|
|
||||||
. "maragu.dev/gomponents/html"
|
|
||||||
)
|
|
||||||
|
|
||||||
func Admin(r *ui.Request, content Node) Node {
|
|
||||||
return Doctype(
|
|
||||||
HTML(
|
|
||||||
Lang("en"),
|
|
||||||
Head(
|
|
||||||
Metatags(r),
|
|
||||||
CSS(),
|
|
||||||
JS(r),
|
|
||||||
),
|
|
||||||
Body(
|
|
||||||
Div(
|
|
||||||
Class("box"),
|
|
||||||
Div(
|
|
||||||
Class("columns"),
|
|
||||||
Div(
|
|
||||||
Class("column is-2"),
|
|
||||||
adminMenu(r),
|
|
||||||
),
|
|
||||||
Div(
|
|
||||||
Class("column is-10"),
|
|
||||||
If(len(r.Title) > 0, H1(Class("title"), Text(r.Title))),
|
|
||||||
FlashMessages(r),
|
|
||||||
content,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
HtmxListeners(r),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
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("Entities"),
|
|
||||||
),
|
|
||||||
Ul(
|
|
||||||
Class("menu-list"),
|
|
||||||
entityTypeLinks,
|
|
||||||
),
|
|
||||||
P(
|
|
||||||
Class("menu-label"),
|
|
||||||
Text("Account"),
|
|
||||||
),
|
|
||||||
Ul(
|
|
||||||
Class("menu-list"),
|
|
||||||
If(r.IsAuth, MenuLink(r, "Logout", routenames.Logout)),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package layouts
|
package layouts
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/mikestefanello/pagoda/ent/admin"
|
||||||
"github.com/mikestefanello/pagoda/pkg/routenames"
|
"github.com/mikestefanello/pagoda/pkg/routenames"
|
||||||
"github.com/mikestefanello/pagoda/pkg/ui"
|
"github.com/mikestefanello/pagoda/pkg/ui"
|
||||||
"github.com/mikestefanello/pagoda/pkg/ui/cache"
|
"github.com/mikestefanello/pagoda/pkg/ui/cache"
|
||||||
|
|
@ -128,6 +129,25 @@ func search(r *ui.Request) Node {
|
||||||
}
|
}
|
||||||
|
|
||||||
func sidebarMenu(r *ui.Request) Node {
|
func sidebarMenu(r *ui.Request) Node {
|
||||||
|
adminSubMenu := func() Node {
|
||||||
|
entityTypeNames := admin.GetEntityTypeNames()
|
||||||
|
entityTypeLinks := make(Group, len(entityTypeNames))
|
||||||
|
for _, n := range entityTypeNames {
|
||||||
|
entityTypeLinks = append(entityTypeLinks, MenuLink(r, n, routenames.AdminEntityList(n)))
|
||||||
|
}
|
||||||
|
|
||||||
|
return Group{
|
||||||
|
P(
|
||||||
|
Class("menu-label"),
|
||||||
|
Text("Entities"),
|
||||||
|
),
|
||||||
|
Ul(
|
||||||
|
Class("menu-list"),
|
||||||
|
entityTypeLinks,
|
||||||
|
),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return Aside(
|
return Aside(
|
||||||
Class("menu"),
|
Class("menu"),
|
||||||
HxBoost(),
|
HxBoost(),
|
||||||
|
|
@ -155,5 +175,6 @@ func sidebarMenu(r *ui.Request) Node {
|
||||||
If(!r.IsAuth, MenuLink(r, "Register", routenames.Register)),
|
If(!r.IsAuth, MenuLink(r, "Register", routenames.Register)),
|
||||||
If(!r.IsAuth, MenuLink(r, "Forgot password", routenames.ForgotPasswordSubmit)),
|
If(!r.IsAuth, MenuLink(r, "Forgot password", routenames.ForgotPasswordSubmit)),
|
||||||
),
|
),
|
||||||
|
Iff(r.IsAdmin, adminSubMenu),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ func AdminEntityDelete(ctx echo.Context, entityTypeName string) error {
|
||||||
CSRF(r),
|
CSRF(r),
|
||||||
)
|
)
|
||||||
|
|
||||||
return r.Render(layouts.Admin, form)
|
return r.Render(layouts.Primary, form)
|
||||||
}
|
}
|
||||||
|
|
||||||
func AdminEntityForm(ctx echo.Context, isNew bool, schema *load.Schema, values url.Values) error {
|
func AdminEntityForm(ctx echo.Context, isNew bool, schema *load.Schema, values url.Values) error {
|
||||||
|
|
@ -138,7 +138,7 @@ func AdminEntityForm(ctx echo.Context, isNew bool, schema *load.Schema, values u
|
||||||
ButtonLink(r.Path(routenames.AdminEntityList(schema.Name)), "is-secondary", "Cancel"),
|
ButtonLink(r.Path(routenames.AdminEntityList(schema.Name)), "is-secondary", "Cancel"),
|
||||||
), CSRF(r))
|
), CSRF(r))
|
||||||
|
|
||||||
return r.Render(layouts.Admin, Form(
|
return r.Render(layouts.Primary, Form(
|
||||||
Method(http.MethodPost),
|
Method(http.MethodPost),
|
||||||
nodes,
|
nodes,
|
||||||
))
|
))
|
||||||
|
|
@ -204,7 +204,7 @@ func AdminEntityList(ctx echo.Context, params AdminEntityListParams) error {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
return r.Render(layouts.Admin, Group{
|
return r.Render(layouts.Primary, Group{
|
||||||
ButtonLink(
|
ButtonLink(
|
||||||
r.Path(routenames.AdminEntityAdd(params.EntityType.Name)),
|
r.Path(routenames.AdminEntityAdd(params.EntityType.Name)),
|
||||||
"is-primary",
|
"is-primary",
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,9 @@ type (
|
||||||
// IsAuth stores whether the user is authenticated.
|
// IsAuth stores whether the user is authenticated.
|
||||||
IsAuth bool
|
IsAuth bool
|
||||||
|
|
||||||
|
// IsAdmin stores whether the user is an admin.
|
||||||
|
IsAdmin bool
|
||||||
|
|
||||||
// AuthUser stores the authenticated user.
|
// AuthUser stores the authenticated user.
|
||||||
AuthUser *ent.User
|
AuthUser *ent.User
|
||||||
|
|
||||||
|
|
@ -77,6 +80,7 @@ func NewRequest(ctx echo.Context) *Request {
|
||||||
if u := ctx.Get(context.AuthenticatedUserKey); u != nil {
|
if u := ctx.Get(context.AuthenticatedUserKey); u != nil {
|
||||||
p.IsAuth = true
|
p.IsAuth = true
|
||||||
p.AuthUser = u.(*ent.User)
|
p.AuthUser = u.(*ent.User)
|
||||||
|
p.IsAdmin = p.AuthUser.Admin
|
||||||
}
|
}
|
||||||
|
|
||||||
if cfg := ctx.Get(context.ConfigKey); cfg != nil {
|
if cfg := ctx.Get(context.ConfigKey); cfg != nil {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue