Browse Source

Merge UI from ArtemDzhereleiko

Notification rule trigger settings to persent
pull/12616/head
Andrii Landiak 2 years ago
committed by GitHub
parent
commit
7e701eb135
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 52
      ui-ngx/src/app/modules/home/pages/notification/rule/rule-notification-dialog.component.html
  2. 2
      ui-ngx/src/app/modules/home/pages/notification/rule/rule-notification-dialog.component.scss
  3. 27
      ui-ngx/src/app/modules/home/pages/notification/rule/rule-notification-dialog.component.ts
  4. 8
      ui-ngx/src/app/shared/models/notification.models.ts

52
ui-ngx/src/app/modules/home/pages/notification/rule/rule-notification-dialog.component.html

@ -480,17 +480,18 @@
ignoreAuthorityFilter ignoreAuthorityFilter
[allowedEntityTypes]="allowEntityTypeForEntitiesLimit"> [allowedEntityTypes]="allowEntityTypeForEntitiesLimit">
</tb-entity-type-list> </tb-entity-type-list>
<div class="limit-slider-container flex flex-row items-center justify-start xs:flex-col xs:items-stretch"> <div class="limit-slider-container mb-4 flex flex-row items-center justify-start xs:flex-col xs:items-stretch">
<label translate>notification.threshold</label> <span translate>notification.threshold</span>
<div class="flex flex-1 flex-row items-center justify-start"> <div class="flex flex-1 flex-row items-center justify-start">
<mat-slider class="flex-1" min="0" max="1" step="0.01" discrete [displayWith]="formatLabel"> <mat-slider class="flex-1" min="0" max="100" step="1" discrete [displayWith]="formatLabel">
<input matSliderThumb formControlName="threshold"> <input matSliderThumb formControlName="threshold">
</mat-slider> </mat-slider>
<mat-form-field class="limit-slider-value"> <mat-form-field class="limit-slider-value" subscriptSizing="dynamic">
<input matInput formControlName="threshold" type="number" step="0.01" <input matInput formControlName="threshold" type="number" step="1"
[value]="entitiesLimitTemplateForm.get('triggerConfig.threshold').value" [value]="entitiesLimitTemplateForm.get('triggerConfig.threshold').value"
min="0" min="0"
max="1"/> max="100"/>
<span class="mr-2" matSuffix>%</span>
</mat-form-field> </mat-form-field>
</div> </div>
</div> </div>
@ -598,45 +599,48 @@
<form [formGroup]="resourceUsageShortageTemplateForm"> <form [formGroup]="resourceUsageShortageTemplateForm">
<fieldset class="fields-group tb-margin" formGroupName="triggerConfig"> <fieldset class="fields-group tb-margin" formGroupName="triggerConfig">
<legend translate>notification.filter</legend> <legend translate>notification.filter</legend>
<div class="limit-slider-container flex flex-row items-center justify-start xs:flex-col xs:items-stretch"> <div class="limit-slider-container mb-4 flex flex-row items-center justify-start xs:flex-col xs:items-stretch">
<label translate>notification.cpu-threshold</label> <span translate>notification.cpu-threshold</span>
<div class="flex flex-1 flex-row items-center justify-start"> <div class="flex flex-1 flex-row items-center justify-start">
<mat-slider class="flex-1" min="0" max="1" step="0.01" discrete [displayWith]="formatLabel"> <mat-slider class="flex-1" min="0" max="100" step="1" discrete [displayWith]="formatLabel">
<input matSliderThumb formControlName="cpuThreshold"> <input matSliderThumb formControlName="cpuThreshold">
</mat-slider> </mat-slider>
<mat-form-field class="limit-slider-value"> <mat-form-field class="limit-slider-value" subscriptSizing="dynamic">
<input matInput formControlName="cpuThreshold" type="number" step="0.01" <input matInput formControlName="cpuThreshold" type="number" step="1"
[value]="resourceUsageShortageTemplateForm.get('triggerConfig.cpuThreshold').value" [value]="resourceUsageShortageTemplateForm.get('triggerConfig.cpuThreshold').value"
min="0" min="0"
max="1"/> max="100"/>
<span class="mr-2" matSuffix>%</span>
</mat-form-field> </mat-form-field>
</div> </div>
</div> </div>
<div class="limit-slider-container flex flex-row items-center justify-start xs:flex-col xs:items-stretch"> <div class="limit-slider-container mb-4 flex flex-row items-center justify-start xs:flex-col xs:items-stretch">
<label translate>notification.ram-threshold</label> <span translate>notification.ram-threshold</span>
<div class="flex flex-1 flex-row items-center justify-start"> <div class="flex flex-1 flex-row items-center justify-start">
<mat-slider class="flex-1" min="0" max="1" step="0.01" discrete [displayWith]="formatLabel"> <mat-slider class="flex-1" min="0" max="100" step="1" discrete [displayWith]="formatLabel">
<input matSliderThumb formControlName="ramThreshold"> <input matSliderThumb formControlName="ramThreshold">
</mat-slider> </mat-slider>
<mat-form-field class="limit-slider-value"> <mat-form-field class="limit-slider-value" subscriptSizing="dynamic">
<input matInput formControlName="ramThreshold" type="number" step="0.01" <input matInput formControlName="ramThreshold" type="number" step="1"
[value]="resourceUsageShortageTemplateForm.get('triggerConfig.ramThreshold').value" [value]="resourceUsageShortageTemplateForm.get('triggerConfig.ramThreshold').value"
min="0" min="0"
max="1"/> max="100"/>
<span class="mr-2" matSuffix>%</span>
</mat-form-field> </mat-form-field>
</div> </div>
</div> </div>
<div class="limit-slider-container flex flex-row items-center justify-start xs:flex-col xs:items-stretch"> <div class="limit-slider-container mb-4 flex flex-row items-center justify-start xs:flex-col xs:items-stretch">
<label translate>notification.storage-threshold</label> <span translate>notification.storage-threshold</span>
<div class="flex flex-1 flex-row items-center justify-start"> <div class="flex flex-1 flex-row items-center justify-start">
<mat-slider class="flex-1" min="0" max="1" step="0.01" discrete [displayWith]="formatLabel"> <mat-slider class="flex-1" min="0" max="100" step="1" discrete [displayWith]="formatLabel">
<input matSliderThumb formControlName="storageThreshold"> <input matSliderThumb formControlName="storageThreshold">
</mat-slider> </mat-slider>
<mat-form-field class="limit-slider-value"> <mat-form-field class="limit-slider-value" subscriptSizing="dynamic">
<input matInput formControlName="storageThreshold" type="number" step="0.01" <input matInput formControlName="storageThreshold" type="number" step="1"
[value]="resourceUsageShortageTemplateForm.get('triggerConfig.storageThreshold').value" [value]="resourceUsageShortageTemplateForm.get('triggerConfig.storageThreshold').value"
min="0" min="0"
max="1"/> max="100"/>
<span class="mr-2" matSuffix>%</span>
</mat-form-field> </mat-form-field>
</div> </div>
</div> </div>

