helpers

package
v0.25.0 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2026 License: MIT Imports: 32 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UserProfileAreaCode        = "admin.users.detail.profile"
	UserActivityAreaCode       = "admin.users.detail.activity"
	UserProfileWidgetCode      = admin.WidgetUserProfileOverview
	UserActivityWidgetCode     = admin.WidgetUserActivityFeed
	UserProfileWidgetLabel     = "Profile Overview"
	UserActivityWidgetLabel    = "User Activity"
	UserDetailAreaScope        = "users.detail"
	UserDetailEmptyPanelNotice = "No widgets configured for this tab."
)
View Source
const (
	// UserActivityDefaultLimit is the default number of activity entries to return.
	UserActivityDefaultLimit = 10
	// UserActivityMinLimit is the minimum allowed limit.
	UserActivityMinLimit = 1
	// UserActivityMaxLimit is the maximum allowed limit.
	UserActivityMaxLimit = 50
)

Variables

This section is empty.

Functions

func ActorRefFromContext

func ActorRefFromContext(ctx context.Context) userstypes.ActorRef

ActorRefFromContext maps the go-auth actor in context to a go-users ActorRef.

func ApplyUserProfileWidgetOverrides added in v0.4.0

func ApplyUserProfileWidgetOverrides(widgets []map[string]any, record map[string]any)

ApplyUserProfileWidgetOverrides injects record data into profile widgets. Emits only the `sections` payload for typed profile rendering.

func BuildNavItems

func BuildNavItems(adm *admin.Admin, cfg admin.Config, ctx context.Context, active string) []map[string]any

BuildNavItems builds navigation menu items from the admin menu service (shared quickstart implementation).

func BuildPanelTabViews added in v0.2.0

func BuildPanelTabViews(tabs []admin.PanelTab, opts PanelTabViewOptions) []map[string]any

BuildPanelTabViews maps admin tabs to template-friendly payloads with hrefs.

func ClampActivityLimit added in v0.24.0

func ClampActivityLimit(limit int) int

ClampActivityLimit ensures the limit is within the valid range [1, 50]. Returns the default limit (10) if the input is <= 0.

func FetchPanelTabs added in v0.2.0

func FetchPanelTabs(c router.Context, cfg admin.Config, panelName, id string, adm ...*admin.Admin) ([]admin.PanelTab, error)

FetchPanelTabs loads panel tabs from the admin detail API for the given record.

func IsInlineTab added in v0.4.0

func IsInlineTab(spec TabContentSpec) bool

IsInlineTab returns true for tab specs intended to render inside the detail view.

func IsValidActivityTimestamp added in v0.24.0

func IsValidActivityTimestamp(t time.Time) bool

IsValidActivityTimestamp checks if a timestamp is valid for activity sorting.

func MustSubFS

func MustSubFS(fsys embed.FS, dir string) fs.FS

MustSubFS returns a sub-FS or nil without failing the example

func NewScopeAuthorizationPolicy

func NewScopeAuthorizationPolicy() userstypes.AuthorizationPolicy

NewScopeAuthorizationPolicy guards cross-tenant/org access unless the caller holds tenant/org admin permissions.

func NewScopeResolver

func NewScopeResolver() userstypes.ScopeResolver

NewScopeResolver returns a go-users resolver that tolerates missing claims and backfills tenant/org from the request context.

func NewUserFormGenerator

func NewUserFormGenerator(openapiFS fs.FS, templatesFS fs.FS) *formgenorchestrator.Orchestrator

NewUserFormGenerator creates a form generator for user forms from an OpenAPI filesystem

func PanelTabHref added in v0.4.0

func PanelTabHref(tab admin.PanelTab, basePath string, record map[string]any) string

PanelTabHref builds the target URL for a tab target (panel/path/external).

func RenderTemplateView added in v0.25.0

func RenderTemplateView(c router.Context, template string, viewCtx router.ViewContext) error

RenderTemplateView normalizes numeric values in template view context before rendering. This avoids float-style JSON number formatting leaks in templates.

