UI: Remove rule node config map; Add new function extractComponentsFromModule

This commit is contained in:
Vladyslav_Prykhodko 2025-01-14 12:43:47 +02:00
parent 36b2998a0d
commit 4cc01d58c0
9 changed files with 45 additions and 119 deletions

View File

@ -184,8 +184,8 @@ export class RuleChainService {
return this.http.post<TestScriptResult>(url, inputParams, defaultHttpOptionsFromConfig(config)); return this.http.post<TestScriptResult>(url, inputParams, defaultHttpOptionsFromConfig(config));
} }
public registemSystemRuleNodeConfigComponent(componentMap: Record<string, Type<IRuleNodeConfigurationComponent>>) { public registerSystemRuleNodeConfigModule(module: any) {
this.systemRuleNodeConfigComponents = componentMap; this.systemRuleNodeConfigComponents = this.resourcesService.extractComponentsFromModule(module, true);
} }
private loadRuleNodeComponents(ruleChainType: RuleChainType, config?: RequestConfig): Observable<Array<RuleNodeComponentDescriptor>> { private loadRuleNodeComponents(ruleChainType: RuleChainType, config?: RequestConfig): Observable<Array<RuleNodeComponentDescriptor>> {

View File

@ -31,7 +31,7 @@ import { forkJoin, from, Observable, ReplaySubject, throwError } from 'rxjs';
import { HttpClient } from '@angular/common/http'; import { HttpClient } from '@angular/common/http';
import { IModulesMap } from '@modules/common/modules-map.models'; import { IModulesMap } from '@modules/common/modules-map.models';
import { TbResourceId } from '@shared/models/id/tb-resource-id'; import { TbResourceId } from '@shared/models/id/tb-resource-id';
import { isObject } from '@core/utils'; import { camelCase, isObject } from '@core/utils';
import { AuthService } from '@core/auth/auth.service'; import { AuthService } from '@core/auth/auth.service';
import { select, Store } from '@ngrx/store'; import { select, Store } from '@ngrx/store';
import { selectIsAuthenticated } from '@core/auth/auth.selectors'; import { selectIsAuthenticated } from '@core/auth/auth.selectors';
@ -51,6 +51,8 @@ export interface ModulesWithComponents {
standaloneComponents: ɵComponentDef<any>[]; standaloneComponents: ɵComponentDef<any>[];
} }
export type ComponentsSelectorMap = Record<string, Type<any>>;
export const flatModulesWithComponents = (modulesWithComponentsList: ModulesWithComponents[]): ModulesWithComponents => { export const flatModulesWithComponents = (modulesWithComponentsList: ModulesWithComponents[]): ModulesWithComponents => {
const modulesWithComponents: ModulesWithComponents = { const modulesWithComponents: ModulesWithComponents = {
modules: [], modules: [],
@ -91,6 +93,17 @@ export const componentTypeBySelector = (modulesWithComponents: ModulesWithCompon
const matchesSelector = (selectors: ɵCssSelectorList, selector: string) => const matchesSelector = (selectors: ɵCssSelectorList, selector: string) =>
selectors.some(s => s.some(s1 => typeof s1 === 'string' && s1 === selector)); selectors.some(s => s.some(s1 => typeof s1 === 'string' && s1 === selector));
const extractSelectorFromComponent = (comp: ɵComponentDef<any>): string => {
for (const selectors of comp.selectors) {
for (const selector of selectors) {
if (typeof selector === 'string') {
return selector;
}
}
}
return null;
}
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
}) })
@ -252,6 +265,27 @@ export class ResourcesService {
); );
} }
public extractComponentsFromModule(module: any, isCamelCaseSelector = false): ComponentsSelectorMap {
const modulesWithComponents = this.extractModulesWithComponents(module);
const componentMap = {};
const processComponents = (components: Array<ɵComponentDef<any>>) => {
components.forEach(item => {
let selector = extractSelectorFromComponent(item);
if (isCamelCaseSelector) {
selector = camelCase(selector);
}
componentMap[selector] = item.type;
});
};
processComponents(modulesWithComponents.standaloneComponents);
modulesWithComponents.modules.forEach(module => {
processComponents(module.components);
})
return componentMap;
}
private extractModulesWithComponents(module: any, private extractModulesWithComponents(module: any,
modulesWithComponents: ModulesWithComponents = { modulesWithComponents: ModulesWithComponents = {
@ -284,7 +318,7 @@ export class ResourcesService {
modulesWithComponents.standaloneComponents.push(component); modulesWithComponents.standaloneComponents.push(component);
} }
} else { } else {
this.extractModulesWithComponents(module, modulesWithComponents, visitedModules); this.extractModulesWithComponents(element, modulesWithComponents, visitedModules);
} }
} }
} else if (ɵNG_COMP_DEF in module) { } else if (ɵNG_COMP_DEF in module) {

View File

@ -103,29 +103,3 @@ import { SendRestApiCallReplyConfigComponent } from './send-rest-api-call-reply-
}) })
export class ActionRuleNodeConfigModule { export class ActionRuleNodeConfigModule {
} }
export const actionRuleNodeConfigComponentsMap: Record<string, Type<IRuleNodeConfigurationComponent>> = {
'tbActionNodeAssignToCustomerConfig': AssignCustomerConfigComponent,
'tbActionNodeAttributesConfig': AttributesConfigComponent,
'tbActionNodeClearAlarmConfig': ClearAlarmConfigComponent,
'tbActionNodeCreateAlarmConfig': CreateAlarmConfigComponent,
'tbActionNodeCreateRelationConfig': CreateRelationConfigComponent,
'tbActionNodeDeleteAttributesConfig': DeleteAttributesConfigComponent,
'tbActionNodeDeleteRelationConfig': DeleteRelationConfigComponent,
'tbActionNodeDeviceProfileConfig': DeviceProfileConfigComponent,
'tbActionNodeDeviceStateConfig': DeviceStateConfigComponent,
'tbActionNodeGeneratorConfig': GeneratorConfigComponent,
'tbActionNodeGpsGeofencingConfig': GpsGeoActionConfigComponent,
'tbActionNodeLogConfig': LogConfigComponent,
'tbActionNodeMathFunctionConfig': MathFunctionConfigComponent,
'tbActionNodeMsgCountConfig': MsgCountConfigComponent,
'tbActionNodeMsgDelayConfig': MsgDelayConfigComponent,
'tbActionNodePushToCloudConfig': PushToCloudConfigComponent,
'tbActionNodePushToEdgeConfig': PushToEdgeConfigComponent,
'tbActionNodeRpcReplyConfig': RpcReplyConfigComponent,
'tbActionNodeRpcRequestConfig': RpcRequestConfigComponent,
'tbActionNodeCustomTableConfig': SaveToCustomTableConfigComponent,
'tbActionNodeSendRestApiCallReplyConfig': SendRestApiCallReplyConfigComponent,
'tbActionNodeTimeseriesConfig': TimeseriesConfigComponent,
'tbActionNodeUnAssignToCustomerConfig': UnassignCustomerConfigComponent
};

