Edge and Core rulechains refactored types

This commit is contained in:
Artem Babak 2020-10-27 09:19:42 +02:00
parent ac94a063ac
commit ae6e889a46
5 changed files with 19 additions and 17 deletions

View File

@ -21,6 +21,7 @@ import { defaultHttpOptionsFromConfig, RequestConfig } from '@core/http/http-uti
import { Observable, of } from 'rxjs'; import { Observable, of } from 'rxjs';
import { map } from 'rxjs/operators'; import { map } from 'rxjs/operators';
import { RuleNodeType } from '@shared/models/rule-node.models'; import { RuleNodeType } from '@shared/models/rule-node.models';
import { RuleChainType } from "@shared/models/rule-chain.models";
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
@ -53,7 +54,7 @@ export class ComponentDescriptorService {
} }
} }
public getComponentDescriptorsByTypes(componentTypes: Array<ComponentType>, ruleChainType: string, config?: RequestConfig): Observable<Array<ComponentDescriptor>> { public getComponentDescriptorsByTypes(componentTypes: Array<ComponentType>, ruleChainType: RuleChainType, config?: RequestConfig): Observable<Array<ComponentDescriptor>> {
let result: ComponentDescriptor[] = []; let result: ComponentDescriptor[] = [];
for (let i = componentTypes.length - 1; i >= 0; i--) { for (let i = componentTypes.length - 1; i >= 0; i--) {
const componentType = componentTypes[i]; const componentType = componentTypes[i];

View File

@ -25,7 +25,7 @@ import {
RuleChain, RuleChain,
RuleChainConnectionInfo, RuleChainConnectionInfo,
RuleChainMetaData, RuleChainMetaData,
ruleChainNodeComponent, ruleChainNodeComponent, RuleChainType,
ruleNodeTypeComponentTypes, ruleNodeTypeComponentTypes,
unknownNodeComponent unknownNodeComponent
} from '@shared/models/rule-chain.models'; } 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<Array<RuleNodeComponentDescriptor>> { Observable<Array<RuleNodeComponentDescriptor>> {
if (this.ruleNodeComponents) { if (this.ruleNodeComponents) {
return of(this.ruleNodeComponents); return of(this.ruleNodeComponents);
@ -204,7 +204,7 @@ export class RuleChainService {
} }
} }
private loadRuleNodeComponents(ruleChainType: string, config?: RequestConfig): Observable<Array<RuleNodeComponentDescriptor>> { private loadRuleNodeComponents(ruleChainType: RuleChainType, config?: RequestConfig): Observable<Array<RuleNodeComponentDescriptor>> {
return this.componentDescriptorService.getComponentDescriptorsByTypes(ruleNodeTypeComponentTypes, ruleChainType, config).pipe( return this.componentDescriptorService.getComponentDescriptorsByTypes(ruleNodeTypeComponentTypes, ruleChainType, config).pipe(
map((components) => { map((components) => {
const ruleNodeComponents: RuleNodeComponentDescriptor[] = []; const ruleNodeComponents: RuleNodeComponentDescriptor[] = [];

View File

@ -31,7 +31,12 @@ import { Authority } from '@shared/models/authority.enum';
import { RuleChainsTableConfigResolver } from '@modules/home/pages/rulechain/rulechains-table-config.resolver'; import { RuleChainsTableConfigResolver } from '@modules/home/pages/rulechain/rulechains-table-config.resolver';
import { Observable } from 'rxjs'; import { Observable } from 'rxjs';
import { BreadCrumbConfig, BreadCrumbLabelFunction } from '@shared/components/breadcrumb'; 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 { RuleChainService } from '@core/http/rule-chain.service';
import { RuleChainPageComponent } from '@home/pages/rulechain/rulechain-page.component'; import { RuleChainPageComponent } from '@home/pages/rulechain/rulechain-page.component';
import { RuleNodeComponentDescriptor } from '@shared/models/rule-node.models'; import { RuleNodeComponentDescriptor } from '@shared/models/rule-node.models';
@ -71,7 +76,7 @@ export class RuleNodeComponentsResolver implements Resolve<Array<RuleNodeCompone
} }
resolve(route: ActivatedRouteSnapshot): Observable<Array<RuleNodeComponentDescriptor>> { resolve(route: ActivatedRouteSnapshot): Observable<Array<RuleNodeComponentDescriptor>> {
const ruleChainType = route.data.type; const ruleChainType: RuleChainType = route.data.type;
return this.ruleChainService.getRuleNodeComponents(this.modulesMap, ruleChainType); return this.ruleChainService.getRuleNodeComponents(this.modulesMap, ruleChainType);
} }
} }
@ -228,8 +233,7 @@ const routes: Routes = [
} as BreadCrumbConfig<RuleChainPageComponent>, } as BreadCrumbConfig<RuleChainPageComponent>,
auth: [Authority.TENANT_ADMIN], auth: [Authority.TENANT_ADMIN],
title: 'rulechain.rulechain', title: 'rulechain.rulechain',
import: true, import: true
type: ruleChainType.edge
}, },
resolve: { resolve: {
ruleNodeComponents: RuleNodeComponentsResolver ruleNodeComponents: RuleNodeComponentsResolver

View File

@ -29,7 +29,7 @@ import { TranslateService } from '@ngx-translate/core';
import { DatePipe } from '@angular/common'; import { DatePipe } from '@angular/common';
import { EntityType, entityTypeResources, entityTypeTranslations } from '@shared/models/entity-type.models'; import { EntityType, entityTypeResources, entityTypeTranslations } from '@shared/models/entity-type.models';
import { EntityAction } from '@home/models/entity/entity-component.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 { RuleChainService } from '@core/http/rule-chain.service';
import { RuleChainComponent } from '@modules/home/pages/rulechain/rulechain.component'; import { RuleChainComponent } from '@modules/home/pages/rulechain/rulechain.component';
import { DialogService } from '@core/services/dialog.service'; import { DialogService } from '@core/services/dialog.service';

View File

@ -64,11 +64,6 @@ export interface RuleChainConnectionInfo {
type: string; type: string;
} }
export interface RuleChainType {
core: string;
edge: string;
}
export const ruleNodeTypeComponentTypes: ComponentType[] = export const ruleNodeTypeComponentTypes: ComponentType[] =
[ [
ComponentType.FILTER, ComponentType.FILTER,
@ -118,7 +113,9 @@ export const inputNodeComponent: RuleNodeComponentDescriptor = {
clazz: 'tb.internal.Input' clazz: 'tb.internal.Input'
}; };
export const ruleChainType: RuleChainType = { export declare type RuleChainType = 'CORE' | 'EDGE';
core: 'CORE',
edge: 'EDGE' export enum ruleChainType {
core = 'CORE',
edge = 'EDGE'
} }