admin

package
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 15, 2026 License: EUPL-1.2 Imports: 12 Imported by: 0

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 ModelAdmin instances that provide per-model CRUD views.

Index

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 RequestPathFromContext

func RequestPathFromContext(ctx context.Context) string

RequestPathFromContext retrieves the current request path from the context.

func WithNavGroups

func WithNavGroups(ctx context.Context, groups []NavGroup) context.Context

WithNavGroups stores nav groups in the context.

Example
package main

import (
	"context"
	"fmt"

	"github.com/oliverandrich/burrow"
	"github.com/oliverandrich/burrow/contrib/admin"
)

func main() {
	groups := []admin.NavGroup{
		{AppName: "users", Items: []burrow.NavItem{{Label: "All Users", URL: "/admin/users"}}},
	}
	ctx := admin.WithNavGroups(context.Background(), groups)

	result := admin.NavGroupsFromContext(ctx)
	fmt.Println(result[0].AppName, result[0].Items[0].Label)
}
Output:

users All Users

func WithRequestPath

func WithRequestPath(ctx context.Context, path string) context.Context

WithRequestPath stores the current request path in the context.

Example
package main

import (
	"context"
	"fmt"

	"github.com/oliverandrich/burrow/contrib/admin"
)

func main() {
	ctx := admin.WithRequestPath(context.Background(), "/admin/users/42")

	fmt.Println(admin.RequestPathFromContext(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

func New(opts ...Option) *App

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

func (a *App) Dependencies() []string

func (*App) FuncMap

func (a *App) FuncMap() template.FuncMap

FuncMap returns static template functions for admin icons.

func (*App) Name

func (a *App) Name() string

func (*App) Register

func (a *App) Register(cfg *burrow.AppConfig) error

func (*App) RequestFuncMap added in v0.4.0

func (a *App) RequestFuncMap(r *http.Request) template.FuncMap

RequestFuncMap returns request-scoped template functions for the admin sidebar.

func (*App) Routes

func (a *App) Routes(r chi.Router)

Routes creates the /admin group with auth middleware and delegates to all HasAdmin apps.

func (*App) TemplateFS

func (a *App) TemplateFS() fs.FS

TemplateFS returns the embedded HTML template files.

func (*App) TranslationFS

func (a *App) TranslationFS() fs.FS

TranslationFS returns the embedded translation files (modeladmin UI labels).

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 struct {
	AppName string
	Items   []burrow.NavItem
}

NavGroup groups navigation items belonging to one admin app. Each HasAdmin app contributes one group to the admin sidebar.

func NavGroupsFromContext(ctx context.Context) []NavGroup

NavGroupsFromContext retrieves nav groups from the context.

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

func WithLayout(layout string) Option

WithLayout sets the layout template name for admin pages.

type SidebarGroup

type SidebarGroup struct {
	AppName string
	Label   string
	Items   []SidebarItem
}

SidebarGroup holds pre-computed sidebar data for template rendering.

func PrepareSidebar

func PrepareSidebar(ctx context.Context, groups []NavGroup) []SidebarGroup

PrepareSidebar pre-computes sidebar groups with translated labels and active-state CSS classes, ready for template rendering.

type SidebarItem

type SidebarItem struct {
	Label     string
	URL       string
	Icon      template.HTML
	LinkClass string
}

SidebarItem holds pre-computed data for a single sidebar nav link.

Directories

Path Synopsis
Package modeladmin provides a generic, Django-style ModelAdmin for auto-generating CRUD admin views from Bun models.
Package modeladmin provides a generic, Django-style ModelAdmin for auto-generating CRUD admin views from Bun models.
templates
Package templates provides the default HTML template renderer for modeladmin CRUD views.
Package templates provides the default HTML template renderer for modeladmin CRUD views.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL