From c10aff3910b140e8dddf141b0421ceab10f6c1e3 Mon Sep 17 00:00:00 2001 From: ArtemDzhereleiko Date: Wed, 19 Nov 2025 10:31:34 +0200 Subject: [PATCH] UI: bug fixes with alarm rule --- ui-ngx/src/app/core/http/entity.service.ts | 6 ++ .../alarm-rule-dialog.component.html | 5 +- .../alarm-rule-dialog.component.ts | 4 +- .../alarm-rule-filter-config.component.ts | 2 +- ...alarm-rule-condition-dialog.component.html | 5 +- .../cf-alarm-rule-condition.component.ts | 16 +++-- .../alarm-rules/cf-alarm-rule.component.html | 2 +- .../alarm-rules/cf-alarm-rule.component.ts | 21 +++--- .../cf-alarm-rules-dialog.component.scss | 65 +++++++++---------- .../create-cf-alarm-rules.component.html | 1 + .../create-cf-alarm-rules.component.ts | 2 +- ...culated-field-arguments-table.component.ts | 2 +- .../entity-debug-settings-button.component.ts | 2 + .../add-device-profile-dialog.component.html | 11 ---- .../add-device-profile-dialog.component.ts | 11 ---- .../entity/entity-autocomplete.component.ts | 12 ++++ .../assets/locale/locale.constant-en_US.json | 6 +- 17 files changed, 89 insertions(+), 84 deletions(-) diff --git a/ui-ngx/src/app/core/http/entity.service.ts b/ui-ngx/src/app/core/http/entity.service.ts index 5cd4167afa..4daae2115d 100644 --- a/ui-ngx/src/app/core/http/entity.service.ts +++ b/ui-ngx/src/app/core/http/entity.service.ts @@ -189,6 +189,12 @@ export class EntityService { case EntityType.AI_MODEL: observable = this.aiModelService.getAiModelById(entityId, config); break; + case EntityType.DEVICE_PROFILE: + observable = this.deviceProfileService.getDeviceProfile(entityId, config); + break; + case EntityType.ASSET_PROFILE: + observable = this.assetProfileService.getAssetProfile(entityId, config); + break; } return observable; } diff --git a/ui-ngx/src/app/modules/home/components/alarm-rules/alarm-rule-dialog.component.html b/ui-ngx/src/app/modules/home/components/alarm-rules/alarm-rule-dialog.component.html index b023853faf..d4a93d461f 100644 --- a/ui-ngx/src/app/modules/home/components/alarm-rules/alarm-rule-dialog.component.html +++ b/ui-ngx/src/app/modules/home/components/alarm-rules/alarm-rule-dialog.component.html @@ -47,6 +47,7 @@
-
{{ 'alarm-rule.create-alarm-rules' | translate }}
+
{{ 'alarm-rule.create-conditions' | translate }}
-
{{ 'alarm-rule.clear-alarm-rule' | translate }}
+
{{ 'alarm-rule.clear-condition' | translate }}
diff --git a/ui-ngx/src/app/modules/home/components/alarm-rules/alarm-rule-dialog.component.ts b/ui-ngx/src/app/modules/home/components/alarm-rules/alarm-rule-dialog.component.ts index aa9e9223fb..b3176414ab 100644 --- a/ui-ngx/src/app/modules/home/components/alarm-rules/alarm-rule-dialog.component.ts +++ b/ui-ngx/src/app/modules/home/components/alarm-rules/alarm-rule-dialog.component.ts @@ -79,7 +79,7 @@ export class AlarmRuleDialogComponent extends DialogComponent {{ 'alarm-rule.expression-type.simple' | translate }} - {{ 'alarm-rule.expression-type.tbel' | translate }} + {{ 'alarm-rule.expression-type.script' | translate }}
diff --git a/ui-ngx/src/app/modules/home/components/alarm-rules/cf-alarm-rule-condition.component.ts b/ui-ngx/src/app/modules/home/components/alarm-rules/cf-alarm-rule-condition.component.ts index 17ed11d892..2e8d116ad2 100644 --- a/ui-ngx/src/app/modules/home/components/alarm-rules/cf-alarm-rule-condition.component.ts +++ b/ui-ngx/src/app/modules/home/components/alarm-rules/cf-alarm-rule-condition.component.ts @@ -74,12 +74,16 @@ export class CfAlarmRuleConditionComponent implements ControlValueAccessor, Vali @coerceBoolean() disabled: boolean; + @Input() + @coerceBoolean() + required: boolean; + @Input() arguments: Record; alarmRuleConditionFormGroup = this.fb.group({ type: ['SIMPLE'], - expression: [{type: AlarmRuleExpressionType.SIMPLE}, Validators.required], + expression: [{type: AlarmRuleExpressionType.SIMPLE}], schedule: [null], }); @@ -114,19 +118,21 @@ export class CfAlarmRuleConditionComponent implements ControlValueAccessor, Vali } writeValue(value: AlarmRuleCondition): void { - this.modelValue = value; - this.updateConditionInfo(); + if (value) { + this.modelValue = value; + this.updateConditionInfo(); + } } public conditionSet() { - return this.modelValue && (this.modelValue.expression?.expression || this.modelValue.expression?.filters); + return this.modelValue && (this.modelValue.expression?.expression || this.modelValue.expression?.filters) || !this.required; } public validate(c: UntypedFormControl) { return this.conditionSet() ? null : { alarmRuleCondition: { valid: false, - }, + } }; } diff --git a/ui-ngx/src/app/modules/home/components/alarm-rules/cf-alarm-rule.component.html b/ui-ngx/src/app/modules/home/components/alarm-rules/cf-alarm-rule.component.html index cd6b2c3796..14a88b2bf1 100644 --- a/ui-ngx/src/app/modules/home/components/alarm-rules/cf-alarm-rule.component.html +++ b/ui-ngx/src/app/modules/home/components/alarm-rules/cf-alarm-rule.component.html @@ -16,7 +16,7 @@ -->
- + @if (!disabled || alarmRuleFormGroup.get('alarmDetails').value) {
diff --git a/ui-ngx/src/app/modules/home/components/alarm-rules/cf-alarm-rule.component.ts b/ui-ngx/src/app/modules/home/components/alarm-rules/cf-alarm-rule.component.ts index 88ae1dd79d..f5e57310a2 100644 --- a/ui-ngx/src/app/modules/home/components/alarm-rules/cf-alarm-rule.component.ts +++ b/ui-ngx/src/app/modules/home/components/alarm-rules/cf-alarm-rule.component.ts @@ -21,14 +21,13 @@ import { NG_VALIDATORS, NG_VALUE_ACCESSOR, UntypedFormControl, - Validator, - Validators + Validator } from '@angular/forms'; import { MatDialog } from '@angular/material/dialog'; import { isDefinedAndNotNull } from '@core/utils'; import { DashboardId } from '@shared/models/id/dashboard-id'; import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; -import { AlarmRule } from "@shared/models/alarm-rule.models"; +import { AlarmRule, AlarmRuleCondition } from "@shared/models/alarm-rule.models"; import { CalculatedFieldArgument } from "@shared/models/calculated-field.models"; import { AlarmRuleDetailsDialogComponent, @@ -69,7 +68,7 @@ export class CfAlarmRuleComponent implements ControlValueAccessor, OnInit, Valid private modelValue: AlarmRule; alarmRuleFormGroup = this.fb.group({ - condition: this.fb.control({}, Validators.required), + condition: this.fb.control(null), alarmDetails: [null], dashboardId: [null] }); @@ -106,12 +105,14 @@ export class CfAlarmRuleComponent implements ControlValueAccessor, OnInit, Valid } writeValue(value: AlarmRule): void { - this.modelValue = value; - const model = this.modelValue ? { - ...this.modelValue, - dashboardId: this.modelValue.dashboardId?.id - } : null; - this.alarmRuleFormGroup.patchValue(model, {emitEvent: false}); + if (value) { + this.modelValue = value; + const model = this.modelValue ? { + ...this.modelValue, + dashboardId: this.modelValue.dashboardId?.id + } : null; + this.alarmRuleFormGroup.patchValue(model, {emitEvent: false}); + } } public openEditDetailsDialog($event: Event) { diff --git a/ui-ngx/src/app/modules/home/components/alarm-rules/cf-alarm-rules-dialog.component.scss b/ui-ngx/src/app/modules/home/components/alarm-rules/cf-alarm-rules-dialog.component.scss index 14df9a3972..b66573f417 100644 --- a/ui-ngx/src/app/modules/home/components/alarm-rules/cf-alarm-rules-dialog.component.scss +++ b/ui-ngx/src/app/modules/home/components/alarm-rules/cf-alarm-rules-dialog.component.scss @@ -20,41 +20,38 @@ display: grid; grid-template-rows: min-content minmax(auto, 1fr) min-content; } - - .tbel-script-lang-chip { - line-height: 20px; - font-size: 14px; - font-weight: 500; - color: white; - border-radius: 100px; - width: 70px; - min-width: 70px; - display: flex; - justify-content: center; - margin-top: 2px; - margin-right: 4px; - } - - .tb-js-func { - .ace_tb { - &.ace_calculated-field { - &-ctx { - color: #C52F00; - } - &-args { - color: #185F2A; - } - &-key { - color: #c24c1a; - } - &-time-window, &-values, &-func, &-value, &-ts, &-latestTs { - color: #7214D0; - } - &-start-ts, &-end-ts { - color: #2CAA00; - } +} +.tbel-script-lang-chip { + line-height: 20px; + font-size: 14px; + font-weight: 500; + color: white; + border-radius: 100px; + width: 70px; + min-width: 70px; + display: flex; + justify-content: center; + margin-top: 2px; + margin-right: 4px; +} +.tb-js-func { + .ace_tb { + &.ace_calculated-field { + &-ctx { + color: #C52F00; + } + &-args { + color: #185F2A; + } + &-key { + color: #c24c1a; + } + &-time-window, &-values, &-func, &-value, &-ts, &-latestTs { + color: #7214D0; + } + &-start-ts, &-end-ts { + color: #2CAA00; } } } } - diff --git a/ui-ngx/src/app/modules/home/components/alarm-rules/create-cf-alarm-rules.component.html b/ui-ngx/src/app/modules/home/components/alarm-rules/create-cf-alarm-rules.component.html index 820418a6b0..b0e6164d30 100644 --- a/ui-ngx/src/app/modules/home/components/alarm-rules/create-cf-alarm-rules.component.html +++ b/ui-ngx/src/app/modules/home/components/alarm-rules/create-cf-alarm-rules.component.html @@ -55,6 +55,7 @@