2
ui-ngx/src/app/modules/home/pages/notification/rule/rule-notification-dialog.component.scss

@ -81,7 +81,7 @@
min-width: 364px; min-width: 364px;
} }
.limit-slider-container { .limit-slider-container {
> label { > span {
margin-right: 16px; margin-right: 16px;
width: min-content; width: min-content;
max-width: 40%; max-width: 40%;

27
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({ this.entitiesLimitTemplateForm = this.fb.group({
triggerConfig: this.fb.group({ triggerConfig: this.fb.group({
entityTypes: [], 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({ this.resourceUsageShortageTemplateForm = this.fb.group({
triggerConfig: this.fb.group({ triggerConfig: this.fb.group({
cpuThreshold: [.8, [Validators.min(0), Validators.max(1)]], cpuThreshold: [80, [Validators.min(0), Validators.max(100)]],
ramThreshold: [.8, [Validators.min(0), Validators.max(1)]], ramThreshold: [80, [Validators.min(0), Validators.max(100)]],
storageThreshold: [.8, [Validators.min(0), Validators.max(1)]] storageThreshold: [80, [Validators.min(0), Validators.max(100)]]
}) })
}); });
@ -390,6 +390,14 @@ export class RuleNotificationDialogComponent extends
this.deviceInactivityTemplateForm.get('triggerConfig.filterByDevice') this.deviceInactivityTemplateForm.get('triggerConfig.filterByDevice')
.patchValue(!!this.ruleNotification.triggerConfig.devices, {onlySelf: true}); .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) { if (triggerType === TriggerType.DEVICE_ACTIVITY) {
delete formValue.triggerConfig.filterByDevice; 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.recipientsConfig.triggerType = triggerType;
formValue.triggerConfig.triggerType = triggerType; formValue.triggerConfig.triggerType = triggerType;
if (this.ruleNotification && !this.data.isCopy) { if (this.ruleNotification && !this.data.isCopy) {
@ -493,8 +509,7 @@ export class RuleNotificationDialogComponent extends
} }
formatLabel(value: number): string { formatLabel(value: number): string {
const formatValue = (value * 100).toFixed(); return `${value}%`;
return `${formatValue}%`;
} }
private isSysAdmin(): boolean { private isSysAdmin(): boolean {

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

@ -129,7 +129,7 @@ export interface NotificationRule extends Omit<BaseData<NotificationRuleId>, 'la
export type NotificationRuleTriggerConfig = Partial<AlarmNotificationRuleTriggerConfig & DeviceInactivityNotificationRuleTriggerConfig & export type NotificationRuleTriggerConfig = Partial<AlarmNotificationRuleTriggerConfig & DeviceInactivityNotificationRuleTriggerConfig &
EntityActionNotificationRuleTriggerConfig & AlarmCommentNotificationRuleTriggerConfig & AlarmAssignmentNotificationRuleTriggerConfig & EntityActionNotificationRuleTriggerConfig & AlarmCommentNotificationRuleTriggerConfig & AlarmAssignmentNotificationRuleTriggerConfig &
RuleEngineLifecycleEventNotificationRuleTriggerConfig & EntitiesLimitNotificationRuleTriggerConfig & RuleEngineLifecycleEventNotificationRuleTriggerConfig & EntitiesLimitNotificationRuleTriggerConfig &
ApiUsageLimitNotificationRuleTriggerConfig & RateLimitsNotificationRuleTriggerConfig>; ApiUsageLimitNotificationRuleTriggerConfig & RateLimitsNotificationRuleTriggerConfig & ResourceUsageShortageNotificationRuleTriggerConfig>;
export interface AlarmNotificationRuleTriggerConfig { export interface AlarmNotificationRuleTriggerConfig {
alarmTypes?: Array<string>; alarmTypes?: Array<string>;
@ -183,6 +183,12 @@ export interface EntitiesLimitNotificationRuleTriggerConfig {
threshold: number; threshold: number;
} }
export interface ResourceUsageShortageNotificationRuleTriggerConfig {
cpuThreshold: number;
ramThreshold: number;
storageThreshold: number;
}
export interface ApiUsageLimitNotificationRuleTriggerConfig { export interface ApiUsageLimitNotificationRuleTriggerConfig {
apiFeatures: ApiFeature[]; apiFeatures: ApiFeature[];
notifyOn: ApiUsageStateValue[]; notifyOn: ApiUsageStateValue[];

Loading…
Cancel
Save