diff --git a/ui-ngx/src/app/modules/home/components/calculated-fields/components/output/calculated-field-output.component.html b/ui-ngx/src/app/modules/home/components/calculated-fields/components/output/calculated-field-output.component.html index a4cd8e3a3c..7e23acceae 100644 --- a/ui-ngx/src/app/modules/home/components/calculated-fields/components/output/calculated-field-output.component.html +++ b/ui-ngx/src/app/modules/home/components/calculated-fields/components/output/calculated-field-output.component.html @@ -46,7 +46,7 @@ @if (hiddenName) {
- +
} @else {
@@ -74,93 +74,94 @@
- + } }
-
-
- {{ 'calculated-fields.output-strategy.strategy' | translate }} -
- - @for (outputStrategyType of OutputStrategyTypes; track outputStrategyType) { - {{ OutputStrategyTypeTranslations.get(outputStrategyType) | translate }} + + + +
+
+ {{ 'calculated-fields.output-strategy.strategy' | translate }} +
+ + @for (outputStrategyType of OutputStrategyTypes; track outputStrategyType) { + {{ OutputStrategyTypeTranslations.get(outputStrategyType) | translate }} + } + +
+
+
+ @if (outputForm.get('strategy.type').value === OutputStrategyType.IMMEDIATE) { + @if (outputForm.get('type').value === OutputType.Timeseries) { +
+ +
+
calculated-fields.output-strategy.save-time-series
+
+
+
+
+ +
+
calculated-fields.output-strategy.save-latest-values
+
+
+
+ } @else { +
+ +
+
calculated-fields.output-strategy.save-database
+
+
+
} -
-
- @if (outputForm.get('strategy.type').value === OutputStrategyType.IMMEDIATE) { -
-
- {{ 'calculated-fields.output-strategy.processing-options' | translate }} +
+ +
+
calculated-fields.output-strategy.send-web-sockets
+
+
- - @if (outputForm.get('type').value === OutputType.Timeseries) { - - {{ 'calculated-fields.output-strategy.save-time-series' | translate }} - - - {{ 'calculated-fields.output-strategy.save-latest-values' | translate }} - - } @else { - - {{ 'calculated-fields.output-strategy.save-database' | translate }} - - } - - {{ 'calculated-fields.output-strategy.send-web-sockets' | translate }} - - - {{ 'calculated-fields.output-strategy.save-calculated-fields' | translate }} - - -
- @if (outputForm.get('type').value === OutputType.Attribute) {
- -
-
calculated-fields.output-strategy.update-attributes-only-on-value-change
+ +
+
calculated-fields.output-strategy.save-calculated-fields
- } @else { - - - help_outline - - + @if (outputForm.get('type').value === OutputType.Attribute) { +
+ +
+
calculated-fields.output-strategy.update-attributes-only-on-value-change
+
+
+
+ } @else { +
+ +
+
calculated-fields.output-strategy.ttl
+
+
+ + +
+ } } - } +
@@ -172,3 +173,6 @@ } + + + diff --git a/ui-ngx/src/app/modules/home/components/calculated-fields/components/output/calculated-field-output.component.ts b/ui-ngx/src/app/modules/home/components/calculated-fields/components/output/calculated-field-output.component.ts index 4ed8c4ffba..4a975e59b9 100644 --- a/ui-ngx/src/app/modules/home/components/calculated-fields/components/output/calculated-field-output.component.ts +++ b/ui-ngx/src/app/modules/home/components/calculated-fields/components/output/calculated-field-output.component.ts @@ -38,6 +38,8 @@ import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; import { EntityId } from '@shared/models/id/entity-id'; import { EntityType } from '@shared/models/entity-type.models'; import { coerceBoolean } from '@shared/decorators/coercion'; +import { merge } from 'rxjs'; +import { deepClone } from '@core/utils'; @Component({ selector: 'tb-calculate-field-output', @@ -102,6 +104,7 @@ export class CalculatedFieldOutputComponent implements ControlValueAccessor, Val sendWsUpdate: [true], processCfs: [true], updateAttributesOnlyOnValueChange: [true], + useCustomTtl: [false], ttl: [0] }) }); @@ -116,7 +119,10 @@ export class CalculatedFieldOutputComponent implements ControlValueAccessor, Val this.updatedStrategy(); }); - this.outputForm.get('strategy.type').valueChanges + merge( + this.outputForm.get('strategy.type').valueChanges, + this.outputForm.get('strategy.useCustomTtl').valueChanges + ) .pipe(takeUntilDestroyed(this.destroyRef)) .subscribe(() => { this.updatedStrategy(); @@ -151,6 +157,9 @@ export class CalculatedFieldOutputComponent implements ControlValueAccessor, Val writeValue(value: CalculatedFieldOutput | CalculatedFieldSimpleOutput): void { this.outputForm.patchValue(value, {emitEvent: false}); + if (value.type === OutputType.Timeseries && value.strategy?.type === OutputStrategyType.IMMEDIATE && value.strategy?.ttl) { + this.outputForm.get('strategy.useCustomTtl').setValue(true, {emitEvent: false}); + } this.outputForm.get('type').updateValueAndValidity({onlySelf: true}); } @@ -171,13 +180,6 @@ export class CalculatedFieldOutputComponent implements ControlValueAccessor, Val } } - toggleChip(controlName: string) { - const control = this.outputForm.get('strategy').get(controlName); - if (control && control.enabled) { - control.setValue(!control.value); - } - } - private updatedModel(value: CalculatedFieldOutput | CalculatedFieldSimpleOutput) { if (this.simpleMode && 'name' in value) { value.name = value.name?.trim() ?? ''; @@ -185,6 +187,10 @@ export class CalculatedFieldOutputComponent implements ControlValueAccessor, Val if (this.disableType) { value.type = this.outputForm.get('type').value; } + if (value.type === OutputType.Timeseries && value.strategy.type === OutputStrategyType.IMMEDIATE) { + value = deepClone(value); + delete (value.strategy as any).useCustomTtl + } this.propagateChange(value); } @@ -227,7 +233,10 @@ export class CalculatedFieldOutputComponent implements ControlValueAccessor, Val } else { this.outputForm.get('strategy.saveTimeSeries').enable({emitEvent: false}); this.outputForm.get('strategy.saveLatest').enable({emitEvent: false}); - this.outputForm.get('strategy.ttl').enable({emitEvent: false}); + this.outputForm.get('strategy.useCustomTtl').enable({emitEvent: false}); + if (this.outputForm.get('strategy.useCustomTtl').value) { + this.outputForm.get('strategy.ttl').enable({emitEvent: false}); + } } } } 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 c0623c49fc..09dfb9cb2c 100644 --- a/ui-ngx/src/assets/locale/locale.constant-en_US.json +++ b/ui-ngx/src/assets/locale/locale.constant-en_US.json @@ -1248,15 +1248,15 @@ "send-web-sockets": "Send to WebSockets", "save-calculated-fields": "Send to Calculated fields", "update-attributes-only-on-value-change": "Save attributes only if the value changes", - "ttl": "TTL", - "ttl-required": "TTL is required.", - "ttl-min": "Only 0 minimum TTL is allowed.", + "ttl": "Custom TTL", + "ttl-required": "TTL is required", + "ttl-min": "Only 0 minimum TTL is allowed", "hint": { "strategy": "Strategy", "processing-options": "Processing options", "update-attributes-only-on-value-change": "Updates the attributes on every incoming message disregarding if their value has changed. Increases API usage and reduces performance.", "update-attributes-only-on-value-change-enabled": "Updates the attributes only if their value has changed. If the value is not changed, no update to the attribute timestamp nor attribute change notification will be sent.", - "ttl": "If no value is present, it defaults to the TTL specified in the configuration. If the value is set to 0, the TTL from the tenant profile configuration will be applied." + "ttl": "Uncheck to use the default system settings" } }, "aggregate-interval-type": "Aggregate interval type",