View File

@ -62,16 +62,3 @@ import { FetchDeviceCredentialsConfigComponent } from './fetch-device-credential
}) })
export class EnrichmentRuleNodeCoreModule { export class EnrichmentRuleNodeCoreModule {
} }
export const enrichmentRuleNodeConfigComponentsMap: Record<string, Type<IRuleNodeConfigurationComponent>> = {
'tbEnrichmentNodeCalculateDeltaConfig': CalculateDeltaConfigComponent,
'tbEnrichmentNodeCustomerAttributesConfig': CustomerAttributesConfigComponent,
'tbEnrichmentNodeDeviceAttributesConfig': DeviceAttributesConfigComponent,
'tbEnrichmentNodeEntityDetailsConfig': EntityDetailsConfigComponent,
'tbEnrichmentNodeFetchDeviceCredentialsConfig': FetchDeviceCredentialsConfigComponent,
'tbEnrichmentNodeGetTelemetryFromDatabase': GetTelemetryFromDatabaseConfigComponent,
'tbEnrichmentNodeOriginatorAttributesConfig': OriginatorAttributesConfigComponent,
'tbEnrichmentNodeOriginatorFieldsConfig': OriginatorFieldsConfigComponent,
'tbEnrichmentNodeRelatedAttributesConfig': RelatedAttributesConfigComponent,
'tbEnrichmentNodeTenantAttributesConfig': TenantAttributesConfigComponent
}

