dashboard

package
v0.26.0 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2026 License: MIT Imports: 9 Imported by: 0

README

admin/internal/dashboard

Dashboard-related helpers and CMS-backed widget persistence.

Purpose

  • Centralize widget area/definition bootstrapping and provider wiring helpers.
  • Provide a CMS-backed store for widget instances (used by go-dashboard integration).

Key Files

  • types.go: Core dashboard/widget types shared with CMS bindings.
  • helpers.go: Widget areas/definitions + provider wiring helpers.
  • cms_widget_store.go: Widget instance store backed by CMS widget services.

Dependencies

  • May depend on CMS interfaces via admin/internal/cmsboot type aliases.
  • Must not import other peer feature packages (navigation, settings, etc).

Where To Change X

  • Default areas/definitions: helpers.go.
  • CMS widget instance persistence behavior: cms_widget_store.go.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterDefaultWidgets

func RegisterDefaultWidgets(widgetSvc WidgetService, features FeatureFlags, registerProviders func() error) error

RegisterDefaultWidgets seeds default widget definitions and optionally invokes a provider registration callback.

func RegisterProviders

func RegisterProviders(host ProviderHost, widgetSvc WidgetService, auth Authorizer, features FeatureFlags, register func() error) error

RegisterProviders wires dashboard dependencies before invoking the provided registration callback.

func RegisterWidgetAreas

func RegisterWidgetAreas(registrar DashboardAreaRegistrar, widgetSvc WidgetService, features FeatureFlags) error

RegisterWidgetAreas seeds default widget areas into the dashboard or widget service.

Types

type ActivityRecorder

type ActivityRecorder interface {
	RecordWidgetEvent(ctx context.Context, action string, inst godash.WidgetInstance)
}

ActivityRecorder captures widget lifecycle events for auditing/telemetry.

type Authorizer

type Authorizer interface {
	Can(ctx context.Context, action string, resource string) bool
}

Authorizer determines whether a subject can perform an action on a resource.

type CMSWidgetStore

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

CMSWidgetStore adapts the admin CMSWidgetService to go-dashboard's WidgetStore interface. It uses the underlying service for persistence and maps fields between the two models.

func NewCMSWidgetStore

func NewCMSWidgetStore(svc WidgetService) *CMSWidgetStore

NewCMSWidgetStore builds a widget store backed by the provided CMS widget service.

func NewCMSWidgetStoreWithActivity

func NewCMSWidgetStoreWithActivity(svc WidgetService, recorder ActivityRecorder) *CMSWidgetStore

NewCMSWidgetStoreWithActivity wires an optional activity recorder for widget events.

func (*CMSWidgetStore) AssignInstance

func (s *CMSWidgetStore) AssignInstance(ctx context.Context, input godash.AssignWidgetInput) error

AssignInstance associates a widget with an area and optional position.

func (*CMSWidgetStore) CreateInstance

CreateInstance stores a widget instance.

func (*CMSWidgetStore) DeleteInstance

func (s *CMSWidgetStore) DeleteInstance(ctx context.Context, instanceID string) error

DeleteInstance removes a widget instance.

func (*CMSWidgetStore) EnsureArea

func (s *CMSWidgetStore) EnsureArea(ctx context.Context, def godash.WidgetAreaDefinition) (bool, error)

EnsureArea registers an area definition when missing.

func (*CMSWidgetStore) EnsureDefinition

func (s *CMSWidgetStore) EnsureDefinition(ctx context.Context, def godash.WidgetDefinition) (bool, error)

EnsureDefinition registers a widget definition when missing.

func (*CMSWidgetStore) GetInstance

func (s *CMSWidgetStore) GetInstance(ctx context.Context, instanceID string) (godash.WidgetInstance, error)

GetInstance fetches a widget instance by ID.

func (*CMSWidgetStore) ReorderArea

func (s *CMSWidgetStore) ReorderArea(ctx context.Context, input godash.ReorderAreaInput) error

ReorderArea reassigns positions within an area.

func (*CMSWidgetStore) ResolveArea

ResolveArea returns the widgets for an area.

