Browse Source

Refactoring

pull/8836/head
rusikv 3 years ago
parent
commit
552be228a3
  1. 6
      ui-ngx/src/app/core/services/script/node-script-test.service.ts
  2. 5
      ui-ngx/src/app/modules/home/components/details-panel.component.ts
  3. 4
      ui-ngx/src/app/modules/home/components/entity/entities-table.component.ts
  4. 45
      ui-ngx/src/app/modules/home/components/event/event-table-config.ts
  5. 36
      ui-ngx/src/app/modules/home/components/event/event-table.component.ts
  6. 1
      ui-ngx/src/app/modules/home/models/entity/entity-table-component.models.ts
  7. 25
      ui-ngx/src/app/modules/home/pages/rulechain/rule-node-config.component.ts
  8. 2
      ui-ngx/src/app/modules/home/pages/rulechain/rule-node-details.component.html
  9. 7
      ui-ngx/src/app/modules/home/pages/rulechain/rule-node-details.component.ts
  10. 9
      ui-ngx/src/app/modules/home/pages/rulechain/rulechain-page.component.html
  11. 27
      ui-ngx/src/app/modules/home/pages/rulechain/rulechain-page.component.ts
  12. 48
      ui-ngx/src/app/shared/models/rule-node.models.ts
  13. 10
      ui-ngx/src/assets/locale/locale.constant-en_US.json

6
ui-ngx/src/app/core/services/script/node-script-test.service.ts

