@c8y/ngx-components
Version:
Angular modules for Cumulocity IoT applications
141 lines (135 loc) • 6.17 kB
JavaScript
import { PreviewService, DynamicDatapointsResolver, hookWidget, hookPreview } from '@c8y/ngx-components';
import { gettext } from '@c8y/ngx-components/gettext';
import * as i0 from '@angular/core';
import { inject, Injectable } from '@angular/core';
import { map } from 'rxjs';
import { defaultWidgetIds } from '@c8y/ngx-components/widgets/definitions';
import cloneDeep from 'lodash/cloneDeep';
import { importConfigWithTargets, exportConfigWithTargets } from '@c8y/ngx-components/widgets/import-export-config';
import { PRESET_NAME } from '@c8y/ngx-components/global-context';
import { hookWidgetConfig } from '@c8y/ngx-components/context-dashboard';
class DatapointGraphFactory {
constructor() {
this.previewFeatureService = inject(PreviewService);
this.baseWidgetDefinition = {
id: defaultWidgetIds.DATAPOINTS_GRAPH,
label: gettext('Data graph'),
description: gettext('Displays a graph of selected data points'),
loadComponent: () => import('@c8y/ngx-components/widgets/implementations/datapoints-graph').then(m => m.DatapointsGraphWidgetViewComponent),
loadConfigComponent: () => import('@c8y/ngx-components/widgets/implementations/datapoints-graph').then(m => m.DatapointsGraphWidgetConfigComponent),
previewImage: 'c8y-style-assets/datapoints-graph-widget.png',
resolve: {
datapoints: DynamicDatapointsResolver
},
data: {
schema: () => import('c8y-schema-loader?interfaceName=DatapointsGraphWidgetConfig&type=widget-config!@c8y/ngx-components/echart'),
export: exportConfigWithTargets,
import: importConfigWithTargets,
controls: PRESET_NAME.DATAPOINTS_GRAPH,
settings: {
noNewWidgets: false,
widgetDefaults: {
_width: 8,
_height: 4
},
noDeviceTarget: true,
groupsSelectable: false
},
displaySettings: {
globalTimeContext: true,
globalAggregationContext: true,
globalRealtimeContext: true
}
}
};
}
get() {
return this.previewFeatureService.getState$('ui.datapoint-graph.v2').pipe(map(state => {
if (state) {
const newWidgetDefinition = cloneDeep(this.baseWidgetDefinition);
newWidgetDefinition.id = defaultWidgetIds.DATAPOINTS_GRAPH_NEW;
newWidgetDefinition.data.settings.noNewWidgets = true;
return [this.baseWidgetDefinition, newWidgetDefinition];
}
return [];
}));
}
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: DatapointGraphFactory, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: DatapointGraphFactory }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: DatapointGraphFactory, decorators: [{
type: Injectable
}] });
const DATAPOINT_SELECT_DEFAULT_OPTIONS = {
showRange: true,
showChart: true
};
const MIN_ACTIVE_COUNT = 1;
const datapointGraphWidgetproviders = [
hookWidget(DatapointGraphFactory),
hookPreview({
key: 'ui.datapoint-graph.v2',
label: 'Data graph',
description: () => import('@c8y/style/markdown-files/datapoint-graph-preview.md').then(m => m.default),
settings: {
reload: true
}
}),
/* We need to register the widget config for both the new and old widget IDs. This ensures compatibility for widgets
created with the new data graph id (e.g. if a data point graph widget was created via community plugins)
and widgets using the default one (toggled via preview feature)
*/
hookWidgetConfig({
widgetId: defaultWidgetIds.DATAPOINTS_GRAPH_NEW,
priority: 10,
label: gettext('Time context'),
initialState: {
controls: PRESET_NAME.DATAPOINTS_GRAPH_CONFIG
},
loadComponent: () => import('@c8y/ngx-components/context-dashboard').then(m => m.GlobalContextSectionComponent)
}),
hookWidgetConfig({
widgetId: defaultWidgetIds.DATAPOINTS_GRAPH,
priority: 10,
label: gettext('Time context'),
initialState: {
controls: PRESET_NAME.DATAPOINTS_GRAPH_CONFIG
},
loadComponent: () => import('@c8y/ngx-components/context-dashboard').then(m => m.GlobalContextSectionComponent)
}),
hookWidgetConfig({
widgetId: defaultWidgetIds.DATAPOINTS_GRAPH,
label: gettext('Alarm selection'),
loadComponent: () => import('@c8y/ngx-components/alarm-event-selector').then(m => m.WidgetAlarmSelectorComponent),
initialState: {
configStoreMode: 'MIXED'
},
priority: 100
}),
hookWidgetConfig({
widgetId: defaultWidgetIds.DATAPOINTS_GRAPH,
label: gettext('Event selection'),
loadComponent: () => import('@c8y/ngx-components/alarm-event-selector').then(m => m.WidgetEventSelectorComponent),
initialState: {
configStoreMode: 'MIXED'
},
priority: 110
}),
hookWidgetConfig({
widgetId: defaultWidgetIds.DATAPOINTS_GRAPH,
label: gettext('Data point selection'),
loadComponent: () => import('@c8y/ngx-components/datapoint-selector').then(m => m.WidgetDatapointsSelectorComponent),
initialState: {
minActiveCount: MIN_ACTIVE_COUNT,
defaultFormOptions: DATAPOINT_SELECT_DEFAULT_OPTIONS,
useAdvancedChartOptions: true
},
expanded: true,
priority: 120
})
];
/**
* Generated bundle index. Do not edit.
*/
export { datapointGraphWidgetproviders };
//# sourceMappingURL=c8y-ngx-components-widgets-definitions-datapoints-graph.mjs.map