templates: Add a proper menu and navigation
This commit is contained in:
parent
0bb7f99fa3
commit
a00195be16
76 changed files with 336 additions and 233 deletions
|
|
@ -40,6 +40,7 @@ type Admin struct {
|
|||
var (
|
||||
_ component.DistilleryFetcher = (*Admin)(nil)
|
||||
_ component.Routeable = (*Admin)(nil)
|
||||
_ component.Menuable = (*Admin)(nil)
|
||||
)
|
||||
|
||||
func (admin *Admin) Routes() component.Routes {
|
||||
|
|
@ -50,6 +51,19 @@ func (admin *Admin) Routes() component.Routes {
|
|||
}
|
||||
}
|
||||
|
||||
func (admin *Admin) Menu(r *http.Request) []component.MenuItem {
|
||||
if !admin.Dependencies.Auth.Has(auth.Admin, r) {
|
||||
return nil
|
||||
}
|
||||
return []component.MenuItem{
|
||||
{
|
||||
Title: "Admin",
|
||||
Path: "/admin/",
|
||||
Priority: component.MenuAdmin,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (admin *Admin) HandleRoute(ctx context.Context, route string) (handler http.Handler, err error) {
|
||||
|
||||
router := httprouter.New()
|
||||
|
|
@ -62,17 +76,17 @@ func (admin *Admin) HandleRoute(ctx context.Context, route string) (handler http
|
|||
}
|
||||
}
|
||||
|
||||
// handle everything
|
||||
router.HandlerFunc(http.MethodGet, route, func(w http.ResponseWriter, r *http.Request) {
|
||||
http.Redirect(w, r, route+"index", http.StatusTemporaryRedirect)
|
||||
})
|
||||
|
||||
// add a handler for the index page
|
||||
router.Handler(http.MethodGet, route+"index", httpx.HTMLHandler[indexContext]{
|
||||
router.Handler(http.MethodGet, route, httpx.HTMLHandler[indexContext]{
|
||||
Handler: admin.index,
|
||||
Template: admin.Dependencies.Custom.Template(indexTemplate),
|
||||
})
|
||||
|
||||
// fallback to the "/" page
|
||||
router.HandlerFunc(http.MethodGet, route+"index", func(w http.ResponseWriter, r *http.Request) {
|
||||
http.Redirect(w, r, route, http.StatusTemporaryRedirect)
|
||||
})
|
||||
|
||||
// add a handler for the user page
|
||||
router.Handler(http.MethodGet, route+"users", httpx.HTMLHandler[userContext]{
|
||||
Handler: admin.users,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue