|
|
@ -34,7 +34,7 @@ import { Router } from '@angular/router'; |
|
|
import { MAT_DIALOG_DATA, MatDialog, MatDialogRef } from '@angular/material/dialog'; |
|
|
import { MAT_DIALOG_DATA, MatDialog, MatDialogRef } from '@angular/material/dialog'; |
|
|
import { FormBuilder, FormGroup, Validators } from '@angular/forms'; |
|
|
import { FormBuilder, FormGroup, Validators } from '@angular/forms'; |
|
|
import { NotificationService } from '@core/http/notification.service'; |
|
|
import { NotificationService } from '@core/http/notification.service'; |
|
|
import { EntityType } from '@shared/models/entity-type.models'; |
|
|
import { EntityType, entityTypeTranslations } from '@shared/models/entity-type.models'; |
|
|
import { deepClone, deepTrim, isDefined } from '@core/utils'; |
|
|
import { deepClone, deepTrim, isDefined } from '@core/utils'; |
|
|
import { Observable, Subject } from 'rxjs'; |
|
|
import { Observable, Subject } from 'rxjs'; |
|
|
import { map, takeUntil } from 'rxjs/operators'; |
|
|
import { map, takeUntil } from 'rxjs/operators'; |
|
|
@ -54,6 +54,10 @@ import { |
|
|
TargetsNotificationDialogData |
|
|
TargetsNotificationDialogData |
|
|
} from '@home/pages/notification-center/targets-table/target-notification-dialog.componet'; |
|
|
} from '@home/pages/notification-center/targets-table/target-notification-dialog.componet'; |
|
|
import { MatButton } from '@angular/material/button'; |
|
|
import { MatButton } from '@angular/material/button'; |
|
|
|
|
|
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'; |
|
|
|
|
|
|
|
|
export interface RuleNotificationDialogData { |
|
|
export interface RuleNotificationDialogData { |
|
|
rule?: NotificationRule; |
|
|
rule?: NotificationRule; |
|
|
@ -80,9 +84,10 @@ export class RuleNotificationDialogComponent extends |
|
|
alarmCommentTemplateForm: FormGroup; |
|
|
alarmCommentTemplateForm: FormGroup; |
|
|
alarmAssignmentTemplateForm: FormGroup; |
|
|
alarmAssignmentTemplateForm: FormGroup; |
|
|
ruleEngineEventsTemplateForm: FormGroup; |
|
|
ruleEngineEventsTemplateForm: FormGroup; |
|
|
|
|
|
entitiesLimitTemplateForm: FormGroup; |
|
|
|
|
|
|
|
|
triggerType = TriggerType; |
|
|
triggerType = TriggerType; |
|
|
triggerTypes: TriggerType[] = Object.values(TriggerType); |
|
|
triggerTypes: TriggerType[]; |
|
|
triggerTypeTranslationMap = TriggerTypeTranslationMap; |
|
|
triggerTypeTranslationMap = TriggerTypeTranslationMap; |
|
|
|
|
|
|
|
|
alarmSearchStatuses = [ |
|
|
alarmSearchStatuses = [ |
|
|
@ -106,7 +111,7 @@ export class RuleNotificationDialogComponent extends |
|
|
componentLifecycleEventTranslationMap = ComponentLifecycleEventTranslationMap; |
|
|
componentLifecycleEventTranslationMap = ComponentLifecycleEventTranslationMap; |
|
|
|
|
|
|
|
|
entityType = EntityType; |
|
|
entityType = EntityType; |
|
|
entityTypes: EntityType[] = Object.values(EntityType); |
|
|
entityTypes = Array.from(entityTypeTranslations.keys()).filter(type => !!this.entityType[type]); |
|
|
isAdd = true; |
|
|
isAdd = true; |
|
|
|
|
|
|
|
|
selectedIndex = 0; |
|
|
selectedIndex = 0; |
|
|
@ -118,6 +123,8 @@ export class RuleNotificationDialogComponent extends |
|
|
private readonly ruleNotification: NotificationRule; |
|
|
private readonly ruleNotification: NotificationRule; |
|
|
|
|
|
|
|
|
private triggerTypeFormsMap: Map<TriggerType, FormGroup>; |
|
|
private triggerTypeFormsMap: Map<TriggerType, FormGroup>; |
|
|
|
|
|
private authState: AuthState = getCurrentAuthState(this.store); |
|
|
|
|
|
private authUser: AuthUser = this.authState.authUser; |
|
|
|
|
|
|
|
|
constructor(protected store: Store<AppState>, |
|
|
constructor(protected store: Store<AppState>, |
|
|
protected router: Router, |
|
|
protected router: Router, |
|
|
@ -130,6 +137,8 @@ export class RuleNotificationDialogComponent extends |
|
|
private dialog: MatDialog) { |
|
|
private dialog: MatDialog) { |
|
|
super(store, router, dialogRef); |
|
|
super(store, router, dialogRef); |
|
|
|
|
|
|
|
|
|
|
|
this.triggerTypes = this.allowTriggerTypes(); |
|
|
|
|
|
|
|
|
if (isDefined(data.isAdd)) { |
|
|
if (isDefined(data.isAdd)) { |
|
|
this.isAdd = data.isAdd; |
|
|
this.isAdd = data.isAdd; |
|
|
} |
|
|
} |
|
|
@ -140,10 +149,10 @@ export class RuleNotificationDialogComponent extends |
|
|
this.ruleNotificationForm = this.fb.group({ |
|
|
this.ruleNotificationForm = this.fb.group({ |
|
|
name: [null, Validators.required], |
|
|
name: [null, Validators.required], |
|
|
templateId: [null, Validators.required], |
|
|
templateId: [null, Validators.required], |
|
|
triggerType: [TriggerType.ALARM, Validators.required], |
|
|
triggerType: [this.isSysAdmin() ? TriggerType.ENTITIES_LIMIT : TriggerType.ALARM, Validators.required], |
|
|
recipientsConfig: this.fb.group({ |
|
|
recipientsConfig: this.fb.group({ |
|
|
targets: [{value: null, disabled: true}, Validators.required], |
|
|
targets: [{value: null, disabled: !this.isSysAdmin()}, Validators.required], |
|
|
escalationTable: [null, Validators.required] |
|
|
escalationTable: [{value: null, disabled: this.isSysAdmin()}, Validators.required] |
|
|
}), |
|
|
}), |
|
|
triggerConfig: [null], |
|
|
triggerConfig: [null], |
|
|
additionalConfig: this.fb.group({ |
|
|
additionalConfig: this.fb.group({ |
|
|
@ -243,13 +252,21 @@ export class RuleNotificationDialogComponent extends |
|
|
}) |
|
|
}) |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
this.entitiesLimitTemplateForm = this.fb.group({ |
|
|
|
|
|
triggerConfig: this.fb.group({ |
|
|
|
|
|
entityTypes: [], |
|
|
|
|
|
threshold: [.8, [Validators.min(0), Validators.max(1)]] |
|
|
|
|
|
}) |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
this.triggerTypeFormsMap = new Map<TriggerType, FormGroup>([ |
|
|
this.triggerTypeFormsMap = new Map<TriggerType, FormGroup>([ |
|
|
[TriggerType.ALARM, this.alarmTemplateForm], |
|
|
[TriggerType.ALARM, this.alarmTemplateForm], |
|
|
[TriggerType.ALARM_COMMENT, this.alarmCommentTemplateForm], |
|
|
[TriggerType.ALARM_COMMENT, this.alarmCommentTemplateForm], |
|
|
[TriggerType.DEVICE_INACTIVITY, this.deviceInactivityTemplateForm], |
|
|
[TriggerType.DEVICE_INACTIVITY, this.deviceInactivityTemplateForm], |
|
|
[TriggerType.ENTITY_ACTION, this.entityActionTemplateForm], |
|
|
[TriggerType.ENTITY_ACTION, this.entityActionTemplateForm], |
|
|
[TriggerType.ALARM_ASSIGNMENT, this.alarmAssignmentTemplateForm], |
|
|
[TriggerType.ALARM_ASSIGNMENT, this.alarmAssignmentTemplateForm], |
|
|
[TriggerType.RULE_ENGINE_COMPONENT_LIFECYCLE_EVENT, this.ruleEngineEventsTemplateForm] |
|
|
[TriggerType.RULE_ENGINE_COMPONENT_LIFECYCLE_EVENT, this.ruleEngineEventsTemplateForm], |
|
|
|
|
|
[TriggerType.ENTITIES_LIMIT, this.entitiesLimitTemplateForm] |
|
|
]); |
|
|
]); |
|
|
|
|
|
|
|
|
if (data.isAdd || data.isCopy) { |
|
|
if (data.isAdd || data.isCopy) { |
|
|
@ -368,4 +385,20 @@ export class RuleNotificationDialogComponent extends |
|
|
countRecipientsChainConfig(): number { |
|
|
countRecipientsChainConfig(): number { |
|
|
return Object.keys(this.ruleNotificationForm.get('recipientsConfig.escalationTable').value ?? {}).length; |
|
|
return Object.keys(this.ruleNotificationForm.get('recipientsConfig.escalationTable').value ?? {}).length; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
formatLabel(value: number): string { |
|
|
|
|
|
const formatValue = (value * 100).toFixed(); |
|
|
|
|
|
return `${formatValue}%`; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private isSysAdmin(): boolean { |
|
|
|
|
|
return this.authUser.authority === Authority.SYS_ADMIN; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private allowTriggerTypes(): TriggerType[] { |
|
|
|
|
|
if (this.isSysAdmin()) { |
|
|
|
|
|
return [TriggerType.ENTITIES_LIMIT]; |
|
|
|
|
|
} |
|
|
|
|
|
return Object.values(TriggerType).filter(type => type !== TriggerType.ENTITIES_LIMIT); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|