func ResolveScope

func ResolveScope(ctx context.Context, requested userstypes.ScopeFilter) userstypes.ScopeFilter

ResolveScope merges the requested scope with the actor-derived defaults.

func ResolveTabWidgets added in v0.4.0

func ResolveTabWidgets(ctx admin.AdminContext, adm *admin.Admin, basePath, areaCode string) ([]map[string]any, error)

ResolveTabWidgets builds template-ready widget payloads for a dashboard/CMS area.

func ScopeBuilder

func ScopeBuilder() func(context.Context) userstypes.ScopeFilter

ScopeBuilder adapts ResolveScope for admin adapters that accept a simple func.

func ScopeFromContext

func ScopeFromContext(ctx context.Context) userstypes.ScopeFilter

ScopeFromContext extracts tenant/org identifiers into a go-users scope filter.

func ScopeFromContextRaw added in v0.24.0

func ScopeFromContextRaw(ctx context.Context) userstypes.ScopeFilter

ScopeFromContextRaw extracts tenant/org identifiers without applying defaults.

func TabKey added in v0.4.0

func TabKey(panelName, tabID string) string

TabKey builds a stable map key for per-panel tab overrides.

func TemplateFuncOptions added in v0.12.0

func TemplateFuncOptions() []quickstart.TemplateFuncOption

TemplateFuncOptions returns example-specific template function options.

func WithFallbackFS

func WithFallbackFS(primary fs.FS, fallbacks ...fs.FS) fs.FS

WithFallbackFS builds a MultiFS preferring the primary FS first.

func WithNav

func WithNav(ctx router.ViewContext, adm *admin.Admin, cfg admin.Config, active string, reqCtx context.Context, c router.Context) router.ViewContext

WithNav adds navigation items to the view context using the shared quickstart helper.

func WithTheme

func WithTheme(ctx router.ViewContext, adm *admin.Admin, req router.Context) router.ViewContext

WithTheme resolves the active theme (with optional query/header overrides) and adds it to the view context.

Types

type BulkActionContext added in v0.24.0

type BulkActionContext struct {
	Primary  []admin.Action `json:"primary"`
	Overflow []admin.Action `json:"overflow"`
	BaseURL  string         `json:"base_url"`
}

BulkActionContext holds pre-split bulk actions for template rendering.

func BuildBulkActionContext added in v0.24.0

func BuildBulkActionContext(adm *admin.Admin, panelName, basePath string, ctx context.Context) BulkActionContext

BuildBulkActionContext extracts bulk actions from a registered panel, filters by permission, and pre-splits into primary vs overflow.

type DataGridColumn

type DataGridColumn struct {
	Field      string `json:"field"`
	Label      string `json:"label"`
	Sortable   bool   `json:"sortable,omitempty"`
	Filterable bool   `json:"filterable,omitempty"`
	Default    bool   `json:"default"`
}

DataGridColumn describes allowlisted column metadata for resource lists. It is used by templates and API endpoints to keep column schemas consistent.

type ExportConfig

type ExportConfig struct {
	Endpoint   string `json:"endpoint"`
	Definition string `json:"definition"`
	Variant    string `json:"variant,omitempty"`
}

ExportConfig captures export wiring for templates.

func BuildExportConfig

func BuildExportConfig(cfg admin.Config, definition, variant string) ExportConfig

BuildExportConfig returns the export endpoint and definition for UI wiring.

type MultiFS

type MultiFS []fs.FS

MultiFS tries each filesystem in order until one succeeds.

func (MultiFS) Open

func (m MultiFS) Open(name string) (fs.File, error)

Open implements fs.FS to provide fallback resolution.

func (MultiFS) Stat

func (m MultiFS) Stat(name string) (fs.FileInfo, error)

Stat implements fs.StatFS so callers can validate roots without requiring Open(".") to exist.

type PanelTabViewOptions added in v0.4.0

type PanelTabViewOptions struct {
	Context      context.Context
	PanelName    string
	BasePath     string
	DetailPath   string
	Record       map[string]any
	Resolver     TabContentResolver
	ModeSelector TabRenderModeSelector
}

