2023-01-23 14:54:15 +02:00
|
|
|
///
|
2024-01-09 10:46:16 +02:00
|
|
|
/// Copyright © 2016-2024 The Thingsboard Authors
|
2023-01-23 14:54:15 +02: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-10 18:31:05 +02:00
|
|
|
import {
|
2023-03-16 15:45:34 +02:00
|
|
|
AlarmAction,
|
|
|
|
|
AlarmActionTranslationMap,
|
2023-03-17 16:35:34 +02:00
|
|
|
AlarmAssignmentAction,
|
|
|
|
|
AlarmAssignmentActionTranslationMap,
|
2023-03-17 18:53:03 +02:00
|
|
|
ComponentLifecycleEvent,
|
2023-03-28 16:51:43 +03:00
|
|
|
ComponentLifecycleEventTranslationMap,
|
|
|
|
|
DeviceEvent,
|
|
|
|
|
DeviceEventTranslationMap,
|
2023-02-10 18:31:05 +02:00
|
|
|
NotificationRule,
|
|
|
|
|
NotificationTarget,
|
|
|
|
|
TriggerType,
|
|
|
|
|
TriggerTypeTranslationMap
|
|
|
|
|
} from '@shared/models/notification.models';
|
2023-02-02 15:25:04 +02:00
|
|
|
import { Component, Inject, OnDestroy, ViewChild } from '@angular/core';
|
2023-01-23 14:54:15 +02:00
|
|
|
import { DialogComponent } from '@shared/components/dialog.component';
|
|
|
|
|
import { Store } from '@ngrx/store';
|
|
|
|
|
import { AppState } from '@core/core.state';
|
|
|
|
|
import { Router } from '@angular/router';
|
2023-02-10 18:31:05 +02:00
|
|
|
import { MAT_DIALOG_DATA, MatDialog, MatDialogRef } from '@angular/material/dialog';
|
2023-01-23 14:54:15 +02:00
|
|
|
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
|
|
|
|
|
import { NotificationService } from '@core/http/notification.service';
|
2023-04-05 17:42:14 +03:00
|
|
|
import { EntityType } from '@shared/models/entity-type.models';
|
2023-02-01 02:02:27 +02:00
|
|
|
import { deepClone, deepTrim, isDefined } from '@core/utils';
|
2023-02-02 15:25:04 +02:00
|
|
|
import { Observable, Subject } from 'rxjs';
|
|
|
|
|
import { map, takeUntil } from 'rxjs/operators';
|
2023-01-27 15:47:08 +02:00
|
|
|
import { StepperOrientation, StepperSelectionEvent } from '@angular/cdk/stepper';
|
|
|
|
|
import { MatStepper } from '@angular/material/stepper';
|
|
|
|
|
import { MediaBreakpoints } from '@shared/models/constants';
|
|
|
|
|
import { BreakpointObserver } from '@angular/cdk/layout';
|
2023-03-10 18:23:25 +02:00
|
|
|
import {
|
|
|
|
|
AlarmSearchStatus,
|
|
|
|
|
alarmSearchStatusTranslations,
|
|
|
|
|
AlarmSeverity,
|
|
|
|
|
alarmSeverityTranslations
|
|
|
|
|
} from '@shared/models/alarm.models';
|
2023-01-27 15:47:08 +02:00
|
|
|
import { TranslateService } from '@ngx-translate/core';
|
2023-02-10 18:31:05 +02:00
|
|
|
import {
|
2023-03-21 17:56:12 +02:00
|
|
|
RecipientNotificationDialogComponent,
|
|
|
|
|
RecipientNotificationDialogData
|
2023-03-28 13:47:24 +03:00
|
|
|
} from '@home/pages/notification/recipient/recipient-notification-dialog.component';
|
2023-02-10 18:31:05 +02:00
|
|
|
import { MatButton } from '@angular/material/button';
|
2023-03-21 15:03:30 +02:00
|
|
|
import { AuthState } from '@core/auth/auth.models';
|
|
|
|
|
import { getCurrentAuthState } from '@core/auth/auth.selectors';
|
|
|
|
|
import { AuthUser } from '@shared/models/user.model';
|
|
|
|
|
import { Authority } from '@shared/models/authority.enum';
|
2023-03-28 16:51:43 +03:00
|
|
|
import {
|
|
|
|
|
ApiFeature,
|
|
|
|
|
ApiFeatureTranslationMap,
|
|
|
|
|
ApiUsageStateValue,
|
|
|
|
|
ApiUsageStateValueTranslationMap
|
|
|
|
|
} from '@shared/models/api-usage.models';
|
2023-06-05 11:13:29 +03:00
|
|
|
import { LimitedApi, LimitedApiTranslationMap } from '@shared/models/limited-api.models';
|
|
|
|
|
import { StringItemsOption } from '@shared/components/string-items-list.component';
|
2023-01-23 14:54:15 +02:00
|
|
|
|
|
|
|
|
export interface RuleNotificationDialogData {
|
|
|
|
|
rule?: NotificationRule;
|
|
|
|
|
isAdd?: boolean;
|
2023-02-01 02:02:27 +02:00
|
|
|
isCopy?: boolean;
|
2023-01-23 14:54:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
selector: 'tb-rule-notification-dialog',
|
|
|
|
|
templateUrl: './rule-notification-dialog.component.html',
|
|
|
|
|
styleUrls: ['rule-notification-dialog.component.scss']
|
|
|
|
|
})
|
|
|
|
|
export class RuleNotificationDialogComponent extends
|
|
|
|
|
DialogComponent<RuleNotificationDialogComponent, NotificationRule> implements OnDestroy {
|
|
|
|
|
|
2023-01-27 15:47:08 +02:00
|
|
|
@ViewChild('addNotificationRule', {static: true}) addNotificationRule: MatStepper;
|
|
|
|
|
|
|
|
|
|
stepperOrientation: Observable<StepperOrientation>;
|
|
|
|
|
|
2023-01-23 14:54:15 +02:00
|
|
|
ruleNotificationForm: FormGroup;
|
2023-01-27 15:47:08 +02:00
|
|
|
alarmTemplateForm: FormGroup;
|
|
|
|
|
deviceInactivityTemplateForm: FormGroup;
|
|
|
|
|
entityActionTemplateForm: FormGroup;
|
2023-02-01 20:00:47 +02:00
|
|
|
alarmCommentTemplateForm: FormGroup;
|
2023-03-15 18:39:06 +02:00
|
|
|
alarmAssignmentTemplateForm: FormGroup;
|
2023-03-17 18:53:03 +02:00
|
|
|
ruleEngineEventsTemplateForm: FormGroup;
|
2023-03-21 15:03:30 +02:00
|
|
|
entitiesLimitTemplateForm: FormGroup;
|
2023-03-28 16:51:43 +03:00
|
|
|
apiUsageLimitTemplateForm: FormGroup;
|
2023-04-06 14:18:12 +03:00
|
|
|
newPlatformVersionTemplateForm: FormGroup;
|
2023-06-02 15:09:35 +03:00
|
|
|
rateLimitsTemplateForm: FormGroup;
|
2024-01-19 11:22:45 +02:00
|
|
|
edgeTemplateForm: FormGroup;
|
2023-01-27 15:47:08 +02:00
|
|
|
|
|
|
|
|
triggerType = TriggerType;
|
2023-03-21 15:03:30 +02:00
|
|
|
triggerTypes: TriggerType[];
|
2023-01-27 15:47:08 +02:00
|
|
|
triggerTypeTranslationMap = TriggerTypeTranslationMap;
|
|
|
|
|
|
2023-03-10 18:23:25 +02:00
|
|
|
alarmSearchStatuses = [
|
|
|
|
|
AlarmSearchStatus.ACTIVE,
|
|
|
|
|
AlarmSearchStatus.CLEARED,
|
|
|
|
|
AlarmSearchStatus.ACK,
|
|
|
|
|
AlarmSearchStatus.UNACK
|
|
|
|
|
];
|
|
|
|
|
alarmSearchStatusTranslationMap = alarmSearchStatusTranslations;
|
|
|
|
|
|
|
|
|
|
alarmSeverityTranslationMap = alarmSeverityTranslations;
|
|
|
|
|
alarmSeverities = Object.keys(AlarmSeverity) as Array<AlarmSeverity>;
|
2023-01-27 15:47:08 +02:00
|
|
|
|
2023-03-16 15:45:34 +02:00
|
|
|
alarmActions: AlarmAction[] = Object.values(AlarmAction);
|
|
|
|
|
alarmActionTranslationMap = AlarmActionTranslationMap;
|
|
|
|
|
|
2023-03-17 16:35:34 +02:00
|
|
|
alarmAssignmentActions: AlarmAssignmentAction[] = Object.values(AlarmAssignmentAction);
|
|
|
|
|
alarmAssignmentActionTranslationMap = AlarmAssignmentActionTranslationMap;
|
|
|
|
|
|
2023-03-17 18:53:03 +02:00
|
|
|
componentLifecycleEvents: ComponentLifecycleEvent[] = Object.values(ComponentLifecycleEvent);
|
|
|
|
|
componentLifecycleEventTranslationMap = ComponentLifecycleEventTranslationMap;
|
|
|
|
|
|
2023-03-28 13:47:24 +03:00
|
|
|
deviceEvents: DeviceEvent[] = Object.values(DeviceEvent);
|
|
|
|
|
deviceEventTranslationMap = DeviceEventTranslationMap;
|
|
|
|
|
|
2023-03-28 16:51:43 +03:00
|
|
|
apiUsageStateValues: ApiUsageStateValue[] = Object.values(ApiUsageStateValue);
|
|
|
|
|
apiUsageStateValueTranslationMap = ApiUsageStateValueTranslationMap;
|
|
|
|
|
|
|
|
|
|
apiFeatures: ApiFeature[] = Object.values(ApiFeature);
|
|
|
|
|
apiFeatureTranslationMap = ApiFeatureTranslationMap;
|
|
|
|
|
|
2023-06-05 11:13:29 +03:00
|
|
|
limitedApis: StringItemsOption[];
|
|
|
|
|
|
2023-01-23 14:54:15 +02:00
|
|
|
entityType = EntityType;
|
|
|
|
|
isAdd = true;
|
|
|
|
|
|
2023-04-05 17:42:14 +03:00
|
|
|
allowEntityTypeForEntitiesLimit = [
|
|
|
|
|
EntityType.DEVICE,
|
|
|
|
|
EntityType.ASSET,
|
|
|
|
|
EntityType.CUSTOMER,
|
|
|
|
|
EntityType.USER,
|
|
|
|
|
EntityType.DASHBOARD,
|
|
|
|
|
EntityType.RULE_CHAIN
|
|
|
|
|
];
|
|
|
|
|
|
2023-01-27 15:47:08 +02:00
|
|
|
selectedIndex = 0;
|
|
|
|
|
|
2023-02-01 02:02:27 +02:00
|
|
|
dialogTitle = 'notification.edit-rule';
|
|
|
|
|
|
2023-02-14 11:39:29 +02:00
|
|
|
private destroy$ = new Subject<void>();
|
2023-01-23 14:54:15 +02:00
|
|
|
|
2023-02-01 02:02:27 +02:00
|
|
|
private readonly ruleNotification: NotificationRule;
|
|
|
|
|
|
2023-02-02 15:25:04 +02:00
|
|
|
private triggerTypeFormsMap: Map<TriggerType, FormGroup>;
|
2023-03-21 15:03:30 +02:00
|
|
|
private authState: AuthState = getCurrentAuthState(this.store);
|
|
|
|
|
private authUser: AuthUser = this.authState.authUser;
|
2023-04-05 17:42:14 +03:00
|
|
|
private _allowEntityTypeForEntityAction: EntityType[];
|
2023-02-02 15:25:04 +02:00
|
|
|
|
2023-01-23 14:54:15 +02:00
|
|
|
constructor(protected store: Store<AppState>,
|
|
|
|
|
protected router: Router,
|
|
|
|
|
protected dialogRef: MatDialogRef<RuleNotificationDialogComponent, NotificationRule>,
|
|
|
|
|
@Inject(MAT_DIALOG_DATA) public data: RuleNotificationDialogData,
|
2023-01-27 15:47:08 +02:00
|
|
|
private breakpointObserver: BreakpointObserver,
|
2023-01-23 14:54:15 +02:00
|
|
|
private fb: FormBuilder,
|
2023-01-27 15:47:08 +02:00
|
|
|
public translate: TranslateService,
|
2023-02-10 18:31:05 +02:00
|
|
|
private notificationService: NotificationService,
|
|
|
|
|
private dialog: MatDialog) {
|
2023-01-23 14:54:15 +02:00
|
|
|
super(store, router, dialogRef);
|
|
|
|
|
|
2023-03-21 15:03:30 +02:00
|
|
|
this.triggerTypes = this.allowTriggerTypes();
|
|
|
|
|
|
2023-01-23 14:54:15 +02:00
|
|
|
if (isDefined(data.isAdd)) {
|
|
|
|
|
this.isAdd = data.isAdd;
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-05 11:13:29 +03:00
|
|
|
this.limitedApis = Object.values(LimitedApi).map(value => ({
|
|
|
|
|
name: this.translate.instant(LimitedApiTranslationMap.get(value)),
|
|
|
|
|
value
|
|
|
|
|
}));
|
|
|
|
|
|
2023-01-27 15:47:08 +02:00
|
|
|
this.stepperOrientation = this.breakpointObserver.observe(MediaBreakpoints['gt-xs'])
|
|
|
|
|
.pipe(map(({matches}) => matches ? 'horizontal' : 'vertical'));
|
|
|
|
|
|
2023-01-23 14:54:15 +02:00
|
|
|
this.ruleNotificationForm = this.fb.group({
|
|
|
|
|
name: [null, Validators.required],
|
2023-05-11 14:57:40 +03:00
|
|
|
enabled: [true, Validators.required],
|
2023-01-23 14:54:15 +02:00
|
|
|
templateId: [null, Validators.required],
|
2023-03-21 15:03:30 +02:00
|
|
|
triggerType: [this.isSysAdmin() ? TriggerType.ENTITIES_LIMIT : TriggerType.ALARM, Validators.required],
|
2023-02-10 18:31:05 +02:00
|
|
|
recipientsConfig: this.fb.group({
|
2023-03-21 15:03:30 +02:00
|
|
|
targets: [{value: null, disabled: !this.isSysAdmin()}, Validators.required],
|
|
|
|
|
escalationTable: [{value: null, disabled: this.isSysAdmin()}, Validators.required]
|
2023-02-10 18:31:05 +02:00
|
|
|
}),
|
2023-02-02 15:25:04 +02:00
|
|
|
triggerConfig: [null],
|
2023-02-01 02:02:27 +02:00
|
|
|
additionalConfig: this.fb.group({
|
2023-02-02 15:25:04 +02:00
|
|
|
description: ['']
|
2023-01-23 14:54:15 +02:00
|
|
|
})
|
|
|
|
|
});
|
|
|
|
|
|
2023-02-10 18:31:05 +02:00
|
|
|
this.ruleNotificationForm.get('triggerType').valueChanges.pipe(
|
|
|
|
|
takeUntil(this.destroy$)
|
|
|
|
|
).subscribe(value => {
|
|
|
|
|
if (value === TriggerType.ALARM) {
|
|
|
|
|
this.ruleNotificationForm.get('recipientsConfig.escalationTable').enable({emitEvent: false});
|
|
|
|
|
this.ruleNotificationForm.get('recipientsConfig.targets').disable({emitEvent: false});
|
|
|
|
|
} else {
|
|
|
|
|
this.ruleNotificationForm.get('recipientsConfig.escalationTable').disable({emitEvent: false});
|
|
|
|
|
this.ruleNotificationForm.get('recipientsConfig.targets').enable({emitEvent: false});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2023-03-15 13:28:31 +02:00
|
|
|
this.ruleNotificationForm.get('recipientsConfig.escalationTable').valueChanges.pipe(
|
|
|
|
|
takeUntil(this.destroy$)
|
2023-03-20 16:51:42 +02:00
|
|
|
).subscribe(() => {
|
2023-03-15 13:28:31 +02:00
|
|
|
if (this.countRecipientsChainConfig() > 1) {
|
|
|
|
|
this.alarmTemplateForm.get('triggerConfig.clearRule').enable({emitEvent: false});
|
|
|
|
|
} else {
|
|
|
|
|
this.alarmTemplateForm.get('triggerConfig.clearRule').disable({emitEvent: false});
|
|
|
|
|
}
|
2023-03-20 16:51:42 +02:00
|
|
|
});
|
2023-03-15 13:28:31 +02:00
|
|
|
|
2024-01-19 11:22:45 +02:00
|
|
|
this.edgeTemplateForm = this.fb.group({
|
|
|
|
|
triggerConfig: this.fb.group({
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
2023-01-27 15:47:08 +02:00
|
|
|
this.alarmTemplateForm = this.fb.group({
|
2023-02-02 15:25:04 +02:00
|
|
|
triggerConfig: this.fb.group({
|
|
|
|
|
alarmTypes: [null],
|
2023-03-10 18:23:25 +02:00
|
|
|
alarmSeverities: [[]],
|
2023-02-02 15:25:04 +02:00
|
|
|
clearRule: this.fb.group({
|
2023-03-14 16:37:05 +02:00
|
|
|
alarmStatuses: [[]]
|
2023-03-16 15:45:34 +02:00
|
|
|
}),
|
|
|
|
|
notifyOn: [[AlarmAction.CREATED], Validators.required]
|
2023-02-02 15:25:04 +02:00
|
|
|
})
|
2023-01-27 15:47:08 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
this.deviceInactivityTemplateForm = this.fb.group({
|
2023-02-02 15:25:04 +02:00
|
|
|
triggerConfig: this.fb.group({
|
|
|
|
|
filterByDevice: [true],
|
|
|
|
|
devices: [null],
|
2023-03-28 13:47:24 +03:00
|
|
|
deviceProfiles: [{value: null, disabled: true}],
|
|
|
|
|
notifyOn: [[DeviceEvent.INACTIVE], Validators.required]
|
2023-02-02 15:25:04 +02:00
|
|
|
})
|
2023-01-27 15:47:08 +02:00
|
|
|
});
|
|
|
|
|
|
2023-02-02 15:25:04 +02:00
|
|
|
this.deviceInactivityTemplateForm.get('triggerConfig.filterByDevice').valueChanges.pipe(
|
2023-01-31 02:03:51 +02:00
|
|
|
takeUntil(this.destroy$)
|
2023-02-01 15:58:00 +02:00
|
|
|
).subscribe(value => {
|
|
|
|
|
if (value) {
|
2023-02-02 15:25:04 +02:00
|
|
|
this.deviceInactivityTemplateForm.get('triggerConfig.devices').enable({emitEvent: false});
|
|
|
|
|
this.deviceInactivityTemplateForm.get('triggerConfig.deviceProfiles').disable({emitEvent: false});
|
2023-02-01 15:58:00 +02:00
|
|
|
} else {
|
2023-02-02 15:25:04 +02:00
|
|
|
this.deviceInactivityTemplateForm.get('triggerConfig.deviceProfiles').enable({emitEvent: false});
|
|
|
|
|
this.deviceInactivityTemplateForm.get('triggerConfig.devices').disable({emitEvent: false});
|
2023-02-01 15:58:00 +02:00
|
|
|
}
|
|
|
|
|
});
|
2023-01-31 02:03:51 +02:00
|
|
|
|
2023-01-27 15:47:08 +02:00
|
|
|
this.entityActionTemplateForm = this.fb.group({
|
2023-02-02 15:25:04 +02:00
|
|
|
triggerConfig: this.fb.group({
|
2023-03-28 13:47:24 +03:00
|
|
|
entityTypes: [[EntityType.DEVICE], Validators.required],
|
2023-02-02 15:25:04 +02:00
|
|
|
created: [false],
|
|
|
|
|
updated: [false],
|
|
|
|
|
deleted: [false]
|
|
|
|
|
})
|
2023-01-27 15:47:08 +02:00
|
|
|
});
|
|
|
|
|
|
2023-03-10 18:23:25 +02:00
|
|
|
this.alarmCommentTemplateForm = this.fb.group({
|
|
|
|
|
triggerConfig: this.fb.group({
|
|
|
|
|
alarmTypes: [null],
|
|
|
|
|
alarmSeverities: [[]],
|
2023-03-16 15:45:34 +02:00
|
|
|
alarmStatuses: [[]],
|
2023-03-17 16:35:34 +02:00
|
|
|
onlyUserComments: [false],
|
|
|
|
|
notifyOnCommentUpdate: [false]
|
2023-03-10 18:23:25 +02:00
|
|
|
})
|
|
|
|
|
});
|
2023-02-01 20:00:47 +02:00
|
|
|
|
2023-03-15 18:39:06 +02:00
|
|
|
this.alarmAssignmentTemplateForm = this.fb.group({
|
|
|
|
|
triggerConfig: this.fb.group({
|
|
|
|
|
alarmTypes: [null],
|
|
|
|
|
alarmSeverities: [[]],
|
|
|
|
|
alarmStatuses: [[]],
|
2023-03-17 16:35:34 +02:00
|
|
|
notifyOn: [[AlarmAssignmentAction.ASSIGNED], Validators.required]
|
2023-03-15 18:39:06 +02:00
|
|
|
})
|
|
|
|
|
});
|
|
|
|
|
|
2023-03-17 18:53:03 +02:00
|
|
|
this.ruleEngineEventsTemplateForm = this.fb.group({
|
|
|
|
|
triggerConfig: this.fb.group({
|
|
|
|
|
ruleChains: [null],
|
|
|
|
|
ruleChainEvents: [null],
|
|
|
|
|
onlyRuleChainLifecycleFailures: [false],
|
|
|
|
|
trackRuleNodeEvents: [false],
|
|
|
|
|
ruleNodeEvents: [null],
|
|
|
|
|
onlyRuleNodeLifecycleFailures: [false]
|
|
|
|
|
})
|
|
|
|
|
});
|
|
|
|
|
|
2023-03-21 15:03:30 +02:00
|
|
|
this.entitiesLimitTemplateForm = this.fb.group({
|
|
|
|
|
triggerConfig: this.fb.group({
|
|
|
|
|
entityTypes: [],
|
|
|
|
|
threshold: [.8, [Validators.min(0), Validators.max(1)]]
|
|
|
|
|
})
|
|
|
|
|
});
|
|
|
|
|
|
2023-03-28 16:51:43 +03:00
|
|
|
this.apiUsageLimitTemplateForm = this.fb.group({
|
|
|
|
|
triggerConfig: this.fb.group({
|
|
|
|
|
apiFeatures: [[]],
|
|
|
|
|
notifyOn: [[ApiUsageStateValue.WARNING], Validators.required]
|
|
|
|
|
})
|
|
|
|
|
});
|
|
|
|
|
|
2023-04-06 14:18:12 +03:00
|
|
|
this.newPlatformVersionTemplateForm = this.fb.group({
|
|
|
|
|
triggerConfig: this.fb.group({
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
|
});
|
|
|
|
|
|
2023-06-02 15:09:35 +03:00
|
|
|
this.rateLimitsTemplateForm = this.fb.group({
|
|
|
|
|
triggerConfig: this.fb.group({
|
2023-06-05 11:13:29 +03:00
|
|
|
apis: []
|
2023-06-02 15:09:35 +03:00
|
|
|
})
|
|
|
|
|
});
|
|
|
|
|
|
2023-02-02 15:25:04 +02:00
|
|
|
this.triggerTypeFormsMap = new Map<TriggerType, FormGroup>([
|
|
|
|
|
[TriggerType.ALARM, this.alarmTemplateForm],
|
2023-02-02 15:34:39 +02:00
|
|
|
[TriggerType.ALARM_COMMENT, this.alarmCommentTemplateForm],
|
2023-03-28 13:47:24 +03:00
|
|
|
[TriggerType.DEVICE_ACTIVITY, this.deviceInactivityTemplateForm],
|
2023-03-16 15:45:34 +02:00
|
|
|
[TriggerType.ENTITY_ACTION, this.entityActionTemplateForm],
|
|
|
|
|
[TriggerType.ALARM_ASSIGNMENT, this.alarmAssignmentTemplateForm],
|
2023-03-21 15:03:30 +02:00
|
|
|
[TriggerType.RULE_ENGINE_COMPONENT_LIFECYCLE_EVENT, this.ruleEngineEventsTemplateForm],
|
2023-03-28 16:51:43 +03:00
|
|
|
[TriggerType.ENTITIES_LIMIT, this.entitiesLimitTemplateForm],
|
2023-04-06 14:18:12 +03:00
|
|
|
[TriggerType.API_USAGE_LIMIT, this.apiUsageLimitTemplateForm],
|
2023-06-02 15:09:35 +03:00
|
|
|
[TriggerType.NEW_PLATFORM_VERSION, this.newPlatformVersionTemplateForm],
|
|
|
|
|
[TriggerType.RATE_LIMITS, this.rateLimitsTemplateForm]
|
2023-02-02 15:25:04 +02:00
|
|
|
]);
|
2023-02-01 02:02:27 +02:00
|
|
|
|
|
|
|
|
if (data.isAdd || data.isCopy) {
|
|
|
|
|
this.dialogTitle = 'notification.add-rule';
|
|
|
|
|
}
|
|
|
|
|
this.ruleNotification = deepClone(this.data.rule);
|
|
|
|
|
|
|
|
|
|
if (this.ruleNotification) {
|
|
|
|
|
if (this.data.isCopy) {
|
|
|
|
|
this.ruleNotification.name += ` (${this.translate.instant('action.copy')})`;
|
2023-04-07 11:18:12 +03:00
|
|
|
} else {
|
|
|
|
|
this.ruleNotificationForm.get('triggerType').disable({emitEvent: false});
|
2023-02-01 02:02:27 +02:00
|
|
|
}
|
|
|
|
|
this.ruleNotificationForm.reset({}, {emitEvent: false});
|
|
|
|
|
this.ruleNotificationForm.patchValue(this.ruleNotification, {emitEvent: false});
|
2023-02-10 18:31:05 +02:00
|
|
|
this.ruleNotificationForm.get('triggerType').updateValueAndValidity({onlySelf: true});
|
2023-02-02 15:25:04 +02:00
|
|
|
const currentForm = this.triggerTypeFormsMap.get(this.ruleNotification.triggerType);
|
|
|
|
|
currentForm.patchValue(this.ruleNotification, {emitEvent: false});
|
2023-03-28 13:47:24 +03:00
|
|
|
if (this.ruleNotification.triggerType === TriggerType.DEVICE_ACTIVITY) {
|
2023-02-02 15:25:04 +02:00
|
|
|
this.deviceInactivityTemplateForm.get('triggerConfig.filterByDevice')
|
|
|
|
|
.patchValue(!!this.ruleNotification.triggerConfig.devices, {onlySelf: true});
|
2023-01-27 15:47:08 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-10 18:31:05 +02:00
|
|
|
ngOnDestroy() {
|
|
|
|
|
super.ngOnDestroy();
|
|
|
|
|
this.destroy$.next();
|
|
|
|
|
this.destroy$.complete();
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-27 15:47:08 +02:00
|
|
|
changeStep($event: StepperSelectionEvent) {
|
|
|
|
|
this.selectedIndex = $event.selectedIndex;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
backStep() {
|
|
|
|
|
this.addNotificationRule.previous();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nextStep() {
|
|
|
|
|
if (this.selectedIndex >= this.maxStepperIndex) {
|
|
|
|
|
this.add();
|
|
|
|
|
} else {
|
|
|
|
|
this.addNotificationRule.next();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nextStepLabel(): string {
|
2023-02-02 15:25:04 +02:00
|
|
|
if (this.selectedIndex !== 0) {
|
2023-02-01 15:58:00 +02:00
|
|
|
return (this.data.isAdd || this.data.isCopy) ? 'action.add' : 'action.save';
|
2023-01-27 15:47:08 +02:00
|
|
|
}
|
|
|
|
|
return 'action.next';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private get maxStepperIndex(): number {
|
|
|
|
|
return this.addNotificationRule?._steps?.length - 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private add(): void {
|
|
|
|
|
if (this.allValid()) {
|
2023-02-01 02:02:27 +02:00
|
|
|
let formValue = this.ruleNotificationForm.value;
|
2023-02-02 15:25:04 +02:00
|
|
|
const triggerType: TriggerType = this.ruleNotificationForm.get('triggerType').value;
|
|
|
|
|
const currentForm = this.triggerTypeFormsMap.get(triggerType);
|
|
|
|
|
Object.assign(formValue, currentForm.value);
|
2023-03-28 13:47:24 +03:00
|
|
|
if (triggerType === TriggerType.DEVICE_ACTIVITY) {
|
2023-01-31 02:03:51 +02:00
|
|
|
delete formValue.triggerConfig.filterByDevice;
|
|
|
|
|
}
|
2023-02-02 15:25:04 +02:00
|
|
|
formValue.recipientsConfig.triggerType = triggerType;
|
|
|
|
|
formValue.triggerConfig.triggerType = triggerType;
|
|
|
|
|
if (this.ruleNotification && !this.data.isCopy) {
|
2023-02-01 02:02:27 +02:00
|
|
|
formValue = {...this.ruleNotification, ...formValue};
|
|
|
|
|
}
|
2023-01-27 15:47:08 +02:00
|
|
|
this.notificationService.saveNotificationRule(deepTrim(formValue)).subscribe(
|
|
|
|
|
(target) => this.dialogRef.close(target)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private allValid(): boolean {
|
|
|
|
|
return !this.addNotificationRule.steps.find((item, index) => {
|
|
|
|
|
if (item.stepControl.invalid) {
|
|
|
|
|
item.interacted = true;
|
|
|
|
|
this.addNotificationRule.selectedIndex = index;
|
|
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
});
|
2023-01-23 14:54:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cancel(): void {
|
|
|
|
|
this.dialogRef.close(null);
|
|
|
|
|
}
|
2023-02-10 18:31:05 +02:00
|
|
|
|
|
|
|
|
createTarget($event: Event, button: MatButton) {
|
|
|
|
|
if ($event) {
|
|
|
|
|
$event.stopPropagation();
|
|
|
|
|
}
|
|
|
|
|
button._elementRef.nativeElement.blur();
|
2023-03-21 17:56:12 +02:00
|
|
|
this.dialog.open<RecipientNotificationDialogComponent, RecipientNotificationDialogData,
|
|
|
|
|
NotificationTarget>(RecipientNotificationDialogComponent, {
|
2023-02-10 18:31:05 +02:00
|
|
|
disableClose: true,
|
|
|
|
|
panelClass: ['tb-dialog', 'tb-fullscreen-dialog'],
|
|
|
|
|
data: {}
|
|
|
|
|
}).afterClosed()
|
|
|
|
|
.subscribe((res) => {
|
|
|
|
|
if (res) {
|
|
|
|
|
let formValue: string[] = this.ruleNotificationForm.get('recipientsConfig.targets').value;
|
|
|
|
|
if (!formValue) {
|
|
|
|
|
formValue = [];
|
|
|
|
|
}
|
|
|
|
|
formValue.push(res.id.id);
|
|
|
|
|
this.ruleNotificationForm.get('recipientsConfig.targets').patchValue(formValue);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2023-03-15 13:28:31 +02:00
|
|
|
|
|
|
|
|
countRecipientsChainConfig(): number {
|
|
|
|
|
return Object.keys(this.ruleNotificationForm.get('recipientsConfig.escalationTable').value ?? {}).length;
|
|
|
|
|
}
|
2023-03-21 15:03:30 +02:00
|
|
|
|
|
|
|
|
formatLabel(value: number): string {
|
|
|
|
|
const formatValue = (value * 100).toFixed();
|
|
|
|
|
return `${formatValue}%`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private isSysAdmin(): boolean {
|
|
|
|
|
return this.authUser.authority === Authority.SYS_ADMIN;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private allowTriggerTypes(): TriggerType[] {
|
2023-04-10 11:21:11 +03:00
|
|
|
const sysAdminAllowTriggerTypes = new Set([
|
|
|
|
|
TriggerType.ENTITIES_LIMIT,
|
|
|
|
|
TriggerType.API_USAGE_LIMIT,
|
|
|
|
|
TriggerType.NEW_PLATFORM_VERSION,
|
2023-06-02 15:09:35 +03:00
|
|
|
TriggerType.RATE_LIMITS
|
2023-04-10 11:21:11 +03:00
|
|
|
]);
|
|
|
|
|
|
2023-03-21 15:03:30 +02:00
|
|
|
if (this.isSysAdmin()) {
|
2023-04-10 11:21:11 +03:00
|
|
|
return Array.from(sysAdminAllowTriggerTypes);
|
2023-03-21 15:03:30 +02:00
|
|
|
}
|
2023-04-10 11:21:11 +03:00
|
|
|
return Object.values(TriggerType).filter(type => !sysAdminAllowTriggerTypes.has(type));
|
2023-03-21 15:03:30 +02:00
|
|
|
}
|
2023-04-05 17:42:14 +03:00
|
|
|
|
|
|
|
|
get allowEntityTypeForEntityAction(): EntityType[] {
|
|
|
|
|
if (!this._allowEntityTypeForEntityAction) {
|
|
|
|
|
const excludeEntityType: Set<EntityType> = new Set([
|
|
|
|
|
EntityType.API_USAGE_STATE,
|
|
|
|
|
EntityType.TENANT_PROFILE,
|
|
|
|
|
EntityType.RPC,
|
|
|
|
|
EntityType.QUEUE,
|
|
|
|
|
EntityType.NOTIFICATION,
|
|
|
|
|
EntityType.NOTIFICATION_REQUEST,
|
|
|
|
|
EntityType.WIDGET_TYPE
|
|
|
|
|
]);
|
|
|
|
|
this._allowEntityTypeForEntityAction = Object.values(EntityType).filter(type => !excludeEntityType.has(type));
|
|
|
|
|
}
|
|
|
|
|
return this._allowEntityTypeForEntityAction;
|
|
|
|
|
}
|
2023-01-23 14:54:15 +02:00
|
|
|
}
|