added test argument type
This commit is contained in:
parent
e7d14df44f
commit
29a6f1255b
@ -30,14 +30,14 @@
|
||||
<input matInput formControlName="argumentName" placeholder="{{ 'action.set' | translate }}">
|
||||
</mat-form-field>
|
||||
<mat-form-field appearance="outline" class="tb-inline-field w-1/5 lt-sm:hidden" subscriptSizing="dynamic">
|
||||
<mat-select [value]="group.get('type').value" formControlName="type">
|
||||
<mat-option [value]="group.get('type').value">
|
||||
{{ ArgumentTypeTranslations.get(group.get('type').value) | translate }}
|
||||
<mat-select [value]="argumentsTypeMap.get(group.get('argumentName').value)" [disabled]="true">
|
||||
<mat-option [value]="argumentsTypeMap.get(group.get('argumentName').value)">
|
||||
{{ ArgumentTypeTranslations.get(argumentsTypeMap.get(group.get('argumentName').value)) | translate }}
|
||||
</mat-option>
|
||||
</mat-select>
|
||||
</mat-form-field>
|
||||
<div class="flex flex-1 items-center gap-2">
|
||||
@if (group.get('type').value === ArgumentType.Rolling) {
|
||||
@if (argumentsTypeMap.get(group.get('argumentName').value) === ArgumentType.Rolling) {
|
||||
<mat-form-field appearance="outline" subscriptSizing="dynamic" class="tb-inline-field flex-1">
|
||||
<input matInput tb-json-to-string name="values" formControlName="values" placeholder="{{ 'value.json-value' | translate }}*"/>
|
||||
</mat-form-field>
|
||||
|
||||
@ -14,7 +14,7 @@
|
||||
/// limitations under the License.
|
||||
///
|
||||
|
||||
import { AfterViewInit, Component, forwardRef } from '@angular/core';
|
||||
import { Component, forwardRef, Input } from '@angular/core';
|
||||
import {
|
||||
ControlValueAccessor,
|
||||
NG_VALIDATORS,
|
||||
@ -60,7 +60,9 @@ import { MatDialog } from '@angular/material/dialog';
|
||||
}
|
||||
]
|
||||
})
|
||||
export class CalculatedFieldTestArgumentsComponent extends PageComponent implements ControlValueAccessor, Validator, AfterViewInit {
|
||||
export class CalculatedFieldTestArgumentsComponent extends PageComponent implements ControlValueAccessor, Validator {
|
||||
|
||||
@Input() argumentsTypeMap: Map<string, ArgumentType>;
|
||||
|
||||
argumentsFormArray = this.fb.array<FormGroup>([]);
|
||||
|
||||
@ -78,10 +80,6 @@ export class CalculatedFieldTestArgumentsComponent extends PageComponent impleme
|
||||
.subscribe(() => this.propagateChange(this.getValue()));
|
||||
}
|
||||
|
||||
ngAfterViewInit(): void {
|
||||
this.argumentsFormArray.updateValueAndValidity();
|
||||
}
|
||||
|
||||
registerOnChange(propagateChange: (value: CalculatedFieldEventArguments) => void): void {
|
||||
this.propagateChange = propagateChange;
|
||||
}
|
||||
@ -122,27 +120,25 @@ export class CalculatedFieldTestArgumentsComponent extends PageComponent impleme
|
||||
: group.patchValue({ ts: (result as CalculatedFieldSingleArgumentValue).ts, value: (result as CalculatedFieldSingleArgumentValue).value }) );
|
||||
}
|
||||
|
||||
private getSimpleArgumentFormGroup({ argumentName, type, ts, value }: CalculatedFieldSingleArgumentValue): FormGroup {
|
||||
private getSimpleArgumentFormGroup({ argumentName, ts, value }: CalculatedFieldSingleArgumentValue): FormGroup {
|
||||
return this.fb.group({
|
||||
argumentName: [{ value: argumentName, disabled: true}],
|
||||
type: [{ value: type , disabled: true }],
|
||||
ts: [ts],
|
||||
value: [value]
|
||||
}) as FormGroup;
|
||||
}
|
||||
|
||||
private getRollingArgumentFormGroup({ argumentName, type, timewindow, values }: CalculatedFieldRollingTelemetryArgumentValue): FormGroup {
|
||||
private getRollingArgumentFormGroup({ argumentName, timewindow, values }: CalculatedFieldRollingTelemetryArgumentValue): FormGroup {
|
||||
return this.fb.group({
|
||||
...timewindow ?? {},
|
||||
argumentName: [{ value: argumentName, disabled: true }],
|
||||
type: [{ value: type , disabled: true }],
|
||||
values: [values]
|
||||
}) as FormGroup;
|
||||
}
|
||||
|
||||
private getValue(): CalculatedFieldEventArguments {
|
||||
return this.argumentsFormArray.getRawValue().reduce((acc, rowItem) => {
|
||||
const { argumentName, type, ...value } = rowItem;
|
||||
const { argumentName, ...value } = rowItem;
|
||||
acc[argumentName] = value;
|
||||
return acc;
|
||||
}, {});
|
||||
|
||||
@ -52,7 +52,7 @@
|
||||
<div class="block-label-container right-top">
|
||||
<span class="block-label">{{ 'calculated-fields.arguments' | translate }}</span>
|
||||
</div>
|
||||
<tb-calculated-field-test-arguments class="size-full" formControlName="arguments"/>
|
||||
<tb-calculated-field-test-arguments class="size-full" formControlName="arguments" [argumentsTypeMap]="argumentsTypeMap"/>
|
||||
</div>
|
||||
</div>
|
||||
<div #bottomRightPanel class="test-block-content">
|
||||
|
||||
@ -38,7 +38,11 @@ import { beautifyJs } from '@shared/models/beautify.models';
|
||||
import { CalculatedFieldsService } from '@core/http/calculated-fields.service';
|
||||
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
|
||||
import { filter } from 'rxjs/operators';
|
||||
import { CalculatedFieldTestScriptDialogData } from '@shared/models/calculated-field.models';
|
||||
import {
|
||||
ArgumentType, CalculatedFieldEventArguments,
|
||||
CalculatedFieldTestScriptDialogData,
|
||||
TestArgumentTypeMap
|
||||
} from '@shared/models/calculated-field.models';
|
||||
|
||||
@Component({
|
||||
selector: 'tb-calculated-field-script-test-dialog',
|
||||
@ -61,6 +65,7 @@ export class CalculatedFieldScriptTestDialogComponent extends DialogComponent<Ca
|
||||
arguments: [],
|
||||
output: []
|
||||
});
|
||||
argumentsTypeMap = new Map<string, ArgumentType>();
|
||||
|
||||
readonly ContentType = ContentType;
|
||||
readonly ScriptLanguage = ScriptLanguage;
|
||||
@ -81,7 +86,7 @@ export class CalculatedFieldScriptTestDialogComponent extends DialogComponent<Ca
|
||||
beautifyJs(this.data.expression, {indent_size: 4}).pipe(filter(Boolean), takeUntilDestroyed()).subscribe(
|
||||
(res) => this.calculatedFieldScriptTestFormGroup.get('expression').patchValue(res, {emitEvent: false})
|
||||
);
|
||||
this.calculatedFieldScriptTestFormGroup.get('arguments').patchValue(this.data.arguments);
|
||||
this.calculatedFieldScriptTestFormGroup.get('arguments').patchValue(this.getArgumentsValue());
|
||||
}
|
||||
|
||||
ngAfterViewInit(): void {
|
||||
@ -117,7 +122,7 @@ export class CalculatedFieldScriptTestDialogComponent extends DialogComponent<Ca
|
||||
if (this.checkInputParamErrors()) {
|
||||
return this.calculatedFieldService.testScript({
|
||||
expression: this.calculatedFieldScriptTestFormGroup.get('expression').value,
|
||||
arguments: this.calculatedFieldScriptTestFormGroup.get('arguments').value
|
||||
arguments: this.getTestArguments()
|
||||
}).pipe(
|
||||
switchMap(result => {
|
||||
if (result.error) {
|
||||
@ -157,6 +162,26 @@ export class CalculatedFieldScriptTestDialogComponent extends DialogComponent<Ca
|
||||
this.initSplitLayout(this.testScriptContainer.nativeElement.clientWidth <= 960);
|
||||
}
|
||||
|
||||
private getTestArguments(): CalculatedFieldEventArguments {
|
||||
const argumentsValue = this.calculatedFieldScriptTestFormGroup.get('arguments').value;
|
||||
return Object.keys(argumentsValue)
|
||||
.reduce((acc, key) => {
|
||||
acc[key] = argumentsValue[key];
|
||||
acc[key].type = TestArgumentTypeMap.get(this.argumentsTypeMap.get(key));
|
||||
return acc;
|
||||
}, {});
|
||||
}
|
||||
|
||||
private getArgumentsValue(): CalculatedFieldEventArguments {
|
||||
return Object.keys(this.data.arguments)
|
||||
.reduce((acc, key) => {
|
||||
const { type, ...argumentObj } = this.data.arguments[key];
|
||||
this.argumentsTypeMap.set(key, type);
|
||||
acc[key] = argumentObj;
|
||||
return acc;
|
||||
}, {});
|
||||
}
|
||||
|
||||
private initSplitLayout(smallMode = false): void {
|
||||
const [leftPanel, rightPanel, topRightPanel, bottomRightPanel] = [
|
||||
this.leftPanelElmRef.nativeElement,
|
||||
|
||||
@ -85,6 +85,19 @@ export enum ArgumentType {
|
||||
Rolling = 'TS_ROLLING',
|
||||
}
|
||||
|
||||
export enum TestArgumentType {
|
||||
Single = 'SINGLE_VALUE',
|
||||
Rolling = 'TS_ROLLING',
|
||||
}
|
||||
|
||||
export const TestArgumentTypeMap = new Map<ArgumentType, TestArgumentType>(
|
||||
[
|
||||
[ArgumentType.Attribute, TestArgumentType.Single],
|
||||
[ArgumentType.LatestTelemetry, TestArgumentType.Single],
|
||||
[ArgumentType.Rolling, TestArgumentType.Rolling],
|
||||
]
|
||||
)
|
||||
|
||||
export enum OutputType {
|
||||
Attribute = 'ATTRIBUTES',
|
||||
Timeseries = 'TIME_SERIES',
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user