PanelTabViewOptions controls how panel tabs are mapped to template payloads.

type ProfileField added in v0.24.0

type ProfileField struct {
	Key         string           `json:"key"`
	Label       string           `json:"label"`
	Value       any              `json:"value"`
	Type        ProfileFieldType `json:"type"`
	HideIfEmpty bool             `json:"hide_if_empty,omitempty"`
	Verified    bool             `json:"verified,omitempty"`
}

ProfileField represents a typed field in a profile section.

type ProfileFieldType added in v0.24.0

type ProfileFieldType string

ProfileFieldType defines the rendering type for a profile field.

const (
	ProfileFieldText     ProfileFieldType = "text"
	ProfileFieldBadge    ProfileFieldType = "badge"
	ProfileFieldStatus   ProfileFieldType = "status"
	ProfileFieldDate     ProfileFieldType = "date"
	ProfileFieldRelative ProfileFieldType = "relative"
	ProfileFieldVerified ProfileFieldType = "verified"
)

type ProfileSection added in v0.24.0

type ProfileSection struct {
	ID     string         `json:"id"`
	Label  string         `json:"label"`
	Fields []ProfileField `json:"fields"`
}

ProfileSection represents a group of related profile fields.

type ResourceRoutes

type ResourceRoutes struct {
	BasePath string
	Resource string
}

ResourceRoutes builds CRUD-style URLs for a resource.

func NewResourceRoutes

func NewResourceRoutes(basePath, resource string) ResourceRoutes

NewResourceRoutes normalizes base path/resource and returns a route builder.

func (ResourceRoutes) ActionsMap

func (r ResourceRoutes) ActionsMap(id any) map[string]string

ActionsMap builds action URLs for a specific record id.

func (ResourceRoutes) Delete

func (r ResourceRoutes) Delete(id any) string

Delete returns the delete action URL for a record.

func (ResourceRoutes) Edit

func (r ResourceRoutes) Edit(id any) string

Edit returns the edit form URL for a record.

func (ResourceRoutes) Index

func (r ResourceRoutes) Index() string

Index returns the collection URL (e.g., /admin/users).

func (ResourceRoutes) New

func (r ResourceRoutes) New() string

New returns the create form URL (e.g., /admin/users/new).

func (ResourceRoutes) RoutesMap

func (r ResourceRoutes) RoutesMap() map[string]string

RoutesMap returns a map suitable for templates.

func (ResourceRoutes) Show

func (r ResourceRoutes) Show(id any) string

Show returns the detail URL for a record.

type SessionUser

type SessionUser struct {
	ID              string            `json:"id,omitempty"`
	Subject         string            `json:"subject,omitempty"`
	Username        string            `json:"username,omitempty"`
	Email           string            `json:"email,omitempty"`
	Role            string            `json:"role,omitempty"`
	TenantID        string            `json:"tenant_id,omitempty"`
	OrganizationID  string            `json:"organization_id,omitempty"`
	ResourceRoles   map[string]string `json:"resource_roles,omitempty"`
	Metadata        map[string]any    `json:"metadata,omitempty"`
	Scopes          []string          `json:"scopes,omitempty"`
	IssuedAt        *time.Time        `json:"issued_at,omitempty"`
	ExpiresAt       *time.Time        `json:"expires_at,omitempty"`
	IsAuthenticated bool              `json:"is_authenticated"`
	DisplayName     string            `json:"display_name,omitempty"`
	Subtitle        string            `json:"subtitle,omitempty"`
	Initial         string            `json:"initial,omitempty"`
	AvatarURL       string            `json:"avatar_url,omitempty"`
}

SessionUser captures session metadata to expose in templates and APIs.

func BuildSessionUser

func BuildSessionUser(ctx context.Context) SessionUser

BuildSessionUser extracts actor/claims data from the request context.

func FilterSessionUser

func FilterSessionUser(session SessionUser, gate fggate.FeatureGate) SessionUser

