Documentation
¶
Index ¶
- func ExtractWidgetData(meta map[string]any) map[string]any
- func HiddenFromMetadata(meta map[string]any) bool
- func LocaleFromMetadata(meta map[string]any) string
- func NumericToInt(val any) int
- func OrderFromMetadata(meta map[string]any) int
- func OrderedAreaCodes(areaMap map[string][]dashcmp.WidgetInstance) []string
- func RegisterDefaultWidgets(widgetSvc WidgetService, features FeatureFlags, registerProviders func() error) error
- func RegisterProviders(host ProviderHost, widgetSvc WidgetService, auth Authorizer, ...) error
- func RegisterWidgetAreas(registrar DashboardAreaRegistrar, widgetSvc WidgetService, ...) error
- func SanitizeWidgetData(data map[string]any) map[string]any
- func SpanFromMetadata(meta map[string]any) int
- type ActivityRecorder
- type Authorizer
- type CMSWidgetStore
- func (s *CMSWidgetStore) AssignInstance(ctx context.Context, input godash.AssignWidgetInput) error
- func (s *CMSWidgetStore) CreateInstance(ctx context.Context, input godash.CreateWidgetInstanceInput) (godash.WidgetInstance, error)
- func (s *CMSWidgetStore) DeleteInstance(ctx context.Context, instanceID string) error
- func (s *CMSWidgetStore) EnsureArea(ctx context.Context, def godash.WidgetAreaDefinition) (bool, error)
- func (s *CMSWidgetStore) EnsureDefinition(ctx context.Context, def godash.WidgetDefinition) (bool, error)
- func (s *CMSWidgetStore) GetInstance(ctx context.Context, instanceID string) (godash.WidgetInstance, error)
- func (s *CMSWidgetStore) ReorderArea(ctx context.Context, input godash.ReorderAreaInput) error
- func (s *CMSWidgetStore) ResolveArea(ctx context.Context, input godash.ResolveAreaInput) (godash.ResolvedArea, error)
- func (s *CMSWidgetStore) UpdateInstance(ctx context.Context, input godash.UpdateWidgetInstanceInput) (godash.WidgetInstance, error)
- type DashboardAreaRegistrar
- type DashboardPreferences
- type DashboardPreferencesWithContext
- type DashboardWidgetInstance
- type FeatureFlags
- type GoDashPreferenceStore
- type GoDashPreferenceStoreOption
- type InMemoryDashboardPreferences
- type LayoutPreferenceBackend
- type ProviderHost
- type StoredLayoutOverrides
- type StoredLayoutRow
- type StoredLayoutSlot
- type WidgetAreaDefinition
- type WidgetDefinition
- type WidgetDefinitionSyncResult
- type WidgetDefinitionSyncStatus
- type WidgetInstance
- type WidgetInstanceFilter
- type WidgetService
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExtractWidgetData ¶ added in v0.32.0
ExtractWidgetData returns widget data from metadata in canonical map form.
func HiddenFromMetadata ¶ added in v0.32.0
HiddenFromMetadata reports whether metadata marks the widget hidden.
func LocaleFromMetadata ¶ added in v0.32.0
LocaleFromMetadata extracts an optional widget locale from metadata.
func NumericToInt ¶ added in v0.32.0
NumericToInt coerces numeric-ish values used in dashboard metadata.
func OrderFromMetadata ¶ added in v0.32.0
OrderFromMetadata extracts explicit widget ordering from metadata.
func OrderedAreaCodes ¶ added in v0.32.0
func OrderedAreaCodes(areaMap map[string][]dashcmp.WidgetInstance) []string
OrderedAreaCodes returns dashboard layout areas in preferred order with extras sorted.
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.
func SanitizeWidgetData ¶ added in v0.32.0
SanitizeWidgetData removes blocked payload fields and scrubs unsafe HTML-like values.
func SpanFromMetadata ¶ added in v0.32.0
SpanFromMetadata extracts the widget width/span from layout metadata.
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 ¶
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 ¶
func (s *CMSWidgetStore) CreateInstance(ctx context.Context, input godash.CreateWidgetInstanceInput) (godash.WidgetInstance, error)
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 ¶
func (s *CMSWidgetStore) ResolveArea(ctx context.Context, input godash.ResolveAreaInput) (godash.ResolvedArea, error)
ResolveArea returns the widgets for an area.
func (*CMSWidgetStore) UpdateInstance ¶
func (s *CMSWidgetStore) UpdateInstance(ctx context.Context, input godash.UpdateWidgetInstanceInput) (godash.WidgetInstance, error)
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 `json:"cms"`
Dashboard bool `json:"dashboard"`
Settings bool `json:"settings"`
}
FeatureFlags captures the minimal flags needed for dashboard helpers.
type GoDashPreferenceStore ¶ added in v0.32.0
type GoDashPreferenceStore struct {
// contains filtered or unexported fields
}
GoDashPreferenceStore adapts persisted dashboard overrides to the go-dashboard preference store contract.
func NewGoDashPreferenceStore ¶ added in v0.32.0
func NewGoDashPreferenceStore(backend LayoutPreferenceBackend, store godash.WidgetStore, opts ...GoDashPreferenceStoreOption) *GoDashPreferenceStore
NewGoDashPreferenceStore builds the dashboard-local go-dashboard preference bridge.
func (*GoDashPreferenceStore) LayoutOverrides ¶ added in v0.32.0
func (s *GoDashPreferenceStore) LayoutOverrides(ctx context.Context, viewer godash.ViewerContext) (godash.LayoutOverrides, error)
LayoutOverrides returns persisted overrides for a viewer in go-dashboard format.
func (*GoDashPreferenceStore) SaveLayoutOverrides ¶ added in v0.32.0
func (s *GoDashPreferenceStore) SaveLayoutOverrides(ctx context.Context, viewer godash.ViewerContext, overrides godash.LayoutOverrides) error
SaveLayoutOverrides persists go-dashboard overrides and the derived dashboard layout.
type GoDashPreferenceStoreOption ¶ added in v0.32.0
type GoDashPreferenceStoreOption func(*GoDashPreferenceStore)
GoDashPreferenceStoreOption configures the dashboard-local go-dashboard preference bridge.
func WithMissingViewerUserIDError ¶ added in v0.32.0
func WithMissingViewerUserIDError(fn func() error) GoDashPreferenceStoreOption
WithMissingViewerUserIDError preserves caller-specific missing-viewer error contracts.
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 ¶
func (p *InMemoryDashboardPreferences) ForUser(userID string) []DashboardWidgetInstance
ForUser returns the saved layout for a user.
func (*InMemoryDashboardPreferences) Save ¶
func (p *InMemoryDashboardPreferences) Save(userID string, layout []DashboardWidgetInstance) error
Save stores a user layout.
type LayoutPreferenceBackend ¶ added in v0.32.0
type LayoutPreferenceBackend interface {
LoadDashboardLayoutOverrides(ctx context.Context, userID string) StoredLayoutOverrides
SaveDashboardLayoutOverrides(ctx context.Context, userID string, overrides StoredLayoutOverrides) error
SaveDashboardLayout(ctx context.Context, userID string, layout []DashboardWidgetInstance) error
}
LayoutPreferenceBackend exposes the persistence hooks needed by the go-dashboard preference bridge.
type ProviderHost ¶
type ProviderHost interface {
WithWidgetService(WidgetService)
WithAuthorizer(Authorizer)
}
ProviderHost exposes wiring hooks needed before registering providers.
type StoredLayoutOverrides ¶ added in v0.32.0
type StoredLayoutOverrides struct {
Locale string `json:"locale,omitempty"`
AreaOrder map[string][]string `json:"area_order,omitempty"`
AreaRows map[string][]StoredLayoutRow `json:"area_rows,omitempty"`
HiddenWidgets map[string]bool `json:"hidden_widgets,omitempty"`
}
StoredLayoutOverrides is the dashboard-local persisted override contract.
type StoredLayoutRow ¶ added in v0.32.0
type StoredLayoutRow struct {
Widgets []StoredLayoutSlot `json:"widgets,omitempty"`
}
StoredLayoutRow captures a persisted row of widget slots.
type StoredLayoutSlot ¶ added in v0.32.0
StoredLayoutSlot captures a persisted widget slot.
type WidgetAreaDefinition ¶
type WidgetAreaDefinition struct {
Code string `json:"code"`
Name string `json:"name"`
Scope string `json:"scope"`
}
WidgetAreaDefinition captures CMS widget area metadata.
func DefaultAreaDefinitions ¶ added in v0.27.0
func DefaultAreaDefinitions() []WidgetAreaDefinition
DefaultAreaDefinitions returns the built-in dashboard area definitions.
type WidgetDefinition ¶
type WidgetDefinition struct {
Code string `json:"code"`
Name string `json:"name"`
Schema map[string]any `json:"schema"`
}
WidgetDefinition captures admin widget metadata.
type WidgetDefinitionSyncResult ¶ added in v0.52.0
type WidgetDefinitionSyncResult struct {
Definition WidgetDefinition `json:"definition"`
Status WidgetDefinitionSyncStatus `json:"status"`
}
type WidgetDefinitionSyncStatus ¶ added in v0.52.0
type WidgetDefinitionSyncStatus string
const ( WidgetDefinitionSyncStatusCreated WidgetDefinitionSyncStatus = "created" WidgetDefinitionSyncStatusUpdated WidgetDefinitionSyncStatus = "updated" WidgetDefinitionSyncStatusUnchanged WidgetDefinitionSyncStatus = "unchanged" )
type WidgetInstance ¶
type WidgetInstance struct {
ID string `json:"id"`
DefinitionCode string `json:"definition_code"`
Area string `json:"area"`
PageID string `json:"page_id"`
Locale string `json:"locale"`
Config map[string]any `json:"config"`
Position int `json:"position"`
Span int `json:"span"`
Hidden bool `json:"hidden"`
}
WidgetInstance links a widget definition to a specific area/page.
type WidgetInstanceFilter ¶
type WidgetInstanceFilter struct {
Area string `json:"area"`
PageID string `json:"page_id"`
Locale string `json:"locale"`
FallbackLocales []string `json:"fallback_locales,omitempty"`
}
WidgetInstanceFilter narrows widget instance queries.
type WidgetService ¶
type WidgetService interface {
RegisterAreaDefinition(ctx context.Context, def WidgetAreaDefinition) error
RegisterDefinition(ctx context.Context, def WidgetDefinition) error
SyncDefinition(ctx context.Context, def WidgetDefinition) (*WidgetDefinitionSyncResult, 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.