From a302451a5bd77f3edecffc575525e2648c2de496 Mon Sep 17 00:00:00 2001 From: Artem Dzhereleiko Date: Wed, 26 Feb 2025 16:28:28 +0200 Subject: [PATCH] UI: Trigger settings to persent --- .../rule-notification-dialog.component.html | 32 +++++++++---------- .../rule-notification-dialog.component.scss | 2 +- .../rule-notification-dialog.component.ts | 27 ++++++++++++---- .../app/shared/models/notification.models.ts | 8 ++++- 4 files changed, 45 insertions(+), 24 deletions(-) diff --git a/ui-ngx/src/app/modules/home/pages/notification/rule/rule-notification-dialog.component.html b/ui-ngx/src/app/modules/home/pages/notification/rule/rule-notification-dialog.component.html index 028796f470..0951acfea8 100644 --- a/ui-ngx/src/app/modules/home/pages/notification/rule/rule-notification-dialog.component.html +++ b/ui-ngx/src/app/modules/home/pages/notification/rule/rule-notification-dialog.component.html @@ -481,16 +481,16 @@ [allowedEntityTypes]="allowEntityTypeForEntitiesLimit">
- + notification.threshold
- + - + max="100"/>
@@ -599,44 +599,44 @@
notification.filter
- + notification.cpu-threshold
- + - + max="100"/>
- + notification.ram-threshold
- + - + max="100"/>
- + notification.storage-threshold
- + - + max="100"/>
diff --git a/ui-ngx/src/app/modules/home/pages/notification/rule/rule-notification-dialog.component.scss b/ui-ngx/src/app/modules/home/pages/notification/rule/rule-notification-dialog.component.scss index 5e495655f1..9f1221cad5 100644 --- a/ui-ngx/src/app/modules/home/pages/notification/rule/rule-notification-dialog.component.scss +++ b/ui-ngx/src/app/modules/home/pages/notification/rule/rule-notification-dialog.component.scss @@ -81,7 +81,7 @@ min-width: 364px; } .limit-slider-container { - > label { + > span { margin-right: 16px; width: min-content; max-width: 40%; diff --git a/ui-ngx/src/app/modules/home/pages/notification/rule/rule-notification-dialog.component.ts b/ui-ngx/src/app/modules/home/pages/notification/rule/rule-notification-dialog.component.ts index 1ea55ed106..e0ddefcbe8 100644 --- a/ui-ngx/src/app/modules/home/pages/notification/rule/rule-notification-dialog.component.ts +++ b/ui-ngx/src/app/modules/home/pages/notification/rule/rule-notification-dialog.component.ts @@ -316,7 +316,7 @@ export class RuleNotificationDialogComponent extends this.entitiesLimitTemplateForm = this.fb.group({ triggerConfig: this.fb.group({ entityTypes: [], - threshold: [.8, [Validators.min(0), Validators.max(1)]] + threshold: [80, [Validators.min(0), Validators.max(100)]] }) }); @@ -347,9 +347,9 @@ export class RuleNotificationDialogComponent extends this.resourceUsageShortageTemplateForm = this.fb.group({ triggerConfig: this.fb.group({ - cpuThreshold: [.8, [Validators.min(0), Validators.max(1)]], - ramThreshold: [.8, [Validators.min(0), Validators.max(1)]], - storageThreshold: [.8, [Validators.min(0), Validators.max(1)]] + cpuThreshold: [80, [Validators.min(0), Validators.max(100)]], + ramThreshold: [80, [Validators.min(0), Validators.max(100)]], + storageThreshold: [80, [Validators.min(0), Validators.max(100)]] }) }); @@ -390,6 +390,14 @@ export class RuleNotificationDialogComponent extends this.deviceInactivityTemplateForm.get('triggerConfig.filterByDevice') .patchValue(!!this.ruleNotification.triggerConfig.devices, {onlySelf: true}); } + if (this.ruleNotification.triggerType === TriggerType.ENTITIES_LIMIT) { + this.entitiesLimitTemplateForm.get('triggerConfig.threshold').patchValue(this.ruleNotification.triggerConfig.threshold * 100, {emitEvent: false}); + } + if (this.ruleNotification.triggerType === TriggerType.RESOURCES_SHORTAGE) { + this.resourceUsageShortageTemplateForm.get('triggerConfig.cpuThreshold').patchValue(this.ruleNotification.triggerConfig.cpuThreshold * 100, {emitEvent: false}); + this.resourceUsageShortageTemplateForm.get('triggerConfig.ramThreshold').patchValue(this.ruleNotification.triggerConfig.ramThreshold * 100, {emitEvent: false}); + this.resourceUsageShortageTemplateForm.get('triggerConfig.storageThreshold').patchValue(this.ruleNotification.triggerConfig.storageThreshold * 100, {emitEvent: false}); + } } } @@ -438,6 +446,14 @@ export class RuleNotificationDialogComponent extends if (triggerType === TriggerType.DEVICE_ACTIVITY) { delete formValue.triggerConfig.filterByDevice; } + if (triggerType === TriggerType.ENTITIES_LIMIT) { + formValue.triggerConfig.threshold = formValue.triggerConfig.threshold / 100; + } + if (triggerType === TriggerType.RESOURCES_SHORTAGE) { + formValue.triggerConfig.cpuThreshold = formValue.triggerConfig.cpuThreshold / 100; + formValue.triggerConfig.ramThreshold = formValue.triggerConfig.ramThreshold / 100; + formValue.triggerConfig.storageThreshold = formValue.triggerConfig.storageThreshold / 100; + } formValue.recipientsConfig.triggerType = triggerType; formValue.triggerConfig.triggerType = triggerType; if (this.ruleNotification && !this.data.isCopy) { @@ -493,8 +509,7 @@ export class RuleNotificationDialogComponent extends } formatLabel(value: number): string { - const formatValue = (value * 100).toFixed(); - return `${formatValue}%`; + return `${value}%`; } private isSysAdmin(): boolean { diff --git a/ui-ngx/src/app/shared/models/notification.models.ts b/ui-ngx/src/app/shared/models/notification.models.ts index 369bc08c15..63d7edd2a2 100644 --- a/ui-ngx/src/app/shared/models/notification.models.ts +++ b/ui-ngx/src/app/shared/models/notification.models.ts @@ -129,7 +129,7 @@ export interface NotificationRule extends Omit, 'la export type NotificationRuleTriggerConfig = Partial; + ApiUsageLimitNotificationRuleTriggerConfig & RateLimitsNotificationRuleTriggerConfig & ResourceUsageShortageNotificationRuleTriggerConfig>; export interface AlarmNotificationRuleTriggerConfig { alarmTypes?: Array; @@ -183,6 +183,12 @@ export interface EntitiesLimitNotificationRuleTriggerConfig { threshold: number; } +export interface ResourceUsageShortageNotificationRuleTriggerConfig { + cpuThreshold: number; + ramThreshold: number; + storageThreshold: number; +} + export interface ApiUsageLimitNotificationRuleTriggerConfig { apiFeatures: ApiFeature[]; notifyOn: ApiUsageStateValue[];