From 14b05a57bd372e7ee30c0aa053e0fa11982324bb Mon Sep 17 00:00:00 2001 From: Vladyslav_Prykhodko Date: Fri, 17 Mar 2023 18:53:03 +0200 Subject: [PATCH] UI: Add new notification template/rule RULE_ENGINE_COMPONENT_LIFECYCLE_EVENT --- .../rule-notification-dialog.component.html | 59 +++++++++++++++++++ .../rule-notification-dialog.component.scss | 4 ++ .../rule-notification-dialog.component.ts | 18 ++++++ .../app/shared/models/notification.models.ts | 38 +++++++++++- .../assets/locale/locale.constant-en_US.json | 25 ++++++-- 5 files changed, 136 insertions(+), 8 deletions(-) diff --git a/ui-ngx/src/app/modules/home/pages/notification-center/rule-table/rule-notification-dialog.component.html b/ui-ngx/src/app/modules/home/pages/notification-center/rule-table/rule-notification-dialog.component.html index 1a472e7246..e912a0eab6 100644 --- a/ui-ngx/src/app/modules/home/pages/notification-center/rule-table/rule-notification-dialog.component.html +++ b/ui-ngx/src/app/modules/home/pages/notification-center/rule-table/rule-notification-dialog.component.html @@ -333,6 +333,65 @@ + + {{ 'notification.rule-engine-events-trigger-settings' | translate }} +
+
+
+ notification.rule-engine-filter + + + + rulechain.rulechain-events + + + {{ componentLifecycleEventTranslationMap.get(componentLifecycleEvent) | translate }} + + + + + {{ 'notification.only-rule-chain-lifecycle-failures' | translate }} + +
+
+ notification.rule-node-filter + + {{ 'notification.track-rule-node-events' | translate }} + +
+ + rulenode.rule-node-events + + + {{ componentLifecycleEventTranslationMap.get(componentLifecycleEvent) | translate }} + + + + + {{ 'notification.only-rule-node-lifecycle-failures' | translate }} + +
+
+
+
+
+
+ + notification.description + + +
+
+
diff --git a/ui-ngx/src/app/modules/home/pages/notification-center/rule-table/rule-notification-dialog.component.scss b/ui-ngx/src/app/modules/home/pages/notification-center/rule-table/rule-notification-dialog.component.scss index a3db5bf58b..a02b2e1f97 100644 --- a/ui-ngx/src/app/modules/home/pages/notification-center/rule-table/rule-notification-dialog.component.scss +++ b/ui-ngx/src/app/modules/home/pages/notification-center/rule-table/rule-notification-dialog.component.scss @@ -60,6 +60,10 @@ .clear-button-space { margin-right: 48px; } + + .mat-mdc-slide-toggle { + margin-bottom: 16px; + } } ::ng-deep { diff --git a/ui-ngx/src/app/modules/home/pages/notification-center/rule-table/rule-notification-dialog.component.ts b/ui-ngx/src/app/modules/home/pages/notification-center/rule-table/rule-notification-dialog.component.ts index 4939b0e861..439eaed964 100644 --- a/ui-ngx/src/app/modules/home/pages/notification-center/rule-table/rule-notification-dialog.component.ts +++ b/ui-ngx/src/app/modules/home/pages/notification-center/rule-table/rule-notification-dialog.component.ts @@ -19,6 +19,8 @@ import { AlarmActionTranslationMap, AlarmAssignmentAction, AlarmAssignmentActionTranslationMap, + ComponentLifecycleEvent, + ComponentLifecycleEventTranslationMap, NotificationRule, NotificationTarget, TriggerType, @@ -77,6 +79,7 @@ export class RuleNotificationDialogComponent extends entityActionTemplateForm: FormGroup; alarmCommentTemplateForm: FormGroup; alarmAssignmentTemplateForm: FormGroup; + ruleEngineEventsTemplateForm: FormGroup; triggerType = TriggerType; triggerTypes: TriggerType[] = Object.values(TriggerType); @@ -99,6 +102,9 @@ export class RuleNotificationDialogComponent extends alarmAssignmentActions: AlarmAssignmentAction[] = Object.values(AlarmAssignmentAction); alarmAssignmentActionTranslationMap = AlarmAssignmentActionTranslationMap; + componentLifecycleEvents: ComponentLifecycleEvent[] = Object.values(ComponentLifecycleEvent); + componentLifecycleEventTranslationMap = ComponentLifecycleEventTranslationMap; + entityType = EntityType; entityTypes: EntityType[] = Object.values(EntityType); isAdd = true; @@ -226,12 +232,24 @@ export class RuleNotificationDialogComponent extends }) }); + this.ruleEngineEventsTemplateForm = this.fb.group({ + triggerConfig: this.fb.group({ + ruleChains: [null], + ruleChainEvents: [null], + onlyRuleChainLifecycleFailures: [false], + trackRuleNodeEvents: [false], + ruleNodeEvents: [null], + onlyRuleNodeLifecycleFailures: [false] + }) + }); + this.triggerTypeFormsMap = new Map([ [TriggerType.ALARM, this.alarmTemplateForm], [TriggerType.ALARM_COMMENT, this.alarmCommentTemplateForm], [TriggerType.DEVICE_INACTIVITY, this.deviceInactivityTemplateForm], [TriggerType.ENTITY_ACTION, this.entityActionTemplateForm], [TriggerType.ALARM_ASSIGNMENT, this.alarmAssignmentTemplateForm], + [TriggerType.RULE_ENGINE_COMPONENT_LIFECYCLE_EVENT, this.ruleEngineEventsTemplateForm] ]); if (data.isAdd || data.isCopy) { diff --git a/ui-ngx/src/app/shared/models/notification.models.ts b/ui-ngx/src/app/shared/models/notification.models.ts index bdff88c9fd..908efd7fe0 100644 --- a/ui-ngx/src/app/shared/models/notification.models.ts +++ b/ui-ngx/src/app/shared/models/notification.models.ts @@ -109,7 +109,8 @@ export interface NotificationRule extends Omit, 'la additionalConfig: {description: string}; } -export type NotificationRuleTriggerConfig = Partial +export type NotificationRuleTriggerConfig = Partial export interface AlarmNotificationRuleTriggerConfig { alarmTypes?: Array; @@ -149,6 +150,27 @@ export interface AlarmAssignmentNotificationRuleTriggerConfig { notifyOn: Array; } +export interface RuleEngineLifecycleEventNotificationRuleTriggerConfig { + ruleChains?: Array; + ruleChainEvents?: Array; + onlyRuleChainLifecycleFailures: boolean; + trackRuleNodeEvents: boolean; + ruleNodeEvents: Array; + onlyRuleNodeLifecycleFailures: ComponentLifecycleEvent; +} + +export enum ComponentLifecycleEvent { + STARTED = 'STARTED', + UPDATED = 'UPDATED', + STOPPED = 'STOPPED' +} + +export const ComponentLifecycleEventTranslationMap = new Map([ + [ComponentLifecycleEvent.STARTED, 'event.started'], + [ComponentLifecycleEvent.UPDATED, 'event.updated'], + [ComponentLifecycleEvent.STOPPED, 'event.stopped'] +]) + export enum AlarmAction { CREATED = 'CREATED', SEVERITY_CHANGED = 'SEVERITY_CHANGED', @@ -347,7 +369,8 @@ export enum NotificationType { DEVICE_INACTIVITY = 'DEVICE_INACTIVITY', ENTITY_ACTION = 'ENTITY_ACTION', ALARM_COMMENT = 'ALARM_COMMENT', - ALARM_ASSIGNMENT = 'ALARM_ASSIGNMENT' + ALARM_ASSIGNMENT = 'ALARM_ASSIGNMENT', + RULE_ENGINE_COMPONENT_LIFECYCLE_EVENT = 'RULE_ENGINE_COMPONENT_LIFECYCLE_EVENT' } export const NotificationTypeIcons = new Map([ @@ -356,6 +379,7 @@ export const NotificationTypeIcons = new Map([ [NotificationType.ENTITY_ACTION, 'devices'], [NotificationType.ALARM_COMMENT, 'comment'], [NotificationType.ALARM_ASSIGNMENT, 'assignment_turned_in'], + [NotificationType.RULE_ENGINE_COMPONENT_LIFECYCLE_EVENT, 'settings_ethernet'] ]); export const AlarmSeverityNotificationColors = new Map( @@ -419,6 +443,12 @@ export const NotificationTemplateTypeTranslateMap = new Map([ @@ -436,4 +467,5 @@ export const TriggerTypeTranslationMap = new Map([ [TriggerType.ENTITY_ACTION, 'notification.trigger.entity-action'], [TriggerType.ALARM_COMMENT, 'notification.trigger.alarm-comment'], [TriggerType.ALARM_ASSIGNMENT, 'notification.trigger.alarm-assignment'], + [TriggerType.RULE_ENGINE_COMPONENT_LIFECYCLE_EVENT, 'notification.trigger.rule-engine-lifecycle-event'], ]); diff --git a/ui-ngx/src/assets/locale/locale.constant-en_US.json b/ui-ngx/src/assets/locale/locale.constant-en_US.json index 74b7e31fb5..eb3072e1a7 100644 --- a/ui-ngx/src/assets/locale/locale.constant-en_US.json +++ b/ui-ngx/src/assets/locale/locale.constant-en_US.json @@ -2174,7 +2174,10 @@ "entity-type": "Entity type", "clear-filter": "Clear Filter", "clear-request-title": "Clear all events", - "clear-request-text": "Are you sure you want to clear all events?" + "clear-request-text": "Are you sure you want to clear all events?", + "started": "Started", + "updated": "Updated", + "stopped": "Stopped" }, "extension": { "extensions": "Extensions", @@ -2836,8 +2839,12 @@ }, "review": "Review", "rule": "Rule", + "rule-chain-list-rule-hint": "If the field is empty, the trigger will be applied to all rule chains", + "rule-engine-events-trigger-settings": "Rule engine events trigger settings", + "rule-engine-filter": "Rule engine filter", "rule-name": "Rule name", "rule-name-required": "Name is required", + "rule-node-filter": "Rule node filter", "rules": "Rules", "scheduler-later": "Schedule for later", "search-notification": "Search notification", @@ -2882,7 +2889,8 @@ "alarm-comment": "Available params: ${comment}, ${alarmType}, ${alarmId}, ${alarmType}, ${alarmSeverity}, ${alarmStatus}, ${alarmOriginatorEntityType}, ${alarmOriginatorId}, ${alarmId}, ${alarmAction}", "device-inactivity": "Available params: ${deviceName}, ${deviceLabel}, ${deviceType}, ${deviceId}", "entity-action": "Available params: ${actionType}, ${entityType}, ${entityName}, ${entityId}, ${originatorUserName}, ${originatorUserId}", - "general": "Available params: ${recipientEmail}, ${recipientFirstName}, ${recipientLastName}" + "general": "Available params: ${recipientEmail}, ${recipientFirstName}, ${recipientLastName}", + "rule-engine-lifecycle-event": "Available params: ${ruleChainName}, ${componentName}, ${eventType}, ${error}, ${ruleChainId}, ${componentId}" }, "template-name": "Template name", "template-required": "Template is required", @@ -2892,12 +2900,14 @@ "alarm-comment": "Alarm comment", "device-inactivity": "Device inactivity", "entity-action": "Entity action", - "general": "General" + "general": "General", + "rule-engine-lifecycle-event": "Rule engine lifecycle event" }, "templates": "Templates", "tenants-list-rule-hint": "If the field is empty, the trigger will be applied to all tenants", "tenant-profiles-list-rule-hint": "If the field is empty, the trigger will be applied to all tenant profiles", "time": "Time", + "track-rule-node-events": "Track rule node events", "trigger": { "alarm": "Alarm", "alarm-assignment": "Alarm assignment", @@ -2905,14 +2915,17 @@ "device-inactivity": "Device inactivity", "entity-action": "Entity action", "trigger": "Trigger", - "trigger-required": "Trigger is required" + "trigger-required": "Trigger is required", + "rule-engine-lifecycle-event": "Rule engine lifecycle event" }, "type": "Type", "unread": "Unread", "updated": "Updated", "use-template": "Use template", "view-all": "View all", - "web-settings": "Web settings" + "web-settings": "Web settings", + "only-rule-chain-lifecycle-failures": "Only rule chain lifecycle failures", + "only-rule-node-lifecycle-failures": "Only rule node lifecycle failures" }, "ota-update": { "add": "Add package", @@ -3145,6 +3158,7 @@ }, "rulechain": { "rulechain": "Rule chain", + "rulechain-events": "Rule chain events", "rulechains": "Rule chains", "root": "Root", "delete": "Delete rule chain", @@ -3206,6 +3220,7 @@ "unassign-rulechains": "Unassign rulechains" }, "rulenode": { + "rule-node-events": "Rule node events", "details": "Details", "events": "Events", "search": "Search nodes",