View File

@ -73,19 +73,3 @@ import { LambdaConfigComponent } from './lambda-config.component';
}) })
export class ExternalRuleNodeConfigModule { export class ExternalRuleNodeConfigModule {
} }
export const externalRuleNodeConfigComponentsMap: Record<string, Type<IRuleNodeConfigurationComponent>> = {
'tbExternalNodeAzureIotHubConfig': AzureIotHubConfigComponent,
'tbExternalNodeKafkaConfig': KafkaConfigComponent,
'tbExternalNodeLambdaConfig': LambdaConfigComponent,
'tbExternalNodeMqttConfig': MqttConfigComponent,
'tbExternalNodeNotificationConfig': NotificationConfigComponent,
'tbExternalNodePubSubConfig': PubSubConfigComponent,
'tbExternalNodeRabbitMqConfig': RabbitMqConfigComponent,
'tbExternalNodeRestApiCallConfig': RestApiCallConfigComponent,
'tbExternalNodeSendEmailConfig': SendEmailConfigComponent,
'tbExternalNodeSendSmsConfig': SendSmsConfigComponent,
'tbExternalNodeSlackConfig': SlackConfigComponent,
'tbExternalNodeSnsConfig': SnsConfigComponent,
'tbExternalNodeSqsConfig': SqsConfigComponent
}

View File

@ -56,14 +56,3 @@ import { CommonRuleNodeConfigModule } from '../common/common-rule-node-config.mo
}) })
export class FilterRuleNodeConfigModule { export class FilterRuleNodeConfigModule {
} }
export const filterRuleNodeConfigComponentsMap: Record<string, Type<IRuleNodeConfigurationComponent>> = {
'tbFilterNodeCheckAlarmStatusConfig': CheckAlarmStatusComponent,
'tbFilterNodeCheckMessageConfig': CheckMessageConfigComponent,
'tbFilterNodeCheckRelationConfig': CheckRelationConfigComponent,
'tbFilterNodeGpsGeofencingConfig': GpsGeoFilterConfigComponent,
'tbFilterNodeMessageTypeConfig': MessageTypeConfigComponent,
'tbFilterNodeOriginatorTypeConfig': OriginatorTypeConfigComponent,
'tbFilterNodeScriptConfig': ScriptConfigComponent,
'tbFilterNodeSwitchConfig': SwitchConfigComponent
}

View File

@ -36,8 +36,3 @@ import { RuleChainOutputComponent } from './rule-chain-output.component';
}) })
export class FlowRuleNodeConfigModule { export class FlowRuleNodeConfigModule {
} }
export const flowRuleNodeConfigComponentsMap: Record<string, Type<IRuleNodeConfigurationComponent>> = {
'tbFlowNodeRuleChainInputConfig': RuleChainInputComponent,
'tbFlowNodeRuleChainOutputConfig': RuleChainOutputComponent
}

View File

