From 2aa50f8cbc168062ef59370239060e25ae0d6a68 Mon Sep 17 00:00:00 2001 From: Artem Babak Date: Thu, 5 Nov 2020 14:58:20 +0200 Subject: [PATCH] Refactored edgeId entity table-resolvers --- .../device/devices-table-config.resolver.ts | 16 +++++------ .../entity-views-table-config.resolver.ts | 15 +++++------ .../rulechains-table-config.resolver.ts | 27 +++++++++---------- 3 files changed, 28 insertions(+), 30 deletions(-) diff --git a/ui-ngx/src/app/modules/home/pages/device/devices-table-config.resolver.ts b/ui-ngx/src/app/modules/home/pages/device/devices-table-config.resolver.ts index ccf0a34437..21ef8c1a36 100644 --- a/ui-ngx/src/app/modules/home/pages/device/devices-table-config.resolver.ts +++ b/ui-ngx/src/app/modules/home/pages/device/devices-table-config.resolver.ts @@ -73,7 +73,6 @@ export class DevicesTableConfigResolver implements Resolve = new EntityTableConfig(); private customerId: string; - private edgeId: string; constructor(private store: Store, private broadcast: BroadcastService, @@ -120,10 +119,11 @@ export class DevicesTableConfigResolver implements Resolve { if (authUser.authority === Authority.CUSTOMER_USER) { @@ -142,7 +142,7 @@ export class DevicesTableConfigResolver implements Resolve this.config.tableTitle = edge.name + ': ' + this.translate.instant('device.devices') ); } else { @@ -195,7 +195,7 @@ export class DevicesTableConfigResolver implements Resolve this.deviceService.deleteDevice(id.id); } else if (deviceScope === 'edge') { this.config.entitiesFetchFunction = pageLink => - this.deviceService.getEdgeDevices(this.edgeId, pageLink, this.config.componentsData.edgeType); + this.deviceService.getEdgeDevices(this.config.componentsData.edgeId, pageLink, this.config.componentsData.edgeType); } else { this.config.entitiesFetchFunction = pageLink => this.deviceService.getCustomerDeviceInfosByDeviceProfileId(this.customerId, pageLink, @@ -535,7 +535,7 @@ export class DevicesTableConfigResolver implements Resolve { if (res) { - this.deviceService.unassignDeviceFromEdge(this.edgeId, device.id.id).subscribe( + this.deviceService.unassignDeviceFromEdge(this.config.componentsData.edgeId, device.id.id).subscribe( () => { this.config.table.updateData(); } @@ -583,7 +583,7 @@ export class DevicesTableConfigResolver implements Resolve[] = []; devices.forEach( (device) => { - tasks.push(this.deviceService.unassignDeviceFromEdge(this.edgeId, device.id.id)); + tasks.push(this.deviceService.unassignDeviceFromEdge(this.config.componentsData.edgeId, device.id.id)); } ); forkJoin(tasks).subscribe( diff --git a/ui-ngx/src/app/modules/home/pages/entity-view/entity-views-table-config.resolver.ts b/ui-ngx/src/app/modules/home/pages/entity-view/entity-views-table-config.resolver.ts index 60342a0bb3..cc2f5b3e60 100644 --- a/ui-ngx/src/app/modules/home/pages/entity-view/entity-views-table-config.resolver.ts +++ b/ui-ngx/src/app/modules/home/pages/entity-view/entity-views-table-config.resolver.ts @@ -68,7 +68,6 @@ export class EntityViewsTableConfigResolver implements Resolve = new EntityTableConfig(); private customerId: string; - private edgeId: string; constructor(private store: Store, private broadcast: BroadcastService, @@ -115,10 +114,10 @@ export class EntityViewsTableConfigResolver implements Resolve { if (authUser.authority === Authority.CUSTOMER_USER) { @@ -137,7 +136,7 @@ export class EntityViewsTableConfigResolver implements Resolve this.config.tableTitle = edge.name + ': ' + this.translate.instant('entity-view.entity-views') ); } @@ -182,7 +181,7 @@ export class EntityViewsTableConfigResolver implements Resolve this.entityViewService.deleteEntityView(id.id); } else if (entityViewScope === 'edge') { this.config.entitiesFetchFunction = pageLink => - this.entityViewService.getEdgeEntityViews(this.edgeId, pageLink, this.config.componentsData.entityViewType); + this.entityViewService.getEdgeEntityViews(this.config.componentsData.edgeId, pageLink, this.config.componentsData.entityViewType); } else { this.config.entitiesFetchFunction = pageLink => this.entityViewService.getCustomerEntityViewInfos(this.customerId, pageLink, this.config.componentsData.entityViewType); @@ -455,7 +454,7 @@ export class EntityViewsTableConfigResolver implements Resolve { if (res) { - this.entityViewService.unassignEntityViewFromEdge(this.edgeId, entityView.id.id).subscribe( + this.entityViewService.unassignEntityViewFromEdge(this.config.componentsData.edgeId, entityView.id.id).subscribe( () => { this.config.table.updateData(); } @@ -503,7 +502,7 @@ export class EntityViewsTableConfigResolver implements Resolve[] = []; entityViews.forEach( (entityView) => { - tasks.push(this.entityViewService.unassignEntityViewFromEdge(this.edgeId, entityView.id.id)); + tasks.push(this.entityViewService.unassignEntityViewFromEdge(this.config.componentsData.edgeId, entityView.id.id)); } ); forkJoin(tasks).subscribe( 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 c6a842dc7c..cf8e9e1420 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 @@ -52,7 +52,6 @@ import { Edge } from "@shared/models/edge.models"; export class RuleChainsTableConfigResolver implements Resolve> { private readonly config: EntityTableConfig = new EntityTableConfig(); - private edgeId: string; private edge: Edge; constructor(private ruleChainService: RuleChainService, @@ -75,7 +74,7 @@ export class RuleChainsTableConfigResolver implements Resolve('name', 'rulechain.name', '100%'), new EntityTableColumn('root', 'rulechain.root', '60px', entity => { - if (isDefined(this.edgeId) && this.edgeId != null) { + if (isDefined(this.config.componentsData.edgeId)) { return checkBoxCell((this.edge.rootRuleChainId.id == entity.id.id)); } else { return checkBoxCell(entity.root); @@ -91,9 +90,9 @@ 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.edgeId; + this.config.deleteEnabled = (ruleChain) => ruleChain && !ruleChain.root && !this.config.componentsData.edgeId; this.config.entitySelectionEnabled = (ruleChain) => { - if (isDefined(this.edgeId) && this.edgeId != null) { + if (isDefined(this.config.componentsData.edgeId)) { return this.edge.rootRuleChainId.id != ruleChain.id.id; } else { return ruleChain && !ruleChain.root; @@ -105,9 +104,9 @@ export class RuleChainsTableConfigResolver implements Resolve this.fetchEdgeRuleChains(pageLink); } else if (ruleChainScope === 'edge') { - if (isDefined(this.edgeId) && this.edgeId != null) { - this.edgeService.getEdge(this.edgeId).subscribe( + 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.edgeId, pageLink); + this.config.entitiesFetchFunction = pageLink => this.ruleChainService.getEdgeRuleChains(this.config.componentsData.edgeId, pageLink); } } @@ -298,8 +297,8 @@ export class RuleChainsTableConfigResolver implements Resolve { if (res) { - if (isDefined(this.edgeId) && this.edgeId != null) { - this.edgeService.setRootRuleChain(this.edgeId, ruleChain.id.id).subscribe( + if (isDefined(this.config.componentsData.edgeId)) { + this.edgeService.setRootRuleChain(this.config.componentsData.edgeId, ruleChain.id.id).subscribe( (edge) => { this.edge = edge; this.config.table.updateData(); @@ -363,7 +362,7 @@ export class RuleChainsTableConfigResolver implements Resolve { if (res) { - this.ruleChainService.unassignRuleChainFromEdge(this.edgeId, ruleChain.id.id).subscribe( + this.ruleChainService.unassignRuleChainFromEdge(this.config.componentsData.edgeId, ruleChain.id.id).subscribe( () => { this.config.table.updateData(); } @@ -470,7 +469,7 @@ export class RuleChainsTableConfigResolver implements Resolve