func (*CMSWidgetStore) UpdateInstance

UpdateInstance updates an existing widget instance.

type DashboardAreaRegistrar

type DashboardAreaRegistrar interface {
	Areas() []WidgetAreaDefinition
	RegisterArea(def WidgetAreaDefinition)
}

DashboardAreaRegistrar exposes minimal area registration hooks.

type DashboardPreferences

type DashboardPreferences interface {
	ForUser(userID string) []DashboardWidgetInstance
	Save(userID string, layout []DashboardWidgetInstance) error
}

DashboardPreferences stores per-user layouts.

type DashboardPreferencesWithContext

type DashboardPreferencesWithContext interface {
	DashboardPreferences
	ForUserWithContext(ctx context.Context, userID string) []DashboardWidgetInstance
	SaveWithContext(ctx context.Context, userID string, layout []DashboardWidgetInstance) error
}

DashboardPreferencesWithContext allows contextual access to preferences (for activity/locale-aware stores).

type DashboardWidgetInstance

type DashboardWidgetInstance struct {
	ID             string         `json:"id,omitempty"`
	DefinitionCode string         `json:"definition"`
	AreaCode       string         `json:"area"`
	Config         map[string]any `json:"config,omitempty"`
	Position       int            `json:"position,omitempty"`
	Span           int            `json:"span,omitempty"`
	Hidden         bool           `json:"hidden,omitempty"`
	Locale         string         `json:"locale,omitempty"`
}

DashboardWidgetInstance represents a widget placed in an area.

func CloneDashboardInstances

func CloneDashboardInstances(in []DashboardWidgetInstance) []DashboardWidgetInstance

CloneDashboardInstances copies widget instances.

type FeatureFlags

type FeatureFlags struct {
	CMS       bool
	Dashboard bool
	Settings  bool
}

FeatureFlags captures the minimal flags needed for dashboard helpers.

type InMemoryDashboardPreferences

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

InMemoryDashboardPreferences stores layouts in memory.

func NewInMemoryDashboardPreferences

func NewInMemoryDashboardPreferences() *InMemoryDashboardPreferences

NewInMemoryDashboardPreferences constructs a preference store.

func (*InMemoryDashboardPreferences) ForUser

ForUser returns the saved layout for a user.

func (*InMemoryDashboardPreferences) Save

Save stores a user layout.

type ProviderHost

type ProviderHost interface {
	WithWidgetService(WidgetService)
	WithAuthorizer(Authorizer)
}

ProviderHost exposes wiring hooks needed before registering providers.

type WidgetAreaDefinition

type WidgetAreaDefinition struct {
	Code  string
	Name  string
	Scope string
}

WidgetAreaDefinition captures CMS widget area metadata.

type WidgetDefinition

type WidgetDefinition struct {
	Code   string
	Name   string
	Schema map[string]any
}

WidgetDefinition captures admin widget metadata.

type WidgetInstance

type WidgetInstance struct {
	ID             string
	DefinitionCode string
	Area           string
	PageID         string
	Locale         string
	Config         map[string]any
	Position       int
	Span           int
	Hidden         bool
}

WidgetInstance links a widget definition to a specific area/page.

type WidgetInstanceFilter

type WidgetInstanceFilter struct {
	Area   string
	PageID string
	Locale string
}

WidgetInstanceFilter narrows widget instance queries.

type WidgetService

type WidgetService interface {
	RegisterAreaDefinition(ctx context.Context, def WidgetAreaDefinition) error
	RegisterDefinition(ctx context.Context, def WidgetDefinition) error
	DeleteDefinition(ctx context.Context, code string) error
	Areas() []WidgetAreaDefinition
	Definitions() []WidgetDefinition
	SaveInstance(ctx context.Context, instance WidgetInstance) (*WidgetInstance, error)
	DeleteInstance(ctx context.Context, id string) error
	ListInstances(ctx context.Context, filter WidgetInstanceFilter) ([]WidgetInstance, error)
}

WidgetService registers dashboard widget areas/definitions and instances.

Jump to

Keyboard shortcuts

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