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 | 1281 | if (this.isImport) { |
1282 | 1282 | this.isDirtyValue = false; |
1283 | 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 | 1285 | } else { |
1286 | 1286 | this.createRuleChainModel(); |
1287 | 1287 | } | ... | ... |
... | ... | @@ -34,7 +34,6 @@ import { BreadCrumbConfig, BreadCrumbLabelFunction } from '@shared/components/br |
34 | 34 | import { |
35 | 35 | ResolvedRuleChainMetaData, |
36 | 36 | RuleChain, |
37 | - RuleChainType, | |
38 | 37 | ruleChainType, |
39 | 38 | } from '@shared/models/rule-chain.models'; |
40 | 39 | import { RuleChainService } from '@core/http/rule-chain.service'; |
... | ... | @@ -76,8 +75,7 @@ export class RuleNodeComponentsResolver implements Resolve<Array<RuleNodeCompone |
76 | 75 | } |
77 | 76 | |
78 | 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 | 149 | data: { |
152 | 150 | auth: [Authority.TENANT_ADMIN], |
153 | 151 | title: 'rulechain.rulechains', |
154 | - ruleChainsType: 'tenant', | |
155 | - type: ruleChainType.core | |
152 | + ruleChainsType: 'tenant' | |
156 | 153 | }, |
157 | 154 | resolve: { |
158 | 155 | entitiesTableConfig: RuleChainsTableConfigResolver |
... | ... | @@ -170,7 +167,7 @@ const routes: Routes = [ |
170 | 167 | auth: [Authority.TENANT_ADMIN], |
171 | 168 | title: 'rulechain.rulechain', |
172 | 169 | import: false, |
173 | - type: ruleChainType.core | |
170 | + ruleChainType: ruleChainType.core | |
174 | 171 | }, |
175 | 172 | resolve: { |
176 | 173 | ruleChain: RuleChainResolver, |
... | ... | @@ -190,7 +187,8 @@ const routes: Routes = [ |
190 | 187 | } as BreadCrumbConfig<RuleChainPageComponent>, |
191 | 188 | auth: [Authority.TENANT_ADMIN], |
192 | 189 | title: 'rulechain.rulechain', |
193 | - import: true | |
190 | + import: true, | |
191 | + ruleChainType: ruleChainType.core | |
194 | 192 | }, |
195 | 193 | resolve: { |
196 | 194 | ruleNodeComponents: RuleNodeComponentsResolver |
... | ... | @@ -204,8 +202,7 @@ const routes: Routes = [ |
204 | 202 | breadcrumb: { |
205 | 203 | label: 'rulechain.edge-rulechains', |
206 | 204 | icon: 'settings_ethernet' |
207 | - }, | |
208 | - type: 'edge' | |
205 | + } | |
209 | 206 | }, |
210 | 207 | children: [ |
211 | 208 | { |
... | ... | @@ -214,48 +211,48 @@ const routes: Routes = [ |
214 | 211 | data: { |
215 | 212 | auth: [Authority.TENANT_ADMIN], |
216 | 213 | title: 'edge.rulechains', |
217 | - ruleChainsType: 'edges', | |
218 | - type: ruleChainType.edge | |
214 | + ruleChainsType: 'edges' | |
219 | 215 | }, |
220 | 216 | resolve: { |
221 | 217 | entitiesTableConfig: RuleChainsTableConfigResolver |
222 | 218 | } |
223 | 219 | }, |
224 | 220 | { |
225 | - path: 'ruleChain/import', | |
221 | + path: ':ruleChainId', | |
226 | 222 | component: RuleChainPageComponent, |
227 | - canActivate: [RuleChainImportGuard], | |
228 | 223 | canDeactivate: [ConfirmOnExitGuard], |
229 | 224 | data: { |
230 | 225 | breadcrumb: { |
231 | - labelFunction: importRuleChainBreadcumbLabelFunction, | |
226 | + labelFunction: ruleChainBreadcumbLabelFunction, | |
232 | 227 | icon: 'settings_ethernet' |
233 | 228 | } as BreadCrumbConfig<RuleChainPageComponent>, |
234 | 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 | 234 | resolve: { |
235 | + ruleChain: RuleChainResolver, | |
236 | + ruleChainMetaData: ResolvedRuleChainMetaDataResolver, | |
239 | 237 | ruleNodeComponents: RuleNodeComponentsResolver |
240 | 238 | } |
241 | 239 | }, |
242 | 240 | { |
243 | - path: ':ruleChainId', | |
241 | + path: 'ruleChain/import', | |
244 | 242 | component: RuleChainPageComponent, |
243 | + canActivate: [RuleChainImportGuard], | |
245 | 244 | canDeactivate: [ConfirmOnExitGuard], |
246 | 245 | data: { |
247 | 246 | breadcrumb: { |
248 | - labelFunction: ruleChainBreadcumbLabelFunction, | |
247 | + labelFunction: importRuleChainBreadcumbLabelFunction, | |
249 | 248 | icon: 'settings_ethernet' |
250 | 249 | } as BreadCrumbConfig<RuleChainPageComponent>, |
251 | 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 | 255 | resolve: { |
257 | - ruleChain: RuleChainResolver, | |
258 | - ruleChainMetaData: ResolvedRuleChainMetaDataResolver, | |
259 | 256 | ruleNodeComponents: RuleNodeComponentsResolver |
260 | 257 | } |
261 | 258 | } | ... | ... |
... | ... | @@ -74,7 +74,7 @@ export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig< |
74 | 74 | new EntityTableColumn<RuleChain>('name', 'rulechain.name', '100%'), |
75 | 75 | new EntityTableColumn<RuleChain>('root', 'rulechain.root', '60px', |
76 | 76 | entity => { |
77 | - if (isDefined(this.config.componentsData.edgeId)) { | |
77 | + if (this.config.componentsData.edgeId) { | |
78 | 78 | return checkBoxCell((this.edge.rootRuleChainId.id == entity.id.id)); |
79 | 79 | } else { |
80 | 80 | return checkBoxCell(entity.root); |
... | ... | @@ -90,23 +90,25 @@ export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig< |
90 | 90 | this.config.saveEntity = ruleChain => this.saveRuleChain(ruleChain); |
91 | 91 | this.config.deleteEntity = id => this.ruleChainService.deleteRuleChain(id.id); |
92 | 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 | 95 | resolve(route: ActivatedRouteSnapshot): EntityTableConfig<RuleChain> { |
104 | 96 | const routeParams = route.params; |
105 | 97 | this.config.componentsData = { |
106 | 98 | ruleChainScope: route.data.ruleChainsType, |
107 | - type: route.data.type, | |
108 | 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 | 112 | this.configureEntityFunctions(this.config.componentsData.ruleChainScope); |
111 | 113 | this.config.groupActionDescriptors = this.configureGroupActions(this.config.componentsData.ruleChainScope); |
112 | 114 | this.config.addActionDescriptors = this.configureAddActions(this.config.componentsData.ruleChainScope); |
... | ... | @@ -153,13 +155,6 @@ export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig< |
153 | 155 | this.config.tableTitle = this.translate.instant('rulechain.edge-rulechains'); |
154 | 156 | this.config.entitiesFetchFunction = pageLink => this.fetchEdgeRuleChains(pageLink); |
155 | 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 | 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 | 292 | true |
298 | 293 | ).subscribe((res) => { |
299 | 294 | if (res) { |
300 | - if (isDefined(this.config.componentsData.edgeId)) { | |
295 | + if (this.config.componentsData.edgeId) { | |
301 | 296 | this.edgeService.setRootRuleChain(this.config.componentsData.edgeId, ruleChain.id.id).subscribe( |
302 | 297 | (edge) => { |
303 | 298 | this.edge = edge; |
... | ... | @@ -469,7 +464,7 @@ export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig< |
469 | 464 | } |
470 | 465 | |
471 | 466 | isNonRootRuleChain(ruleChain: RuleChain) { |
472 | - if (isDefined(this.config.componentsData.edgeId)) { | |
467 | + if (this.config.componentsData.edgeId) { | |
473 | 468 | return (isDefined(this.edge.rootRuleChainId) && this.edge.rootRuleChainId != null && this.edge.rootRuleChainId.id != ruleChain.id.id); |
474 | 469 | } |
475 | 470 | return (isDefined(ruleChain)) && !ruleChain.root; |
... | ... | @@ -489,21 +484,16 @@ export class RuleChainsTableConfigResolver implements Resolve<EntityTableConfig< |
489 | 484 | |
490 | 485 | fetchEdgeRuleChains(pageLink: PageLink) { |
491 | 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 | 490 | return this.ruleChainService.getRuleChains(pageLink, ruleChainType.edge).pipe( |
500 | - map((response) => { | |
491 | + map(response => { | |
501 | 492 | response.data.map(ruleChain => |
502 | 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 | } | ... | ... |