2019-09-25 19:37:29 +03:00
|
|
|
///
|
2023-01-31 10:43:56 +02:00
|
|
|
/// Copyright © 2016-2023 The Thingsboard Authors
|
2019-09-25 19:37:29 +03:00
|
|
|
///
|
|
|
|
|
/// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
/// you may not use this file except in compliance with the License.
|
|
|
|
|
/// You may obtain a copy of the License at
|
|
|
|
|
///
|
|
|
|
|
/// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
///
|
|
|
|
|
/// Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
/// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
/// See the License for the specific language governing permissions and
|
|
|
|
|
/// limitations under the License.
|
|
|
|
|
///
|
|
|
|
|
|
2023-02-23 19:01:53 +02:00
|
|
|
import { ChangeDetectionStrategy, Component, forwardRef, Input, OnInit } from '@angular/core';
|
2019-09-25 19:37:29 +03:00
|
|
|
import { PageComponent } from '@shared/components/page.component';
|
|
|
|
|
import { Store } from '@ngrx/store';
|
|
|
|
|
import { AppState } from '@core/core.state';
|
|
|
|
|
import {
|
2019-10-10 13:00:29 +03:00
|
|
|
DataKey,
|
2023-01-30 16:35:19 +02:00
|
|
|
Datasource,
|
|
|
|
|
datasourcesHasAggregation,
|
|
|
|
|
datasourcesHasOnlyComparisonAggregation,
|
2019-10-24 19:52:19 +03:00
|
|
|
DatasourceType,
|
2020-02-21 19:04:49 +02:00
|
|
|
datasourceTypeTranslationMap,
|
2020-04-27 09:27:14 +03:00
|
|
|
defaultLegendConfig,
|
|
|
|
|
GroupInfo,
|
2022-03-30 11:14:54 +03:00
|
|
|
JsonSchema,
|
|
|
|
|
JsonSettingsSchema,
|
|
|
|
|
Widget,
|
2019-10-24 19:52:19 +03:00
|
|
|
widgetType
|
2019-09-25 19:37:29 +03:00
|
|
|
} from '@shared/models/widget.models';
|
2019-10-10 13:00:29 +03:00
|
|
|
import {
|
|
|
|
|
ControlValueAccessor,
|
2023-02-02 15:55:06 +02:00
|
|
|
UntypedFormArray,
|
|
|
|
|
UntypedFormBuilder,
|
|
|
|
|
UntypedFormControl,
|
|
|
|
|
UntypedFormGroup,
|
2019-10-10 13:00:29 +03:00
|
|
|
NG_VALIDATORS,
|
|
|
|
|
NG_VALUE_ACCESSOR,
|
2019-10-24 19:52:19 +03:00
|
|
|
Validator,
|
2019-10-10 13:00:29 +03:00
|
|
|
Validators
|
|
|
|
|
} from '@angular/forms';
|
2019-09-25 19:37:29 +03:00
|
|
|
import { WidgetConfigComponentData } from '@home/models/widget-component.models';
|
2023-01-30 16:35:19 +02:00
|
|
|
import { deepClone, genNextLabel, isDefined, isObject } from '@app/core/utils';
|
2020-07-06 14:42:36 +03:00
|
|
|
import {
|
|
|
|
|
alarmFields,
|
|
|
|
|
AlarmSearchStatus,
|
|
|
|
|
alarmSearchStatusTranslations,
|
|
|
|
|
AlarmSeverity,
|
|
|
|
|
alarmSeverityTranslations
|
|
|
|
|
} from '@shared/models/alarm.models';
|
2019-09-25 19:37:29 +03:00
|
|
|
import { IAliasController } from '@core/api/widget-api.models';
|
2022-09-08 18:51:13 +03:00
|
|
|
import { EntityAlias } from '@shared/models/alias.models';
|
2019-10-10 13:00:29 +03:00
|
|
|
import { UtilsService } from '@core/services/utils.service';
|
|
|
|
|
import { DataKeyType } from '@shared/models/telemetry/telemetry.models';
|
|
|
|
|
import { TranslateService } from '@ngx-translate/core';
|
2019-10-11 19:22:03 +03:00
|
|
|
import { EntityType } from '@shared/models/entity-type.models';
|
2020-12-17 13:32:03 +02:00
|
|
|
import { Observable, of, Subscription } from 'rxjs';
|
2019-10-11 19:22:03 +03:00
|
|
|
import { WidgetConfigCallbacks } from '@home/components/widget/widget-config.component.models';
|
|
|
|
|
import {
|
|
|
|
|
EntityAliasDialogComponent,
|
|
|
|
|
EntityAliasDialogData
|
|
|
|
|
} from '@home/components/alias/entity-alias-dialog.component';
|
2020-12-17 13:32:03 +02:00
|
|
|
import { catchError, mergeMap, tap } from 'rxjs/operators';
|
2023-02-17 19:24:01 +02:00
|
|
|
import { MatDialog } from '@angular/material/dialog';
|
2019-10-17 18:23:53 +03:00
|
|
|
import { EntityService } from '@core/http/entity.service';
|
2019-10-21 19:57:18 +03:00
|
|
|
import { JsonFormComponentData } from '@shared/components/json-form/json-form-component.models';
|
2019-10-24 19:52:19 +03:00
|
|
|
import { WidgetActionsData } from './action/manage-widget-actions.component.models';
|
2022-09-08 18:51:13 +03:00
|
|
|
import { Dashboard } from '@shared/models/dashboard.models';
|
2020-02-21 19:04:49 +02:00
|
|
|
import { entityFields } from '@shared/models/entity.models';
|
2022-09-08 18:51:13 +03:00
|
|
|
import { Filter } from '@shared/models/query/query.models';
|
2020-06-30 19:37:50 +03:00
|
|
|
import { FilterDialogComponent, FilterDialogData } from '@home/components/filter/filter-dialog.component';
|
2020-07-06 14:42:36 +03:00
|
|
|
import { COMMA, ENTER, SEMICOLON } from '@angular/cdk/keycodes';
|
2023-02-17 19:24:01 +02:00
|
|
|
import { MatChipInputEvent } from '@angular/material/chips';
|
2022-04-06 16:07:42 +03:00
|
|
|
import { CdkDragDrop } from '@angular/cdk/drag-drop';
|
2019-10-21 19:57:18 +03:00
|
|
|
|
2020-02-24 17:16:02 +02:00
|
|
|
const emptySettingsSchema: JsonSchema = {
|
2019-10-21 19:57:18 +03:00
|
|
|
type: 'object',
|
|
|
|
|
properties: {}
|
|
|
|
|
};
|
2020-02-24 17:16:02 +02:00
|
|
|
const emptySettingsGroupInfoes: GroupInfo[] = [];
|
2019-10-21 19:57:18 +03:00
|
|
|
const defaultSettingsForm = [
|
|
|
|
|
'*'
|
|
|
|
|
];
|
2019-09-25 19:37:29 +03:00
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
selector: 'tb-widget-config',
|
|
|
|
|
templateUrl: './widget-config.component.html',
|
|
|
|
|
styleUrls: ['./widget-config.component.scss'],
|
|
|
|
|
providers: [
|
|
|
|
|
{
|
|
|
|
|
provide: NG_VALUE_ACCESSOR,
|
|
|
|
|
useExisting: forwardRef(() => WidgetConfigComponent),
|
|
|
|
|
multi: true
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
provide: NG_VALIDATORS,
|
|
|
|
|
useExisting: forwardRef(() => WidgetConfigComponent),
|
|
|
|
|
multi: true,
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
})
|
|
|
|
|
export class WidgetConfigComponent extends PageComponent implements OnInit, ControlValueAccessor, Validator {
|
|
|
|
|
|
2020-07-06 14:42:36 +03:00
|
|
|
readonly separatorKeysCodes: number[] = [ENTER, COMMA, SEMICOLON];
|
|
|
|
|
|
2019-09-25 19:37:29 +03:00
|
|
|
widgetTypes = widgetType;
|
|
|
|
|
|
2019-10-11 19:22:03 +03:00
|
|
|
entityTypes = EntityType;
|
|
|
|
|
|
2020-07-06 14:42:36 +03:00
|
|
|
alarmSearchStatuses = [AlarmSearchStatus.ACTIVE,
|
|
|
|
|
AlarmSearchStatus.CLEARED,
|
|
|
|
|
AlarmSearchStatus.ACK,
|
|
|
|
|
AlarmSearchStatus.UNACK];
|
|
|
|
|
|
|
|
|
|
alarmSearchStatusTranslationMap = alarmSearchStatusTranslations;
|
|
|
|
|
|
|
|
|
|
alarmSeverities = Object.keys(AlarmSeverity);
|
|
|
|
|
alarmSeverityEnum = AlarmSeverity;
|
|
|
|
|
|
|
|
|
|
alarmSeverityTranslationMap = alarmSeverityTranslations;
|
2019-10-10 13:00:29 +03:00
|
|
|
|
2019-09-25 19:37:29 +03:00
|
|
|
@Input()
|
|
|
|
|
forceExpandDatasources: boolean;
|
|
|
|
|
|
|
|
|
|
@Input()
|
|
|
|
|
aliasController: IAliasController;
|
|
|
|
|
|
2019-10-11 19:22:03 +03:00
|
|
|
@Input()
|
2022-03-22 17:13:21 +02:00
|
|
|
dashboard: Dashboard;
|
2019-10-11 19:22:03 +03:00
|
|
|
|
2020-06-30 19:37:50 +03:00
|
|
|
@Input()
|
2022-03-22 17:13:21 +02:00
|
|
|
widget: Widget;
|
2020-06-30 19:37:50 +03:00
|
|
|
|
2019-09-25 19:37:29 +03:00
|
|
|
@Input()
|
|
|
|
|
functionsOnly: boolean;
|
|
|
|
|
|
|
|
|
|
@Input() disabled: boolean;
|
|
|
|
|
|
2019-10-10 13:00:29 +03:00
|
|
|
widgetType: widgetType;
|
|
|
|
|
|
2019-10-11 19:22:03 +03:00
|
|
|
datasourceType = DatasourceType;
|
2021-03-02 12:04:45 +02:00
|
|
|
datasourceTypes: Array<DatasourceType> = [];
|
2019-10-11 19:22:03 +03:00
|
|
|
datasourceTypesTranslations = datasourceTypeTranslationMap;
|
|
|
|
|
|
|
|
|
|
widgetConfigCallbacks: WidgetConfigCallbacks = {
|
|
|
|
|
createEntityAlias: this.createEntityAlias.bind(this),
|
2020-06-30 19:37:50 +03:00
|
|
|
createFilter: this.createFilter.bind(this),
|
2019-10-17 18:23:53 +03:00
|
|
|
generateDataKey: this.generateDataKey.bind(this),
|
2019-10-24 19:52:19 +03:00
|
|
|
fetchEntityKeys: this.fetchEntityKeys.bind(this),
|
|
|
|
|
fetchDashboardStates: this.fetchDashboardStates.bind(this)
|
2019-10-11 19:22:03 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
widgetEditMode = this.utils.widgetEditMode;
|
|
|
|
|
|
2019-09-25 19:37:29 +03:00
|
|
|
selectedTab: number;
|
|
|
|
|
|
2019-12-23 14:36:44 +02:00
|
|
|
modelValue: WidgetConfigComponentData;
|
2019-09-25 19:37:29 +03:00
|
|
|
|
2021-12-23 14:16:22 +02:00
|
|
|
showLegendFieldset = true;
|
|
|
|
|
|
2019-09-25 19:37:29 +03:00
|
|
|
private propagateChange = null;
|
|
|
|
|
|
2023-02-02 15:55:06 +02:00
|
|
|
public dataSettings: UntypedFormGroup;
|
|
|
|
|
public targetDeviceSettings: UntypedFormGroup;
|
|
|
|
|
public alarmSourceSettings: UntypedFormGroup;
|
|
|
|
|
public widgetSettings: UntypedFormGroup;
|
|
|
|
|
public layoutSettings: UntypedFormGroup;
|
|
|
|
|
public advancedSettings: UntypedFormGroup;
|
|
|
|
|
public actionsSettings: UntypedFormGroup;
|
2022-09-16 11:40:21 +03:00
|
|
|
public openExtensionPanel = true;
|
|
|
|
|
public timeseriesKeyError = false;
|
2022-03-28 13:39:26 +03:00
|
|
|
|
|
|
|
|
public datasourceError: string[] = [];
|
|
|
|
|
|
2019-10-11 19:22:03 +03:00
|
|
|
private dataSettingsChangesSubscription: Subscription;
|
|
|
|
|
private targetDeviceSettingsSubscription: Subscription;
|
2019-10-24 19:52:19 +03:00
|
|
|
private alarmSourceSettingsSubscription: Subscription;
|
|
|
|
|
private widgetSettingsSubscription: Subscription;
|
|
|
|
|
private layoutSettingsSubscription: Subscription;
|
2019-10-21 19:57:18 +03:00
|
|
|
private advancedSettingsSubscription: Subscription;
|
2019-10-24 19:52:19 +03:00
|
|
|
private actionsSettingsSubscription: Subscription;
|
2019-10-10 13:00:29 +03:00
|
|
|
|
|
|
|
|
constructor(protected store: Store<AppState>,
|
|
|
|
|
private utils: UtilsService,
|
2019-10-17 18:23:53 +03:00
|
|
|
private entityService: EntityService,
|
2019-10-11 19:22:03 +03:00
|
|
|
private dialog: MatDialog,
|
2019-10-10 13:00:29 +03:00
|
|
|
private translate: TranslateService,
|
2023-02-02 15:55:06 +02:00
|
|
|
private fb: UntypedFormBuilder) {
|
2019-09-25 19:37:29 +03:00
|
|
|
super(store);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ngOnInit(): void {
|
2019-10-31 18:33:51 +02:00
|
|
|
this.dataSettings = this.fb.group({});
|
|
|
|
|
this.targetDeviceSettings = this.fb.group({});
|
|
|
|
|
this.alarmSourceSettings = this.fb.group({});
|
|
|
|
|
this.advancedSettings = this.fb.group({});
|
2019-10-24 19:52:19 +03:00
|
|
|
this.widgetSettings = this.fb.group({
|
|
|
|
|
title: [null, []],
|
|
|
|
|
showTitleIcon: [null, []],
|
|
|
|
|
titleIcon: [null, []],
|
|
|
|
|
iconColor: [null, []],
|
|
|
|
|
iconSize: [null, []],
|
2020-02-25 19:11:25 +02:00
|
|
|
titleTooltip: [null, []],
|
2019-10-24 19:52:19 +03:00
|
|
|
showTitle: [null, []],
|
|
|
|
|
dropShadow: [null, []],
|
|
|
|
|
enableFullscreen: [null, []],
|
|
|
|
|
backgroundColor: [null, []],
|
|
|
|
|
color: [null, []],
|
|
|
|
|
padding: [null, []],
|
|
|
|
|
margin: [null, []],
|
|
|
|
|
widgetStyle: [null, []],
|
2021-12-22 17:15:10 +02:00
|
|
|
widgetCss: [null, []],
|
2019-10-24 19:52:19 +03:00
|
|
|
titleStyle: [null, []],
|
2022-05-16 16:35:07 +03:00
|
|
|
pageSize: [1024, [Validators.min(1), Validators.pattern(/^\d*$/)]],
|
2019-10-24 19:52:19 +03:00
|
|
|
units: [null, []],
|
|
|
|
|
decimals: [null, [Validators.min(0), Validators.max(15), Validators.pattern(/^\d*$/)]],
|
2021-10-13 12:14:18 +03:00
|
|
|
noDataDisplayMessage: [null, []],
|
2019-10-24 19:52:19 +03:00
|
|
|
showLegend: [null, []],
|
|
|
|
|
legendConfig: [null, []]
|
|
|
|
|
});
|
2021-10-27 13:33:51 +03:00
|
|
|
this.widgetSettings.get('showTitle').valueChanges.subscribe((value: boolean) => {
|
|
|
|
|
if (value) {
|
|
|
|
|
this.widgetSettings.get('titleStyle').enable({emitEvent: false});
|
|
|
|
|
this.widgetSettings.get('titleTooltip').enable({emitEvent: false});
|
|
|
|
|
this.widgetSettings.get('showTitleIcon').enable({emitEvent: false});
|
|
|
|
|
} else {
|
|
|
|
|
this.widgetSettings.get('titleStyle').disable({emitEvent: false});
|
|
|
|
|
this.widgetSettings.get('titleTooltip').disable({emitEvent: false});
|
|
|
|
|
this.widgetSettings.get('showTitleIcon').patchValue(false);
|
|
|
|
|
this.widgetSettings.get('showTitleIcon').disable({emitEvent: false});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2019-10-24 19:52:19 +03:00
|
|
|
this.widgetSettings.get('showTitleIcon').valueChanges.subscribe((value: boolean) => {
|
|
|
|
|
if (value) {
|
|
|
|
|
this.widgetSettings.get('titleIcon').enable({emitEvent: false});
|
2021-10-27 13:33:51 +03:00
|
|
|
this.widgetSettings.get('iconColor').enable({emitEvent: false});
|
|
|
|
|
this.widgetSettings.get('iconSize').enable({emitEvent: false});
|
2019-10-24 19:52:19 +03:00
|
|
|
} else {
|
|
|
|
|
this.widgetSettings.get('titleIcon').disable({emitEvent: false});
|
2021-10-27 13:33:51 +03:00
|
|
|
this.widgetSettings.get('iconColor').disable({emitEvent: false});
|
|
|
|
|
this.widgetSettings.get('iconSize').disable({emitEvent: false});
|
2019-10-24 19:52:19 +03:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
this.widgetSettings.get('showLegend').valueChanges.subscribe((value: boolean) => {
|
|
|
|
|
if (value) {
|
|
|
|
|
this.widgetSettings.get('legendConfig').enable({emitEvent: false});
|
|
|
|
|
} else {
|
|
|
|
|
this.widgetSettings.get('legendConfig').disable({emitEvent: false});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
this.layoutSettings = this.fb.group({
|
|
|
|
|
mobileOrder: [null, [Validators.pattern(/^-?[0-9]+$/)]],
|
2021-07-22 15:44:40 +03:00
|
|
|
mobileHeight: [null, [Validators.min(1), Validators.max(10), Validators.pattern(/^\d*$/)]],
|
2022-11-20 00:32:32 +05:00
|
|
|
mobileHide: [false],
|
|
|
|
|
desktopHide: [false]
|
2019-10-24 19:52:19 +03:00
|
|
|
});
|
|
|
|
|
this.actionsSettings = this.fb.group({
|
|
|
|
|
actionsData: [null, []]
|
|
|
|
|
});
|
2019-10-11 19:22:03 +03:00
|
|
|
}
|
|
|
|
|
|
2021-10-27 13:33:51 +03:00
|
|
|
ngOnDestroy(): void {
|
|
|
|
|
this.removeChangeSubscriptions();
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-11 19:22:03 +03:00
|
|
|
private removeChangeSubscriptions() {
|
|
|
|
|
if (this.dataSettingsChangesSubscription) {
|
|
|
|
|
this.dataSettingsChangesSubscription.unsubscribe();
|
|
|
|
|
this.dataSettingsChangesSubscription = null;
|
|
|
|
|
}
|
|
|
|
|
if (this.targetDeviceSettingsSubscription) {
|
|
|
|
|
this.targetDeviceSettingsSubscription.unsubscribe();
|
|
|
|
|
this.targetDeviceSettingsSubscription = null;
|
|
|
|
|
}
|
2019-10-24 19:52:19 +03:00
|
|
|
if (this.alarmSourceSettingsSubscription) {
|
|
|
|
|
this.alarmSourceSettingsSubscription.unsubscribe();
|
|
|
|
|
this.alarmSourceSettingsSubscription = null;
|
|
|
|
|
}
|
|
|
|
|
if (this.widgetSettingsSubscription) {
|
|
|
|
|
this.widgetSettingsSubscription.unsubscribe();
|
|
|
|
|
this.widgetSettingsSubscription = null;
|
|
|
|
|
}
|
|
|
|
|
if (this.layoutSettingsSubscription) {
|
|
|
|
|
this.layoutSettingsSubscription.unsubscribe();
|
|
|
|
|
this.layoutSettingsSubscription = null;
|
|
|
|
|
}
|
2019-10-21 19:57:18 +03:00
|
|
|
if (this.advancedSettingsSubscription) {
|
|
|
|
|
this.advancedSettingsSubscription.unsubscribe();
|
|
|
|
|
this.advancedSettingsSubscription = null;
|
|
|
|
|
}
|
2019-10-24 19:52:19 +03:00
|
|
|
if (this.actionsSettingsSubscription) {
|
|
|
|
|
this.actionsSettingsSubscription.unsubscribe();
|
|
|
|
|
this.actionsSettingsSubscription = null;
|
|
|
|
|
}
|
2019-10-11 19:22:03 +03:00
|
|
|
}
|
2019-10-10 13:00:29 +03:00
|
|
|
|
2019-10-11 19:22:03 +03:00
|
|
|
private createChangeSubscriptions() {
|
|
|
|
|
this.dataSettingsChangesSubscription = this.dataSettings.valueChanges.subscribe(
|
|
|
|
|
() => this.updateDataSettings()
|
|
|
|
|
);
|
|
|
|
|
this.targetDeviceSettingsSubscription = this.targetDeviceSettings.valueChanges.subscribe(
|
|
|
|
|
() => this.updateTargetDeviceSettings()
|
|
|
|
|
);
|
2019-10-24 19:52:19 +03:00
|
|
|
this.alarmSourceSettingsSubscription = this.alarmSourceSettings.valueChanges.subscribe(
|
|
|
|
|
() => this.updateAlarmSourceSettings()
|
|
|
|
|
);
|
|
|
|
|
this.widgetSettingsSubscription = this.widgetSettings.valueChanges.subscribe(
|
|
|
|
|
() => this.updateWidgetSettings()
|
|
|
|
|
);
|
|
|
|
|
this.layoutSettingsSubscription = this.layoutSettings.valueChanges.subscribe(
|
|
|
|
|
() => this.updateLayoutSettings()
|
|
|
|
|
);
|
2019-10-21 19:57:18 +03:00
|
|
|
this.advancedSettingsSubscription = this.advancedSettings.valueChanges.subscribe(
|
|
|
|
|
() => this.updateAdvancedSettings()
|
|
|
|
|
);
|
2019-10-24 19:52:19 +03:00
|
|
|
this.actionsSettingsSubscription = this.actionsSettings.valueChanges.subscribe(
|
|
|
|
|
() => this.updateActionSettings()
|
|
|
|
|
);
|
2019-10-10 13:00:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private buildForms() {
|
2021-03-02 12:04:45 +02:00
|
|
|
if (this.functionsOnly) {
|
|
|
|
|
this.datasourceTypes = [DatasourceType.function];
|
|
|
|
|
} else {
|
|
|
|
|
this.datasourceTypes = [DatasourceType.function, DatasourceType.entity];
|
|
|
|
|
if (this.widgetType === widgetType.latest) {
|
|
|
|
|
this.datasourceTypes.push(DatasourceType.entityCount);
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-12-23 14:16:22 +02:00
|
|
|
|
2019-10-10 13:00:29 +03:00
|
|
|
this.dataSettings = this.fb.group({});
|
2019-10-11 19:22:03 +03:00
|
|
|
this.targetDeviceSettings = this.fb.group({});
|
2019-10-24 19:52:19 +03:00
|
|
|
this.alarmSourceSettings = this.fb.group({});
|
2019-10-21 19:57:18 +03:00
|
|
|
this.advancedSettings = this.fb.group({});
|
2022-09-08 18:51:13 +03:00
|
|
|
if (this.widgetType === widgetType.timeseries || this.widgetType === widgetType.alarm || this.widgetType === widgetType.latest) {
|
|
|
|
|
this.dataSettings.addControl('useDashboardTimewindow', this.fb.control(true));
|
|
|
|
|
this.dataSettings.addControl('displayTimewindow', this.fb.control({value: true, disabled: true}));
|
|
|
|
|
this.dataSettings.addControl('timewindow', this.fb.control({value: null, disabled: true}));
|
2019-10-10 13:00:29 +03:00
|
|
|
this.dataSettings.get('useDashboardTimewindow').valueChanges.subscribe((value: boolean) => {
|
|
|
|
|
if (value) {
|
|
|
|
|
this.dataSettings.get('displayTimewindow').disable({emitEvent: false});
|
|
|
|
|
this.dataSettings.get('timewindow').disable({emitEvent: false});
|
|
|
|
|
} else {
|
|
|
|
|
this.dataSettings.get('displayTimewindow').enable({emitEvent: false});
|
|
|
|
|
this.dataSettings.get('timewindow').enable({emitEvent: false});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
if (this.widgetType === widgetType.alarm) {
|
2020-07-06 14:42:36 +03:00
|
|
|
this.dataSettings.addControl('alarmStatusList', this.fb.control(null));
|
|
|
|
|
this.dataSettings.addControl('alarmSeverityList', this.fb.control(null));
|
|
|
|
|
this.dataSettings.addControl('alarmTypeList', this.fb.control(null));
|
|
|
|
|
this.dataSettings.addControl('searchPropagatedAlarms', this.fb.control(null));
|
2019-10-10 13:00:29 +03:00
|
|
|
}
|
|
|
|
|
}
|
2019-10-21 19:57:18 +03:00
|
|
|
if (this.modelValue.isDataEnabled) {
|
2019-10-10 13:00:29 +03:00
|
|
|
if (this.widgetType !== widgetType.rpc &&
|
|
|
|
|
this.widgetType !== widgetType.alarm &&
|
|
|
|
|
this.widgetType !== widgetType.static) {
|
|
|
|
|
this.dataSettings.addControl('datasources',
|
|
|
|
|
this.fb.array([]));
|
2019-10-11 19:22:03 +03:00
|
|
|
} else if (this.widgetType === widgetType.rpc) {
|
|
|
|
|
this.targetDeviceSettings.addControl('targetDeviceAliasId',
|
|
|
|
|
this.fb.control(null,
|
|
|
|
|
this.widgetEditMode ? [] : [Validators.required]));
|
2019-10-24 19:52:19 +03:00
|
|
|
} else if (this.widgetType === widgetType.alarm) {
|
|
|
|
|
this.alarmSourceSettings = this.buildDatasourceForm();
|
2019-10-10 13:00:29 +03:00
|
|
|
}
|
|
|
|
|
}
|
2019-10-21 19:57:18 +03:00
|
|
|
this.advancedSettings.addControl('settings',
|
|
|
|
|
this.fb.control(null, []));
|
2019-09-25 19:37:29 +03:00
|
|
|
}
|
|
|
|
|
|
2023-02-02 15:55:06 +02:00
|
|
|
datasourcesFormArray(): UntypedFormArray {
|
|
|
|
|
return this.dataSettings.get('datasources') as UntypedFormArray;
|
2019-12-23 14:36:44 +02:00
|
|
|
}
|
|
|
|
|
|
2019-09-25 19:37:29 +03:00
|
|
|
registerOnChange(fn: any): void {
|
|
|
|
|
this.propagateChange = fn;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
registerOnTouched(fn: any): void {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setDisabledState(isDisabled: boolean): void {
|
|
|
|
|
this.disabled = isDisabled;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
writeValue(value: WidgetConfigComponentData): void {
|
|
|
|
|
this.modelValue = value;
|
2019-10-11 19:22:03 +03:00
|
|
|
this.removeChangeSubscriptions();
|
2019-09-25 19:37:29 +03:00
|
|
|
if (this.modelValue) {
|
2019-10-10 13:00:29 +03:00
|
|
|
if (this.widgetType !== this.modelValue.widgetType) {
|
|
|
|
|
this.widgetType = this.modelValue.widgetType;
|
2021-12-24 11:13:28 +02:00
|
|
|
this.showLegendFieldset = (this.widgetType === widgetType.timeseries || this.widgetType === widgetType.latest);
|
2019-10-10 13:00:29 +03:00
|
|
|
this.buildForms();
|
|
|
|
|
}
|
2019-09-25 19:37:29 +03:00
|
|
|
const config = this.modelValue.config;
|
|
|
|
|
const layout = this.modelValue.layout;
|
|
|
|
|
if (config) {
|
|
|
|
|
this.selectedTab = 0;
|
2022-01-17 18:38:04 +02:00
|
|
|
const displayWidgetTitle = isDefined(config.showTitle) ? config.showTitle : false;
|
2019-10-24 19:52:19 +03:00
|
|
|
this.widgetSettings.patchValue({
|
|
|
|
|
title: config.title,
|
2022-01-17 18:38:04 +02:00
|
|
|
showTitleIcon: isDefined(config.showTitleIcon) && displayWidgetTitle ? config.showTitleIcon : false,
|
2019-10-24 19:52:19 +03:00
|
|
|
titleIcon: isDefined(config.titleIcon) ? config.titleIcon : '',
|
|
|
|
|
iconColor: isDefined(config.iconColor) ? config.iconColor : 'rgba(0, 0, 0, 0.87)',
|
|
|
|
|
iconSize: isDefined(config.iconSize) ? config.iconSize : '24px',
|
2020-02-25 19:11:25 +02:00
|
|
|
titleTooltip: isDefined(config.titleTooltip) ? config.titleTooltip : '',
|
2022-01-17 18:38:04 +02:00
|
|
|
showTitle: displayWidgetTitle,
|
2019-10-24 19:52:19 +03:00
|
|
|
dropShadow: isDefined(config.dropShadow) ? config.dropShadow : true,
|
|
|
|
|
enableFullscreen: isDefined(config.enableFullscreen) ? config.enableFullscreen : true,
|
|
|
|
|
backgroundColor: config.backgroundColor,
|
|
|
|
|
color: config.color,
|
|
|
|
|
padding: config.padding,
|
|
|
|
|
margin: config.margin,
|
|
|
|
|
widgetStyle: isDefined(config.widgetStyle) ? config.widgetStyle : {},
|
2021-12-22 17:15:10 +02:00
|
|
|
widgetCss: isDefined(config.widgetCss) ? config.widgetCss : '',
|
2019-10-24 19:52:19 +03:00
|
|
|
titleStyle: isDefined(config.titleStyle) ? config.titleStyle : {
|
|
|
|
|
fontSize: '16px',
|
|
|
|
|
fontWeight: 400
|
|
|
|
|
},
|
2022-05-16 16:35:07 +03:00
|
|
|
pageSize: isDefined(config.pageSize) ? config.pageSize : 1024,
|
2019-10-24 19:52:19 +03:00
|
|
|
units: config.units,
|
|
|
|
|
decimals: config.decimals,
|
2021-10-13 12:14:18 +03:00
|
|
|
noDataDisplayMessage: isDefined(config.noDataDisplayMessage) ? config.noDataDisplayMessage : '',
|
2019-10-24 19:52:19 +03:00
|
|
|
showLegend: isDefined(config.showLegend) ? config.showLegend :
|
|
|
|
|
this.widgetType === widgetType.timeseries,
|
|
|
|
|
legendConfig: config.legendConfig || defaultLegendConfig(this.widgetType)
|
|
|
|
|
},
|
|
|
|
|
{emitEvent: false}
|
|
|
|
|
);
|
2021-10-27 13:33:51 +03:00
|
|
|
const showTitle: boolean = this.widgetSettings.get('showTitle').value;
|
|
|
|
|
if (showTitle) {
|
|
|
|
|
this.widgetSettings.get('titleTooltip').enable({emitEvent: false});
|
|
|
|
|
this.widgetSettings.get('titleStyle').enable({emitEvent: false});
|
|
|
|
|
this.widgetSettings.get('showTitleIcon').enable({emitEvent: false});
|
|
|
|
|
} else {
|
|
|
|
|
this.widgetSettings.get('titleTooltip').disable({emitEvent: false});
|
|
|
|
|
this.widgetSettings.get('titleStyle').disable({emitEvent: false});
|
|
|
|
|
this.widgetSettings.get('showTitleIcon').disable({emitEvent: false});
|
|
|
|
|
}
|
2019-10-24 19:52:19 +03:00
|
|
|
const showTitleIcon: boolean = this.widgetSettings.get('showTitleIcon').value;
|
|
|
|
|
if (showTitleIcon) {
|
|
|
|
|
this.widgetSettings.get('titleIcon').enable({emitEvent: false});
|
2021-10-27 13:33:51 +03:00
|
|
|
this.widgetSettings.get('iconColor').enable({emitEvent: false});
|
|
|
|
|
this.widgetSettings.get('iconSize').enable({emitEvent: false});
|
2019-10-24 19:52:19 +03:00
|
|
|
} else {
|
|
|
|
|
this.widgetSettings.get('titleIcon').disable({emitEvent: false});
|
2021-10-27 13:33:51 +03:00
|
|
|
this.widgetSettings.get('iconColor').disable({emitEvent: false});
|
|
|
|
|
this.widgetSettings.get('iconSize').disable({emitEvent: false});
|
2019-10-24 19:52:19 +03:00
|
|
|
}
|
|
|
|
|
const showLegend: boolean = this.widgetSettings.get('showLegend').value;
|
|
|
|
|
if (showLegend) {
|
|
|
|
|
this.widgetSettings.get('legendConfig').enable({emitEvent: false});
|
|
|
|
|
} else {
|
|
|
|
|
this.widgetSettings.get('legendConfig').disable({emitEvent: false});
|
2019-09-25 19:37:29 +03:00
|
|
|
}
|
2019-10-24 19:52:19 +03:00
|
|
|
const actionsData: WidgetActionsData = {
|
|
|
|
|
actionsMap: config.actions || {},
|
|
|
|
|
actionSources: this.modelValue.actionSources || {}
|
|
|
|
|
};
|
|
|
|
|
this.actionsSettings.patchValue(
|
|
|
|
|
{
|
|
|
|
|
actionsData
|
|
|
|
|
},
|
|
|
|
|
{emitEvent: false}
|
|
|
|
|
);
|
2022-09-08 18:51:13 +03:00
|
|
|
if (this.widgetType === widgetType.timeseries || this.widgetType === widgetType.alarm || this.widgetType === widgetType.latest) {
|
2019-10-10 13:00:29 +03:00
|
|
|
const useDashboardTimewindow = isDefined(config.useDashboardTimewindow) ?
|
|
|
|
|
config.useDashboardTimewindow : true;
|
|
|
|
|
this.dataSettings.patchValue(
|
|
|
|
|
{ useDashboardTimewindow }, {emitEvent: false}
|
|
|
|
|
);
|
|
|
|
|
if (useDashboardTimewindow) {
|
|
|
|
|
this.dataSettings.get('displayTimewindow').disable({emitEvent: false});
|
|
|
|
|
this.dataSettings.get('timewindow').disable({emitEvent: false});
|
|
|
|
|
} else {
|
|
|
|
|
this.dataSettings.get('displayTimewindow').enable({emitEvent: false});
|
|
|
|
|
this.dataSettings.get('timewindow').enable({emitEvent: false});
|
|
|
|
|
}
|
|
|
|
|
this.dataSettings.patchValue(
|
|
|
|
|
{ displayTimewindow: isDefined(config.displayTimewindow) ?
|
|
|
|
|
config.displayTimewindow : true }, {emitEvent: false}
|
|
|
|
|
);
|
|
|
|
|
this.dataSettings.patchValue(
|
|
|
|
|
{ timewindow: config.timewindow }, {emitEvent: false}
|
|
|
|
|
);
|
|
|
|
|
}
|
2019-10-21 19:57:18 +03:00
|
|
|
if (this.modelValue.isDataEnabled) {
|
2019-09-25 19:37:29 +03:00
|
|
|
if (this.widgetType !== widgetType.rpc &&
|
|
|
|
|
this.widgetType !== widgetType.alarm &&
|
|
|
|
|
this.widgetType !== widgetType.static) {
|
2023-02-02 15:55:06 +02:00
|
|
|
const datasourcesFormArray = this.dataSettings.get('datasources') as UntypedFormArray;
|
2019-10-11 19:22:03 +03:00
|
|
|
datasourcesFormArray.clear();
|
2019-09-25 19:37:29 +03:00
|
|
|
if (config.datasources) {
|
2019-10-10 13:00:29 +03:00
|
|
|
config.datasources.forEach((datasource) => {
|
2019-10-11 19:22:03 +03:00
|
|
|
datasourcesFormArray.push(this.buildDatasourceForm(datasource));
|
2019-10-10 13:00:29 +03:00
|
|
|
});
|
2019-09-25 19:37:29 +03:00
|
|
|
}
|
|
|
|
|
} else if (this.widgetType === widgetType.rpc) {
|
2019-10-11 19:22:03 +03:00
|
|
|
let targetDeviceAliasId: string;
|
2019-09-25 19:37:29 +03:00
|
|
|
if (config.targetDeviceAliasIds && config.targetDeviceAliasIds.length > 0) {
|
|
|
|
|
const aliasId = config.targetDeviceAliasIds[0];
|
|
|
|
|
const entityAliases = this.aliasController.getEntityAliases();
|
|
|
|
|
if (entityAliases[aliasId]) {
|
2019-10-11 19:22:03 +03:00
|
|
|
targetDeviceAliasId = entityAliases[aliasId].id;
|
2019-09-25 19:37:29 +03:00
|
|
|
} else {
|
2019-10-11 19:22:03 +03:00
|
|
|
targetDeviceAliasId = null;
|
2019-09-25 19:37:29 +03:00
|
|
|
}
|
|
|
|
|
} else {
|
2019-10-11 19:22:03 +03:00
|
|
|
targetDeviceAliasId = null;
|
2019-09-25 19:37:29 +03:00
|
|
|
}
|
2019-10-11 19:22:03 +03:00
|
|
|
this.targetDeviceSettings.patchValue({
|
|
|
|
|
targetDeviceAliasId
|
|
|
|
|
}, {emitEvent: false});
|
2019-09-25 19:37:29 +03:00
|
|
|
} else if (this.widgetType === widgetType.alarm) {
|
2020-07-06 14:42:36 +03:00
|
|
|
let alarmStatusList: AlarmSearchStatus[] = [];
|
|
|
|
|
if (isDefined(config.alarmStatusList) && config.alarmStatusList.length) {
|
|
|
|
|
alarmStatusList = config.alarmStatusList;
|
|
|
|
|
} else if (isDefined(config.alarmSearchStatus) && config.alarmSearchStatus !== AlarmSearchStatus.ANY) {
|
|
|
|
|
alarmStatusList = [config.alarmSearchStatus];
|
|
|
|
|
}
|
2019-10-10 13:00:29 +03:00
|
|
|
this.dataSettings.patchValue(
|
2020-07-06 14:42:36 +03:00
|
|
|
{ alarmStatusList }, {emitEvent: false}
|
2019-10-10 13:00:29 +03:00
|
|
|
);
|
|
|
|
|
this.dataSettings.patchValue(
|
2020-07-06 14:42:36 +03:00
|
|
|
{ alarmSeverityList: isDefined(config.alarmSeverityList) ? config.alarmSeverityList : [] }, {emitEvent: false}
|
2019-10-10 13:00:29 +03:00
|
|
|
);
|
2020-02-21 16:31:03 +02:00
|
|
|
this.dataSettings.patchValue(
|
2020-07-06 14:42:36 +03:00
|
|
|
{ alarmTypeList: isDefined(config.alarmTypeList) ? config.alarmTypeList : [] }, {emitEvent: false}
|
2020-02-21 16:31:03 +02:00
|
|
|
);
|
|
|
|
|
this.dataSettings.patchValue(
|
2020-07-06 14:42:36 +03:00
|
|
|
{ searchPropagatedAlarms: isDefined(config.searchPropagatedAlarms) ?
|
|
|
|
|
config.searchPropagatedAlarms : true }, {emitEvent: false}
|
2020-02-21 16:31:03 +02:00
|
|
|
);
|
2019-10-24 19:52:19 +03:00
|
|
|
this.alarmSourceSettings.patchValue(
|
|
|
|
|
config.alarmSource, {emitEvent: false}
|
|
|
|
|
);
|
|
|
|
|
const alarmSourceType: DatasourceType = this.alarmSourceSettings.get('type').value;
|
|
|
|
|
this.alarmSourceSettings.get('entityAliasId').setValidators(
|
|
|
|
|
alarmSourceType === DatasourceType.entity ? [Validators.required] : []
|
|
|
|
|
);
|
|
|
|
|
this.alarmSourceSettings.get('entityAliasId').updateValueAndValidity({emitEvent: false});
|
2019-09-25 19:37:29 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-21 19:57:18 +03:00
|
|
|
this.updateSchemaForm(config.settings);
|
2019-09-25 19:37:29 +03:00
|
|
|
|
|
|
|
|
if (layout) {
|
2019-10-24 19:52:19 +03:00
|
|
|
this.layoutSettings.patchValue(
|
|
|
|
|
{
|
|
|
|
|
mobileOrder: layout.mobileOrder,
|
2021-07-22 15:44:40 +03:00
|
|
|
mobileHeight: layout.mobileHeight,
|
2022-11-20 00:32:32 +05:00
|
|
|
mobileHide: layout.mobileHide,
|
|
|
|
|
desktopHide: layout.desktopHide
|
2019-10-24 19:52:19 +03:00
|
|
|
},
|
|
|
|
|
{emitEvent: false}
|
|
|
|
|
);
|
2019-09-25 19:37:29 +03:00
|
|
|
} else {
|
2019-10-24 19:52:19 +03:00
|
|
|
this.layoutSettings.patchValue(
|
|
|
|
|
{
|
|
|
|
|
mobileOrder: null,
|
2021-07-22 15:44:40 +03:00
|
|
|
mobileHeight: null,
|
2022-11-20 00:32:32 +05:00
|
|
|
mobileHide: false,
|
|
|
|
|
desktopHide: false
|
2019-10-24 19:52:19 +03:00
|
|
|
},
|
|
|
|
|
{emitEvent: false}
|
|
|
|
|
);
|
2019-09-25 19:37:29 +03:00
|
|
|
}
|
|
|
|
|
}
|
2019-10-11 19:22:03 +03:00
|
|
|
this.createChangeSubscriptions();
|
2019-09-25 19:37:29 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-28 13:39:26 +03:00
|
|
|
public dataKeysOptional(datasource?: Datasource): boolean {
|
|
|
|
|
if (this.widgetType === widgetType.timeseries && this.modelValue?.typeParameters?.hasAdditionalLatestDataKeys) {
|
|
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
return this.modelValue.typeParameters && this.modelValue.typeParameters.dataKeysOptional
|
|
|
|
|
&& datasource?.type !== DatasourceType.entityCount;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-02 15:55:06 +02:00
|
|
|
private buildDatasourceForm(datasource?: Datasource): UntypedFormGroup {
|
2022-03-28 13:39:26 +03:00
|
|
|
const dataKeysRequired = !this.dataKeysOptional(datasource);
|
2019-10-11 19:22:03 +03:00
|
|
|
const datasourceFormGroup = this.fb.group(
|
|
|
|
|
{
|
|
|
|
|
type: [datasource ? datasource.type : null, [Validators.required]],
|
|
|
|
|
name: [datasource ? datasource.name : null, []],
|
|
|
|
|
entityAliasId: [datasource ? datasource.entityAliasId : null,
|
2021-03-02 12:04:45 +02:00
|
|
|
datasource && (datasource.type === DatasourceType.entity ||
|
|
|
|
|
datasource.type === DatasourceType.entityCount) ? [Validators.required] : []],
|
2020-06-30 19:37:50 +03:00
|
|
|
filterId: [datasource ? datasource.filterId : null, []],
|
2019-10-17 18:23:53 +03:00
|
|
|
dataKeys: [datasource ? datasource.dataKeys : null, dataKeysRequired ? [Validators.required] : []]
|
2019-10-11 19:22:03 +03:00
|
|
|
}
|
|
|
|
|
);
|
2022-03-28 13:39:26 +03:00
|
|
|
if (this.widgetType === widgetType.timeseries && this.modelValue?.typeParameters?.hasAdditionalLatestDataKeys) {
|
|
|
|
|
datasourceFormGroup.addControl('latestDataKeys', this.fb.control(datasource ? datasource.latestDataKeys : null));
|
|
|
|
|
}
|
2019-10-11 19:22:03 +03:00
|
|
|
datasourceFormGroup.get('type').valueChanges.subscribe((type: DatasourceType) => {
|
|
|
|
|
datasourceFormGroup.get('entityAliasId').setValidators(
|
2021-03-02 12:04:45 +02:00
|
|
|
(type === DatasourceType.entity || type === DatasourceType.entityCount) ? [Validators.required] : []
|
2019-10-11 19:22:03 +03:00
|
|
|
);
|
2022-03-28 13:39:26 +03:00
|
|
|
const newDataKeysRequired = !this.dataKeysOptional(datasourceFormGroup.value);
|
|
|
|
|
datasourceFormGroup.get('dataKeys').setValidators(newDataKeysRequired ? [Validators.required] : []);
|
2019-10-11 19:22:03 +03:00
|
|
|
datasourceFormGroup.get('entityAliasId').updateValueAndValidity();
|
2021-03-02 12:04:45 +02:00
|
|
|
datasourceFormGroup.get('dataKeys').updateValueAndValidity();
|
2019-10-11 19:22:03 +03:00
|
|
|
});
|
|
|
|
|
return datasourceFormGroup;
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-21 19:57:18 +03:00
|
|
|
private updateSchemaForm(settings?: any) {
|
|
|
|
|
const widgetSettingsFormData: JsonFormComponentData = {};
|
|
|
|
|
if (this.modelValue.settingsSchema && this.modelValue.settingsSchema.schema) {
|
|
|
|
|
widgetSettingsFormData.schema = this.modelValue.settingsSchema.schema;
|
|
|
|
|
widgetSettingsFormData.form = this.modelValue.settingsSchema.form || deepClone(defaultSettingsForm);
|
|
|
|
|
widgetSettingsFormData.groupInfoes = this.modelValue.settingsSchema.groupInfoes;
|
|
|
|
|
widgetSettingsFormData.model = settings;
|
2019-09-25 19:37:29 +03:00
|
|
|
} else {
|
2019-10-21 19:57:18 +03:00
|
|
|
widgetSettingsFormData.schema = deepClone(emptySettingsSchema);
|
|
|
|
|
widgetSettingsFormData.form = deepClone(defaultSettingsForm);
|
|
|
|
|
widgetSettingsFormData.groupInfoes = deepClone(emptySettingsGroupInfoes);
|
2022-03-19 10:08:53 +02:00
|
|
|
widgetSettingsFormData.model = settings || {};
|
2019-09-25 19:37:29 +03:00
|
|
|
}
|
2022-05-11 15:58:15 +03:00
|
|
|
widgetSettingsFormData.settingsDirective = this.modelValue.settingsDirective;
|
2019-10-21 19:57:18 +03:00
|
|
|
this.advancedSettings.patchValue({ settings: widgetSettingsFormData }, {emitEvent: false});
|
2019-09-25 19:37:29 +03:00
|
|
|
}
|
|
|
|
|
|
2019-10-11 19:22:03 +03:00
|
|
|
private updateDataSettings() {
|
2019-09-25 19:37:29 +03:00
|
|
|
if (this.modelValue) {
|
|
|
|
|
if (this.modelValue.config) {
|
2019-10-10 13:00:29 +03:00
|
|
|
Object.assign(this.modelValue.config, this.dataSettings.value);
|
2019-09-25 19:37:29 +03:00
|
|
|
}
|
|
|
|
|
this.propagateChange(this.modelValue);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-11 19:22:03 +03:00
|
|
|
private updateTargetDeviceSettings() {
|
|
|
|
|
if (this.modelValue) {
|
|
|
|
|
if (this.modelValue.config) {
|
|
|
|
|
const targetDeviceAliasId: string = this.targetDeviceSettings.get('targetDeviceAliasId').value;
|
|
|
|
|
if (targetDeviceAliasId) {
|
|
|
|
|
this.modelValue.config.targetDeviceAliasIds = [targetDeviceAliasId];
|
|
|
|
|
} else {
|
|
|
|
|
this.modelValue.config.targetDeviceAliasIds = [];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
this.propagateChange(this.modelValue);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-24 19:52:19 +03:00
|
|
|
private updateAlarmSourceSettings() {
|
|
|
|
|
if (this.modelValue) {
|
|
|
|
|
if (this.modelValue.config) {
|
|
|
|
|
const alarmSource: Datasource = this.alarmSourceSettings.value;
|
|
|
|
|
this.modelValue.config.alarmSource = alarmSource;
|
|
|
|
|
}
|
|
|
|
|
this.propagateChange(this.modelValue);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private updateWidgetSettings() {
|
|
|
|
|
if (this.modelValue) {
|
|
|
|
|
if (this.modelValue.config) {
|
|
|
|
|
Object.assign(this.modelValue.config, this.widgetSettings.value);
|
|
|
|
|
}
|
|
|
|
|
this.propagateChange(this.modelValue);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private updateLayoutSettings() {
|
|
|
|
|
if (this.modelValue) {
|
|
|
|
|
if (this.modelValue.layout) {
|
|
|
|
|
Object.assign(this.modelValue.layout, this.layoutSettings.value);
|
|
|
|
|
}
|
|
|
|
|
this.propagateChange(this.modelValue);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-21 19:57:18 +03:00
|
|
|
private updateAdvancedSettings() {
|
|
|
|
|
if (this.modelValue) {
|
|
|
|
|
if (this.modelValue.config) {
|
2022-05-11 15:58:15 +03:00
|
|
|
const settings = this.advancedSettings.get('settings').value?.model;
|
2019-10-21 19:57:18 +03:00
|
|
|
this.modelValue.config.settings = settings;
|
|
|
|
|
}
|
|
|
|
|
this.propagateChange(this.modelValue);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-24 19:52:19 +03:00
|
|
|
private updateActionSettings() {
|
|
|
|
|
if (this.modelValue) {
|
|
|
|
|
if (this.modelValue.config) {
|
|
|
|
|
const actions = (this.actionsSettings.get('actionsData').value as WidgetActionsData).actionsMap;
|
|
|
|
|
this.modelValue.config.actions = actions;
|
|
|
|
|
}
|
|
|
|
|
this.propagateChange(this.modelValue);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-06 14:42:36 +03:00
|
|
|
public alarmTypeList(): string[] {
|
|
|
|
|
return this.dataSettings.get('alarmTypeList').value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public removeAlarmType(type: string): void {
|
|
|
|
|
const types: string[] = this.dataSettings.get('alarmTypeList').value;
|
|
|
|
|
const index = types.indexOf(type);
|
|
|
|
|
if (index >= 0) {
|
|
|
|
|
types.splice(index, 1);
|
|
|
|
|
this.dataSettings.get('alarmTypeList').setValue(types);
|
|
|
|
|
this.dataSettings.get('alarmTypeList').markAsDirty();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public addAlarmType(event: MatChipInputEvent): void {
|
2023-02-02 16:08:41 +02:00
|
|
|
const input = event.chipInput.inputElement;
|
2020-07-06 14:42:36 +03:00
|
|
|
const value = event.value;
|
|
|
|
|
|
|
|
|
|
const types: string[] = this.dataSettings.get('alarmTypeList').value;
|
|
|
|
|
|
|
|
|
|
if ((value || '').trim()) {
|
|
|
|
|
types.push(value.trim());
|
|
|
|
|
this.dataSettings.get('alarmTypeList').setValue(types);
|
|
|
|
|
this.dataSettings.get('alarmTypeList').markAsDirty();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (input) {
|
|
|
|
|
input.value = '';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-25 19:37:29 +03:00
|
|
|
public displayAdvanced(): boolean {
|
2022-03-19 10:08:53 +02:00
|
|
|
return !!this.modelValue && (!!this.modelValue.settingsSchema && !!this.modelValue.settingsSchema.schema ||
|
|
|
|
|
!!this.modelValue.settingsDirective && !!this.modelValue.settingsDirective.length);
|
2019-09-25 19:37:29 +03:00
|
|
|
}
|
|
|
|
|
|
2022-09-08 18:51:13 +03:00
|
|
|
public displayTimewindowConfig(): boolean {
|
|
|
|
|
if (this.widgetType === widgetType.timeseries || this.widgetType === widgetType.alarm) {
|
|
|
|
|
return true;
|
|
|
|
|
} else if (this.widgetType === widgetType.latest) {
|
|
|
|
|
const datasources = this.dataSettings.get('datasources').value;
|
|
|
|
|
return datasourcesHasAggregation(datasources);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-15 14:18:16 +03:00
|
|
|
public onlyHistoryTimewindow(): boolean {
|
|
|
|
|
if (this.widgetType === widgetType.latest) {
|
|
|
|
|
const datasources = this.dataSettings.get('datasources').value;
|
|
|
|
|
return datasourcesHasOnlyComparisonAggregation(datasources);
|
|
|
|
|
} else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-06 16:07:42 +03:00
|
|
|
public onDatasourceDrop(event: CdkDragDrop<string[]>) {
|
|
|
|
|
const datasourcesFormArray = this.datasourcesFormArray();
|
|
|
|
|
const datasourceForm = datasourcesFormArray.at(event.previousIndex);
|
|
|
|
|
datasourcesFormArray.removeAt(event.previousIndex);
|
|
|
|
|
datasourcesFormArray.insert(event.currentIndex, datasourceForm);
|
2021-03-02 12:04:45 +02:00
|
|
|
}
|
|
|
|
|
|
2019-10-10 13:00:29 +03:00
|
|
|
public removeDatasource(index: number) {
|
2021-03-02 12:04:45 +02:00
|
|
|
this.datasourcesFormArray().removeAt(index);
|
2019-10-10 13:00:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public addDatasource() {
|
|
|
|
|
let newDatasource: Datasource;
|
|
|
|
|
if (this.functionsOnly) {
|
2019-10-21 19:57:18 +03:00
|
|
|
newDatasource = deepClone(this.utils.getDefaultDatasource(this.modelValue.dataKeySettingsSchema.schema));
|
2022-03-28 13:39:26 +03:00
|
|
|
newDatasource.dataKeys = [this.generateDataKey('Sin', DataKeyType.function, this.modelValue.dataKeySettingsSchema)];
|
2019-10-10 13:00:29 +03:00
|
|
|
} else {
|
|
|
|
|
newDatasource = { type: DatasourceType.entity,
|
|
|
|
|
dataKeys: []
|
|
|
|
|
};
|
|
|
|
|
}
|
2022-03-28 13:39:26 +03:00
|
|
|
if (this.modelValue?.typeParameters?.hasAdditionalLatestDataKeys) {
|
|
|
|
|
newDatasource.latestDataKeys = [];
|
|
|
|
|
}
|
2021-03-02 12:04:45 +02:00
|
|
|
this.datasourcesFormArray().push(this.buildDatasourceForm(newDatasource));
|
2019-10-10 13:00:29 +03:00
|
|
|
}
|
|
|
|
|
|
2022-03-28 13:39:26 +03:00
|
|
|
public generateDataKey(chip: any, type: DataKeyType, datakeySettingsSchema: JsonSettingsSchema): DataKey {
|
2019-10-10 13:00:29 +03:00
|
|
|
if (isObject(chip)) {
|
|
|
|
|
(chip as DataKey)._hash = Math.random();
|
|
|
|
|
return chip;
|
|
|
|
|
} else {
|
|
|
|
|
let label: string = chip;
|
2020-02-21 19:04:49 +02:00
|
|
|
if (type === DataKeyType.alarm || type === DataKeyType.entityField) {
|
2020-07-02 15:42:58 +03:00
|
|
|
const keyField = type === DataKeyType.alarm ? alarmFields[label] : entityFields[chip];
|
2020-02-21 19:04:49 +02:00
|
|
|
if (keyField) {
|
|
|
|
|
label = this.translate.instant(keyField.name);
|
2019-10-10 13:00:29 +03:00
|
|
|
}
|
|
|
|
|
}
|
2023-01-30 16:35:19 +02:00
|
|
|
const datasources = this.widgetType === widgetType.alarm ? [this.modelValue.config.alarmSource] : this.modelValue.config.datasources;
|
|
|
|
|
label = genNextLabel(label, datasources);
|
2019-10-10 13:00:29 +03:00
|
|
|
const result: DataKey = {
|
|
|
|
|
name: chip,
|
|
|
|
|
type,
|
|
|
|
|
label,
|
|
|
|
|
color: this.genNextColor(),
|
|
|
|
|
settings: {},
|
|
|
|
|
_hash: Math.random()
|
|
|
|
|
};
|
|
|
|
|
if (type === DataKeyType.function) {
|
|
|
|
|
result.name = 'f(x)';
|
|
|
|
|
result.funcBody = this.utils.getPredefinedFunctionBody(chip);
|
|
|
|
|
if (!result.funcBody) {
|
|
|
|
|
result.funcBody = 'return prevValue + 1;';
|
|
|
|
|
}
|
2021-03-02 12:04:45 +02:00
|
|
|
} else if (type === DataKeyType.count) {
|
|
|
|
|
result.name = 'count';
|
2019-10-10 13:00:29 +03:00
|
|
|
}
|
2022-03-28 13:39:26 +03:00
|
|
|
if (datakeySettingsSchema && isDefined(datakeySettingsSchema.schema)) {
|
|
|
|
|
result.settings = this.utils.generateObjectFromJsonSchema(datakeySettingsSchema.schema);
|
2019-10-10 13:00:29 +03:00
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private genNextColor(): string {
|
|
|
|
|
let i = 0;
|
|
|
|
|
const datasources = this.widgetType === widgetType.alarm ? [this.modelValue.config.alarmSource] : this.modelValue.config.datasources;
|
|
|
|
|
if (datasources) {
|
|
|
|
|
datasources.forEach((datasource) => {
|
2022-03-28 13:39:26 +03:00
|
|
|
if (datasource && (datasource.dataKeys || datasource.latestDataKeys)) {
|
|
|
|
|
i += ((datasource.dataKeys ? datasource.dataKeys.length : 0) +
|
|
|
|
|
(datasource.latestDataKeys ? datasource.latestDataKeys.length : 0));
|
2019-10-10 13:00:29 +03:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
return this.utils.getMaterialColor(i);
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-11 19:22:03 +03:00
|
|
|
private createEntityAlias(alias: string, allowedEntityTypes: Array<EntityType>): Observable<EntityAlias> {
|
|
|
|
|
const singleEntityAlias: EntityAlias = {id: null, alias, filter: {resolveMultiple: false}};
|
|
|
|
|
return this.dialog.open<EntityAliasDialogComponent, EntityAliasDialogData,
|
|
|
|
|
EntityAlias>(EntityAliasDialogComponent, {
|
|
|
|
|
disableClose: true,
|
|
|
|
|
panelClass: ['tb-dialog', 'tb-fullscreen-dialog'],
|
|
|
|
|
data: {
|
|
|
|
|
isAdd: true,
|
|
|
|
|
allowedEntityTypes,
|
2022-03-22 17:13:21 +02:00
|
|
|
entityAliases: this.dashboard.configuration.entityAliases,
|
2019-10-11 19:22:03 +03:00
|
|
|
alias: singleEntityAlias
|
|
|
|
|
}
|
|
|
|
|
}).afterClosed().pipe(
|
|
|
|
|
tap((entityAlias) => {
|
|
|
|
|
if (entityAlias) {
|
2022-03-22 17:13:21 +02:00
|
|
|
this.dashboard.configuration.entityAliases[entityAlias.id] = entityAlias;
|
|
|
|
|
this.aliasController.updateEntityAliases(this.dashboard.configuration.entityAliases);
|
2019-10-11 19:22:03 +03:00
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-30 19:37:50 +03:00
|
|
|
private createFilter(filter: string): Observable<Filter> {
|
2020-07-01 20:09:25 +03:00
|
|
|
const singleFilter: Filter = {id: null, filter, keyFilters: [], editable: true};
|
2020-06-30 19:37:50 +03:00
|
|
|
return this.dialog.open<FilterDialogComponent, FilterDialogData,
|
|
|
|
|
Filter>(FilterDialogComponent, {
|
|
|
|
|
disableClose: true,
|
|
|
|
|
panelClass: ['tb-dialog', 'tb-fullscreen-dialog'],
|
|
|
|
|
data: {
|
|
|
|
|
isAdd: true,
|
2022-03-22 17:13:21 +02:00
|
|
|
filters: this.dashboard.configuration.filters,
|
2020-07-02 15:42:58 +03:00
|
|
|
filter: singleFilter
|
2020-06-30 19:37:50 +03:00
|
|
|
}
|
|
|
|
|
}).afterClosed().pipe(
|
|
|
|
|
tap((result) => {
|
|
|
|
|
if (result) {
|
2022-03-22 17:13:21 +02:00
|
|
|
this.dashboard.configuration.filters[result.id] = result;
|
|
|
|
|
this.aliasController.updateFilters(this.dashboard.configuration.filters);
|
2020-06-30 19:37:50 +03:00
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-17 13:32:03 +02:00
|
|
|
private fetchEntityKeys(entityAliasId: string, dataKeyTypes: Array<DataKeyType>): Observable<Array<DataKey>> {
|
|
|
|
|
return this.aliasController.getAliasInfo(entityAliasId).pipe(
|
|
|
|
|
mergeMap((aliasInfo) => {
|
|
|
|
|
return this.entityService.getEntityKeysByEntityFilter(
|
|
|
|
|
aliasInfo.entityFilter,
|
|
|
|
|
dataKeyTypes,
|
|
|
|
|
{ignoreLoading: true, ignoreErrors: true}
|
|
|
|
|
).pipe(
|
|
|
|
|
catchError(() => of([]))
|
|
|
|
|
);
|
2019-10-17 18:23:53 +03:00
|
|
|
}),
|
2020-11-24 10:57:59 +02:00
|
|
|
catchError(() => of([] as Array<DataKey>))
|
2019-10-17 18:23:53 +03:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-24 19:52:19 +03:00
|
|
|
private fetchDashboardStates(query: string): Array<string> {
|
2022-03-22 17:13:21 +02:00
|
|
|
const stateIds = Object.keys(this.dashboard.configuration.states);
|
2019-10-24 19:52:19 +03:00
|
|
|
const result = query ? stateIds.filter(this.createFilterForDashboardState(query)) : stateIds;
|
|
|
|
|
if (result && result.length) {
|
|
|
|
|
return result;
|
|
|
|
|
} else {
|
|
|
|
|
return [query];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private createFilterForDashboardState(query: string): (stateId: string) => boolean {
|
|
|
|
|
const lowercaseQuery = query.toLowerCase();
|
|
|
|
|
return stateId => stateId.toLowerCase().indexOf(lowercaseQuery) === 0;
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-02 15:55:06 +02:00
|
|
|
public validate(c: UntypedFormControl) {
|
2022-09-16 11:40:21 +03:00
|
|
|
this.timeseriesKeyError = false;
|
2022-03-28 13:39:26 +03:00
|
|
|
this.datasourceError = [];
|
2019-10-10 13:00:29 +03:00
|
|
|
if (!this.dataSettings.valid) {
|
|
|
|
|
return {
|
|
|
|
|
dataSettings: {
|
|
|
|
|
valid: false
|
|
|
|
|
}
|
|
|
|
|
};
|
2019-10-24 19:52:19 +03:00
|
|
|
} else if (!this.widgetSettings.valid) {
|
|
|
|
|
return {
|
|
|
|
|
widgetSettings: {
|
|
|
|
|
valid: false
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
} else if (!this.layoutSettings.valid) {
|
|
|
|
|
return {
|
|
|
|
|
widgetSettings: {
|
|
|
|
|
valid: false
|
|
|
|
|
}
|
|
|
|
|
};
|
2022-03-19 10:08:53 +02:00
|
|
|
} else if (!this.advancedSettings.valid || (this.displayAdvanced() && !this.modelValue.config.settings)) {
|
2019-10-21 19:57:18 +03:00
|
|
|
return {
|
|
|
|
|
advancedSettings: {
|
|
|
|
|
valid: false
|
|
|
|
|
}
|
|
|
|
|
};
|
2019-10-31 18:33:51 +02:00
|
|
|
} else if (this.modelValue) {
|
2019-10-10 13:00:29 +03:00
|
|
|
const config = this.modelValue.config;
|
2019-10-21 19:57:18 +03:00
|
|
|
if (this.widgetType === widgetType.rpc && this.modelValue.isDataEnabled) {
|
2022-02-04 20:06:23 +02:00
|
|
|
if (!this.widgetEditMode && (!config.targetDeviceAliasIds || !config.targetDeviceAliasIds.length)) {
|
2019-10-10 13:00:29 +03:00
|
|
|
return {
|
|
|
|
|
targetDeviceAliasIds: {
|
|
|
|
|
valid: false
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
2019-10-21 19:57:18 +03:00
|
|
|
} else if (this.widgetType === widgetType.alarm && this.modelValue.isDataEnabled) {
|
2020-06-30 19:37:50 +03:00
|
|
|
if (!this.alarmSourceSettings.valid || !config.alarmSource) {
|
2019-10-10 13:00:29 +03:00
|
|
|
return {
|
|
|
|
|
alarmSource: {
|
|
|
|
|
valid: false
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
2019-10-21 19:57:18 +03:00
|
|
|
} else if (this.widgetType !== widgetType.static && this.modelValue.isDataEnabled) {
|
2021-10-19 22:22:06 +03:00
|
|
|
if (!this.modelValue.typeParameters.datasourcesOptional && (!config.datasources || !config.datasources.length)) {
|
2019-10-10 13:00:29 +03:00
|
|
|
return {
|
|
|
|
|
datasources: {
|
|
|
|
|
valid: false
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
2022-03-28 13:39:26 +03:00
|
|
|
if (this.widgetType === widgetType.timeseries && this.modelValue?.typeParameters?.hasAdditionalLatestDataKeys) {
|
|
|
|
|
let valid = config.datasources.filter(datasource => datasource?.dataKeys?.length).length > 0;
|
|
|
|
|
if (!valid) {
|
2022-09-16 11:40:21 +03:00
|
|
|
this.timeseriesKeyError = true;
|
2022-03-28 13:39:26 +03:00
|
|
|
return {
|
|
|
|
|
timeseriesDataKeys: {
|
|
|
|
|
valid: false
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
} else {
|
|
|
|
|
const emptyDatasources = config.datasources.filter(datasource => !datasource?.dataKeys?.length &&
|
|
|
|
|
!datasource?.latestDataKeys?.length);
|
|
|
|
|
valid = emptyDatasources.length === 0;
|
|
|
|
|
if (!valid) {
|
|
|
|
|
for (const emptyDatasource of emptyDatasources) {
|
|
|
|
|
const i = config.datasources.indexOf(emptyDatasource);
|
|
|
|
|
this.datasourceError[i] = 'At least one data key should be specified';
|
|
|
|
|
}
|
|
|
|
|
return {
|
|
|
|
|
dataKeys: {
|
|
|
|
|
valid: false
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-10-10 13:00:29 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null;
|
2019-09-25 19:37:29 +03:00
|
|
|
}
|
|
|
|
|
|
2022-09-16 11:40:21 +03:00
|
|
|
public extensionPanelIsOpen(value) {
|
|
|
|
|
this.openExtensionPanel = value;
|
|
|
|
|
}
|
2019-09-25 19:37:29 +03:00
|
|
|
}
|