FilterSessionUser hides tenant/org data when those features are disabled.

func (SessionUser) ToViewContext

func (s SessionUser) ToViewContext() map[string]any

ToViewContext converts the session into snake_case keys for templates.

type SimpleTranslator

type SimpleTranslator struct {
	// contains filtered or unexported fields
}

SimpleTranslator provides basic translation functionality

func NewSimpleTranslator

func NewSimpleTranslator() *SimpleTranslator

NewSimpleTranslator creates a new translator instance

func (*SimpleTranslator) Translate

func (t *SimpleTranslator) Translate(locale, key string, args ...any) (string, error)

Translate translates a key to the specified locale Falls back to English if the locale is not found, or returns the key if no translation exists

type TabContentKind added in v0.4.0

type TabContentKind string

TabContentKind identifies how tab content should be resolved by the host app.

const (
	TabContentUnknown   TabContentKind = ""
	TabContentDetails   TabContentKind = "details"
	TabContentDashboard TabContentKind = "dashboard_area"
	TabContentCMS       TabContentKind = "cms_area"
	TabContentPanel     TabContentKind = "panel"
	TabContentTemplate  TabContentKind = "template"
)

type TabContentRegistry added in v0.4.0

type TabContentRegistry struct {
	// contains filtered or unexported fields
}

TabContentRegistry stores explicit mappings for per-panel tab content.

func NewTabContentRegistry added in v0.4.0

func NewTabContentRegistry() *TabContentRegistry

func (*TabContentRegistry) Register added in v0.4.0

func (r *TabContentRegistry) Register(panelName, tabID string, spec TabContentSpec)

func (*TabContentRegistry) ResolveTabContent added in v0.4.0

func (r *TabContentRegistry) ResolveTabContent(ctx context.Context, panelName string, record map[string]any, tab admin.PanelTab) (TabContentSpec, error)

type TabContentResolver added in v0.4.0

type TabContentResolver interface {
	ResolveTabContent(ctx context.Context, panelName string, record map[string]any, tab admin.PanelTab) (TabContentSpec, error)
}

TabContentResolver maps (panel, record, tab) to a content specification.

type TabContentResolverFunc added in v0.4.0

type TabContentResolverFunc func(ctx context.Context, panelName string, record map[string]any, tab admin.PanelTab) (TabContentSpec, error)

TabContentResolverFunc adapts a function to the TabContentResolver interface.

func (TabContentResolverFunc) ResolveTabContent added in v0.4.0

func (f TabContentResolverFunc) ResolveTabContent(ctx context.Context, panelName string, record map[string]any, tab admin.PanelTab) (TabContentSpec, error)

type TabContentSpec added in v0.4.0

type TabContentSpec struct {
	Kind     TabContentKind
	AreaCode string
	Panel    string
	Template string
	Data     map[string]any
}

TabContentSpec describes where content should be sourced for a tab.

type TabRenderMode added in v0.4.0

type TabRenderMode string

TabRenderMode controls how tab panels are rendered.

const (
	TabRenderModeSSR    TabRenderMode = "ssr"
	TabRenderModeHybrid TabRenderMode = "hybrid"
	TabRenderModeClient TabRenderMode = "client"
)

type TabRenderModeSelector added in v0.4.0

type TabRenderModeSelector struct {
	Default   TabRenderMode
	Overrides map[string]TabRenderMode
}

TabRenderModeSelector picks a render mode for a tab (defaults + overrides).

func (TabRenderModeSelector) ModeFor added in v0.4.0

func (s TabRenderModeSelector) ModeFor(panelName string, tab admin.PanelTab, spec TabContentSpec) TabRenderMode

type UserActivityBuilder added in v0.24.0

type UserActivityBuilder struct {
	// contains filtered or unexported fields
}

UserActivityBuilder provides a fluent interface for building user-tab activity queries.

func NewUserActivityBuilder added in v0.24.0

func NewUserActivityBuilder(sink admin.ActivitySink) *UserActivityBuilder

NewUserActivityBuilder creates a new builder for user-tab activity queries.

