Refactoring
This commit is contained in:
parent
55f2799446
commit
84b9bde577
@ -19,10 +19,10 @@ import { defaultHttpOptionsFromConfig, RequestConfig } from './http-utils';
|
||||
import { Observable } from 'rxjs';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { PageData } from '@shared/models/page/page-data';
|
||||
import { CalculatedField } from '@shared/models/calculated-field.models';
|
||||
import { CalculatedField, CalculatedFieldTestScriptInputParams } from '@shared/models/calculated-field.models';
|
||||
import { PageLink } from '@shared/models/page/page-link';
|
||||
import { EntityId } from '@shared/models/id/entity-id';
|
||||
import { TestScriptResult } from '@shared/models/rule-node.models';
|
||||
import { TestScriptResult } from '@shared/models/entity.models';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@ -50,7 +50,7 @@ export class CalculatedFieldsService {
|
||||
defaultHttpOptionsFromConfig(config));
|
||||
}
|
||||
|
||||
public testScript(inputParams: any, config?: RequestConfig): Observable<TestScriptResult> {
|
||||
public testScript(inputParams: CalculatedFieldTestScriptInputParams, config?: RequestConfig): Observable<TestScriptResult> {
|
||||
return this.http.post<TestScriptResult>('/api/calculatedField/testScript', inputParams, defaultHttpOptionsFromConfig(config));
|
||||
}
|
||||
}
|
||||
|
||||
@ -35,7 +35,6 @@ import {
|
||||
RuleNodeConfiguration,
|
||||
ScriptLanguage,
|
||||
TestScriptInputParams,
|
||||
TestScriptResult
|
||||
} from '@app/shared/models/rule-node.models';
|
||||
import { componentTypeBySelector, ResourcesService } from '../services/resources.service';
|
||||
import { catchError, map, mergeMap } from 'rxjs/operators';
|
||||
@ -44,6 +43,7 @@ import { deepClone, snakeCase } from '@core/utils';
|
||||
import { DebugRuleNodeEventBody } from '@app/shared/models/event.models';
|
||||
import { Edge } from '@shared/models/edge.models';
|
||||
import { IModulesMap } from '@modules/common/modules-map.models';
|
||||
import { TestScriptResult } from '@shared/models/entity.models';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
|
||||
@ -38,7 +38,8 @@ import { catchError, filter, switchMap } from 'rxjs/operators';
|
||||
import {
|
||||
CalculatedField,
|
||||
CalculatedFieldDebugDialogData,
|
||||
CalculatedFieldDialogData, CalculatedFieldScriptTestDialogData
|
||||
CalculatedFieldDialogData,
|
||||
CalculatedFieldScriptTestDialogData
|
||||
} from '@shared/models/calculated-field.models';
|
||||
import {
|
||||
CalculatedFieldDebugDialogComponent,
|
||||
|
||||
@ -16,7 +16,6 @@
|
||||
:host {
|
||||
.debug-dialog-container {
|
||||
height: 77vh;
|
||||
min-width: 80vw;
|
||||
|
||||
.debug-dialog-content {
|
||||
border-radius: 0;
|
||||
|
||||
@ -115,7 +115,10 @@ export class CalculatedFieldDialogComponent extends DialogComponent<CalculatedFi
|
||||
Object.fromEntries(Object.keys(this.configFormGroup.get('arguments').value).map(k => [k, ''])),
|
||||
this.configFormGroup.get('expressionSCRIPT').value,
|
||||
true
|
||||
).pipe(filter(Boolean)).subscribe((expression: string) => this.configFormGroup.get('expressionSCRIPT').setValue(expression));
|
||||
).pipe(filter(Boolean)).subscribe((expression: string) => {
|
||||
this.configFormGroup.get('expressionSCRIPT').setValue(expression);
|
||||
this.configFormGroup.get('expressionSCRIPT').markAsDirty();
|
||||
});
|
||||
}
|
||||
|
||||
private applyDialogData(): void {
|
||||
|
||||
@ -48,10 +48,10 @@
|
||||
<div #rightPanel>
|
||||
<div #topRightPanel class="test-block-content">
|
||||
<div class="relative flex size-full min-w-96 gap-2">
|
||||
<div class="absolute right-4 top-[6px] z-10 text-[12px] font-bold">
|
||||
<div class="absolute right-2 top-[6px] z-10 text-[12px] font-bold">
|
||||
<span class="block-label">{{ 'calculated-fields.arguments' | translate }}</span>
|
||||
</div>
|
||||
<tb-calculated-field-test-arguments formControlName="arguments"/>
|
||||
<tb-calculated-field-test-arguments class="size-full" formControlName="arguments"/>
|
||||
</div>
|
||||
</div>
|
||||
<div #bottomRightPanel class="test-block-content">
|
||||
|
||||
@ -37,6 +37,7 @@ import { beautifyJs } from '@shared/models/beautify.models';
|
||||
import { CalculatedFieldsService } from '@core/http/calculated-fields.service';
|
||||
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
|
||||
import { CalculatedFieldScriptTestDialogData } from '@shared/models/calculated-field.models';
|
||||
import { filter } from 'rxjs/operators';
|
||||
|
||||
@Component({
|
||||
selector: 'tb-calculated-field-script-test-dialog',
|
||||
@ -71,10 +72,8 @@ export class CalculatedFieldScriptTestDialogComponent extends DialogComponent<Ca
|
||||
private destroyRef: DestroyRef,
|
||||
private calculatedFieldService: CalculatedFieldsService) {
|
||||
super(store, router, dialogRef);
|
||||
beautifyJs(this.data.expression, {indent_size: 4}).pipe(takeUntilDestroyed()).subscribe(
|
||||
(res) => {
|
||||
this.calculatedFieldScriptTestFormGroup.get('expression').patchValue(res, {emitEvent: false});
|
||||
}
|
||||
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, {emitEvent: false});
|
||||
}
|
||||
|
||||
@ -360,7 +360,7 @@ export class EventTableConfig extends EntityTableConfig<Event, TimePageLink> {
|
||||
this.columns[1].width = '20%';
|
||||
this.columns.push(
|
||||
new EntityTableColumn<Event>('entityId', 'event.entity-id', '85px',
|
||||
(entity) => `<span style="display: inline-block; width: 7ch">${entity.body.entityId.substring(0, 6)}…</span>`,
|
||||
(entity) => `<span style="display: inline-block; width: 7ch">${entity.body.entityId.substring(0, 8)}…</span>`,
|
||||
() => ({padding: '0 12px 0 0'}),
|
||||
false,
|
||||
() => ({padding: '0 12px 0 0'}),
|
||||
@ -380,7 +380,7 @@ export class EventTableConfig extends EntityTableConfig<Event, TimePageLink> {
|
||||
}
|
||||
),
|
||||
new EntityTableColumn<Event>('messageId', 'event.message-id', '85px',
|
||||
(entity) => `<span style="display: inline-block; width: 7ch">${entity.body.msgId?.substring(0, 6)}…</span>`,
|
||||
(entity) => `<span style="display: inline-block; width: 7ch">${entity.body.msgId?.substring(0, 8)}…</span>`,
|
||||
() => ({padding: '0 12px 0 0'}),
|
||||
false,
|
||||
() => ({padding: '0 12px 0 0'}),
|
||||
@ -462,9 +462,7 @@ export class EventTableConfig extends EntityTableConfig<Event, TimePageLink> {
|
||||
name: this.translate.instant('common.test-with-this-message', {test: this.translate.instant(this.testButtonLabel)}),
|
||||
icon: 'bug_report',
|
||||
isEnabled: () => true,
|
||||
onAction: (_, entity) => {
|
||||
this.debugEventSelected.next(entity.body);
|
||||
}
|
||||
onAction: (_, entity) => this.debugEventSelected.next(entity.body)
|
||||
});
|
||||
break;
|
||||
}
|
||||
|
||||
@ -148,10 +148,13 @@ export interface CalculatedFieldDebugDialogData {
|
||||
testScriptFn: CalculatedFieldTestScriptFn;
|
||||
}
|
||||
|
||||
export interface CalculatedFieldScriptTestDialogData {
|
||||
export interface CalculatedFieldScriptTestDialogData extends CalculatedFieldTestScriptInputParams {
|
||||
withApply: boolean;
|
||||
}
|
||||
|
||||
export interface CalculatedFieldTestScriptInputParams {
|
||||
arguments: Record<string, unknown>,
|
||||
expression: string;
|
||||
withApply: boolean;
|
||||
}
|
||||
|
||||
export interface ArgumentEntityTypeParams {
|
||||
|
||||
@ -203,6 +203,11 @@ export interface EntityDebugSettings {
|
||||
allEnabledUntil?: number;
|
||||
}
|
||||
|
||||
export interface TestScriptResult {
|
||||
output: string;
|
||||
error: string;
|
||||
}
|
||||
|
||||
export interface AdditionalDebugActionConfig {
|
||||
action?: (id?: EntityId, ...restArguments: unknown[]) => void;
|
||||
title: string;
|
||||
|
||||
@ -374,11 +374,6 @@ export interface TestScriptInputParams {
|
||||
msgType: string;
|
||||
}
|
||||
|
||||
export interface TestScriptResult {
|
||||
output: string;
|
||||
error: string;
|
||||
}
|
||||
|
||||
export enum MessageType {
|
||||
POST_ATTRIBUTES_REQUEST = 'POST_ATTRIBUTES_REQUEST',
|
||||
POST_TELEMETRY_REQUEST = 'POST_TELEMETRY_REQUEST',
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user