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 { 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<ComponentType>, ruleChainType: string, config?: RequestConfig): Observable<Array<ComponentDescriptor>> {
public getComponentDescriptorsByTypes(componentTypes: Array<ComponentType>, ruleChainType: RuleChainType, config?: RequestConfig): Observable<Array<ComponentDescriptor>> {
let result: ComponentDescriptor[] = [];
for (let i = componentTypes.length - 1; i >= 0; i--) {
const componentType = componentTypes[i];

View File

@ -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<Array<RuleNodeComponentDescriptor>> {
if (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(
map((components) => {
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 { 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<Array<RuleNodeCompone
}
resolve(route: ActivatedRouteSnapshot): Observable<Array<RuleNodeComponentDescriptor>> {
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<RuleChainPageComponent>,
auth: [Authority.TENANT_ADMIN],
title: 'rulechain.rulechain',
import: true,
type: ruleChainType.edge
import: true
},
resolve: {
ruleNodeComponents: RuleNodeComponentsResolver

View File

@ -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'
}