func (*UserActivityBuilder) Build added in v0.24.0

Build executes the dual-query, merges, dedupes, sorts, and returns the result.

func (*UserActivityBuilder) ForUser added in v0.24.0

func (b *UserActivityBuilder) ForUser(userID string) *UserActivityBuilder

ForUser sets the target user ID for the activity query.

func (*UserActivityBuilder) WithLimit added in v0.24.0

func (b *UserActivityBuilder) WithLimit(limit int) *UserActivityBuilder

WithLimit sets the maximum number of entries to return. Values are clamped to the range [1, 50].

type UserActivityResult added in v0.24.0

type UserActivityResult struct {
	Entries []admin.ActivityEntry `json:"entries"`
	Error   error                 `json:"-"`
}

UserActivityResult holds the result of a user activity query.

func BuildUserTabActivity added in v0.24.0

func BuildUserTabActivity(ctx context.Context, sink admin.ActivitySink, userID string, limit int) UserActivityResult

BuildUserTabActivity is a convenience function that creates a builder, configures it, and executes the query in one call.

type WebViewConfig

type WebViewConfig struct {
	// contains filtered or unexported fields
}

WebViewConfig implements the ViewConfig interface for the go-router view engine

func NewWebViewConfig

func NewWebViewConfig(embedded fs.FS) *WebViewConfig

NewWebViewConfig creates a new WebViewConfig from an embedded filesystem

func (*WebViewConfig) AddAssetsFS

func (c *WebViewConfig) AddAssetsFS(fsys fs.FS)

AddAssetsFS prepends an additional assets filesystem (allows overrides/fallbacks).

func (*WebViewConfig) AddTemplatesFS

func (c *WebViewConfig) AddTemplatesFS(fsys fs.FS)

AddTemplatesFS appends an additional templates filesystem (used as fallback).

func (*WebViewConfig) GetAssetsDir

func (c *WebViewConfig) GetAssetsDir() string

GetAssetsDir returns the assets directory path

func (*WebViewConfig) GetAssetsFS

func (c *WebViewConfig) GetAssetsFS() fs.FS

GetAssetsFS returns the assets filesystem

func (*WebViewConfig) GetCSSPath

func (c *WebViewConfig) GetCSSPath() string

GetCSSPath returns the CSS assets path

func (*WebViewConfig) GetDebug

func (c *WebViewConfig) GetDebug() bool

GetDebug returns whether debug mode is enabled

func (*WebViewConfig) GetDevDir

func (c *WebViewConfig) GetDevDir() string

GetDevDir returns the development directory (empty for embedded)

func (*WebViewConfig) GetDirFS

func (c *WebViewConfig) GetDirFS() string

GetDirFS returns the templates directory path in the filesystem

func (*WebViewConfig) GetDirOS

func (c *WebViewConfig) GetDirOS() string

GetDirOS returns the templates directory path on OS filesystem (empty for embedded)

func (*WebViewConfig) GetEmbed

func (c *WebViewConfig) GetEmbed() bool

GetEmbed returns whether to use embedded filesystem

func (*WebViewConfig) GetExt

func (c *WebViewConfig) GetExt() string

GetExt returns the template file extension

func (*WebViewConfig) GetJSPath

func (c *WebViewConfig) GetJSPath() string

GetJSPath returns the JS assets path

func (*WebViewConfig) GetReload

func (c *WebViewConfig) GetReload() bool

GetReload returns whether to reload templates on each request

func (*WebViewConfig) GetTemplateFunctions

func (c *WebViewConfig) GetTemplateFunctions() map[string]any

GetTemplateFunctions returns custom template functions

func (*WebViewConfig) GetTemplatesFS

func (c *WebViewConfig) GetTemplatesFS() []fs.FS

GetTemplatesFS returns the template filesystems

func (*WebViewConfig) GetURLPrefix

func (c *WebViewConfig) GetURLPrefix() string

GetURLPrefix returns the URL prefix for assets

Jump to

Keyboard shortcuts

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