@ -61,7 +61,8 @@ export class NodeScriptTestService {
try { try {
msg = JSON.parse(eventBody.data); msg = JSON.parse(eventBody.data);
} catch (e) {} } catch (e) {}
} else { }
if (!msg) {
msg = { msg = {
temperature: 22.4, temperature: 22.4,
humidity: 78 humidity: 78
@ -71,7 +72,8 @@ export class NodeScriptTestService {
try { try {
metadata = JSON.parse(eventBody.metadata); metadata = JSON.parse(eventBody.metadata);
} catch (e) {} } catch (e) {}
} else { }
if (!metadata) {
metadata = { metadata = {
deviceName: 'Test Device', deviceName: 'Test Device',
deviceType: 'default', deviceType: 'default',

5
ui-ngx/src/app/modules/home/components/details-panel.component.ts

@ -56,9 +56,6 @@ export class DetailsPanelComponent extends PageComponent implements OnDestroy {
this.theFormValue = value; this.theFormValue = value;
if (this.theFormValue !== null) { if (this.theFormValue !== null) {
this.formSubscription = this.theFormValue.valueChanges.subscribe(() => { this.formSubscription = this.theFormValue.valueChanges.subscribe(() => {
if (this.isReadOnly) {
this.switchToFirstTab.emit();
}
this.cd.detectChanges() this.cd.detectChanges()
}); });
} }
@ -77,8 +74,6 @@ export class DetailsPanelComponent extends PageComponent implements OnDestroy {
applyDetails = new EventEmitter<void>(); applyDetails = new EventEmitter<void>();
@Output() @Output()
closeSearch = new EventEmitter<void>(); closeSearch = new EventEmitter<void>();
@Output()
switchToFirstTab = new EventEmitter<void>()
isEditValue = false; isEditValue = false;
showSearchPane = false; showSearchPane = false;

4
ui-ngx/src/app/modules/home/components/entity/entities-table.component.ts

@ -637,6 +637,10 @@ export class EntitiesTableComponent extends PageComponent implements IEntitiesTa
} }
} }
cellActionDescriptorsUpdated() {
this.cellActionDescriptors = [...this.entitiesTableConfig.cellActionDescriptors];
}
headerCellStyle(column: EntityColumn<BaseData<HasId>>) { headerCellStyle(column: EntityColumn<BaseData<HasId>>) {
const index = this.entitiesTableConfig.columns.indexOf(column); const index = this.entitiesTableConfig.columns.indexOf(column);
let res = this.headerCellStyleCache[index]; let res = this.headerCellStyleCache[index];

45
ui-ngx/src/app/modules/home/components/event/event-table-config.ts

@ -30,7 +30,7 @@ import { EntityId } from '@shared/models/id/entity-id';
import { EventService } from '@app/core/http/event.service'; import { EventService } from '@app/core/http/event.service';
import { EventTableHeaderComponent } from '@home/components/event/event-table-header.component'; import { EventTableHeaderComponent } from '@home/components/event/event-table-header.component';
import { EntityTypeResource } from '@shared/models/entity-type.models'; import { EntityTypeResource } from '@shared/models/entity-type.models';
import { BehaviorSubject, Observable } from 'rxjs'; import { Observable } from 'rxjs';
import { PageData } from '@shared/models/page/page-data'; import { PageData } from '@shared/models/page/page-data';
import { Direction } from '@shared/models/page/sort-order'; import { Direction } from '@shared/models/page/sort-order';
import { DialogService } from '@core/services/dialog.service'; import { DialogService } from '@core/services/dialog.service';
@ -41,7 +41,7 @@ import {
} from '@home/components/event/event-content-dialog.component'; } from '@home/components/event/event-content-dialog.component';
import { isEqual, sortObjectKeys } from '@core/utils'; import { isEqual, sortObjectKeys } from '@core/utils';
import { ConnectedPosition, Overlay, OverlayConfig, OverlayRef } from '@angular/cdk/overlay'; import { ConnectedPosition, Overlay, OverlayConfig, OverlayRef } from '@angular/cdk/overlay';
import { ChangeDetectorRef, Injector, StaticProvider, ViewContainerRef } from '@angular/core'; import { ChangeDetectorRef, EventEmitter, Injector, StaticProvider, ViewContainerRef } from '@angular/core';
import { ComponentPortal } from '@angular/cdk/portal'; import { ComponentPortal } from '@angular/cdk/portal';
import { import {
EVENT_FILTER_PANEL_DATA, EVENT_FILTER_PANEL_DATA,
@ -50,7 +50,6 @@ import {
FilterEntityColumn FilterEntityColumn
} from '@home/components/event/event-filter-panel.component'; } from '@home/components/event/event-filter-panel.component';
import { NodeScriptTestService } from '@core/services/script/node-script-test.service'; import { NodeScriptTestService } from '@core/services/script/node-script-test.service';
import { ruleNodeClazzFunctionNameTranslations } from '@shared/models/rule-node.models';
export class EventTableConfig extends EntityTableConfig<Event, TimePageLink> { export class EventTableConfig extends EntityTableConfig<Event, TimePageLink> {
@ -63,6 +62,7 @@ export class EventTableConfig extends EntityTableConfig<Event, TimePageLink> {
set eventType(eventType: EventType | DebugEventType) { set eventType(eventType: EventType | DebugEventType) {
if (this.eventTypeValue !== eventType) { if (this.eventTypeValue !== eventType) {
this.eventTypeValue = eventType; this.eventTypeValue = eventType;
this.updateCellAction();
this.updateColumns(true); this.updateColumns(true);
this.updateFilterColumns(); this.updateFilterColumns();
} }
@ -74,8 +74,6 @@ export class EventTableConfig extends EntityTableConfig<Event, TimePageLink> {
eventTypes: Array<EventType | DebugEventType>; eventTypes: Array<EventType | DebugEventType>;
debugEventSelectedSubject = new BehaviorSubject<DebugRuleNodeEventBody>(null);
constructor(private eventService: EventService, constructor(private eventService: EventService,
private dialogService: DialogService, private dialogService: DialogService,
private translate: TranslateService, private translate: TranslateService,
@ -90,9 +88,8 @@ export class EventTableConfig extends EntityTableConfig<Event, TimePageLink> {
private viewContainerRef: ViewContainerRef, private viewContainerRef: ViewContainerRef,
private cd: ChangeDetectorRef, private cd: ChangeDetectorRef,
private nodeScriptTestService: NodeScriptTestService, private nodeScriptTestService: NodeScriptTestService,
private isRuleNodeDebugModeEnabled: boolean, public testButtonLabel?: string,
private editingRuleNodeHasScript: boolean, private debugEventSelected?: EventEmitter<DebugRuleNodeEventBody>) {
private rulenodeClazz: string) {
super(); super();
this.loadDataOnInit = false; this.loadDataOnInit = false;
this.tableTitle = ''; this.tableTitle = '';
@ -128,6 +125,7 @@ export class EventTableConfig extends EntityTableConfig<Event, TimePageLink> {
this.defaultSortOrder = {property: 'createdTime', direction: Direction.DESC}; this.defaultSortOrder = {property: 'createdTime', direction: Direction.DESC};
this.updateColumns(); this.updateColumns();
this.updateCellAction();
this.updateFilterColumns(); this.updateFilterColumns();
this.headerActionDescriptors.push({ this.headerActionDescriptors.push({
@ -325,18 +323,6 @@ export class EventTableConfig extends EntityTableConfig<Event, TimePageLink> {
onAction: ($event, entity) => this.showContent($event, entity.body.error, onAction: ($event, entity) => this.showContent($event, entity.body.error,
'event.error') 'event.error')
}, },
'48px'),
new EntityActionTableColumn<Event>('test', '',
{
name: this.translate.instant('rulenode.test-function',
{function: this.translate.instant(ruleNodeClazzFunctionNameTranslations[this.rulenodeClazz])}),
icon: 'bug_report',
isEnabled: (entity) => this.isRuleNodeDebugModeEnabled && entity.body.type === 'IN' &&
this.editingRuleNodeHasScript,
onAction: ($event, entity) => {
this.debugEventSelectedSubject.next(entity.body);
}
},
'48px') '48px')
); );
break; break;
@ -369,6 +355,25 @@ export class EventTableConfig extends EntityTableConfig<Event, TimePageLink> {
} }
} }
updateCellAction() {
this.cellActionDescriptors = [];
switch (this.eventType) {
case DebugEventType.DEBUG_RULE_NODE:
if (this.testButtonLabel) {
this.cellActionDescriptors.push({
name: this.translate.instant('rulenode.test-with-this-message', {test: this.testButtonLabel}),
icon: 'bug_report',
isEnabled: (entity) => entity.body.type === 'IN',
onAction: ($event, entity) => {
this.debugEventSelected.next(entity.body);
}
});
}
break;
}
this.getTable()?.cellActionDescriptorsUpdated();
}
showContent($event: MouseEvent, content: string, title: string, contentType: ContentType = null, sortKeys = false): void { showContent($event: MouseEvent, content: string, title: string, contentType: ContentType = null, sortKeys = false): void {
if ($event) { if ($event) {
$event.stopPropagation(); $event.stopPropagation();

36
ui-ngx/src/app/modules/home/components/event/event-table.component.ts

@ -36,6 +36,7 @@ import { DebugEventType, DebugRuleNodeEventBody, EventType } from '@shared/model
import { Overlay } from '@angular/cdk/overlay'; import { Overlay } from '@angular/cdk/overlay';
import { Subscription } from 'rxjs'; import { Subscription } from 'rxjs';
import { NodeScriptTestService } from '@core/services/script/node-script-test.service'; import { NodeScriptTestService } from '@core/services/script/node-script-test.service';
import { isNotEmptyStr } from '@core/utils';
@Component({ @Component({
selector: 'tb-event-table', selector: 'tb-event-table',
@ -60,6 +61,10 @@ export class EventTableComponent implements OnInit, AfterViewInit, OnDestroy {
dirtyValue = false; dirtyValue = false;
entityIdValue: EntityId; entityIdValue: EntityId;
get active(): boolean {
return this.activeValue;
}
@Input() @Input()
set active(active: boolean) { set active(active: boolean) {
if (this.activeValue !== active) { if (this.activeValue !== active) {
@ -84,14 +89,24 @@ export class EventTableComponent implements OnInit, AfterViewInit, OnDestroy {
} }
} }
@Input() private ruleNodeTestButtonLabelValue: string;
isRuleNodeDebugModeEnabled: boolean;
@Input() get ruleNodeTestButtonLabel(): string {
editingRuleNodeHasScript: boolean; return this.ruleNodeTestButtonLabelValue;
}
@Input() @Input()
rulenodeClazz: string; set ruleNodeTestButtonLabel(value: string) {
if (isNotEmptyStr(value)) {
this.ruleNodeTestButtonLabelValue = value;
} else {
this.ruleNodeTestButtonLabelValue = '';
}
if (this.eventTableConfig) {
this.eventTableConfig.testButtonLabel = this.ruleNodeTestButtonLabel;
this.eventTableConfig.updateCellAction();
}
}
@Output() @Output()
debugEventSelected = new EventEmitter<DebugRuleNodeEventBody>(null); debugEventSelected = new EventEmitter<DebugRuleNodeEventBody>(null);
@ -130,16 +145,9 @@ export class EventTableComponent implements OnInit, AfterViewInit, OnDestroy {
this.viewContainerRef, this.viewContainerRef,
this.cd, this.cd,
this.nodeScriptTestService, this.nodeScriptTestService,
this.isRuleNodeDebugModeEnabled, this.ruleNodeTestButtonLabel,
this.editingRuleNodeHasScript, this.debugEventSelected
this.rulenodeClazz
); );
this.eventTableConfig.debugEventSelectedSubject.subscribe((debugEventBody: DebugRuleNodeEventBody) => {
if (debugEventBody) {
this.debugEventSelected.emit(debugEventBody);
}
})
} }
ngAfterViewInit() { ngAfterViewInit() {

1
ui-ngx/src/app/modules/home/models/entity/entity-table-component.models.ts

@ -80,6 +80,7 @@ export interface IEntitiesTableComponent {
exitFilterMode(): void; exitFilterMode(): void;
resetSortAndFilter(update?: boolean, preserveTimewindow?: boolean): void; resetSortAndFilter(update?: boolean, preserveTimewindow?: boolean): void;
columnsUpdated(resetData?: boolean): void; columnsUpdated(resetData?: boolean): void;
cellActionDescriptorsUpdated(): void;
headerCellStyle(column: EntityColumn<BaseData<HasId>>): any; headerCellStyle(column: EntityColumn<BaseData<HasId>>): any;
clearCellCache(col: number, row: number): void; clearCellCache(col: number, row: number): void;
cellContent(entity: BaseData<HasId>, column: EntityColumn<BaseData<HasId>>, row: number): any; cellContent(entity: BaseData<HasId>, column: EntityColumn<BaseData<HasId>>, row: number): any;

25
ui-ngx/src/app/modules/home/pages/rulechain/rule-node-config.component.ts

@ -18,14 +18,22 @@ import {
AfterViewInit, AfterViewInit,
Component, Component,
ComponentRef, ComponentRef,
EventEmitter,
forwardRef, forwardRef,
Input, Input,
OnDestroy, OnDestroy,
OnInit, OnInit,
Output,
ViewChild, ViewChild,
ViewContainerRef ViewContainerRef
} from '@angular/core'; } from '@angular/core';
import { ControlValueAccessor, UntypedFormBuilder, UntypedFormGroup, NG_VALUE_ACCESSOR, Validators } from '@angular/forms'; import {
ControlValueAccessor,
NG_VALUE_ACCESSOR,
UntypedFormBuilder,
UntypedFormGroup,
Validators
} from '@angular/forms';
import { import {
IRuleNodeConfigurationComponent, IRuleNodeConfigurationComponent,
RuleNodeConfiguration, RuleNodeConfiguration,
@ -38,7 +46,6 @@ import { TranslateService } from '@ngx-translate/core';
import { JsonObjectEditComponent } from '@shared/components/json-object-edit.component'; import { JsonObjectEditComponent } from '@shared/components/json-object-edit.component';
import { deepClone } from '@core/utils'; import { deepClone } from '@core/utils';
import { RuleChainType } from '@shared/models/rule-chain.models'; import { RuleChainType } from '@shared/models/rule-chain.models';
import { DebugRuleNodeEventBody } from '@shared/models/event.models';
@Component({ @Component({
selector: 'tb-rule-node-config', selector: 'tb-rule-node-config',
@ -77,6 +84,9 @@ export class RuleNodeConfigComponent implements ControlValueAccessor, OnInit, On
@Input() @Input()
ruleChainType: RuleChainType; ruleChainType: RuleChainType;
@Output()
initRuleNode = new EventEmitter<void>();
nodeDefinitionValue: RuleNodeDefinition; nodeDefinitionValue: RuleNodeDefinition;
@Input() @Input()
@ -86,6 +96,7 @@ export class RuleNodeConfigComponent implements ControlValueAccessor, OnInit, On
if (this.nodeDefinitionValue) { if (this.nodeDefinitionValue) {
this.validateDefinedDirective(); this.validateDefinedDirective();
} }
setTimeout(() => this.initRuleNode.emit());
} }
} }
@ -93,21 +104,15 @@ export class RuleNodeConfigComponent implements ControlValueAccessor, OnInit, On
return this.nodeDefinitionValue; return this.nodeDefinitionValue;
} }
@Input()
set debugEventBody(debugEventBody: DebugRuleNodeEventBody) {
if (debugEventBody) {
this.definedConfigComponent?.testScript(debugEventBody);
}
}
definedDirectiveError: string; definedDirectiveError: string;
ruleNodeConfigFormGroup: UntypedFormGroup; ruleNodeConfigFormGroup: UntypedFormGroup;
changeSubscription: Subscription; changeSubscription: Subscription;
definedConfigComponent: IRuleNodeConfigurationComponent;
private definedConfigComponentRef: ComponentRef<IRuleNodeConfigurationComponent>; private definedConfigComponentRef: ComponentRef<IRuleNodeConfigurationComponent>;
private definedConfigComponent: IRuleNodeConfigurationComponent;
private configuration: RuleNodeConfiguration; private configuration: RuleNodeConfiguration;

2
ui-ngx/src/app/modules/home/pages/rulechain/rule-node-details.component.html

@ -51,7 +51,7 @@
[ruleChainId]="ruleChainId" [ruleChainId]="ruleChainId"
[ruleChainType]="ruleChainType" [ruleChainType]="ruleChainType"
[nodeDefinition]="ruleNode.component.configurationDescriptor.nodeDefinition" [nodeDefinition]="ruleNode.component.configurationDescriptor.nodeDefinition"
[debugEventBody]="debugEventBody"> (initRuleNode)="initRuleNode.emit($event)">
</tb-rule-node-config> </tb-rule-node-config>
<div formGroupName="additionalInfo" fxLayout="column" class="description-block"> <div formGroupName="additionalInfo" fxLayout="column" class="description-block">
<mat-form-field class="mat-block"> <mat-form-field class="mat-block">

7
ui-ngx/src/app/modules/home/pages/rulechain/rule-node-details.component.ts

@ -14,7 +14,7 @@
/// limitations under the License. /// limitations under the License.
/// ///
import { Component, Input, OnChanges, OnInit, SimpleChanges, ViewChild } from '@angular/core'; import { Component, EventEmitter, Input, OnChanges, OnInit, Output, SimpleChanges, ViewChild } from '@angular/core';
import { PageComponent } from '@shared/components/page.component'; import { PageComponent } from '@shared/components/page.component';
import { Store } from '@ngrx/store'; import { Store } from '@ngrx/store';
import { AppState } from '@core/core.state'; import { AppState } from '@core/core.state';
@ -27,7 +27,6 @@ import { RuleNodeConfigComponent } from './rule-node-config.component';
import { Router } from '@angular/router'; import { Router } from '@angular/router';
import { RuleChainType } from '@app/shared/models/rule-chain.models'; import { RuleChainType } from '@app/shared/models/rule-chain.models';
import { ComponentClusteringMode } from '@shared/models/component-descriptor.models'; import { ComponentClusteringMode } from '@shared/models/component-descriptor.models';
import { DebugRuleNodeEventBody } from '@shared/models/event.models';
@Component({ @Component({
selector: 'tb-rule-node', selector: 'tb-rule-node',
@ -56,8 +55,8 @@ export class RuleNodeDetailsComponent extends PageComponent implements OnInit, O
@Input() @Input()
isAdd = false; isAdd = false;
@Input() @Output()
debugEventBody: DebugRuleNodeEventBody; initRuleNode = new EventEmitter<void>();
ruleNodeType = RuleNodeType; ruleNodeType = RuleNodeType;
entityType = EntityType; entityType = EntityType;

9
ui-ngx/src/app/modules/home/pages/rulechain/rulechain-page.component.html

@ -100,8 +100,7 @@
(closeDetails)="onEditRuleNodeClosed()" (closeDetails)="onEditRuleNodeClosed()"
(toggleDetailsEditMode)="onRevertRuleNodeEdit()" (toggleDetailsEditMode)="onRevertRuleNodeEdit()"
(applyDetails)="saveRuleNode()" (applyDetails)="saveRuleNode()"
[theForm]="tbRuleNode.ruleNodeFormGroup" [theForm]="tbRuleNode.ruleNodeFormGroup">
(switchToFirstTab)="onSwitchToFirstTab()">
<div class="details-buttons"> <div class="details-buttons">
<div [tb-help]="helpLinkIdForRuleNodeType()"></div> <div [tb-help]="helpLinkIdForRuleNodeType()"></div>
</div> </div>
@ -113,7 +112,7 @@
[ruleChainType]="ruleChainType" [ruleChainType]="ruleChainType"
[isEdit]="true" [isEdit]="true"
[isReadOnly]="false" [isReadOnly]="false"
[debugEventBody]="debugEventBody"> (initRuleNode)="onRuleNodeInit()">
</tb-rule-node> </tb-rule-node>
</mat-tab> </mat-tab>
<mat-tab *ngIf="editingRuleNode.ruleNodeId" label="{{ 'rulenode.events' | translate }}" #eventsTab="matTab"> <mat-tab *ngIf="editingRuleNode.ruleNodeId" label="{{ 'rulenode.events' | translate }}" #eventsTab="matTab">
@ -122,9 +121,7 @@
[active]="eventsTab.isActive" [active]="eventsTab.isActive"
[tenantId]="ruleChain.tenantId.id" [tenantId]="ruleChain.tenantId.id"
[entityId]="editingRuleNode.ruleNodeId" [entityId]="editingRuleNode.ruleNodeId"
[isRuleNodeDebugModeEnabled]="editingRuleNode?.debugMode" [ruleNodeTestButtonLabel]="ruleNodeTestButtonLabel"
[editingRuleNodeHasScript]="editingRuleNodeHasScript"
[rulenodeClazz]="editingRuleNode.component.clazz"
(debugEventSelected)="onDebugEventSelected($event)"> (debugEventSelected)="onDebugEventSelected($event)">
</tb-event-table> </tb-event-table>
</mat-tab> </mat-tab>

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

@ -153,8 +153,7 @@ export class RuleChainPageComponent extends PageComponent
editingRuleNodeAllowCustomLabels = false; editingRuleNodeAllowCustomLabels = false;
editingRuleNodeLinkLabels: {[label: string]: LinkLabel}; editingRuleNodeLinkLabels: {[label: string]: LinkLabel};
editingRuleNodeSourceRuleChainId: string; editingRuleNodeSourceRuleChainId: string;
debugEventBody: DebugRuleNodeEventBody; ruleNodeTestButtonLabel: string;
editingRuleNodeHasScript: boolean = false;
@ViewChild('tbRuleNode') ruleNodeComponent: RuleNodeDetailsComponent; @ViewChild('tbRuleNode') ruleNodeComponent: RuleNodeDetailsComponent;
@ViewChild('tbRuleNodeLink') ruleNodeLinkComponent: RuleNodeLinkComponent; @ViewChild('tbRuleNodeLink') ruleNodeLinkComponent: RuleNodeLinkComponent;
@ -1112,7 +1111,6 @@ export class RuleChainPageComponent extends PageComponent
this.isEditingRuleNode = true; this.isEditingRuleNode = true;
this.editingRuleNodeIndex = this.ruleChainModel.nodes.indexOf(node); this.editingRuleNodeIndex = this.ruleChainModel.nodes.indexOf(node);
this.editingRuleNode = deepClone(node, ['component']); this.editingRuleNode = deepClone(node, ['component']);
this.editingRuleNodeHasScript = this.editingRuleNode.configuration.hasOwnProperty('scriptLang');
setTimeout(() => { setTimeout(() => {
this.ruleNodeComponent.ruleNodeFormGroup.markAsPristine(); this.ruleNodeComponent.ruleNodeFormGroup.markAsPristine();
}, 0); }, 0);
@ -1261,7 +1259,6 @@ export class RuleChainPageComponent extends PageComponent
onEditRuleNodeClosed() { onEditRuleNodeClosed() {
this.editingRuleNode = null; this.editingRuleNode = null;
this.isEditingRuleNode = false; this.isEditingRuleNode = false;
this.debugEventBody = null;
} }
onEditRuleNodeLinkClosed() { onEditRuleNodeLinkClosed() {
@ -1282,13 +1279,25 @@ export class RuleChainPageComponent extends PageComponent
} }
onDebugEventSelected(debugEventBody: DebugRuleNodeEventBody) { onDebugEventSelected(debugEventBody: DebugRuleNodeEventBody) {
if (debugEventBody) { if (this.ruleNodeComponent.ruleNodeConfigComponent.useDefinedDirective() &&
this.debugEventBody = debugEventBody; this.ruleNodeComponent.ruleNodeConfigComponent.definedConfigComponent.getSupportTestFunction() &&
} this.ruleNodeComponent.ruleNodeConfigComponent.definedConfigComponent.testScript$) {
this.ruleNodeComponent.ruleNodeConfigComponent.definedConfigComponent.testScript$(debugEventBody)
.subscribe((value) => {
if (value) {
this.selectedRuleNodeTabIndex = 0;
}
})
}
} }
onSwitchToFirstTab() { onRuleNodeInit() {
this.selectedRuleNodeTabIndex = 0; if (this.ruleNodeComponent.ruleNodeConfigComponent.useDefinedDirective() &&
this.ruleNodeComponent.ruleNodeConfigComponent.definedConfigComponent.getSupportTestFunction()) {
this.ruleNodeTestButtonLabel = this.ruleNodeComponent.ruleNodeConfigComponent.definedConfigComponent.getTestButtonLabel();
} else {
this.ruleNodeTestButtonLabel = '';
}
} }
saveRuleNode() { saveRuleNode() {

48
ui-ngx/src/app/shared/models/rule-node.models.ts

@ -27,6 +27,7 @@ import { AppState } from '@core/core.state';
import { AbstractControl, UntypedFormGroup } from '@angular/forms'; import { AbstractControl, UntypedFormGroup } from '@angular/forms';
import { RuleChainType } from '@shared/models/rule-chain.models'; import { RuleChainType } from '@shared/models/rule-chain.models';
import { DebugRuleNodeEventBody } from '@shared/models/event.models'; import { DebugRuleNodeEventBody } from '@shared/models/event.models';
import { TranslateService } from '@ngx-translate/core';
export interface RuleNodeConfiguration { export interface RuleNodeConfiguration {
[key: string]: any; [key: string]: any;
@ -76,7 +77,9 @@ export interface IRuleNodeConfigurationComponent {
configuration: RuleNodeConfiguration; configuration: RuleNodeConfiguration;
configurationChanged: Observable<RuleNodeConfiguration>; configurationChanged: Observable<RuleNodeConfiguration>;
validate(); validate();
testScript? (debugEventBody: DebugRuleNodeEventBody); getSupportTestFunction(): boolean;
getTestButtonLabel? (): string;
testScript$? (debugEventBody?: DebugRuleNodeEventBody): Observable<string>;
[key: string]: any; [key: string]: any;
} }
@ -112,7 +115,8 @@ export abstract class RuleNodeConfigurationComponent extends PageComponent imple
configurationChangedEmiter = new EventEmitter<RuleNodeConfiguration>(); configurationChangedEmiter = new EventEmitter<RuleNodeConfiguration>();
configurationChanged = this.configurationChangedEmiter.asObservable(); configurationChanged = this.configurationChangedEmiter.asObservable();
protected constructor(@Inject(Store) protected store: Store<AppState>) { protected constructor(@Inject(Store) protected store: Store<AppState>,
@Inject(TranslateService) protected translate: TranslateService) {
super(store); super(store);
} }
@ -130,6 +134,14 @@ export abstract class RuleNodeConfigurationComponent extends PageComponent imple
this.onValidate(); this.onValidate();
} }
getSupportTestFunction(): boolean {
return false;
}
getTestButtonLabel(): string {
return this.translate.instant('rulenode.test-script-function');
}
protected setupConfiguration(configuration: RuleNodeConfiguration) { protected setupConfiguration(configuration: RuleNodeConfiguration) {
this.onConfigurationSet(this.prepareInputConfig(configuration)); this.onConfigurationSet(this.prepareInputConfig(configuration));
this.updateValidators(false); this.updateValidators(false);
@ -429,22 +441,13 @@ export const messageTypeNames = new Map<MessageType, string>(
export const ruleChainNodeClazz = 'org.thingsboard.rule.engine.flow.TbRuleChainInputNode'; export const ruleChainNodeClazz = 'org.thingsboard.rule.engine.flow.TbRuleChainInputNode';
export const outputNodeClazz = 'org.thingsboard.rule.engine.flow.TbRuleChainOutputNode'; export const outputNodeClazz = 'org.thingsboard.rule.engine.flow.TbRuleChainOutputNode';
export enum RuleNodeClazz {
TbJsFilterNode = 'org.thingsboard.rule.engine.filter.TbJsFilterNode',
TbLogNode = 'org.thingsboard.rule.engine.action.TbLogNode',
TbJsSwitchNode = 'org.thingsboard.rule.engine.filter.TbJsSwitchNode',
TbClearAlarmNode = 'org.thingsboard.rule.engine.action.TbClearAlarmNode',
TbCreateAlarmNode = 'org.thingsboard.rule.engine.action.TbCreateAlarmNode',
TbTransformMsgNode = 'org.thingsboard.rule.engine.transform.TbTransformMsgNode',
TbMsgGeneratorNode = 'org.thingsboard.rule.engine.debug.TbMsgGeneratorNode'
}
const ruleNodeClazzHelpLinkMap = { const ruleNodeClazzHelpLinkMap = {
'org.thingsboard.rule.engine.filter.TbCheckRelationNode': 'ruleNodeCheckRelation', 'org.thingsboard.rule.engine.filter.TbCheckRelationNode': 'ruleNodeCheckRelation',
'org.thingsboard.rule.engine.filter.TbCheckMessageNode': 'ruleNodeCheckExistenceFields', 'org.thingsboard.rule.engine.filter.TbCheckMessageNode': 'ruleNodeCheckExistenceFields',
'org.thingsboard.rule.engine.geo.TbGpsGeofencingFilterNode': 'ruleNodeGpsGeofencingFilter', 'org.thingsboard.rule.engine.geo.TbGpsGeofencingFilterNode': 'ruleNodeGpsGeofencingFilter',
[RuleNodeClazz.TbJsFilterNode]: 'ruleNodeJsFilter', 'org.thingsboard.rule.engine.filter.TbJsFilterNode': 'ruleNodeJsFilter',
[RuleNodeClazz.TbJsSwitchNode]: 'ruleNodeJsSwitch', 'org.thingsboard.rule.engine.filter.TbJsSwitchNode': 'ruleNodeJsSwitch',
'org.thingsboard.rule.engine.filter.TbAssetTypeSwitchNode': 'ruleNodeAssetProfileSwitch', 'org.thingsboard.rule.engine.filter.TbAssetTypeSwitchNode': 'ruleNodeAssetProfileSwitch',
'org.thingsboard.rule.engine.filter.TbDeviceTypeSwitchNode': 'ruleNodeDeviceProfileSwitch', 'org.thingsboard.rule.engine.filter.TbDeviceTypeSwitchNode': 'ruleNodeDeviceProfileSwitch',
'org.thingsboard.rule.engine.filter.TbCheckAlarmStatusNode': 'ruleNodeCheckAlarmStatus', 'org.thingsboard.rule.engine.filter.TbCheckAlarmStatusNode': 'ruleNodeCheckAlarmStatus',
@ -463,18 +466,18 @@ const ruleNodeClazzHelpLinkMap = {
'org.thingsboard.rule.engine.metadata.TbGetTenantDetailsNode': 'ruleNodeTenantDetails', 'org.thingsboard.rule.engine.metadata.TbGetTenantDetailsNode': 'ruleNodeTenantDetails',
'org.thingsboard.rule.engine.metadata.CalculateDeltaNode': 'ruleNodeCalculateDelta', 'org.thingsboard.rule.engine.metadata.CalculateDeltaNode': 'ruleNodeCalculateDelta',
'org.thingsboard.rule.engine.transform.TbChangeOriginatorNode': 'ruleNodeChangeOriginator', 'org.thingsboard.rule.engine.transform.TbChangeOriginatorNode': 'ruleNodeChangeOriginator',
[RuleNodeClazz.TbTransformMsgNode]: 'ruleNodeTransformMsg', 'org.thingsboard.rule.engine.transform.TbTransformMsgNode': 'ruleNodeTransformMsg',
'org.thingsboard.rule.engine.mail.TbMsgToEmailNode': 'ruleNodeMsgToEmail', 'org.thingsboard.rule.engine.mail.TbMsgToEmailNode': 'ruleNodeMsgToEmail',
'org.thingsboard.rule.engine.action.TbAssignToCustomerNode': 'ruleNodeAssignToCustomer', 'org.thingsboard.rule.engine.action.TbAssignToCustomerNode': 'ruleNodeAssignToCustomer',
'org.thingsboard.rule.engine.action.TbUnassignFromCustomerNode': 'ruleNodeUnassignFromCustomer', 'org.thingsboard.rule.engine.action.TbUnassignFromCustomerNode': 'ruleNodeUnassignFromCustomer',
[RuleNodeClazz.TbClearAlarmNode]: 'ruleNodeClearAlarm', 'org.thingsboard.rule.engine.action.TbClearAlarmNode': 'ruleNodeClearAlarm',
[RuleNodeClazz.TbCreateAlarmNode]: 'ruleNodeCreateAlarm', 'org.thingsboard.rule.engine.action.TbCreateAlarmNode': 'ruleNodeCreateAlarm',
'org.thingsboard.rule.engine.action.TbCreateRelationNode': 'ruleNodeCreateRelation', 'org.thingsboard.rule.engine.action.TbCreateRelationNode': 'ruleNodeCreateRelation',
'org.thingsboard.rule.engine.action.TbDeleteRelationNode': 'ruleNodeDeleteRelation', 'org.thingsboard.rule.engine.action.TbDeleteRelationNode': 'ruleNodeDeleteRelation',
'org.thingsboard.rule.engine.delay.TbMsgDelayNode': 'ruleNodeMsgDelay', 'org.thingsboard.rule.engine.delay.TbMsgDelayNode': 'ruleNodeMsgDelay',
[RuleNodeClazz.TbMsgGeneratorNode]: 'ruleNodeMsgGenerator', 'org.thingsboard.rule.engine.debug.TbMsgGeneratorNode': 'ruleNodeMsgGenerator',
'org.thingsboard.rule.engine.geo.TbGpsGeofencingActionNode': 'ruleNodeGpsGeofencingEvents', 'org.thingsboard.rule.engine.geo.TbGpsGeofencingActionNode': 'ruleNodeGpsGeofencingEvents',
[RuleNodeClazz.TbLogNode]: 'ruleNodeLog', 'org.thingsboard.rule.engine.action.TbLogNode': 'ruleNodeLog',
'org.thingsboard.rule.engine.rpc.TbSendRPCReplyNode': 'ruleNodeRpcCallReply', 'org.thingsboard.rule.engine.rpc.TbSendRPCReplyNode': 'ruleNodeRpcCallReply',
'org.thingsboard.rule.engine.rpc.TbSendRPCRequestNode': 'ruleNodeRpcCallRequest', 'org.thingsboard.rule.engine.rpc.TbSendRPCRequestNode': 'ruleNodeRpcCallRequest',
'org.thingsboard.rule.engine.telemetry.TbMsgAttributesNode': 'ruleNodeSaveAttributes', 'org.thingsboard.rule.engine.telemetry.TbMsgAttributesNode': 'ruleNodeSaveAttributes',
@ -511,12 +514,3 @@ export function getRuleNodeHelpLink(component: RuleNodeComponentDescriptor): str
return 'ruleEngine'; return 'ruleEngine';
} }
export const ruleNodeClazzFunctionNameTranslations = {
[RuleNodeClazz.TbJsFilterNode]: 'rulenode.function-name.filter',
[RuleNodeClazz.TbLogNode]: 'rulenode.function-name.to-string',
[RuleNodeClazz.TbJsSwitchNode]: 'rulenode.function-name.switch',
[RuleNodeClazz.TbClearAlarmNode]: 'rulenode.function-name.details',
[RuleNodeClazz.TbCreateAlarmNode]: 'rulenode.function-name.details',
[RuleNodeClazz.TbTransformMsgNode]: 'rulenode.function-name.transform',
[RuleNodeClazz.TbMsgGeneratorNode]: 'rulenode.function-name.generate'
}

10
ui-ngx/src/assets/locale/locale.constant-en_US.json

@ -3467,15 +3467,7 @@
"test": "Test", "test": "Test",
"help": "Help", "help": "Help",
"reset-debug-mode": "Reset debug mode in all nodes", "reset-debug-mode": "Reset debug mode in all nodes",
"test-function": "Test '{{function}}' function with this message", "test-with-this-message": "{{test}} with this message"
"function-name": {
"filter": "Filter",
"to-string": "ToString",
"details": "Details",
"generate": "Generate",
"switch": "Switch",
"transform": "Transform"
}
}, },
"timezone": { "timezone": {
"timezone": "Timezone", "timezone": "Timezone",

Loading…
Cancel
Save