Added decimals by default
This commit is contained in:
parent
1a4ebd9513
commit
c7c22c69ec
@ -153,26 +153,35 @@
|
||||
}
|
||||
</div>
|
||||
@if (fieldFormGroup.get('type').value === CalculatedFieldType.SIMPLE) {
|
||||
<mat-form-field class="flex-1" appearance="outline" subscriptSizing="dynamic">
|
||||
<mat-label>
|
||||
{{ (outputFormGroup.get('type').value === OutputType.Timeseries
|
||||
? 'calculated-fields.timeseries-key'
|
||||
: 'calculated-fields.attribute-key')
|
||||
| translate }}
|
||||
</mat-label>
|
||||
<input matInput formControlName="name" required>
|
||||
@if (outputFormGroup.get('name').errors && outputFormGroup.get('name').touched) {
|
||||
<mat-error>
|
||||
@if (outputFormGroup.get('name').hasError('required')) {
|
||||
{{ 'common.hint.key-required' | translate }}
|
||||
} @else if (outputFormGroup.get('name').hasError('pattern')) {
|
||||
{{ 'common.hint.key-pattern' | translate }}
|
||||
} @else if (outputFormGroup.get('name').hasError('maxlength')) {
|
||||
{{ 'common.hint.key-max-length' | translate }}
|
||||
}
|
||||
</mat-error>
|
||||
}
|
||||
</mat-form-field>
|
||||
<div class="flex items-center gap-3">
|
||||
<mat-form-field class="flex-1" appearance="outline">
|
||||
<mat-label>
|
||||
{{ (outputFormGroup.get('type').value === OutputType.Timeseries
|
||||
? 'calculated-fields.timeseries-key'
|
||||
: 'calculated-fields.attribute-key')
|
||||
| translate }}
|
||||
</mat-label>
|
||||
<input matInput formControlName="name" required>
|
||||
@if (outputFormGroup.get('name').errors && outputFormGroup.get('name').touched) {
|
||||
<mat-error>
|
||||
@if (outputFormGroup.get('name').hasError('required')) {
|
||||
{{ 'common.hint.key-required' | translate }}
|
||||
} @else if (outputFormGroup.get('name').hasError('pattern')) {
|
||||
{{ 'common.hint.key-pattern' | translate }}
|
||||
} @else if (outputFormGroup.get('name').hasError('maxlength')) {
|
||||
{{ 'common.hint.key-max-length' | translate }}
|
||||
}
|
||||
</mat-error>
|
||||
}
|
||||
</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>
|
||||
</ng-container>
|
||||
|
||||
@ -33,7 +33,7 @@ import {
|
||||
OutputType,
|
||||
OutputTypeTranslations
|
||||
} 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 { EntityType } from '@shared/models/entity-type.models';
|
||||
import { map, startWith, switchMap } from 'rxjs/operators';
|
||||
@ -61,7 +61,8 @@ export class CalculatedFieldDialogComponent extends DialogComponent<CalculatedFi
|
||||
output: this.fb.group({
|
||||
name: ['', [Validators.required, Validators.pattern(oneSpaceInsideRegex), Validators.maxLength(255)]],
|
||||
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)]],
|
||||
}),
|
||||
}),
|
||||
});
|
||||
|
||||
@ -64,6 +64,7 @@ export interface CalculatedFieldOutput {
|
||||
type: OutputType;
|
||||
name: string;
|
||||
scope?: AttributeScope;
|
||||
decimalsByDefault?: number;
|
||||
}
|
||||
|
||||
export enum ArgumentEntityType {
|
||||
|
||||
@ -17,3 +17,5 @@
|
||||
export const oneSpaceInsideRegex = /^\s*\S+(?:\s\S+)*\s*$/;
|
||||
|
||||
export const charsWithNumRegex = /^[a-zA-Z]+[a-zA-Z0-9]*$/;
|
||||
|
||||
export const digitsRegex = /^\d*$/;
|
||||
|
||||
@ -1015,6 +1015,7 @@
|
||||
"script": "Script"
|
||||
},
|
||||
"arguments": "Arguments",
|
||||
"decimals-by-default": "Decimals by default",
|
||||
"debugging": "Calculated field debugging",
|
||||
"argument-name": "Argument name",
|
||||
"datasource": "Datasource",
|
||||
@ -1071,6 +1072,7 @@
|
||||
"argument-name-max-length": "Argument name should be less than 256 characters.",
|
||||
"argument-type-required": "Argument type is required.",
|
||||
"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."
|
||||
}
|
||||
},
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user