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