UI: Add to CF - Use message timestamp

This commit is contained in:
Vladyslav_Prykhodko 2025-05-15 17:12:17 +03:00
parent 9b13e733d7
commit 7a0c2b7763
5 changed files with 45 additions and 6 deletions

View File

@ -160,8 +160,8 @@
}
</div>
@if (fieldFormGroup.get('type').value === CalculatedFieldType.SIMPLE) {
<div class="flex items-center gap-3">
<mat-form-field class="flex-1" appearance="outline">
<div class="flex items-start gap-3">
<mat-form-field class="flex-1" appearance="outline" subscriptSizing="dynamic">
<mat-label>
{{ (outputFormGroup.get('type').value === OutputType.Timeseries
? 'calculated-fields.timeseries-key'
@ -181,7 +181,7 @@
</mat-error>
}
</mat-form-field>
<mat-form-field class="flex-1" appearance="outline">
<mat-form-field class="flex-1" appearance="outline" subscriptSizing="dynamic">
<mat-label>{{ 'calculated-fields.decimals-by-default' | translate }}</mat-label>
<input matInput type="number" formControlName="decimalsByDefault">
@if (outputFormGroup.get('decimalsByDefault').errors && outputFormGroup.get('decimalsByDefault').touched) {
@ -189,6 +189,13 @@
}
</mat-form-field>
</div>
<div class="tb-form-row" [formGroup]="configFormGroup" *ngIf="outputFormGroup.get('type').value === OutputType.Timeseries">
<mat-slide-toggle class="mat-slide" formControlName="preserveMsgTs">
<div tb-hint-tooltip-icon="{{ 'calculated-fields.hint.use-message-timestamp' | translate }}" translate>
calculated-fields.use-message-timestamp
</div>
</mat-slide-toggle>
</div>
}
</div>
</ng-container>

View File

@ -45,7 +45,7 @@
&-key {
color: #c24c1a;
}
&-time-window, &-values, &-func, &-value, &-ts {
&-time-window, &-values, &-func, &-value, &-ts, &-msgTs {
color: #7214D0;
}
&-start-ts, &-end-ts {

View File

@ -77,6 +77,7 @@ export class CalculatedFieldDialogComponent extends DialogComponent<CalculatedFi
type: [OutputType.Timeseries],
decimalsByDefault: [null as number, [Validators.min(0), Validators.max(15), Validators.pattern(digitsRegex)]],
}),
preserveMsgTs: [false]
}),
});
@ -204,7 +205,20 @@ export class CalculatedFieldDialogComponent extends DialogComponent<CalculatedFi
}
private toggleScopeByOutputType(type: OutputType): void {
this.outputFormGroup.get('scope')[type === OutputType.Attribute? 'enable' : 'disable']({emitEvent: false});
if (type === OutputType.Attribute) {
this.outputFormGroup.get('scope').enable({emitEvent: false});
} else {
this.outputFormGroup.get('scope').disable({emitEvent: false});
}
if (this.fieldFormGroup.get('type').value === CalculatedFieldType.SIMPLE) {
if (type === OutputType.Attribute) {
this.configFormGroup.get('preserveMsgTs').disable({emitEvent: false});
} else {
this.configFormGroup.get('preserveMsgTs').enable({emitEvent: false});
}
} else {
this.configFormGroup.get('preserveMsgTs').disable({emitEvent: false});
}
}
private toggleKeyByCalculatedFieldType(type: CalculatedFieldType): void {
@ -212,8 +226,14 @@ export class CalculatedFieldDialogComponent extends DialogComponent<CalculatedFi
this.outputFormGroup.get('name').enable({emitEvent: false});
this.configFormGroup.get('expressionSIMPLE').enable({emitEvent: false});
this.configFormGroup.get('expressionSCRIPT').disable({emitEvent: false});
if (this.outputFormGroup.get('type').value === OutputType.Attribute) {
this.configFormGroup.get('preserveMsgTs').disable({emitEvent: false});
} else {
this.configFormGroup.get('preserveMsgTs').enable({emitEvent: false});
}
} else {
this.outputFormGroup.get('name').disable({emitEvent: false});
this.configFormGroup.get('preserveMsgTs').disable({emitEvent: false});
this.configFormGroup.get('expressionSIMPLE').disable({emitEvent: false});
this.configFormGroup.get('expressionSCRIPT').enable({emitEvent: false});
}

View File

@ -525,6 +525,11 @@ export const getCalculatedFieldArgumentsEditorCompleter = (argumentsObj: Record<
type: '{ [key: string]: object }',
description: 'Calculated field context arguments.',
children: {}
},
msgTs: {
meta: 'constant',
type: 'number',
description: 'Timestamp (ms) of the telemetry message that triggered the calculated field execution.'
}
}
}
@ -576,6 +581,11 @@ const calculatedFieldArgumentsContextValueHighlightRules: AceHighlightRules = {
regex: /args/,
next: 'calculatedFieldCtxArgs'
},
{
token: 'tb.calculated-field-msgTs',
regex: /msgTs/,
next: 'no_regex'
},
endGroupHighlightRule
]
}

View File

@ -1062,6 +1062,7 @@
"delete-multiple-title": "Are you sure you want to delete { count, plural, =1 {1 calculated field} other {# calculated fields} }?",
"delete-multiple-text": "Be careful, after the confirmation all selected calculated fields will be removed and all related data will become unrecoverable.",
"test-with-this-message": "Test with this message",
"use-message-timestamp": "Use message timestamp",
"hint": {
"arguments-simple-with-rolling": "Simple type calculated field should not contain keys with time series rolling type.",
"arguments-empty": "Arguments should not be empty.",
@ -1077,7 +1078,8 @@
"max-args": "Maximum number of arguments reached.",
"decimals-range": "Decimals by default should be a number between 0 and 15.",
"expression": "Default expression demonstrates how to transform a temperature from Fahrenheit to Celsius.",
"arguments-entity-not-found": "Argument target entity not found."
"arguments-entity-not-found": "Argument target entity not found.",
"use-message-timestamp": "If enabled, the calculated value will be persisted using the timestamp of the telemetry that triggered the calculation, instead of the server time."
}
},
"confirm-on-exit": {