UNPKG

@c8y/ngx-components

Version:

Angular modules for Cumulocity IoT applications

129 lines 5.87 kB
import { TemplateRef } from '@angular/core'; import { DynamicComponentComponent, DynamicComponentDefinition } from '@c8y/ngx-components'; import { BehaviorSubject, Observable } from 'rxjs'; import { ContextWidgetConfig } from './context-dashboard.model'; import { WidgetConfigSection } from './widget-config-hook/widget-config-hook.model'; import { WidgetConfigSectionService } from './widget-config-hook/widget-config-hook.service'; import * as i0 from "@angular/core"; export declare class WidgetConfigService { private widgetConfigSectionService; private _currentConfig$; /** * The preview of the currently selected widget. If `null` no preview is shown * (except if the selected widget has no configuration). */ preview$: BehaviorSubject<true | DynamicComponentDefinition | TemplateRef<any>>; /** * The currently selected widget definition. */ selected$: BehaviorSubject<DynamicComponentDefinition>; /** * The currently selected widget component. */ selectedComponent$: BehaviorSubject<DynamicComponentComponent>; /** * The current configuration of the selected widget. * Only to read the value. Use `updateConfig` to update the configuration. **/ get currentConfig(): ContextWidgetConfig; /** * The current configuration of the selected widget as observable. * Only to read the value. Use `updateConfig` to update the configuration. */ currentConfig$: Observable<ContextWidgetConfig>; /** * 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`. */ currentSections$: Observable<WidgetConfigSection[]>; /** * Returns a list of all unique providers used in the current sections. */ providers$: Observable<import("@angular/core").Type<unknown>[]>; /** * Indicates if the current selected widget has a configuration or not. */ hasConfig$: Observable<boolean>; /** * 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. */ previewViewState$: Observable<"noPreview" | "templatePreview" | "configPreview">; private readonly STASH_CONFIG_DELAY; private configChange$; private configChangeReset$; private beforeSaveCallbacks; constructor(widgetConfigSectionService: WidgetConfigSectionService); /** * Use this function to get a typed configuration of the selected widget. * @returns The current configuration of the selected widget or an empty object if no config is defined. */ getWidgetConfig<T>(): Observable<T>; /** * Adds a callback which can check the configuration before saving. */ addOnBeforeSave(callback: (config?: ContextWidgetConfig) => boolean | Promise<boolean> | Observable<boolean>): void; /** * Returns true if the configuration can be saved. */ canSave(): Promise<boolean>; /** * Updates the configuration of the selected widget. * @param change The change to apply to the configuration. * @param force 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. */ updateConfig(change: Partial<ContextWidgetConfig>, force?: boolean): void; /** * Used to initialize the configuration of the selected widget. * @param config The configuration to set. */ initConfig(config: ContextWidgetConfig): void; /** * Select a widget * @param selected The widget to select. */ selectWidget(selected: DynamicComponentDefinition): void; /** * Deselect the currently selected. */ deselectWidget(): void; /** * Enables a preview. * @param preview 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. */ setPreview(preview: true | DynamicComponentDefinition | TemplateRef<any>): void; /** * By default, no sections are added to the configuration. However, to ensure * backwards compatibility with old plugins, we check if the default asset selector * and config section should be shown. * @param selectedWidget The currently selected widget. * @param config The used widget configuration. * @returns The default sections. */ private getWidgetDefaultSections; /** * Sections should not be added by default anymore. But to ensure backwards compatibility, we * check if the default selector should be shown. We assume that a default selector will be shown * when: * 1. The widget has a dynamic component for configuration (which is also deprecated). * OR * 2. The widget has not disabled the default selector. */ private isDefaultDeviceSelectorNeeded; /** * Checks if a default setting section is needed. * @param selectedWidget The currently selected widget. * @returns true if one is needed. */ private isDefaultSettingSectionNeeded; static ɵfac: i0.ɵɵFactoryDeclaration<WidgetConfigService, never>; static ɵprov: i0.ɵɵInjectableDeclaration<WidgetConfigService>; } //# sourceMappingURL=widget-config.service.d.ts.map