Added decimals by default

This commit is contained in:
mpetrov 2025-03-05 12:35:33 +02:00
parent 1a4ebd9513
commit c7c22c69ec
5 changed files with 37 additions and 22 deletions

View File

@ -153,7 +153,8 @@
} }
</div> </div>
@if (fieldFormGroup.get('type').value === CalculatedFieldType.SIMPLE) { @if (fieldFormGroup.get('type').value === CalculatedFieldType.SIMPLE) {
<mat-form-field class="flex-1" appearance="outline" subscriptSizing="dynamic"> <div class="flex items-center gap-3">
<mat-form-field class="flex-1" appearance="outline">
<mat-label> <mat-label>
{{ (outputFormGroup.get('type').value === OutputType.Timeseries {{ (outputFormGroup.get('type').value === OutputType.Timeseries
? 'calculated-fields.timeseries-key' ? 'calculated-fields.timeseries-key'
@ -173,6 +174,14 @@
</mat-error> </mat-error>
} }
</mat-form-field> </mat-form-field>
<mat-form-field class="flex-1" appearance="outline">
<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) {
<mat-error>{{ 'calculated-fields.hint.decimals-range' | translate }}</mat-error>
}
</mat-form-field>
</div>
} }
</div> </div>
</ng-container> </ng-container>

View File

@ -33,7 +33,7 @@ import {
OutputType, OutputType,
OutputTypeTranslations OutputTypeTranslations
} from '@shared/models/calculated-field.models'; } from '@shared/models/calculated-field.models';
import { oneSpaceInsideRegex } from '@shared/models/regex.constants'; import { digitsRegex, oneSpaceInsideRegex } from '@shared/models/regex.constants';
import { AttributeScope } from '@shared/models/telemetry/telemetry.models'; import { AttributeScope } from '@shared/models/telemetry/telemetry.models';
import { EntityType } from '@shared/models/entity-type.models'; import { EntityType } from '@shared/models/entity-type.models';
import { map, startWith, switchMap } from 'rxjs/operators'; import { map, startWith, switchMap } from 'rxjs/operators';
@ -61,7 +61,8 @@ export class CalculatedFieldDialogComponent extends DialogComponent<CalculatedFi
output: this.fb.group({ output: this.fb.group({
name: ['', [Validators.required, Validators.pattern(oneSpaceInsideRegex), Validators.maxLength(255)]], name: ['', [Validators.required, Validators.pattern(oneSpaceInsideRegex), Validators.maxLength(255)]],
scope: [{ value: AttributeScope.SERVER_SCOPE, disabled: true }], scope: [{ value: AttributeScope.SERVER_SCOPE, disabled: true }],
type: [OutputType.Timeseries] type: [OutputType.Timeseries],
decimalsByDefault: [null as number, [Validators.min(0), Validators.max(15), Validators.pattern(digitsRegex)]],
}), }),
}), }),
}); });

View File

@ -64,6 +64,7 @@ export interface CalculatedFieldOutput {
type: OutputType; type: OutputType;
name: string; name: string;
scope?: AttributeScope; scope?: AttributeScope;
decimalsByDefault?: number;
} }
export enum ArgumentEntityType { export enum ArgumentEntityType {

View File

@ -17,3 +17,5 @@
export const oneSpaceInsideRegex = /^\s*\S+(?:\s\S+)*\s*$/; export const oneSpaceInsideRegex = /^\s*\S+(?:\s\S+)*\s*$/;
export const charsWithNumRegex = /^[a-zA-Z]+[a-zA-Z0-9]*$/; export const charsWithNumRegex = /^[a-zA-Z]+[a-zA-Z0-9]*$/;
export const digitsRegex = /^\d*$/;

View File

@ -1015,6 +1015,7 @@
"script": "Script" "script": "Script"
}, },
"arguments": "Arguments", "arguments": "Arguments",
"decimals-by-default": "Decimals by default",
"debugging": "Calculated field debugging", "debugging": "Calculated field debugging",
"argument-name": "Argument name", "argument-name": "Argument name",
"datasource": "Datasource", "datasource": "Datasource",
@ -1071,6 +1072,7 @@
"argument-name-max-length": "Argument name should be less than 256 characters.", "argument-name-max-length": "Argument name should be less than 256 characters.",
"argument-type-required": "Argument type is required.", "argument-type-required": "Argument type is required.",
"max-args": "Maximum number of arguments reached.", "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." "expression": "Default expression demonstrates how to transform a temperature from Fahrenheit to Celsius."
} }
}, },