Initial commit of admin panel.
This commit is contained in:
parent
c8db468292
commit
33e98f9a9e
8 changed files with 466 additions and 7 deletions
65
pkg/ui/layouts/admin.go
Normal file
65
pkg/ui/layouts/admin.go
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
package layouts
|
||||
|
||||
import (
|
||||
"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,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
func adminMenu(r *ui.Request) Node {
|
||||
return Aside(
|
||||
Class("menu"),
|
||||
HxBoost(),
|
||||
P(
|
||||
Class("menu-label"),
|
||||
Text("Content"),
|
||||
),
|
||||
Ul(
|
||||
Class("menu-list"),
|
||||
MenuLink(r, "Users", "admin:user_list"),
|
||||
MenuLink(r, "Tokens", "admin:passwordtoken_list"),
|
||||
),
|
||||
P(
|
||||
Class("menu-label"),
|
||||
Text("Account"),
|
||||
),
|
||||
Ul(
|
||||
Class("menu-list"),
|
||||
If(r.IsAuth, MenuLink(r, "Logout", routenames.Logout)),
|
||||
),
|
||||
)
|
||||
}
|
||||
88
pkg/ui/pages/entity.go
Normal file
88
pkg/ui/pages/entity.go
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
package pages
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
"github.com/mikestefanello/pagoda/pkg/pager"
|
||||
"github.com/mikestefanello/pagoda/pkg/ui"
|
||||
. "github.com/mikestefanello/pagoda/pkg/ui/components"
|
||||
"github.com/mikestefanello/pagoda/pkg/ui/layouts"
|
||||
. "maragu.dev/gomponents"
|
||||
. "maragu.dev/gomponents/html"
|
||||
)
|
||||
|
||||
func Entity(ctx echo.Context) error {
|
||||
return ui.NewRequest(ctx).Render(layouts.Admin, Div(Text("abc")))
|
||||
}
|
||||
|
||||
func AdminEntityDelete(ctx echo.Context) error {
|
||||
r := ui.NewRequest(ctx)
|
||||
form := Form(
|
||||
Method(http.MethodPost),
|
||||
H2(Text("Are you sure you want to delete this entity?")),
|
||||
ControlGroup(
|
||||
FormButton("is-link", "Delete"),
|
||||
ButtonLink("/", "is-secondary", "Cancel"),
|
||||
),
|
||||
CSRF(r),
|
||||
)
|
||||
|
||||
return r.Render(layouts.Admin, form)
|
||||
}
|
||||
|
||||
type AdminEntityListParams struct {
|
||||
Title string
|
||||
Headers []string
|
||||
Rows []AdminEntityListRow
|
||||
EditRoute string
|
||||
DeleteRoute string
|
||||
Pager pager.Pager
|
||||
}
|
||||
|
||||
type AdminEntityListRow struct {
|
||||
ID int
|
||||
Columns []string
|
||||
}
|
||||
|
||||
func AdminEntityList(ctx echo.Context, params AdminEntityListParams) error {
|
||||
r := ui.NewRequest(ctx)
|
||||
r.Title = params.Title
|
||||
|
||||
genHeader := func() Node {
|
||||
g := make(Group, 0, len(params.Headers)+2)
|
||||
for _, h := range params.Headers {
|
||||
g = append(g, Th(Text(h)))
|
||||
}
|
||||
g = append(g, Th(), Th())
|
||||
return g
|
||||
}
|
||||
|
||||
genRow := func(row AdminEntityListRow) Node {
|
||||
g := make(Group, 0, len(row.Columns)+2)
|
||||
for _, h := range row.Columns {
|
||||
g = append(g, Td(Text(h)))
|
||||
}
|
||||
g = append(g,
|
||||
Td(A(Href(r.Path(params.EditRoute, row.ID)), Text("Edit"))),
|
||||
Td(A(Href(r.Path(params.DeleteRoute, row.ID)), Text("Delete"))),
|
||||
)
|
||||
return g
|
||||
}
|
||||
|
||||
genRows := func() Node {
|
||||
g := make(Group, 0, len(params.Rows))
|
||||
for _, row := range params.Rows {
|
||||
g = append(g, Tr(genRow(row)))
|
||||
}
|
||||
return g
|
||||
}
|
||||
|
||||
return r.Render(layouts.Admin, Table(
|
||||
Class("table"),
|
||||
THead(
|
||||
Tr(genHeader()),
|
||||
),
|
||||
TBody(genRows()),
|
||||
))
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue