Browse Source

moved calculated-fields-table to use debug event modal

pull/14513/head
Maksym Tsymbarov 9 months ago
parent
commit
30e3c447f3
  1. 24
      ui-ngx/src/app/modules/home/components/alarm-rules/alarm-rules-table-config.ts
  2. 29
      ui-ngx/src/app/modules/home/components/calculated-fields/calculated-fields-table-config.ts
  3. 47
      ui-ngx/src/app/modules/home/components/calculated-fields/components/debug-dialog/calculated-field-debug-dialog.component.html
  4. 26
      ui-ngx/src/app/modules/home/components/calculated-fields/components/debug-dialog/calculated-field-debug-dialog.component.scss
  5. 77
      ui-ngx/src/app/modules/home/components/calculated-fields/components/debug-dialog/calculated-field-debug-dialog.component.ts
  6. 1
      ui-ngx/src/app/modules/home/components/calculated-fields/components/public-api.ts
  7. 6
      ui-ngx/src/app/modules/home/components/home-components.module.ts
  8. 13
      ui-ngx/src/app/modules/home/dialogs/events-dialog.component.html
  9. 0
      ui-ngx/src/app/modules/home/dialogs/events-dialog.component.scss
  10. 30
      ui-ngx/src/app/modules/home/dialogs/events-dialog.component.ts
  11. 11
      ui-ngx/src/app/modules/home/pages/rulechain/rulechain-page.component.ts

24
ui-ngx/src/app/modules/home/components/alarm-rules/alarm-rules-table-config.ts

@ -55,14 +55,12 @@ import {
AlarmRuleDialogComponent,
AlarmRuleDialogData
} from "@home/components/alarm-rules/alarm-rule-dialog.component";
import {
CalculatedFieldDebugDialogComponent,
CalculatedFieldDebugDialogData
} from "@home/components/calculated-fields/components/debug-dialog/calculated-field-debug-dialog.component";
import { AlarmSeverity, alarmSeverityTranslations } from "@shared/models/alarm.models";
import { UtilsService } from "@core/services/utils.service";
import { deepClone, getEntityDetailsPageURL, isObject } from "@core/utils";
import { AlarmRuleTableHeaderComponent } from "@home/components/alarm-rules/alarm-rule-table-header.component";
import { EventsDialogComponent, EventsDialogData } from '@home/dialogs/events-dialog.component';
import { DebugEventType, Event as DebugEvent, EventType } from '@shared/models/event.models';
import { ActionNotificationShow } from "@core/notification/notification.actions";
import {
CalculatedFieldScriptTestDialogComponent,
@ -266,13 +264,25 @@ export class AlarmRulesTableConfig extends EntityTableConfig<any> {
}
private openDebugEventsDialog(calculatedField: CalculatedField): void {
this.dialog.open<CalculatedFieldDebugDialogComponent, CalculatedFieldDebugDialogData, null>(CalculatedFieldDebugDialogComponent, {
const customCellActionEnabledFn = (event: DebugEvent) => {
return (calculatedField.type === CalculatedFieldType.SCRIPT ||
(calculatedField.type === CalculatedFieldType.PROPAGATION &&
calculatedField.configuration.applyExpressionToResolvedArguments)
) && !!(event as DebugEvent).body.arguments;
};
this.dialog.open<EventsDialogComponent, EventsDialogData, null>(EventsDialogComponent, {
disableClose: true,
panelClass: ['tb-dialog', 'tb-fullscreen-dialog'],
data: {
title: 'alarm-rule.debugging',
tenantId: this.tenantId,
value: calculatedField,
getTestScriptDialogFn: null,
value: calculatedField.id,
debugEventTypes:[DebugEventType.DEBUG_CALCULATED_FIELD],
disabledEventTypes:[EventType.LC_EVENT, EventType.ERROR, EventType.STATS],
defaultEventType: DebugEventType.DEBUG_CALCULATED_FIELD,
onDebugEventSelected: null,
customCellActionEnabledFn: customCellActionEnabledFn
}
})
.afterClosed()

29
ui-ngx/src/app/modules/home/components/calculated-fields/calculated-fields-table-config.ts

@ -22,7 +22,7 @@ import {
import { EntityType, entityTypeTranslations } from '@shared/models/entity-type.models';
import { TranslateService } from '@ngx-translate/core';
import { Direction } from '@shared/models/page/sort-order';
import { MatDialog } from '@angular/material/dialog';
import { MatDialog, MatDialogRef } from '@angular/material/dialog';
import { PageLink } from '@shared/models/page/page-link';
import { EMPTY, Observable, of } from 'rxjs';
import { PageData } from '@shared/models/page/page-data';
@ -48,8 +48,6 @@ import {
PropagationWithExpression,
} from '@shared/models/calculated-field.models';
import {
CalculatedFieldDebugDialogComponent,
CalculatedFieldDebugDialogData,
CalculatedFieldDialogComponent,
CalculatedFieldDialogData,
CalculatedFieldScriptTestDialogComponent,
@ -61,6 +59,8 @@ import { EntityDebugSettingsService } from '@home/components/entity/debug/entity
import { DatePipe } from '@angular/common';
import { UtilsService } from "@core/services/utils.service";
import { ActionNotificationShow } from "@core/notification/notification.actions";
import { CalculatedFieldEventBody, DebugEventType, Event as DebugEvent, EventType } from '@shared/models/event.models';
import { EventsDialogComponent, EventsDialogData } from '@home/dialogs/events-dialog.component';
export class CalculatedFieldsTableConfig extends EntityTableConfig<CalculatedField> {
@ -233,13 +233,30 @@ export class CalculatedFieldsTableConfig extends EntityTableConfig<CalculatedFie
}
private openDebugEventsDialog(calculatedField: CalculatedField): void {
this.dialog.open<CalculatedFieldDebugDialogComponent, CalculatedFieldDebugDialogData, null>(CalculatedFieldDebugDialogComponent, {
const customCellActionEnabledFn = (event: DebugEvent) => {
return (calculatedField.type === CalculatedFieldType.SCRIPT ||
(calculatedField.type === CalculatedFieldType.PROPAGATION &&
calculatedField.configuration.applyExpressionToResolvedArguments)
) && !!(event as DebugEvent).body.arguments;
};
const onDebugEventSelected = (event: CalculatedFieldEventBody, dialogRef: MatDialogRef<EventsDialogComponent, string>) => {
this.getTestScriptDialog(calculatedField, JSON.parse(event.arguments))
.subscribe(expression => dialogRef.close(expression));
};
this.dialog.open<EventsDialogComponent, EventsDialogData, null>(EventsDialogComponent, {
disableClose: true,
panelClass: ['tb-dialog', 'tb-fullscreen-dialog'],
data: {
title: 'alarm-rule.debugging',
tenantId: this.tenantId,
value: calculatedField,
getTestScriptDialogFn: this.getTestScriptDialog.bind(this),
value: calculatedField.id,
debugEventTypes:[DebugEventType.DEBUG_CALCULATED_FIELD],
disabledEventTypes:[EventType.LC_EVENT, EventType.ERROR, EventType.STATS],
defaultEventType: DebugEventType.DEBUG_CALCULATED_FIELD,
onDebugEventSelected: onDebugEventSelected,
customCellActionEnabledFn: customCellActionEnabledFn
}
})
.afterClosed()

47
ui-ngx/src/app/modules/home/components/calculated-fields/components/debug-dialog/calculated-field-debug-dialog.component.html

@ -1,47 +0,0 @@
<!--
Copyright © 2016-2025 The Thingsboard Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<div class="debug-dialog-container flex flex-col xs:h-full">
<mat-toolbar color="primary">
<h2>{{ dialogTitle | translate}}</h2>
<span class="flex-1"></span>
<button mat-icon-button
(click)="cancel()"
type="button">
<mat-icon class="material-icons">close</mat-icon>
</button>
</mat-toolbar>
<div mat-dialog-content class="tb-form-panel stroked debug-dialog-content xs:flex-1">
<tb-event-table
[tenantId]="data.tenantId"
[debugEventTypes]="[debugEventTypes.DEBUG_CALCULATED_FIELD]"
[disabledEventTypes]="[EventType.LC_EVENT, EventType.ERROR, EventType.STATS]"
[defaultEventType]="DebugEventType.DEBUG_CALCULATED_FIELD"
[active]="true"
[entityId]="data.value.id"
(debugEventSelected)="onDebugEventSelected($event)"
/>
</div>
<div mat-dialog-actions class="justify-end">
<button mat-button color="primary"
type="button"
cdkFocusInitial
(click)="cancel()">
{{ 'action.cancel' | translate }}
</button>
</div>
</div>

26
ui-ngx/src/app/modules/home/components/calculated-fields/components/debug-dialog/calculated-field-debug-dialog.component.scss

@ -1,26 +0,0 @@
/**
* Copyright © 2016-2025 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
:host {
.debug-dialog-container {
width: 1080px;
max-width: 100%;
.debug-dialog-content {
height: 65vh;
border-radius: 0;
}
}
}

77
ui-ngx/src/app/modules/home/components/calculated-fields/components/debug-dialog/calculated-field-debug-dialog.component.ts

@ -1,77 +0,0 @@
///
/// Copyright © 2016-2025 The Thingsboard Authors
///
/// Licensed under the Apache License, Version 2.0 (the "License");
/// you may not use this file except in compliance with the License.
/// You may obtain a copy of the License at
///
/// http://www.apache.org/licenses/LICENSE-2.0
///
/// Unless required by applicable law or agreed to in writing, software
/// distributed under the License is distributed on an "AS IS" BASIS,
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
/// See the License for the specific language governing permissions and
/// limitations under the License.
///
import { AfterViewInit, Component, Inject, ViewChild } from '@angular/core';
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
import { Store } from '@ngrx/store';
import { AppState } from '@core/core.state';
import { Router } from '@angular/router';
import { DialogComponent } from '@shared/components/dialog.component';
import { CalculatedFieldEventBody, DebugEventType, Event, EventType } from '@shared/models/event.models';
import { EventTableComponent } from '@home/components/event/event-table.component';
import {
CalculatedField,
CalculatedFieldTestScriptFn,
CalculatedFieldType
} from '@shared/models/calculated-field.models';
export interface CalculatedFieldDebugDialogData {
tenantId: string;
value: CalculatedField;
getTestScriptDialogFn: CalculatedFieldTestScriptFn;
}
@Component({
selector: 'tb-calculated-field-debug-dialog',
styleUrls: ['calculated-field-debug-dialog.component.scss'],
templateUrl: './calculated-field-debug-dialog.component.html',
})
export class CalculatedFieldDebugDialogComponent extends DialogComponent<CalculatedFieldDebugDialogComponent, string> implements AfterViewInit {
@ViewChild(EventTableComponent, {static: true}) eventsTable: EventTableComponent;
readonly DebugEventType = DebugEventType;
readonly debugEventTypes = DebugEventType;
readonly EventType = EventType;
dialogTitle: string;
constructor(protected store: Store<AppState>,
protected router: Router,
@Inject(MAT_DIALOG_DATA) public data: CalculatedFieldDebugDialogData,
protected dialogRef: MatDialogRef<CalculatedFieldDebugDialogComponent, string>) {
super(store, router, dialogRef);
this.dialogTitle = this.data.value.type === CalculatedFieldType.ALARM ? 'alarm-rule.debugging' : 'calculated-fields.debugging';
}
ngAfterViewInit(): void {
this.eventsTable.entitiesTable.cellActionDescriptors[0].isEnabled = (event => {
return (this.data.value.type === CalculatedFieldType.SCRIPT ||
(this.data.value.type === CalculatedFieldType.PROPAGATION && this.data.value.configuration.applyExpressionToResolvedArguments)
) && !!(event as Event).body.arguments
});
this.eventsTable.entitiesTable.updateData();
}
cancel(): void {
this.dialogRef.close(null);
}
onDebugEventSelected(event: CalculatedFieldEventBody): void {
this.data.getTestScriptDialogFn(this.data.value, JSON.parse(event.arguments))
.subscribe(expression => this.dialogRef.close(expression));
}
}

1
ui-ngx/src/app/modules/home/components/calculated-fields/components/public-api.ts

@ -15,5 +15,4 @@
///
export * from './dialog/calculated-field-dialog.component';
export * from './debug-dialog/calculated-field-debug-dialog.component';
export * from './test-dialog/calculated-field-script-test-dialog.component';

6
ui-ngx/src/app/modules/home/components/home-components.module.ts

@ -192,9 +192,6 @@ import { AIModelDialogComponent } from '@home/components/ai-model/ai-model-dialo
import { ResourcesDialogComponent } from "@home/components/resources/resources-dialog.component";
import { ResourcesLibraryComponent } from "@home/components/resources/resources-library.component";
import { CalculatedFieldsTableComponent } from '@home/components/calculated-fields/calculated-fields-table.component';
import {
CalculatedFieldDebugDialogComponent
} from '@home/components/calculated-fields/components/debug-dialog/calculated-field-debug-dialog.component';
import { CalculatedFieldsModule } from '@home/components/calculated-fields/calculated-field.module';
import { AlarmRuleModule } from "@home/components/alarm-rules/alarm-rule.module";
import { AlarmRulesTableComponent } from "@home/components/alarm-rules/alarm-rules-table.component";
@ -204,7 +201,7 @@ import { EditApiKeyDescriptionPanelComponent } from '@home/components/api-key/ed
import { ApiKeyGeneratedDialogComponent } from '@home/components/api-key/api-key-generated-dialog.component';
import { ApiKeysTableDialogComponent } from '@home/components/api-key/api-keys-table-dialog.component';
import { AuditLogFilterComponent } from "@home/components/audit-log/audit-log-filter.component";
import { EventsDialogComponent } from '@home/components/event/events-dialog.component';
import { EventsDialogComponent } from '@home/dialogs/events-dialog.component';
@NgModule({
declarations:
@ -218,7 +215,6 @@ import { EventsDialogComponent } from '@home/components/event/events-dialog.comp
AuditLogTableComponent,
AuditLogDetailsDialogComponent,
CalculatedFieldsTableComponent,
CalculatedFieldDebugDialogComponent,
AlarmRulesTableComponent,
EventContentDialogComponent,
EventTableHeaderComponent,

13
ui-ngx/src/app/modules/home/components/event/events-dialog.component.html → ui-ngx/src/app/modules/home/dialogs/events-dialog.component.html

@ -27,13 +27,14 @@
</mat-toolbar>
<div mat-dialog-content class="tb-form-panel stroked debug-dialog-content xs:flex-1">
<tb-event-table
[debugEventTypes]="[data.debugEventType]"
[defaultEventType]="data.debugEventType"
[debugEventTypes]="data.debugEventTypes"
[defaultEventType]="data.defaultEventType"
[disabledEventTypes]="data.disabledEventTypes ?? []"
[active]="true"
[tenantId]="data.tenantId.id"
[entityId]="data.entityId"
[functionTestButtonLabel]="data.functionTestButtonLabel"
(debugEventSelected)="data.onDebugEventSelected"
[tenantId]="data.tenantId"
[entityId]="data.value"
[functionTestButtonLabel]="data.functionTestButtonLabel ?? ''"
(debugEventSelected)="this.onDebugEventSelected($event)"
/>
</div>
<div mat-dialog-actions class="justify-end">

0
ui-ngx/src/app/modules/home/components/event/events-dialog.component.scss → ui-ngx/src/app/modules/home/dialogs/events-dialog.component.scss

30
ui-ngx/src/app/modules/home/components/event/events-dialog.component.ts → ui-ngx/src/app/modules/home/dialogs/events-dialog.component.ts

@ -21,17 +21,20 @@ import { EventTableComponent } from '@home/components/event/event-table.componen
import { Store } from '@ngrx/store';
import { AppState } from '@core/core.state';
import { Router } from '@angular/router';
import { DebugEventType } from '@shared/models/event.models';
import { TenantId } from '@shared/models/id/tenant-id';
import { DebugEventType, EventType } from '@shared/models/event.models';
import { EntityId } from '@shared/models/id/entity-id';
import { BaseData, HasId } from '@shared/models/base-data';
export interface RuleNodeDebugDialogData {
export interface EventsDialogData {
title: string;
tenantId: TenantId;
entityId: EntityId;
debugEventType: DebugEventType;
functionTestButtonLabel: string;
onDebugEventSelected: ()=> void;
tenantId: string;
value: EntityId;
debugEventTypes: Array<DebugEventType>;
defaultEventType: DebugEventType;
disabledEventTypes?: Array<EventType | DebugEventType>;
functionTestButtonLabel?: string;
onDebugEventSelected?: (event: any, dialogRef: MatDialogRef<EventsDialogComponent, string>) => void;
customCellActionEnabledFn?: (event: BaseData<HasId>) => boolean;
}
@Component({
@ -45,16 +48,25 @@ export class EventsDialogComponent extends DialogComponent<EventsDialogComponent
constructor(protected store: Store<AppState>,
protected router: Router,
@Inject(MAT_DIALOG_DATA) public data: RuleNodeDebugDialogData,
@Inject(MAT_DIALOG_DATA) public data: EventsDialogData,
protected dialogRef: MatDialogRef<EventsDialogComponent, string>) {
super(store, router, dialogRef);
}
ngAfterViewInit() {
if (this.data.customCellActionEnabledFn && this.eventsTable.entitiesTable.cellActionDescriptors?.length > 0) {
this.eventsTable.entitiesTable.cellActionDescriptors[0].isEnabled = this.data.customCellActionEnabledFn;
}
this.eventsTable.entitiesTable.updateData();
}
cancel(): void {
this.dialogRef.close(null);
}
onDebugEventSelected(event: any): void {
if(this.data.onDebugEventSelected) {
this.data.onDebugEventSelected(event, this.dialogRef);
}
}
}

11
ui-ngx/src/app/modules/home/pages/rulechain/rulechain-page.component.ts

@ -100,7 +100,7 @@ import { EntityDebugSettings } from '@shared/models/entity.models';
import Timeout = NodeJS.Timeout;
import { DomSanitizer } from '@angular/platform-browser';
import { AdditionalDebugActionConfig } from '@home/components/entity/debug/entity-debug-settings.model';
import { EventsDialogComponent } from '@home/components/event/events-dialog.component';
import { EventsDialogComponent } from '@home/dialogs/events-dialog.component';
@Component({
selector: 'tb-rulechain-page',
@ -1679,11 +1679,12 @@ export class RuleChainPageComponent extends PageComponent
panelClass: ['tb-dialog', 'tb-fullscreen-dialog'],
data: {
title: 'rulenode.events',
debugEventType: DebugEventType.DEBUG_RULE_CHAIN,
tenantId: this.ruleChain.tenantId,
entityId: this.editingRuleNode.ruleNodeId,
debugEventTypes: [DebugEventType.DEBUG_RULE_CHAIN],
defaultEventType: DebugEventType.DEBUG_RULE_CHAIN,
tenantId: this.ruleChain.tenantId.id,
value: this.editingRuleNode.ruleNodeId,
functionTestButtonLabel: this.ruleNodeTestButtonLabel,
debugEventSelected: this.onDebugEventSelected.bind(this)
onDebugEventSelected: this.onDebugEventSelected.bind(this)
}
})
.afterClosed()

Loading…
Cancel
Save