Browse Source

Merge pull request #14742 from ArtemDzhereleiko/AD/bug-fix/enh/cf-and-alarm-rule

Bug fixes and enhancement for calculated fields
pull/14747/head
Vladyslav Prykhodko 5 months ago
committed by GitHub
parent
commit
c1c5d66fb7
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 2
      ui-ngx/src/app/modules/home/components/calculated-fields/calculated-field.component.scss
  2. 3
      ui-ngx/src/app/modules/home/components/calculated-fields/components/geofencing-configuration/calculated-field-geofencing-zone-groups-panel.component.html
  3. 2
      ui-ngx/src/app/modules/home/components/calculated-fields/components/geofencing-configuration/calculated-field-geofencing-zone-groups-panel.component.ts
  4. 4
      ui-ngx/src/app/modules/home/components/calculated-fields/components/metrics/calculated-field-metrics-panel.component.html
  5. 6
      ui-ngx/src/app/modules/home/components/calculated-fields/components/metrics/calculated-field-metrics-panel.component.ts
  6. 2
      ui-ngx/src/app/modules/home/components/calculated-fields/components/output/calculated-field-output.component.html
  7. 4
      ui-ngx/src/app/modules/home/components/vc/entity-types-version-load.component.html
  8. 11
      ui-ngx/src/app/shared/models/calculated-field.models.ts
  9. 4
      ui-ngx/src/assets/locale/locale.constant-en_US.json

2
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;

3
ui-ngx/src/app/modules/home/components/calculated-fields/components/geofencing-configuration/calculated-field-geofencing-zone-groups-panel.component.html

@ -147,6 +147,7 @@
<button type="button"
mat-icon-button
(click)="removeKey($index)"
[disabled]="readonly"
matTooltip="{{ 'calculated-fields.delete-level' | translate }}"
matTooltipPosition="above">
<mat-icon>delete</mat-icon>
@ -169,7 +170,7 @@
<span>{{ 'calculated-fields.max-allowed-levels-error' | translate }}</span>
</div>
} @else {
<button type="button" mat-stroked-button color="primary" (click)="addKey()">
<button type="button" mat-stroked-button color="primary" (click)="addKey()" [disabled]="readonly">
{{ 'calculated-fields.add-level' | translate }}
</button>
}

2
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;
}
}

4
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')">
<mat-icon class="material-icons" color="primary">bug_report</mat-icon>
</button>
@ -191,7 +191,7 @@
<button mat-button mat-raised-button color="primary"
type="button"
(click)="onTestScript('input.function')"
[disabled]="!arguments.length">
[disabled]="!arguments.length || readonly">
{{ 'calculated-fields.test-script-function' | translate }}
</button>
</div>

6
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]
});

2
ui-ngx/src/app/modules/home/components/calculated-fields/components/output/calculated-field-output.component.html

@ -30,7 +30,7 @@
</mat-select>
</mat-form-field>
@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)) {
<mat-form-field class="flex-1" appearance="outline" subscriptSizing="dynamic">
<mat-label>{{ 'calculated-fields.attribute-scope' | translate }}</mat-label>
<mat-select formControlName="scope" class="w-full">

4
ui-ngx/src/app/modules/home/components/vc/entity-types-version-load.component.html

@ -72,7 +72,9 @@
<mat-checkbox [class.hidden]="entityTypesWithoutRelatedData.has(entityTypeFormGroup.get('entityType').value)" formControlName="loadRelations">
{{ 'version-control.load-relations' | translate }}
</mat-checkbox>
<mat-checkbox [class.hidden]="!typesWithCalculatedFields.has(entityTypeFormGroup.get('entityType').value)" formControlName="loadCalculatedFields">
<mat-checkbox [class.hidden]="!typesWithCalculatedFields.has(entityTypeFormGroup.get('entityType').value)"
formControlName="loadCalculatedFields"
class="checkbox-pre-line">
{{ 'version-control.load-calculated-fields' | translate }}
</mat-checkbox>
</div>

11
ui-ngx/src/app/shared/models/calculated-field.models.ts

@ -1083,3 +1083,14 @@ export interface CalculatedFieldsQuery {
entities?: Array<string>;
name?: Array<string>;
}
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);';

4
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",

Loading…
Cancel
Save