Browse Source

Refactoring

pull/8836/head
rusikv 3 years ago
parent
commit
e557a2d2c4
  1. 5
      ui-ngx/src/app/modules/home/components/details-panel.component.ts
  2. 2
      ui-ngx/src/app/modules/home/components/event/event-table-config.ts
  3. 16
      ui-ngx/src/app/modules/home/pages/rulechain/rule-node-config.component.ts
  4. 3
      ui-ngx/src/app/modules/home/pages/rulechain/rule-node-details.component.html
  5. 3
      ui-ngx/src/app/modules/home/pages/rulechain/rule-node-details.component.ts
  6. 3
      ui-ngx/src/app/modules/home/pages/rulechain/rulechain-page.component.html
  7. 31
      ui-ngx/src/app/modules/home/pages/rulechain/rulechain-page.component.ts
  8. 20
      ui-ngx/src/app/shared/models/rule-node.models.ts

5
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());
}
}
}

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

@ -359,7 +359,7 @@ export class EventTableConfig extends EntityTableConfig<Event, TimePageLink> {
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) => {

16
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<void>();
@Output()
changeScript = new EventEmitter<void>();
nodeDefinitionValue: RuleNodeDefinition;
@Input()
@ -110,6 +113,8 @@ export class RuleNodeConfigComponent implements ControlValueAccessor, OnInit, On
changeSubscription: Subscription;
changeScriptSubscription: Subscription;
definedConfigComponent: IRuleNodeConfigurationComponent;
private definedConfigComponentRef: ComponentRef<IRuleNodeConfigurationComponent>;
@ -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());
}
}
}

3
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)">
</tb-rule-node-config>
<div formGroupName="additionalInfo" fxLayout="column" class="description-block">
<mat-form-field class="mat-block">

3
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<void>();
@Output()
changeScript = new EventEmitter<void>();
ruleNodeType = RuleNodeType;
entityType = EntityType;

3
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()">
</tb-rule-node>
</mat-tab>
<mat-tab *ngIf="editingRuleNode.ruleNodeId" label="{{ 'rulenode.events' | translate }}" #eventsTab="matTab">

31
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() {

20
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<void>;
ruleChainType: RuleChainType;
configuration: RuleNodeConfiguration;
configurationChanged: Observable<RuleNodeConfiguration>;
validate();
getSupportTestFunction(): boolean;
getTestButtonLabel? (): string;
testScript$? (debugEventBody?: DebugRuleNodeEventBody): Observable<string>;
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<RuleNodeConfiguration>();
configurationChanged = this.configurationChangedEmiter.asObservable();
protected constructor(@Inject(Store) protected store: Store<AppState>,
@Inject(TranslateService) protected translate: TranslateService) {
protected constructor(@Inject(Store) protected store: Store<AppState>) {
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);

Loading…
Cancel
Save