File

context-dashboard/widget-config.service.ts

Index

Properties
Methods
Accessors

Constructor

constructor(widgetConfigSectionService: WidgetConfigSectionService)
Parameters :
Name Type Optional
widgetConfigSectionService WidgetConfigSectionService No

Methods

addOnBeforeSave
addOnBeforeSave(callback: (config: ContextWidgetConfig) => void)

Adds a callback which can check the configuration before saving.

Parameters :
Name Type Optional
callback function No
Returns : void
canSave
canSave()

Returns true if the configuration can be saved.

Returns : Promise<boolean>
deselectWidget
deselectWidget()

Deselect the currently selected.

Returns : void
getWidgetConfig
getWidgetConfig()
Type parameters :
  • T

Use this function to get a typed configuration of the selected widget.

Returns : Observable<T>

The current configuration of the selected widget or an empty object if no config is defined.

initConfig
initConfig(config: ContextWidgetConfig)

Used to initialize the configuration of the selected widget.

Parameters :
Name Type Optional Description
config ContextWidgetConfig No

The configuration to set.

Returns : void
selectWidget
selectWidget(selected: DynamicComponentDefinition)

Select a widget

Parameters :
Name Type Optional Description
selected DynamicComponentDefinition No

The widget to select.

Returns : void
setPreview
setPreview(preview: | DynamicComponentDefinition | TemplateRef<any>)

Enables a preview. If set to a DynamicComponentDefinition, the preview will be rendered with the given component. If set to a TemplateRef, the preview will be rendered with the given template.

Parameters :
Name Type Optional Description
preview | DynamicComponentDefinition | TemplateRef<any> No

If set to true, the view component of the current widget will be taken to render the preview. If set to a DynamicComponentDefinition, the preview will be rendered with the given component. If set to a TemplateRef, the preview will be rendered with the given template.

Returns : void
updateConfig
updateConfig(change: Partial, force)

Updates the configuration of the selected widget. Use with caution and only if you want to reset the configuration to some default.

Parameters :
Name Type Optional Default value Description
change Partial<ContextWidgetConfig> No

The change to apply to the configuration.

force No false

If set to true, the configuration will be updated even if no changes are made. Also concurrency checks are ignored and no change is emitted on the component. Use with caution and only if you want to reset the configuration to some default.

Returns : void

Properties

currentConfig$
Default value : this._currentConfig$.asObservable()

The current configuration of the selected widget as observable. Only to read the value. Use updateConfig to update the configuration.

currentSections$
Type : Observable<WidgetConfigSection[]>
Default value : this.selected$.pipe( tap(() => (this.beforeSaveCallbacks = [])), withLatestFrom(this._currentConfig$), mergeMap(([selectedWidget, config]) => selectedWidget === null ? of([]) : this.widgetConfigSectionService.items$.pipe( map(sections => [ ...this.getWidgetDefaultSections(selectedWidget, config), ...sections.filter(section => section.widgetId === selectedWidget.id) ]) ) ), mergeMap((sections: WidgetConfigSectionDefinition[]) => { if (sections.length === 0) { return Promise.resolve([]); } return Promise.all( sections.map(async section => ({ component: await section.loadComponent(), label: section.label, priority: section.priority || 0, expanded: section.expanded || false, initialState: section.initialState, injector: section.injector, providers: section.providers })) ); }), map(sections => sortByPriority(sections)), shareReplay(1) )

Returns all the current sections.

A configuration section is a component that can be used to configure a widget. Sections should be added via the hookWidgetConfig.

hasConfig$
Default value : this.currentSections$.pipe(map(sections => sections.length > 0))

Indicates if the current selected widget has a configuration or not.

preview$
Default value : new BehaviorSubject<true | DynamicComponentDefinition | TemplateRef<any>>(null)

The preview of the currently selected widget. If null no preview is shown (except if the selected widget has no configuration).

previewViewState$
Default value : combineLatest([this.hasConfig$, this.preview$]).pipe( map(([hasConfig, preview]) => { if (preview === null && hasConfig) { return 'noPreview'; } else if (preview instanceof TemplateRef) { return 'templatePreview'; } else if (preview === true || !hasConfig) { return 'configPreview'; } }) )

The view state of the preview. Can be one of:

  • noPreview: No preview is shown and an empty state is shown.
  • configPreview: The preview is shown with the view component of the selected widget.
  • templatePreview: The preview is shown with any template passed with setPreview method.
providers$
Default value : this.currentSections$.pipe( map(sections => Array.from(new Set(sections.flatMap(section => section.providers || [])))) )

Returns a list of all unique providers used in the current sections.

selected$
Default value : new BehaviorSubject<DynamicComponentDefinition>(null)

The currently selected widget definition.

selectedComponent$
Default value : new BehaviorSubject<DynamicComponentComponent>(null)

The currently selected widget component.

Accessors

currentConfig
getcurrentConfig()

The current configuration of the selected widget. Only to read the value. Use updateConfig to update the configuration.

results matching ""

    No results matching ""