Commit 0336906bf2686627238918d0276083d43ebb143d
1 parent
6ac70dd7
Rule Chains routing refactored, fixed import edge save
Showing
3 changed files
with
40 additions
and
53 deletions
@@ -1281,7 +1281,7 @@ export class RuleChainPageComponent extends PageComponent | @@ -1281,7 +1281,7 @@ export class RuleChainPageComponent extends PageComponent | ||
1281 | if (this.isImport) { | 1281 | if (this.isImport) { |
1282 | this.isDirtyValue = false; | 1282 | this.isDirtyValue = false; |
1283 | this.isImport = false; | 1283 | this.isImport = false; |
1284 | - this.router.navigateByUrl(`ruleChains/${this.ruleChain.id.id}`); | 1284 | + this.router.navigateByUrl(`ruleChains/${this.route.snapshot.data.ruleChainType.toLowerCase()}/${this.ruleChain.id.id}`); |
1285 | } else { | 1285 | } else { |
1286 | this.createRuleChainModel(); | 1286 | this.createRuleChainModel(); |
1287 | } | 1287 | } |
@@ -34,7 +34,6 @@ import { BreadCrumbConfig, BreadCrumbLabelFunction } from '@shared/components/br | @@ -34,7 +34,6 @@ import { BreadCrumbConfig, BreadCrumbLabelFunction } from '@shared/components/br | ||
34 | import { | 34 | import { |
35 | ResolvedRuleChainMetaData, | 35 | ResolvedRuleChainMetaData, |
36 | RuleChain, | 36 | RuleChain, |
37 | - RuleChainType, | ||
38 | ruleChainType, | 37 | ruleChainType, |
39 | } from '@shared/models/rule-chain.models'; | 38 | } from '@shared/models/rule-chain.models'; |
40 | import { RuleChainService } from '@core/http/rule-chain.service'; | 39 | import { RuleChainService } from '@core/http/rule-chain.service'; |
@@ -76,8 +75,7 @@ export class RuleNodeComponentsResolver implements Resolve<Array<RuleNodeCompone | @@ -76,8 +75,7 @@ export class RuleNodeComponentsResolver implements Resolve<Array<RuleNodeCompone | ||
76 | } | 75 | } |
77 | 76 | ||
78 | resolve(route: ActivatedRouteSnapshot): Observable<Array<RuleNodeComponentDescriptor>> { | 77 | resolve(route: ActivatedRouteSnapshot): Observable<Array<RuleNodeComponentDescriptor>> { |
79 | - const ruleChainType: RuleChainType = route.data.type; | ||
80 | - return this.ruleChainService.getRuleNodeComponents(this.modulesMap, ruleChainType); | 78 | + return this.ruleChainService.getRuleNodeComponents(this.modulesMap, route.data.ruleChainType); |
81 | } | 79 | } |
82 | } | 80 | } |
83 | 81 | ||
@@ -151,8 +149,7 @@ const routes: Routes = [ | @@ -151,8 +149,7 @@ const routes: Routes = [ | ||
151 | data: { | 149 | data: { |
152 | auth: [Authority.TENANT_ADMIN], | 150 | auth: [Authority.TENANT_ADMIN], |
153 | title: 'rulechain.rulechains', | 151 | title: 'rulechain.rulechains', |
154 | - ruleChainsType: 'tenant', | ||
155 | - type: ruleChainType.core | 152 | + ruleChainsType: 'tenant' |
156 | }, | 153 | }, |
157 | resolve: { | 154 | resolve: { |
158 | entitiesTableConfig: RuleChainsTableConfigResolver | 155 | entitiesTableConfig: RuleChainsTableConfigResolver |
@@ -170,7 +167,7 @@ const routes: Routes = [ | @@ -170,7 +167,7 @@ const routes: Routes = [ | ||
170 | auth: [Authority.TENANT_ADMIN], | 167 | auth: [Authority.TENANT_ADMIN], |
171 | title: 'rulechain.rulechain', | 168 | title: 'rulechain.rulechain', |
172 | import: false, | 169 | import: false, |
173 | - type: ruleChainType.core | 170 | + ruleChainType: ruleChainType.core |
174 | }, | 171 | }, |
175 | resolve: { | 172 | resolve: { |
176 | ruleChain: RuleChainResolver, | 173 | ruleChain: RuleChainResolver, |
@@ -190,7 +187,8 @@ const routes: Routes = [ | @@ -190,7 +187,8 @@ const routes: Routes = [ | ||
190 | } as BreadCrumbConfig<RuleChainPageComponent>, | 187 | } as BreadCrumbConfig<RuleChainPageComponent>, |
191 | auth: [Authority.TENANT_ADMIN], | 188 | auth: [Authority.TENANT_ADMIN], |
192 | title: 'rulechain.rulechain', | 189 | title: 'rulechain.rulechain', |
193 | - import: true | 190 | + import: true, |
191 | + ruleChainType: ruleChainType.core | ||
194 | }, | 192 | }, |
195 | resolve: { | 193 | resolve: { |
196 | ruleNodeComponents: RuleNodeComponentsResolver | 194 | ruleNodeComponents: RuleNodeComponentsResolver |
@@ -204,8 +202,7 @@ const routes: Routes = [ | @@ -204,8 +202,7 @@ const routes: Routes = [ | ||
204 | breadcrumb: { | 202 | breadcrumb: { |
205 | label: 'rulechain.edge-rulechains', | 203 | label: 'rulechain.edge-rulechains', |
206 | icon: 'settings_ethernet' | 204 | icon: 'settings_ethernet' |
207 | - }, | ||
208 | - type: 'edge' | 205 | + } |
209 | }, | 206 | }, |
210 | children: [ | 207 | children: [ |
211 | { | 208 | { |
@@ -214,48 +211,48 @@ const routes: Routes = [ | @@ -214,48 +211,48 @@ const routes: Routes = [ | ||
214 | data: { | 211 | data: { |
215 | auth: [Authority.TENANT_ADMIN], | 212 | auth: [Authority.TENANT_ADMIN], |
216 | title: 'edge.rulechains', | 213 | title: 'edge.rulechains', |
217 | - ruleChainsType: 'edges', | ||
218 | - type: ruleChainType.edge | 214 | + ruleChainsType: 'edges' |
219 | }, | 215 | }, |
220 | resolve: { | 216 | resolve: { |
221 | entitiesTableConfig: RuleChainsTableConfigResolver | 217 | entitiesTableConfig: RuleChainsTableConfigResolver |
222 | } | 218 | } |
223 | }, | 219 | }, |
224 | { | 220 | { |
225 | - path: 'ruleChain/import', | 221 | + path: ':ruleChainId', |
226 | component: RuleChainPageComponent, | 222 | component: RuleChainPageComponent, |
227 | - canActivate: [RuleChainImportGuard], | ||
228 | canDeactivate: [ConfirmOnExitGuard], | 223 | canDeactivate: [ConfirmOnExitGuard], |
229 | data: { | 224 | data: { |
230 | breadcrumb: { | 225 | breadcrumb: { |
231 | - labelFunction: importRuleChainBreadcumbLabelFunction, | 226 | + labelFunction: ruleChainBreadcumbLabelFunction, |
232 | icon: 'settings_ethernet' | 227 | icon: 'settings_ethernet' |
233 | } as BreadCrumbConfig<RuleChainPageComponent>, | 228 | } as BreadCrumbConfig<RuleChainPageComponent>, |
234 | auth: [Authority.TENANT_ADMIN], | 229 | auth: [Authority.TENANT_ADMIN], |
235 | - title: 'rulechain.rulechain', | ||
236 | - import: true | 230 | + title: 'edge.rulechain', |
231 | + import: false, | ||
232 | + ruleChainType: ruleChainType.edge | ||
237 | }, | 233 | }, |
238 | resolve: { | 234 | resolve: { |
235 | + ruleChain: RuleChainResolver, | ||
236 | + ruleChainMetaData: ResolvedRuleChainMetaDataResolver, | ||
239 | ruleNodeComponents: RuleNodeComponentsResolver | 237 | ruleNodeComponents: RuleNodeComponentsResolver |
240 | } | 238 | } |
241 | }, | 239 | }, |
242 | { | 240 | { |
243 | - path: ':ruleChainId', | 241 | + path: 'ruleChain/import', |
244 | component: RuleChainPageComponent, | 242 | component: RuleChainPageComponent, |
243 | + canActivate: [RuleChainImportGuard], | ||
245 | canDeactivate: [ConfirmOnExitGuard], | 244 | canDeactivate: [ConfirmOnExitGuard], |
246 | data: { | 245 | data: { |
247 | breadcrumb: { | 246 | breadcrumb: { |
248 | - labelFunction: ruleChainBreadcumbLabelFunction, | 247 | + labelFunction: importRuleChainBreadcumbLabelFunction, |
249 | icon: 'settings_ethernet' | 248 | icon: 'settings_ethernet' |
250 | } as BreadCrumbConfig<RuleChainPageComponent>, | 249 | } as BreadCrumbConfig<RuleChainPageComponent>, |
251 | auth: [Authority.TENANT_ADMIN], | 250 | auth: [Authority.TENANT_ADMIN], |
252 | - title: 'rulechain.rulechain', | ||
253 | - import: false, | ||
254 | - type: ruleChainType.edge | 251 | + title: 'edge.rulechain', |
252 | + import: true, | ||
253 | + ruleChainType: ruleChainType.edge | ||
255 | }, | 254 | }, |
256 | resolve: { | 255 | resolve: { |
257 | - ruleChain: RuleChainResolver, | ||
258 | - ruleChainMetaData: ResolvedRuleChainMetaDataResolver, | ||
259 | ruleNodeComponents: RuleNodeComponentsResolver | 256 | ruleNodeComponents: RuleNodeComponentsResolver |
260 | } | 257 | } |
261 | } | 258 | } |
@@ -74,7 +74,7 @@ export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig< | @@ -74,7 +74,7 @@ export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig< | ||
74 | new EntityTableColumn<RuleChain>('name', 'rulechain.name', '100%'), | 74 | new EntityTableColumn<RuleChain>('name', 'rulechain.name', '100%'), |
75 | new EntityTableColumn<RuleChain>('root', 'rulechain.root', '60px', | 75 | new EntityTableColumn<RuleChain>('root', 'rulechain.root', '60px', |
76 | entity => { | 76 | entity => { |
77 | - if (isDefined(this.config.componentsData.edgeId)) { | 77 | + if (this.config.componentsData.edgeId) { |
78 | return checkBoxCell((this.edge.rootRuleChainId.id == entity.id.id)); | 78 | return checkBoxCell((this.edge.rootRuleChainId.id == entity.id.id)); |
79 | } else { | 79 | } else { |
80 | return checkBoxCell(entity.root); | 80 | return checkBoxCell(entity.root); |
@@ -90,23 +90,25 @@ export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig< | @@ -90,23 +90,25 @@ export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig< | ||
90 | this.config.saveEntity = ruleChain => this.saveRuleChain(ruleChain); | 90 | this.config.saveEntity = ruleChain => this.saveRuleChain(ruleChain); |
91 | this.config.deleteEntity = id => this.ruleChainService.deleteRuleChain(id.id); | 91 | this.config.deleteEntity = id => this.ruleChainService.deleteRuleChain(id.id); |
92 | this.config.onEntityAction = action => this.onRuleChainAction(action); | 92 | this.config.onEntityAction = action => this.onRuleChainAction(action); |
93 | - this.config.deleteEnabled = (ruleChain) => ruleChain && !ruleChain.root && !this.config.componentsData.edgeId; | ||
94 | - this.config.entitySelectionEnabled = (ruleChain) => { | ||
95 | - if (isDefined(this.config.componentsData.edgeId)) { | ||
96 | - return this.edge.rootRuleChainId.id != ruleChain.id.id; | ||
97 | - } else { | ||
98 | - return ruleChain && !ruleChain.root; | ||
99 | - } | ||
100 | - } | ||
101 | } | 93 | } |
102 | 94 | ||
103 | resolve(route: ActivatedRouteSnapshot): EntityTableConfig<RuleChain> { | 95 | resolve(route: ActivatedRouteSnapshot): EntityTableConfig<RuleChain> { |
104 | const routeParams = route.params; | 96 | const routeParams = route.params; |
105 | this.config.componentsData = { | 97 | this.config.componentsData = { |
106 | ruleChainScope: route.data.ruleChainsType, | 98 | ruleChainScope: route.data.ruleChainsType, |
107 | - type: route.data.type, | ||
108 | edgeId: routeParams.edgeId | 99 | edgeId: routeParams.edgeId |
109 | }; | 100 | }; |
101 | + if (this.config.componentsData.edgeId) { | ||
102 | + this.config.entitySelectionEnabled = ruleChain => this.edge.rootRuleChainId.id != ruleChain.id.id; | ||
103 | + this.config.deleteEnabled = () => false; | ||
104 | + this.edgeService.getEdge(this.config.componentsData.edgeId).subscribe(edge => { | ||
105 | + this.edge = edge; | ||
106 | + this.config.tableTitle = edge.name + ': ' + this.translate.instant('rulechain.edge-rulechains') | ||
107 | + }); | ||
108 | + } else { | ||
109 | + this.config.entitySelectionEnabled = ruleChain => ruleChain && !ruleChain.root; | ||
110 | + this.config.deleteEnabled = (ruleChain) => ruleChain && !ruleChain.root; | ||
111 | + } | ||
110 | this.configureEntityFunctions(this.config.componentsData.ruleChainScope); | 112 | this.configureEntityFunctions(this.config.componentsData.ruleChainScope); |
111 | this.config.groupActionDescriptors = this.configureGroupActions(this.config.componentsData.ruleChainScope); | 113 | this.config.groupActionDescriptors = this.configureGroupActions(this.config.componentsData.ruleChainScope); |
112 | this.config.addActionDescriptors = this.configureAddActions(this.config.componentsData.ruleChainScope); | 114 | this.config.addActionDescriptors = this.configureAddActions(this.config.componentsData.ruleChainScope); |
@@ -153,13 +155,6 @@ export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig< | @@ -153,13 +155,6 @@ export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig< | ||
153 | this.config.tableTitle = this.translate.instant('rulechain.edge-rulechains'); | 155 | this.config.tableTitle = this.translate.instant('rulechain.edge-rulechains'); |
154 | this.config.entitiesFetchFunction = pageLink => this.fetchEdgeRuleChains(pageLink); | 156 | this.config.entitiesFetchFunction = pageLink => this.fetchEdgeRuleChains(pageLink); |
155 | } else if (ruleChainScope === 'edge') { | 157 | } else if (ruleChainScope === 'edge') { |
156 | - if (isDefined(this.config.componentsData.edgeId)) { | ||
157 | - this.edgeService.getEdge(this.config.componentsData.edgeId).subscribe( | ||
158 | - edge => { | ||
159 | - this.edge = edge; | ||
160 | - this.config.tableTitle = edge.name + ': ' + this.translate.instant('rulechain.edge-rulechains') | ||
161 | - }); | ||
162 | - } | ||
163 | this.config.entitiesFetchFunction = pageLink => this.ruleChainService.getEdgeRuleChains(this.config.componentsData.edgeId, pageLink); | 158 | this.config.entitiesFetchFunction = pageLink => this.ruleChainService.getEdgeRuleChains(this.config.componentsData.edgeId, pageLink); |
164 | } | 159 | } |
165 | } | 160 | } |
@@ -297,7 +292,7 @@ export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig< | @@ -297,7 +292,7 @@ export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig< | ||
297 | true | 292 | true |
298 | ).subscribe((res) => { | 293 | ).subscribe((res) => { |
299 | if (res) { | 294 | if (res) { |
300 | - if (isDefined(this.config.componentsData.edgeId)) { | 295 | + if (this.config.componentsData.edgeId) { |
301 | this.edgeService.setRootRuleChain(this.config.componentsData.edgeId, ruleChain.id.id).subscribe( | 296 | this.edgeService.setRootRuleChain(this.config.componentsData.edgeId, ruleChain.id.id).subscribe( |
302 | (edge) => { | 297 | (edge) => { |
303 | this.edge = edge; | 298 | this.edge = edge; |
@@ -469,7 +464,7 @@ export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig< | @@ -469,7 +464,7 @@ export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig< | ||
469 | } | 464 | } |
470 | 465 | ||
471 | isNonRootRuleChain(ruleChain: RuleChain) { | 466 | isNonRootRuleChain(ruleChain: RuleChain) { |
472 | - if (isDefined(this.config.componentsData.edgeId)) { | 467 | + if (this.config.componentsData.edgeId) { |
473 | return (isDefined(this.edge.rootRuleChainId) && this.edge.rootRuleChainId != null && this.edge.rootRuleChainId.id != ruleChain.id.id); | 468 | return (isDefined(this.edge.rootRuleChainId) && this.edge.rootRuleChainId != null && this.edge.rootRuleChainId.id != ruleChain.id.id); |
474 | } | 469 | } |
475 | return (isDefined(ruleChain)) && !ruleChain.root; | 470 | return (isDefined(ruleChain)) && !ruleChain.root; |
@@ -489,21 +484,16 @@ export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig< | @@ -489,21 +484,16 @@ export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig< | ||
489 | 484 | ||
490 | fetchEdgeRuleChains(pageLink: PageLink) { | 485 | fetchEdgeRuleChains(pageLink: PageLink) { |
491 | let defaultEdgeRuleChainIds: Array<string> = []; | 486 | let defaultEdgeRuleChainIds: Array<string> = []; |
492 | - this.ruleChainService.getDefaultEdgeRuleChains().pipe( | ||
493 | - map(ruleChains => | ||
494 | - ruleChains.map(ruleChain => | ||
495 | - defaultEdgeRuleChainIds.push(ruleChain.id.id) | ||
496 | - ) | ||
497 | - ) | ||
498 | - ).subscribe(); | 487 | + this.ruleChainService.getDefaultEdgeRuleChains().subscribe(ruleChains => { |
488 | + ruleChains.map(ruleChain => defaultEdgeRuleChainIds.push(ruleChain.id.id)) | ||
489 | + }); | ||
499 | return this.ruleChainService.getRuleChains(pageLink, ruleChainType.edge).pipe( | 490 | return this.ruleChainService.getRuleChains(pageLink, ruleChainType.edge).pipe( |
500 | - map((response) => { | 491 | + map(response => { |
501 | response.data.map(ruleChain => | 492 | response.data.map(ruleChain => |
502 | ruleChain.isDefault = defaultEdgeRuleChainIds.some(id => ruleChain.id.id.includes(id)) | 493 | ruleChain.isDefault = defaultEdgeRuleChainIds.some(id => ruleChain.id.id.includes(id)) |
503 | ); | 494 | ); |
504 | - return response; | 495 | + return response; |
505 | }) | 496 | }) |
506 | ); | 497 | ); |
507 | } | 498 | } |
508 | - | ||
509 | } | 499 | } |