From ae6e889a464bfafbff9f301da7a654bfe8bb56d3 Mon Sep 17 00:00:00 2001 From: Artem Babak Date: Tue, 27 Oct 2020 09:19:42 +0200 Subject: [PATCH] Edge and Core rulechains refactored types --- .../app/core/http/component-descriptor.service.ts | 3 ++- ui-ngx/src/app/core/http/rule-chain.service.ts | 6 +++--- .../pages/rulechain/rulechain-routing.module.ts | 12 ++++++++---- .../rulechain/rulechains-table-config.resolver.ts | 2 +- ui-ngx/src/app/shared/models/rule-chain.models.ts | 13 +++++-------- 5 files changed, 19 insertions(+), 17 deletions(-) diff --git a/ui-ngx/src/app/core/http/component-descriptor.service.ts b/ui-ngx/src/app/core/http/component-descriptor.service.ts index 875e0d5037..3ec35cad81 100644 --- a/ui-ngx/src/app/core/http/component-descriptor.service.ts +++ b/ui-ngx/src/app/core/http/component-descriptor.service.ts @@ -21,6 +21,7 @@ import { defaultHttpOptionsFromConfig, RequestConfig } from '@core/http/http-uti import { Observable, of } from 'rxjs'; import { map } from 'rxjs/operators'; import { RuleNodeType } from '@shared/models/rule-node.models'; +import { RuleChainType } from "@shared/models/rule-chain.models"; @Injectable({ providedIn: 'root' @@ -53,7 +54,7 @@ export class ComponentDescriptorService { } } - public getComponentDescriptorsByTypes(componentTypes: Array, ruleChainType: string, config?: RequestConfig): Observable> { + public getComponentDescriptorsByTypes(componentTypes: Array, ruleChainType: RuleChainType, config?: RequestConfig): Observable> { let result: ComponentDescriptor[] = []; for (let i = componentTypes.length - 1; i >= 0; i--) { const componentType = componentTypes[i]; diff --git a/ui-ngx/src/app/core/http/rule-chain.service.ts b/ui-ngx/src/app/core/http/rule-chain.service.ts index 7bdbead5f3..1a6c011a4c 100644 --- a/ui-ngx/src/app/core/http/rule-chain.service.ts +++ b/ui-ngx/src/app/core/http/rule-chain.service.ts @@ -25,7 +25,7 @@ import { RuleChain, RuleChainConnectionInfo, RuleChainMetaData, - ruleChainNodeComponent, + ruleChainNodeComponent, RuleChainType, ruleNodeTypeComponentTypes, unknownNodeComponent } from '@shared/models/rule-chain.models'; @@ -116,7 +116,7 @@ export class RuleChainService { ); } - public getRuleNodeComponents(ruleNodeConfigResourcesModulesMap: {[key: string]: any}, ruleChainType: string, config?: RequestConfig): + public getRuleNodeComponents(ruleNodeConfigResourcesModulesMap: {[key: string]: any}, ruleChainType: RuleChainType, config?: RequestConfig): Observable> { if (this.ruleNodeComponents) { return of(this.ruleNodeComponents); @@ -204,7 +204,7 @@ export class RuleChainService { } } - private loadRuleNodeComponents(ruleChainType: string, config?: RequestConfig): Observable> { + private loadRuleNodeComponents(ruleChainType: RuleChainType, config?: RequestConfig): Observable> { return this.componentDescriptorService.getComponentDescriptorsByTypes(ruleNodeTypeComponentTypes, ruleChainType, config).pipe( map((components) => { const ruleNodeComponents: RuleNodeComponentDescriptor[] = []; diff --git a/ui-ngx/src/app/modules/home/pages/rulechain/rulechain-routing.module.ts b/ui-ngx/src/app/modules/home/pages/rulechain/rulechain-routing.module.ts index e213f2cc7b..3be2010445 100644 --- a/ui-ngx/src/app/modules/home/pages/rulechain/rulechain-routing.module.ts +++ b/ui-ngx/src/app/modules/home/pages/rulechain/rulechain-routing.module.ts @@ -31,7 +31,12 @@ import { Authority } from '@shared/models/authority.enum'; import { RuleChainsTableConfigResolver } from '@modules/home/pages/rulechain/rulechains-table-config.resolver'; import { Observable } from 'rxjs'; import { BreadCrumbConfig, BreadCrumbLabelFunction } from '@shared/components/breadcrumb'; -import { ResolvedRuleChainMetaData, RuleChain, ruleChainType} from '@shared/models/rule-chain.models'; +import { + ResolvedRuleChainMetaData, + RuleChain, + RuleChainType, + ruleChainType, +} from '@shared/models/rule-chain.models'; import { RuleChainService } from '@core/http/rule-chain.service'; import { RuleChainPageComponent } from '@home/pages/rulechain/rulechain-page.component'; import { RuleNodeComponentDescriptor } from '@shared/models/rule-node.models'; @@ -71,7 +76,7 @@ export class RuleNodeComponentsResolver implements Resolve> { - const ruleChainType = route.data.type; + const ruleChainType: RuleChainType = route.data.type; return this.ruleChainService.getRuleNodeComponents(this.modulesMap, ruleChainType); } } @@ -228,8 +233,7 @@ const routes: Routes = [ } as BreadCrumbConfig, auth: [Authority.TENANT_ADMIN], title: 'rulechain.rulechain', - import: true, - type: ruleChainType.edge + import: true }, resolve: { ruleNodeComponents: RuleNodeComponentsResolver diff --git a/ui-ngx/src/app/modules/home/pages/rulechain/rulechains-table-config.resolver.ts b/ui-ngx/src/app/modules/home/pages/rulechain/rulechains-table-config.resolver.ts index aca71f6ed5..d67ab7843d 100644 --- a/ui-ngx/src/app/modules/home/pages/rulechain/rulechains-table-config.resolver.ts +++ b/ui-ngx/src/app/modules/home/pages/rulechain/rulechains-table-config.resolver.ts @@ -29,7 +29,7 @@ import { TranslateService } from '@ngx-translate/core'; import { DatePipe } from '@angular/common'; import { EntityType, entityTypeResources, entityTypeTranslations } from '@shared/models/entity-type.models'; import { EntityAction } from '@home/models/entity/entity-component.models'; -import { RuleChain, ruleChainType} from '@shared/models/rule-chain.models'; +import { RuleChain, ruleChainType } from '@shared/models/rule-chain.models'; import { RuleChainService } from '@core/http/rule-chain.service'; import { RuleChainComponent } from '@modules/home/pages/rulechain/rulechain.component'; import { DialogService } from '@core/services/dialog.service'; diff --git a/ui-ngx/src/app/shared/models/rule-chain.models.ts b/ui-ngx/src/app/shared/models/rule-chain.models.ts index dac7b772d2..5fbd94d0ed 100644 --- a/ui-ngx/src/app/shared/models/rule-chain.models.ts +++ b/ui-ngx/src/app/shared/models/rule-chain.models.ts @@ -64,11 +64,6 @@ export interface RuleChainConnectionInfo { type: string; } -export interface RuleChainType { - core: string; - edge: string; -} - export const ruleNodeTypeComponentTypes: ComponentType[] = [ ComponentType.FILTER, @@ -118,7 +113,9 @@ export const inputNodeComponent: RuleNodeComponentDescriptor = { clazz: 'tb.internal.Input' }; -export const ruleChainType: RuleChainType = { - core: 'CORE', - edge: 'EDGE' +export declare type RuleChainType = 'CORE' | 'EDGE'; + +export enum ruleChainType { + core = 'CORE', + edge = 'EDGE' }