diff --git a/ui-ngx/src/app/modules/home/components/calculated-fields/calculated-field.component.scss b/ui-ngx/src/app/modules/home/components/calculated-fields/calculated-field.component.scss index 5bcd2552fc..8dc0346d0c 100644 --- a/ui-ngx/src/app/modules/home/components/calculated-fields/calculated-field.component.scss +++ b/ui-ngx/src/app/modules/home/components/calculated-fields/calculated-field.component.scss @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -:host ::ng-deep { +::ng-deep { .tbel-script-lang-chip { line-height: 20px; font-size: 14px; diff --git a/ui-ngx/src/app/modules/home/components/calculated-fields/components/geofencing-configuration/calculated-field-geofencing-zone-groups-panel.component.html b/ui-ngx/src/app/modules/home/components/calculated-fields/components/geofencing-configuration/calculated-field-geofencing-zone-groups-panel.component.html index 46e10acd4a..94a86b74e4 100644 --- a/ui-ngx/src/app/modules/home/components/calculated-fields/components/geofencing-configuration/calculated-field-geofencing-zone-groups-panel.component.html +++ b/ui-ngx/src/app/modules/home/components/calculated-fields/components/geofencing-configuration/calculated-field-geofencing-zone-groups-panel.component.html @@ -147,6 +147,7 @@ } diff --git a/ui-ngx/src/app/modules/home/components/calculated-fields/components/geofencing-configuration/calculated-field-geofencing-zone-groups-panel.component.ts b/ui-ngx/src/app/modules/home/components/calculated-fields/components/geofencing-configuration/calculated-field-geofencing-zone-groups-panel.component.ts index 94b9e19056..1ec89e411a 100644 --- a/ui-ngx/src/app/modules/home/components/calculated-fields/components/geofencing-configuration/calculated-field-geofencing-zone-groups-panel.component.ts +++ b/ui-ngx/src/app/modules/home/components/calculated-fields/components/geofencing-configuration/calculated-field-geofencing-zone-groups-panel.component.ts @@ -326,6 +326,6 @@ export class CalculatedFieldGeofencingZoneGroupsPanelComponent implements OnInit } get dragEnabled(): boolean { - return this.levelsFormArray().controls.length > 1; + return this.levelsFormArray().controls.length > 1 && !this.readonly; } } diff --git a/ui-ngx/src/app/modules/home/components/calculated-fields/components/metrics/calculated-field-metrics-panel.component.html b/ui-ngx/src/app/modules/home/components/calculated-fields/components/metrics/calculated-field-metrics-panel.component.html index 8d6fc37073..1eeb4d4d5d 100644 --- a/ui-ngx/src/app/modules/home/components/calculated-fields/components/metrics/calculated-field-metrics-panel.component.html +++ b/ui-ngx/src/app/modules/home/components/calculated-fields/components/metrics/calculated-field-metrics-panel.component.html @@ -182,7 +182,7 @@ matTooltip="{{ 'calculated-fields.test-script-function' | translate }}" matTooltipPosition="above" class="tb-mat-32" - [disabled]="!arguments.length" + [disabled]="!arguments.length || readonly" (click)="onTestScript('input.function')"> bug_report @@ -191,7 +191,7 @@ diff --git a/ui-ngx/src/app/modules/home/components/calculated-fields/components/metrics/calculated-field-metrics-panel.component.ts b/ui-ngx/src/app/modules/home/components/calculated-fields/components/metrics/calculated-field-metrics-panel.component.ts index 49dca514d2..e8c8c4984a 100644 --- a/ui-ngx/src/app/modules/home/components/calculated-fields/components/metrics/calculated-field-metrics-panel.component.ts +++ b/ui-ngx/src/app/modules/home/components/calculated-fields/components/metrics/calculated-field-metrics-panel.component.ts @@ -24,6 +24,8 @@ import { AggInputType, AggInputTypeTranslations, CalculatedFieldAggMetricValue, + calculatedFieldMetricFilterDefaultScript, + calculatedFieldMetricMapDefaultScript, FORBIDDEN_NAMES, forbiddenNamesValidator, uniqueNameValidator @@ -64,11 +66,11 @@ export class CalculatedFieldMetricsPanelComponent implements OnInit { name: ['', [Validators.required, forbiddenNamesValidator(FORBIDDEN_NAMES), Validators.pattern(charsWithNumRegex), Validators.maxLength(255)]], function: [AggFunction.AVG], allowFilter: [false], - filter: ['', Validators.required], + filter: [calculatedFieldMetricFilterDefaultScript, Validators.required], input: this.fb.group({ type: [AggInputType.key], key: ['', Validators.required], - function: ['', Validators.required], + function: [calculatedFieldMetricMapDefaultScript, Validators.required], }), defaultValue: [null] }); 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 c1d55dd03a..b0005cad7a 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 @@ -30,7 +30,7 @@ @if (outputForm.get('type').value === OutputType.Attribute - && (entityId.entityType === EntityType.DEVICE || entityId.entityType === EntityType.DEVICE_PROFILE)) { + && (entityId?.entityType === EntityType.DEVICE || entityId?.entityType === EntityType.DEVICE_PROFILE)) { {{ 'calculated-fields.attribute-scope' | translate }} diff --git a/ui-ngx/src/app/modules/home/components/vc/entity-types-version-load.component.html b/ui-ngx/src/app/modules/home/components/vc/entity-types-version-load.component.html index 32da6c4e35..828b5eac1e 100644 --- a/ui-ngx/src/app/modules/home/components/vc/entity-types-version-load.component.html +++ b/ui-ngx/src/app/modules/home/components/vc/entity-types-version-load.component.html @@ -72,7 +72,9 @@ {{ 'version-control.load-relations' | translate }} - + {{ 'version-control.load-calculated-fields' | translate }} diff --git a/ui-ngx/src/app/shared/models/calculated-field.models.ts b/ui-ngx/src/app/shared/models/calculated-field.models.ts index db3da4235e..9370e59835 100644 --- a/ui-ngx/src/app/shared/models/calculated-field.models.ts +++ b/ui-ngx/src/app/shared/models/calculated-field.models.ts @@ -1083,3 +1083,14 @@ export interface CalculatedFieldsQuery { entities?: Array; name?: Array; } + +export const calculatedFieldMetricFilterDefaultScript = + '// Sample filter script to include only active and unoccupied parking spaces\n' + + '// Goal: Count only parking spaces that are active and currently free\n\n' + + 'return active == true && occupied == false;'; + +export const calculatedFieldMetricMapDefaultScript = + '// Sample map script to convert temperature from Fahrenheit to Celsius\n' + + '// Goal: Apply conversion per entity before aggregation (e.g., for average temperature)\n\n' + + 'var temperatureC = (temperature - 32) / 1.8;\n' + + 'return toFixed(temperatureC, 2);'; 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 26a2c938de..5e083ec165 100644 --- a/ui-ngx/src/assets/locale/locale.constant-en_US.json +++ b/ui-ngx/src/assets/locale/locale.constant-en_US.json @@ -1552,7 +1552,7 @@ "mode": "Mode", "type": "Type", "value-required": "Value is required.", - "min-value": "Value must be 0 or greater.", + "min-value": "Value must be 1 or greater.", "argument-in-use": "Argument is used as general argument.", "import-invalid-alarm-rule-type": "Unable to import alarm rule: Invalid alarm rule structure.", "no-filter-preview": "No filter specified", @@ -7257,7 +7257,7 @@ "load-relations": "Load relations", "load-attributes": "Load attributes", "load-credentials": "Load credentials", - "load-calculated-fields": "Load calculated fields", + "load-calculated-fields": "Load calculated fields and alarm rules", "compare-with-current": "Compare with current", "diff-entity-with-version": "Diff with entity version '{{versionName}}'", "previous-difference": "Previous Difference",