From e557a2d2c4cc779135ff4946d79845d9762c633b Mon Sep 17 00:00:00 2001 From: rusikv Date: Fri, 14 Jul 2023 18:59:20 +0300 Subject: [PATCH] Refactoring --- .../components/details-panel.component.ts | 5 ++- .../components/event/event-table-config.ts | 2 +- .../rulechain/rule-node-config.component.ts | 16 ++++++++++ .../rule-node-details.component.html | 3 +- .../rulechain/rule-node-details.component.ts | 3 ++ .../rulechain/rulechain-page.component.html | 3 +- .../rulechain/rulechain-page.component.ts | 31 +++++++++---------- .../src/app/shared/models/rule-node.models.ts | 20 +++++------- 8 files changed, 48 insertions(+), 35 deletions(-) diff --git a/ui-ngx/src/app/modules/home/components/details-panel.component.ts b/ui-ngx/src/app/modules/home/components/details-panel.component.ts index 66facf08d4..b2f8a059f3 100644 --- a/ui-ngx/src/app/modules/home/components/details-panel.component.ts +++ b/ui-ngx/src/app/modules/home/components/details-panel.component.ts @@ -15,6 +15,7 @@ /// import { + ChangeDetectionStrategy, ChangeDetectorRef, Component, EventEmitter, @@ -55,9 +56,7 @@ export class DetailsPanelComponent extends PageComponent implements OnDestroy { } this.theFormValue = value; if (this.theFormValue !== null) { - this.formSubscription = this.theFormValue.valueChanges.subscribe(() => { - this.cd.detectChanges() - }); + this.formSubscription = this.theFormValue.valueChanges.subscribe(() => this.cd.detectChanges()); } } } diff --git a/ui-ngx/src/app/modules/home/components/event/event-table-config.ts b/ui-ngx/src/app/modules/home/components/event/event-table-config.ts index 565dbf14bf..4021d018ce 100644 --- a/ui-ngx/src/app/modules/home/components/event/event-table-config.ts +++ b/ui-ngx/src/app/modules/home/components/event/event-table-config.ts @@ -359,7 +359,7 @@ export class EventTableConfig extends EntityTableConfig { case DebugEventType.DEBUG_RULE_NODE: if (this.testButtonLabel) { this.cellActionDescriptors.push({ - name: this.translate.instant('rulenode.test-with-this-message', {test: this.testButtonLabel}), + name: this.translate.instant('rulenode.test-with-this-message', {test: this.translate.instant(this.testButtonLabel)}), icon: 'bug_report', isEnabled: (entity) => entity.body.type === 'IN', onAction: ($event, entity) => { diff --git a/ui-ngx/src/app/modules/home/pages/rulechain/rule-node-config.component.ts b/ui-ngx/src/app/modules/home/pages/rulechain/rule-node-config.component.ts index 6c19507301..3f3071221e 100644 --- a/ui-ngx/src/app/modules/home/pages/rulechain/rule-node-config.component.ts +++ b/ui-ngx/src/app/modules/home/pages/rulechain/rule-node-config.component.ts @@ -87,6 +87,9 @@ export class RuleNodeConfigComponent implements ControlValueAccessor, OnInit, On @Output() initRuleNode = new EventEmitter(); + @Output() + changeScript = new EventEmitter(); + nodeDefinitionValue: RuleNodeDefinition; @Input() @@ -110,6 +113,8 @@ export class RuleNodeConfigComponent implements ControlValueAccessor, OnInit, On changeSubscription: Subscription; + changeScriptSubscription: Subscription; + definedConfigComponent: IRuleNodeConfigurationComponent; private definedConfigComponentRef: ComponentRef; @@ -140,6 +145,14 @@ export class RuleNodeConfigComponent implements ControlValueAccessor, OnInit, On if (this.definedConfigComponentRef) { this.definedConfigComponentRef.destroy(); } + if (this.changeSubscription) { + this.changeSubscription.unsubscribe(); + this.changeSubscription = null; + } + if (this.changeScriptSubscription) { + this.changeScriptSubscription.unsubscribe(); + this.changeScriptSubscription = null; + } } ngAfterViewInit(): void { @@ -212,6 +225,9 @@ export class RuleNodeConfigComponent implements ControlValueAccessor, OnInit, On this.changeSubscription = this.definedConfigComponent.configurationChanged.subscribe((configuration) => { this.updateModel(configuration); }); + if (this.definedConfigComponent?.changeScript) { + this.changeScriptSubscription = this.definedConfigComponent.changeScript.subscribe(() => this.changeScript.emit()); + } } } diff --git a/ui-ngx/src/app/modules/home/pages/rulechain/rule-node-details.component.html b/ui-ngx/src/app/modules/home/pages/rulechain/rule-node-details.component.html index 2f925ded60..34aa8167e3 100644 --- a/ui-ngx/src/app/modules/home/pages/rulechain/rule-node-details.component.html +++ b/ui-ngx/src/app/modules/home/pages/rulechain/rule-node-details.component.html @@ -51,7 +51,8 @@ [ruleChainId]="ruleChainId" [ruleChainType]="ruleChainType" [nodeDefinition]="ruleNode.component.configurationDescriptor.nodeDefinition" - (initRuleNode)="initRuleNode.emit($event)"> + (initRuleNode)="initRuleNode.emit($event)" + (changeScript)="changeScript.emit($event)">
diff --git a/ui-ngx/src/app/modules/home/pages/rulechain/rule-node-details.component.ts b/ui-ngx/src/app/modules/home/pages/rulechain/rule-node-details.component.ts index 7b0f426c35..f1d6001c88 100644 --- a/ui-ngx/src/app/modules/home/pages/rulechain/rule-node-details.component.ts +++ b/ui-ngx/src/app/modules/home/pages/rulechain/rule-node-details.component.ts @@ -58,6 +58,9 @@ export class RuleNodeDetailsComponent extends PageComponent implements OnInit, O @Output() initRuleNode = new EventEmitter(); + @Output() + changeScript = new EventEmitter(); + ruleNodeType = RuleNodeType; entityType = EntityType; diff --git a/ui-ngx/src/app/modules/home/pages/rulechain/rulechain-page.component.html b/ui-ngx/src/app/modules/home/pages/rulechain/rulechain-page.component.html index ba91b45f16..5f5594cc1a 100644 --- a/ui-ngx/src/app/modules/home/pages/rulechain/rulechain-page.component.html +++ b/ui-ngx/src/app/modules/home/pages/rulechain/rulechain-page.component.html @@ -112,7 +112,8 @@ [ruleChainType]="ruleChainType" [isEdit]="true" [isReadOnly]="false" - (initRuleNode)="onRuleNodeInit()"> + (initRuleNode)="onRuleNodeInit()" + (changeScript)="switchToFirstTab()"> diff --git a/ui-ngx/src/app/modules/home/pages/rulechain/rulechain-page.component.ts b/ui-ngx/src/app/modules/home/pages/rulechain/rulechain-page.component.ts index d5ea093721..6b78d94ac7 100644 --- a/ui-ngx/src/app/modules/home/pages/rulechain/rulechain-page.component.ts +++ b/ui-ngx/src/app/modules/home/pages/rulechain/rulechain-page.component.ts @@ -1279,25 +1279,24 @@ export class RuleChainPageComponent extends PageComponent } onDebugEventSelected(debugEventBody: DebugRuleNodeEventBody) { - if (this.ruleNodeComponent.ruleNodeConfigComponent.useDefinedDirective() && - this.ruleNodeComponent.ruleNodeConfigComponent.definedConfigComponent.getSupportTestFunction() && - this.ruleNodeComponent.ruleNodeConfigComponent.definedConfigComponent.testScript$) { - this.ruleNodeComponent.ruleNodeConfigComponent.definedConfigComponent.testScript$(debugEventBody) - .subscribe((value) => { - if (value) { - this.selectedRuleNodeTabIndex = 0; - } - }) - } + const ruleNodeConfigComponent = this.ruleNodeComponent.ruleNodeConfigComponent; + const ruleNodeConfigDefinedComponent = ruleNodeConfigComponent.definedConfigComponent; + if (ruleNodeConfigComponent.useDefinedDirective() && ruleNodeConfigDefinedComponent.hasScript && ruleNodeConfigDefinedComponent.testScript) { + ruleNodeConfigDefinedComponent.testScript(debugEventBody); + } } onRuleNodeInit() { - if (this.ruleNodeComponent.ruleNodeConfigComponent.useDefinedDirective() && - this.ruleNodeComponent.ruleNodeConfigComponent.definedConfigComponent.getSupportTestFunction()) { - this.ruleNodeTestButtonLabel = this.ruleNodeComponent.ruleNodeConfigComponent.definedConfigComponent.getTestButtonLabel(); - } else { - this.ruleNodeTestButtonLabel = ''; - } + const ruleNodeConfigDefinedComponent = this.ruleNodeComponent.ruleNodeConfigComponent.definedConfigComponent; + if (this.ruleNodeComponent.ruleNodeConfigComponent.useDefinedDirective() && ruleNodeConfigDefinedComponent.hasScript) { + this.ruleNodeTestButtonLabel = ruleNodeConfigDefinedComponent.testScriptLabel; + } else { + this.ruleNodeTestButtonLabel = ''; + } + } + + switchToFirstTab() { + this.selectedRuleNodeTabIndex = 0; } saveRuleNode() { diff --git a/ui-ngx/src/app/shared/models/rule-node.models.ts b/ui-ngx/src/app/shared/models/rule-node.models.ts index dd427aaf09..2a7dedabec 100644 --- a/ui-ngx/src/app/shared/models/rule-node.models.ts +++ b/ui-ngx/src/app/shared/models/rule-node.models.ts @@ -73,13 +73,14 @@ export interface RuleNodeConfigurationDescriptor { export interface IRuleNodeConfigurationComponent { ruleNodeId: string; ruleChainId: string; + hasScript: boolean; + testScriptLabel?: string; + changeScript?: EventEmitter; ruleChainType: RuleChainType; configuration: RuleNodeConfiguration; configurationChanged: Observable; validate(); - getSupportTestFunction(): boolean; - getTestButtonLabel? (): string; - testScript$? (debugEventBody?: DebugRuleNodeEventBody): Observable; + testScript? (debugEventBody?: DebugRuleNodeEventBody); [key: string]: any; } @@ -92,6 +93,8 @@ export abstract class RuleNodeConfigurationComponent extends PageComponent imple ruleChainId: string; + hasScript: boolean = false; + ruleChainType: RuleChainType; configurationValue: RuleNodeConfiguration; @@ -115,8 +118,7 @@ export abstract class RuleNodeConfigurationComponent extends PageComponent imple configurationChangedEmiter = new EventEmitter(); configurationChanged = this.configurationChangedEmiter.asObservable(); - protected constructor(@Inject(Store) protected store: Store, - @Inject(TranslateService) protected translate: TranslateService) { + protected constructor(@Inject(Store) protected store: Store) { super(store); } @@ -134,14 +136,6 @@ export abstract class RuleNodeConfigurationComponent extends PageComponent imple this.onValidate(); } - getSupportTestFunction(): boolean { - return false; - } - - getTestButtonLabel(): string { - return this.translate.instant('rulenode.test-script-function'); - } - protected setupConfiguration(configuration: RuleNodeConfiguration) { this.onConfigurationSet(this.prepareInputConfig(configuration)); this.updateValidators(false);