Documentation
¶
Overview ¶
Package admin provides the admin panel coordinator as a burrow contrib app. It handles layout, navigation, dashboard rendering, and acts as the mount point for admin views contributed by apps implementing HasAdmin.
Index ¶
- func DefaultLayout() string
- func RequestPath(ctx context.Context) string
- func RequestPathFromContext(ctx context.Context) string
- func WithNavGroups(ctx context.Context, groups []NavGroup) context.Context
- func WithRequestPath(ctx context.Context, path string) context.Context
- type App
- func (a *App) Configure(cfg *burrow.AppConfig, _ *cli.Command) error
- func (a *App) Dependencies() []string
- func (a *App) Name() string
- func (a *App) RequestFuncMap(ctx context.Context) template.FuncMap
- func (a *App) Routes(r chi.Router)
- func (a *App) StaticFS() (string, fs.FS)
- func (a *App) TemplateFS() fs.FS
- func (a *App) TranslationFS() fs.FS
- type DashboardGroup
- type DashboardItem
- type DashboardRenderer
- type NavGroup
- type Option
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultLayout ¶
func DefaultLayout() string
DefaultLayout returns the template name for the built-in admin layout.
func RequestPath ¶ added in v0.6.0
RequestPath is a deprecated alias for burrow.RequestPath.
func RequestPathFromContext ¶
RequestPathFromContext is a deprecated alias for burrow.RequestPath.
func WithNavGroups ¶
WithNavGroups stores nav groups in the context.
func WithRequestPath ¶
WithRequestPath is a deprecated alias for burrow.WithRequestPath.
Example ¶
package main
import (
"context"
"fmt"
"github.com/oliverandrich/burrow"
"github.com/oliverandrich/burrow/contrib/admin"
)
func main() {
ctx := admin.WithRequestPath(context.Background(), "/admin/users/42")
fmt.Println(burrow.RequestPath(ctx))
}
Output: /admin/users/42
Types ¶
type App ¶
type App struct {
// contains filtered or unexported fields
}
App implements the admin coordinator contrib app.
func New ¶
New creates a new admin app with the given options. By default, the built-in HTML layout and dashboard renderer are used. Use WithLayout() and WithDashboardRenderer() to override.
func (*App) Dependencies ¶
Dependencies declares contribs the admin app's templates assume are present: staticfiles serves admin.css, htmx powers the boosted nav, mucss provides the css / theme switcher / pagination templates referenced from admin/layout, and messages provides the flash-message template function used at the top of every admin page.
func (*App) RequestFuncMap ¶ added in v0.4.0
RequestFuncMap returns request-scoped template functions for the admin dashboard.
func (*App) Routes ¶
Routes creates the /admin group with auth middleware and delegates to all HasAdmin apps.
func (*App) StaticFS ¶ added in v0.18.0
StaticFS returns the embedded admin static assets under the "admin" prefix.
func (*App) TemplateFS ¶
TemplateFS returns the embedded HTML template files.
func (*App) TranslationFS ¶
TranslationFS returns the embedded translation files (admin UI labels).
type DashboardGroup ¶ added in v0.18.0
type DashboardGroup struct {
AppName string
Label string
Items []DashboardItem
}
DashboardGroup holds pre-computed dashboard data for template rendering.
func PrepareDashboard ¶ added in v0.18.0
func PrepareDashboard(ctx context.Context, groups []NavGroup) []DashboardGroup
PrepareDashboard pre-computes dashboard groups with translated labels, sorted alphabetically by group name, ready for template rendering.
type DashboardItem ¶ added in v0.18.0
DashboardItem holds pre-computed data for a single dashboard nav link.
type DashboardRenderer ¶
type DashboardRenderer interface {
DashboardPage(w http.ResponseWriter, r *http.Request) error
}
DashboardRenderer renders the admin dashboard page.
func DefaultDashboardRenderer ¶
func DefaultDashboardRenderer() DashboardRenderer
DefaultDashboardRenderer returns a DashboardRenderer that uses the built-in HTML templates for the admin dashboard page.
type NavGroup ¶
type NavGroup struct {
}
NavGroup groups navigation items belonging to one admin app. Each HasAdmin app contributes one group to the admin sidebar.
type Option ¶
type Option func(*App)
Option configures the admin app.
func WithDashboardRenderer ¶
func WithDashboardRenderer(r DashboardRenderer) Option
WithDashboardRenderer sets the dashboard page renderer.
func WithLayout ¶
WithLayout sets the layout template name for admin pages.