@ -14,35 +14,18 @@
/// limitations under the License. /// limitations under the License.
/// ///
import { NgModule, Type } from '@angular/core'; import { NgModule } from '@angular/core';
import { EmptyConfigComponent } from './empty-config.component'; import { EmptyConfigComponent } from './empty-config.component';
import { CommonModule } from '@angular/common'; import { CommonModule } from '@angular/common';
import { SharedModule } from '@shared/shared.module'; import { SharedModule } from '@shared/shared.module';
import { ActionRuleNodeConfigModule } from '@home/components/rule-node/action/action-rule-node-config.module';
import { FilterRuleNodeConfigModule } from '@home/components/rule-node/filter/filter-rule-node-config.module';
import { EnrichmentRuleNodeCoreModule } from '@home/components/rule-node/enrichment/enrichment-rule-node-core.module';
import { ExternalRuleNodeConfigModule } from '@home/components/rule-node/external/external-rule-node-config.module';
import { import {
actionRuleNodeConfigComponentsMap,
ActionRuleNodeConfigModule
} from '@home/components/rule-node/action/action-rule-node-config.module';
import {
filterRuleNodeConfigComponentsMap,
FilterRuleNodeConfigModule
} from '@home/components/rule-node/filter/filter-rule-node-config.module';
import {
enrichmentRuleNodeConfigComponentsMap,
EnrichmentRuleNodeCoreModule
} from '@home/components/rule-node/enrichment/enrichment-rule-node-core.module';
import {
externalRuleNodeConfigComponentsMap,
ExternalRuleNodeConfigModule
} from '@home/components/rule-node/external/external-rule-node-config.module';
import {
transformationRuleNodeConfigComponentsMap,
TransformationRuleNodeConfigModule TransformationRuleNodeConfigModule
} from '@home/components/rule-node/transformation/transformation-rule-node-config.module'; } from '@home/components/rule-node/transformation/transformation-rule-node-config.module';
import { import { FlowRuleNodeConfigModule } from '@home/components/rule-node/flow/flow-rule-node-config.module';
flowRuleNodeConfigComponentsMap,
FlowRuleNodeConfigModule
} from '@home/components/rule-node/flow/flow-rule-node-config.module';
import { IRuleNodeConfigurationComponent } from '@shared/models/rule-node.models';
import { RuleChainService } from '@core/http/rule-chain.service'; import { RuleChainService } from '@core/http/rule-chain.service';
@NgModule({ @NgModule({
@ -65,15 +48,6 @@ import { RuleChainService } from '@core/http/rule-chain.service';
}) })
export class RuleNodeConfigModule { export class RuleNodeConfigModule {
constructor(private ruleChainService: RuleChainService) { constructor(private ruleChainService: RuleChainService) {
const ruleNodeConfigComponentsMap: Record<string, Type<IRuleNodeConfigurationComponent>> = { this.ruleChainService.registerSystemRuleNodeConfigModule(this.constructor);
...actionRuleNodeConfigComponentsMap,
...enrichmentRuleNodeConfigComponentsMap,
...externalRuleNodeConfigComponentsMap,
...filterRuleNodeConfigComponentsMap,
...flowRuleNodeConfigComponentsMap,
...transformationRuleNodeConfigComponentsMap,
'tbNodeEmptyConfig': EmptyConfigComponent
};
this.ruleChainService.registemSystemRuleNodeConfigComponent(ruleNodeConfigComponentsMap);
} }
} }

View File

@ -57,14 +57,3 @@ import { ScriptConfigComponent } from '@home/components/rule-node/filter/script-
}) })
export class TransformationRuleNodeConfigModule { export class TransformationRuleNodeConfigModule {
} }
export const transformationRuleNodeConfigComponentsMap: Record<string, Type<IRuleNodeConfigurationComponent>> = {
'tbTransformationNodeChangeOriginatorConfig': ChangeOriginatorConfigComponent,
'tbTransformationNodeCopyKeysConfig': CopyKeysConfigComponent,
'tbTransformationNodeDeduplicationConfig': DeduplicationConfigComponent,
'tbTransformationNodeDeleteKeysConfig': DeleteKeysConfigComponent,
'tbTransformationNodeJsonPathConfig': NodeJsonPathConfigComponent,
'tbTransformationNodeRenameKeysConfig': RenameKeysConfigComponent,
'tbTransformationNodeScriptConfig': ScriptConfigComponent,
'tbTransformationNodeToEmailConfig': ToEmailConfigComponent
}