From 0336906bf2686627238918d0276083d43ebb143d Mon Sep 17 00:00:00 2001 From: Artem Babak Date: Fri, 6 Nov 2020 13:49:00 +0200 Subject: [PATCH] Rule Chains routing refactored, fixed import edge save --- .../rulechain/rulechain-page.component.ts | 2 +- .../rulechain/rulechain-routing.module.ts | 43 ++++++++--------- .../rulechains-table-config.resolver.ts | 48 ++++++++----------- 3 files changed, 40 insertions(+), 53 deletions(-) diff --git a/ui-ngx/src/app/modules/home/pages/rulechain/rulechain-page.component.ts b/ui-ngx/src/app/modules/home/pages/rulechain/rulechain-page.component.ts index 7096045aed..9c235cb8de 100644 --- a/ui-ngx/src/app/modules/home/pages/rulechain/rulechain-page.component.ts +++ b/ui-ngx/src/app/modules/home/pages/rulechain/rulechain-page.component.ts @@ -1281,7 +1281,7 @@ export class RuleChainPageComponent extends PageComponent if (this.isImport) { this.isDirtyValue = false; this.isImport = false; - this.router.navigateByUrl(`ruleChains/${this.ruleChain.id.id}`); + this.router.navigateByUrl(`ruleChains/${this.route.snapshot.data.ruleChainType.toLowerCase()}/${this.ruleChain.id.id}`); } else { this.createRuleChainModel(); } 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 931fd3d70f..fd7b58f0f0 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 @@ -34,7 +34,6 @@ import { BreadCrumbConfig, BreadCrumbLabelFunction } from '@shared/components/br import { ResolvedRuleChainMetaData, RuleChain, - RuleChainType, ruleChainType, } from '@shared/models/rule-chain.models'; import { RuleChainService } from '@core/http/rule-chain.service'; @@ -76,8 +75,7 @@ export class RuleNodeComponentsResolver implements Resolve> { - const ruleChainType: RuleChainType = route.data.type; - return this.ruleChainService.getRuleNodeComponents(this.modulesMap, ruleChainType); + return this.ruleChainService.getRuleNodeComponents(this.modulesMap, route.data.ruleChainType); } } @@ -151,8 +149,7 @@ const routes: Routes = [ data: { auth: [Authority.TENANT_ADMIN], title: 'rulechain.rulechains', - ruleChainsType: 'tenant', - type: ruleChainType.core + ruleChainsType: 'tenant' }, resolve: { entitiesTableConfig: RuleChainsTableConfigResolver @@ -170,7 +167,7 @@ const routes: Routes = [ auth: [Authority.TENANT_ADMIN], title: 'rulechain.rulechain', import: false, - type: ruleChainType.core + ruleChainType: ruleChainType.core }, resolve: { ruleChain: RuleChainResolver, @@ -190,7 +187,8 @@ const routes: Routes = [ } as BreadCrumbConfig, auth: [Authority.TENANT_ADMIN], title: 'rulechain.rulechain', - import: true + import: true, + ruleChainType: ruleChainType.core }, resolve: { ruleNodeComponents: RuleNodeComponentsResolver @@ -204,8 +202,7 @@ const routes: Routes = [ breadcrumb: { label: 'rulechain.edge-rulechains', icon: 'settings_ethernet' - }, - type: 'edge' + } }, children: [ { @@ -214,48 +211,48 @@ const routes: Routes = [ data: { auth: [Authority.TENANT_ADMIN], title: 'edge.rulechains', - ruleChainsType: 'edges', - type: ruleChainType.edge + ruleChainsType: 'edges' }, resolve: { entitiesTableConfig: RuleChainsTableConfigResolver } }, { - path: 'ruleChain/import', + path: ':ruleChainId', component: RuleChainPageComponent, - canActivate: [RuleChainImportGuard], canDeactivate: [ConfirmOnExitGuard], data: { breadcrumb: { - labelFunction: importRuleChainBreadcumbLabelFunction, + labelFunction: ruleChainBreadcumbLabelFunction, icon: 'settings_ethernet' } as BreadCrumbConfig, auth: [Authority.TENANT_ADMIN], - title: 'rulechain.rulechain', - import: true + title: 'edge.rulechain', + import: false, + ruleChainType: ruleChainType.edge }, resolve: { + ruleChain: RuleChainResolver, + ruleChainMetaData: ResolvedRuleChainMetaDataResolver, ruleNodeComponents: RuleNodeComponentsResolver } }, { - path: ':ruleChainId', + path: 'ruleChain/import', component: RuleChainPageComponent, + canActivate: [RuleChainImportGuard], canDeactivate: [ConfirmOnExitGuard], data: { breadcrumb: { - labelFunction: ruleChainBreadcumbLabelFunction, + labelFunction: importRuleChainBreadcumbLabelFunction, icon: 'settings_ethernet' } as BreadCrumbConfig, auth: [Authority.TENANT_ADMIN], - title: 'rulechain.rulechain', - import: false, - type: ruleChainType.edge + title: 'edge.rulechain', + import: true, + ruleChainType: ruleChainType.edge }, resolve: { - ruleChain: RuleChainResolver, - ruleChainMetaData: ResolvedRuleChainMetaDataResolver, 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 d43b38a8d7..19cac32b21 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 @@ -74,7 +74,7 @@ export class RuleChainsTableConfigResolver implements Resolve('name', 'rulechain.name', '100%'), new EntityTableColumn('root', 'rulechain.root', '60px', entity => { - if (isDefined(this.config.componentsData.edgeId)) { + if (this.config.componentsData.edgeId) { return checkBoxCell((this.edge.rootRuleChainId.id == entity.id.id)); } else { return checkBoxCell(entity.root); @@ -90,23 +90,25 @@ export class RuleChainsTableConfigResolver implements Resolve this.saveRuleChain(ruleChain); this.config.deleteEntity = id => this.ruleChainService.deleteRuleChain(id.id); this.config.onEntityAction = action => this.onRuleChainAction(action); - this.config.deleteEnabled = (ruleChain) => ruleChain && !ruleChain.root && !this.config.componentsData.edgeId; - this.config.entitySelectionEnabled = (ruleChain) => { - if (isDefined(this.config.componentsData.edgeId)) { - return this.edge.rootRuleChainId.id != ruleChain.id.id; - } else { - return ruleChain && !ruleChain.root; - } - } } resolve(route: ActivatedRouteSnapshot): EntityTableConfig { const routeParams = route.params; this.config.componentsData = { ruleChainScope: route.data.ruleChainsType, - type: route.data.type, edgeId: routeParams.edgeId }; + if (this.config.componentsData.edgeId) { + this.config.entitySelectionEnabled = ruleChain => this.edge.rootRuleChainId.id != ruleChain.id.id; + this.config.deleteEnabled = () => false; + this.edgeService.getEdge(this.config.componentsData.edgeId).subscribe(edge => { + this.edge = edge; + this.config.tableTitle = edge.name + ': ' + this.translate.instant('rulechain.edge-rulechains') + }); + } else { + this.config.entitySelectionEnabled = ruleChain => ruleChain && !ruleChain.root; + this.config.deleteEnabled = (ruleChain) => ruleChain && !ruleChain.root; + } this.configureEntityFunctions(this.config.componentsData.ruleChainScope); this.config.groupActionDescriptors = this.configureGroupActions(this.config.componentsData.ruleChainScope); this.config.addActionDescriptors = this.configureAddActions(this.config.componentsData.ruleChainScope); @@ -153,13 +155,6 @@ export class RuleChainsTableConfigResolver implements Resolve this.fetchEdgeRuleChains(pageLink); } else if (ruleChainScope === 'edge') { - if (isDefined(this.config.componentsData.edgeId)) { - this.edgeService.getEdge(this.config.componentsData.edgeId).subscribe( - edge => { - this.edge = edge; - this.config.tableTitle = edge.name + ': ' + this.translate.instant('rulechain.edge-rulechains') - }); - } this.config.entitiesFetchFunction = pageLink => this.ruleChainService.getEdgeRuleChains(this.config.componentsData.edgeId, pageLink); } } @@ -297,7 +292,7 @@ export class RuleChainsTableConfigResolver implements Resolve { if (res) { - if (isDefined(this.config.componentsData.edgeId)) { + if (this.config.componentsData.edgeId) { this.edgeService.setRootRuleChain(this.config.componentsData.edgeId, ruleChain.id.id).subscribe( (edge) => { this.edge = edge; @@ -469,7 +464,7 @@ export class RuleChainsTableConfigResolver implements Resolve = []; - this.ruleChainService.getDefaultEdgeRuleChains().pipe( - map(ruleChains => - ruleChains.map(ruleChain => - defaultEdgeRuleChainIds.push(ruleChain.id.id) - ) - ) - ).subscribe(); + this.ruleChainService.getDefaultEdgeRuleChains().subscribe(ruleChains => { + ruleChains.map(ruleChain => defaultEdgeRuleChainIds.push(ruleChain.id.id)) + }); return this.ruleChainService.getRuleChains(pageLink, ruleChainType.edge).pipe( - map((response) => { + map(response => { response.data.map(ruleChain => ruleChain.isDefault = defaultEdgeRuleChainIds.some(id => ruleChain.id.id.includes(id)) ); - return response; + return response; }) ); } - }