Browse Source

UI: Notification rule

pull/8022/head
Artem Dzhereleiko 4 years ago
parent
commit
5d686b7dc6
  1. 27
      ui-ngx/src/app/modules/home/pages/notification-center/notification-table/rule-table-config.ts
  2. 4
      ui-ngx/src/app/modules/home/pages/notification-center/rule-table/escalation-form.component.html
  3. 1
      ui-ngx/src/app/modules/home/pages/notification-center/rule-table/escalation-form.component.ts
  4. 10
      ui-ngx/src/app/modules/home/pages/notification-center/rule-table/rule-notification-dialog.component.html
  5. 64
      ui-ngx/src/app/modules/home/pages/notification-center/rule-table/rule-notification-dialog.component.ts
  6. 3
      ui-ngx/src/app/shared/models/notification.models.ts
  7. 2
      ui-ngx/src/assets/locale/locale.constant-en_US.json

27
ui-ngx/src/app/modules/home/pages/notification-center/notification-table/rule-table-config.ts

@ -62,7 +62,7 @@ export class RuleTableConfig extends EntityTableConfig<NotificationRule> {
this.deleteEntityContent = () => this.translate.instant('notification.delete-rule-text');
this.deleteEntity = id => this.notificationService.deleteNotificationRule(id.id);
// this.cellActionDescriptors = this.configureCellActions();
this.cellActionDescriptors = this.configureCellActions();
this.headerComponent = RuleTableHeaderComponent;
this.onEntityAction = action => this.onTargetAction(action);
@ -70,25 +70,31 @@ export class RuleTableConfig extends EntityTableConfig<NotificationRule> {
this.columns.push(
new EntityTableColumn<NotificationRule>('name', 'notification.rule-name', '30%'),
new EntityTableColumn<NotificationRule>('templateId', 'notification.template', '15%',
(rule) => `${rule.templateId.id}`,
() => ({}), false),
new EntityTableColumn<NotificationRule>('triggerType', 'notification.trigger.trigger', '15%',
new EntityTableColumn<NotificationRule>('templateName', 'notification.template', '20%'),
new EntityTableColumn<NotificationRule>('triggerType', 'notification.trigger.trigger', '20%',
(rule) => this.translate.instant(TriggerTypeTranslationMap.get(rule.triggerType)) || '',
() => ({}), true)
() => ({}), true),
new EntityTableColumn<NotificationRule>('additionalConfig.description', 'notification.description', '30%',
(target) => target.additionalConfig.description || '',
() => ({}), false)
);
}
private configureCellActions(): Array<CellActionDescriptor<NotificationRule>> {
return [{
name: this.translate.instant('device.make-public'),
name: this.translate.instant('notification.copy-rule'),
icon: 'content_copy',
isEnabled: () => true,
onAction: ($event, entity) => this.editRule($event, entity, false, true)
}, {
name: this.translate.instant('notification.edit-rule'),
icon: 'edit',
isEnabled: () => true,
onAction: ($event, entity) => this.editTarget($event, entity)
onAction: ($event, entity) => this.editRule($event, entity)
}];
}
private editTarget($event: Event, rule: NotificationRule, isAdd = false) {
private editRule($event: Event, rule: NotificationRule, isAdd = false, isCopy = false) {
if ($event) {
$event.stopPropagation();
}
@ -98,6 +104,7 @@ export class RuleTableConfig extends EntityTableConfig<NotificationRule> {
panelClass: ['tb-dialog', 'tb-fullscreen-dialog'],
data: {
isAdd,
isCopy,
rule
}
}).afterClosed()
@ -111,7 +118,7 @@ export class RuleTableConfig extends EntityTableConfig<NotificationRule> {
private onTargetAction(action: EntityAction<NotificationRule>): boolean {
switch (action.action) {
case 'add':
this.editTarget(action.event, action.entity, true);
this.editRule(action.event, action.entity, true);
return true;
}
return false;

4
ui-ngx/src/app/modules/home/pages/notification-center/rule-table/escalation-form.component.html

@ -19,8 +19,8 @@
<form [formGroup]="escalationFormGroup" fxLayout="column">
<div class="escalation" fxLayout="row" fxLayout.xs="column" fxLayoutAlign="center center" fxLayoutAlign.xs="start">
<div fxFlex fxLayout="row" ngStyle.xs="padding-top: 10px">
<div fxFlex [fxShow]="systemEscalation" class="escalation-padding" translate>notification.first-recipient</div>
<div fxFlex [fxShow]="!systemEscalation" fxLayout="row" fxLayout.xs="column" fxLayoutAlign="center center">
<div fxFlex *ngIf="systemEscalation" class="escalation-padding" translate>notification.first-recipient</div>
<div fxFlex *ngIf="!systemEscalation" fxLayout="row" fxLayout.xs="column" fxLayoutAlign="center center">
<span class="escalation-padding">After</span>
<tb-timeinterval
style="min-width: 100px;"

1
ui-ngx/src/app/modules/home/pages/notification-center/rule-table/escalation-form.component.ts

@ -111,6 +111,7 @@ export class EscalationFormComponent implements ControlValueAccessor, OnInit, On
writeValue(value: NonConfirmedNotificationEscalation): void {
this.propagateChangePending = false;
this.modelValue = value;
this.modelValue.delayInSec = +value.delayInSec;
if (isDefinedAndNotNull(this.modelValue)) {
this.escalationFormGroup.patchValue(this.modelValue, {emitEvent: false});
}

10
ui-ngx/src/app/modules/home/pages/notification-center/rule-table/rule-notification-dialog.component.html

@ -17,7 +17,7 @@
-->
<section style="width: 800px; min-width: 100%; max-width: 100%">
<mat-toolbar color="primary">
<h2>{{'notification.add-rule' | translate }}</h2>
<h2>{{ dialogTitle | translate }}</h2>
<span fxFlex></span>
<button mat-icon-button
(click)="cancel()"
@ -176,16 +176,16 @@
*ngIf="deviceInactivityTemplateForm.get('filterByDevice').value"
required
formControlName="devices"
[labelText]="translate.instant('notification.devices')"
[placeholderText]="translate.instant('notification.device')"
[labelText]="'notification.devices'"
[placeholderText]="'notification.device'"
[entityType]="entityType.DEVICE">
</tb-entity-list>
<tb-entity-list
*ngIf="!deviceInactivityTemplateForm.get('filterByDevice').value"
required
formControlName="deviceProfiles"
[labelText]="translate.instant('notification.device-profiles')"
[placeholderText]="translate.instant('notification.device-profile')"
[labelText]="'notification.device-profiles'"
[placeholderText]="'notification.device-profile'"
[entityType]="entityType.DEVICE_PROFILE">
</tb-entity-list>
<tb-entity-list

64
ui-ngx/src/app/modules/home/pages/notification-center/rule-table/rule-notification-dialog.component.ts

@ -24,7 +24,7 @@ import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { NotificationService } from '@core/http/notification.service';
import { EntityType } from '@shared/models/entity-type.models';
import { deepTrim, isDefined } from '@core/utils';
import { deepClone, deepTrim, isDefined } from '@core/utils';
import { Observable, of, Subject } from 'rxjs';
import { map, mergeMap, share, startWith, takeUntil } from 'rxjs/operators';
import { StepperOrientation, StepperSelectionEvent } from '@angular/cdk/stepper';
@ -46,6 +46,7 @@ import { TruncatePipe } from '@shared/pipe/truncate.pipe';
export interface RuleNotificationDialogData {
rule?: NotificationRule;
isAdd?: boolean;
isCopy?: boolean;
}
@Component({
@ -91,10 +92,14 @@ export class RuleNotificationDialogComponent extends
filteredDisplaySeverities: Observable<Array<string>>;
severitySearchText = '';
dialogTitle = 'notification.edit-rule';
severityInputChange = new Subject<string>();
private destroy$ = new Subject();
private readonly ruleNotification: NotificationRule;
constructor(protected store: Store<AppState>,
protected router: Router,
protected dialogRef: MatDialogRef<RuleNotificationDialogComponent, NotificationRule>,
@ -122,6 +127,9 @@ export class RuleNotificationDialogComponent extends
}),
triggerConfig: this.fb.group({
triggerType: []
}),
additionalConfig: this.fb.group({
description: []
})
});
@ -174,6 +182,49 @@ export class RuleNotificationDialogComponent extends
mergeMap(name => this.fetchSeverities(name) ),
share()
);
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')})`;
}
this.ruleNotificationForm.reset({}, {emitEvent: false});
this.ruleNotificationForm.patchValue(this.ruleNotification, {emitEvent: false});
if (this.ruleNotification.triggerType === TriggerType.ALARM) {
const parsedEscalationTable = [];
const escalationTable = this.ruleNotification.recipientsConfig.escalationTable;
for (const escalation in escalationTable) {
parsedEscalationTable.push({delayInSec: escalation, targets: escalationTable[escalation]});
}
this.alarmTemplateForm.patchValue({
escalationTable: parsedEscalationTable,
alarmTypes: this.ruleNotification.triggerConfig.alarmTypes,
alarmSeverities: this.ruleNotification.triggerConfig.alarmSeverities,
clearRule: this.ruleNotification.triggerConfig.clearRule,
description: this.ruleNotification.additionalConfig.description
}, {emitEvent: false});
} else if (this.ruleNotification.triggerType === TriggerType.DEVICE_INACTIVITY) {
this.deviceInactivityTemplateForm.patchValue({
filterByDevice: !!this.ruleNotification.triggerConfig.devices,
deviceProfiles: this.ruleNotification.triggerConfig.devicesProfiles,
devices: this.ruleNotification.triggerConfig.devices,
targets: this.ruleNotification.recipientsConfig.targets,
description: this.ruleNotification.additionalConfig.description
}, {emitEvent: false});
} else {
this.entityActionTemplateForm.patchValue({
entityType: this.ruleNotification.triggerConfig.entityType,
created: this.ruleNotification.triggerConfig.created,
updated: this.ruleNotification.triggerConfig.updated,
deleted: this.ruleNotification.triggerConfig.deleted,
targets: this.ruleNotification.recipientsConfig.targets
}, {emitEvent: false});
}
}
}
onSeverityRemoved(severity: string): void {
@ -318,7 +369,7 @@ export class RuleNotificationDialogComponent extends
private add(): void {
if (this.allValid()) {
const formValue = this.ruleNotificationForm.value;
let formValue = this.ruleNotificationForm.value;
const triggerType = this.ruleNotificationForm.get('triggerType').value;
if (triggerType === TriggerType.ALARM) {
Object.assign(formValue.triggerConfig, this.alarmTemplateForm.value);
@ -327,17 +378,24 @@ export class RuleNotificationDialogComponent extends
escalation => parsedEscalationTable[escalation.delayInSec] = escalation.targets
);
formValue.recipientsConfig.escalationTable = parsedEscalationTable;
formValue.additionalConfig.description = this.alarmTemplateForm.get('description').value;
delete formValue.triggerConfig.escalationTable;
} else if (triggerType === TriggerType.DEVICE_INACTIVITY) {
Object.assign(formValue.triggerConfig, this.deviceInactivityTemplateForm.value);
formValue.recipientsConfig.targets = this.deviceInactivityTemplateForm.get('targets').value;
formValue.additionalConfig.description = this.deviceInactivityTemplateForm.get('description').value;
delete formValue.triggerConfig.filterByDevice;
} else {
Object.assign(formValue.triggerConfig, this.entityActionTemplateForm.value);
formValue.recipientsConfig.targets = this.entityActionTemplateForm.get('targets').value;
formValue.additionalConfig.description = this.entityActionTemplateForm.get('description').value;
}
if (triggerType === TriggerType.DEVICE_INACTIVITY || triggerType === TriggerType.ENTITY_ACTION) {
formValue.recipientsConfig.targets = this.entityActionTemplateForm.get('targets').value;
delete formValue.triggerConfig.trigger;
}
if (this.ruleNotification) {
formValue = {...this.ruleNotification, ...formValue};
}
this.notificationService.saveNotificationRule(deepTrim(formValue)).subscribe(
(target) => this.dialogRef.close(target)
);

3
ui-ngx/src/app/shared/models/notification.models.ts

@ -104,7 +104,8 @@ export interface NotificationRule extends Omit<BaseData<NotificationRuleId>, 'la
templateId: NotificationTemplateId;
triggerType: TriggerType;
triggerConfig: NotificationRuleTriggerConfig;
recipientConfig: NotificationRuleRecipientConfig;
recipientsConfig: NotificationRuleRecipientConfig;
additionalConfig: {description: string};
}
export interface NotificationRuleTriggerConfig {

2
ui-ngx/src/assets/locale/locale.constant-en_US.json

@ -2690,6 +2690,8 @@
"conversation": "Conversation",
"conversation-required": "Conversation is required",
"add-rule": "Add rule",
"edit-rule": "Edit rule",
"copy-rule": "Copy rule",
"copy-notification-template": "Copy notification template",
"copy-template": "Copy template",
"create-target": "Create recipient",

Loading…
Cancel
Save