From 0351b83286f9eeecb7513d674da68f7af3d01584 Mon Sep 17 00:00:00 2001 From: Vladyslav Prykhodko Date: Sat, 15 Jan 2022 10:46:01 +0200 Subject: [PATCH] UI: Fixed generate url for entity details page --- .../models/entity/entity-table-component.models.ts | 2 ++ .../home/pages/asset/assets-table-config.resolver.ts | 11 ++++++----- .../pages/customer/customers-table-config.resolver.ts | 11 ++++++----- .../device-profiles-table-config.resolver.ts | 3 ++- .../pages/device/devices-table-config.resolver.ts | 11 ++++++----- .../home/pages/edge/edges-table-config.resolver.ts | 11 ++++++----- .../entity-view/entity-views-table-config.resolver.ts | 11 ++++++----- .../ota-update/ota-update-table-config.resolve.ts | 3 ++- .../tenant-profiles-table-config.resolver.ts | 3 ++- .../pages/tenant/tenants-table-config.resolver.ts | 11 ++++++----- .../home/pages/user/users-table-config.resolver.ts | 11 ++++++----- 11 files changed, 50 insertions(+), 38 deletions(-) diff --git a/ui-ngx/src/app/modules/home/models/entity/entity-table-component.models.ts b/ui-ngx/src/app/modules/home/models/entity/entity-table-component.models.ts index 3c1a7428ab..f28daf36a3 100644 --- a/ui-ngx/src/app/modules/home/models/entity/entity-table-component.models.ts +++ b/ui-ngx/src/app/modules/home/models/entity/entity-table-component.models.ts @@ -31,6 +31,7 @@ import { GroupActionDescriptor, HeaderActionDescriptor } from '@home/models/entity/entities-table-config.models'; +import { ActivatedRoute } from '@angular/router'; export interface IEntitiesTableComponent { entitiesTableConfig: EntityTableConfig>; @@ -60,6 +61,7 @@ export interface IEntitiesTableComponent { searchInputField: ElementRef; paginator: MatPaginator; sort: MatSort; + route: ActivatedRoute; addEnabled(): boolean; clearSelection(): void; diff --git a/ui-ngx/src/app/modules/home/pages/asset/assets-table-config.resolver.ts b/ui-ngx/src/app/modules/home/pages/asset/assets-table-config.resolver.ts index bb6fb934ac..93b0aef495 100644 --- a/ui-ngx/src/app/modules/home/pages/asset/assets-table-config.resolver.ts +++ b/ui-ngx/src/app/modules/home/pages/asset/assets-table-config.resolver.ts @@ -103,7 +103,7 @@ export class AssetsTableConfigResolver implements Resolve this.assetService.getAssetInfo(savedAsset.id.id) )); }; - this.config.onEntityAction = action => this.onAssetAction(action); + this.config.onEntityAction = action => this.onAssetAction(action, this.config); this.config.detailsReadonly = () => (this.config.componentsData.assetScope === 'customer_user' || this.config.componentsData.assetScope === 'edge_customer_user'); this.config.headerComponent = AssetTableHeaderComponent; @@ -337,11 +337,12 @@ export class AssetsTableConfigResolver implements Resolve) { if ($event) { $event.stopPropagation(); } - this.router.navigateByUrl(`${this.router.url}/${asset.id.id}`); + const url = this.router.createUrlTree([asset.id.id], {relativeTo: config.table.route}) + this.router.navigateByUrl(url); } addAssetsToCustomer($event: Event) { @@ -466,10 +467,10 @@ export class AssetsTableConfigResolver implements Resolve): boolean { + onAssetAction(action: EntityAction, config: EntityTableConfig): boolean { switch (action.action) { case 'open': - this.openAsset(action.event, action.entity); + this.openAsset(action.event, action.entity, config); return true; case 'makePublic': this.makePublic(action.event, action.entity); diff --git a/ui-ngx/src/app/modules/home/pages/customer/customers-table-config.resolver.ts b/ui-ngx/src/app/modules/home/pages/customer/customers-table-config.resolver.ts index 8dca7c71bd..fafa5bb4f2 100644 --- a/ui-ngx/src/app/modules/home/pages/customer/customers-table-config.resolver.ts +++ b/ui-ngx/src/app/modules/home/pages/customer/customers-table-config.resolver.ts @@ -125,7 +125,7 @@ export class CustomersTableConfigResolver implements Resolve this.customerService.getCustomer(id.id); this.config.saveEntity = customer => this.customerService.saveCustomer(customer); this.config.deleteEntity = id => this.customerService.deleteCustomer(id.id); - this.config.onEntityAction = action => this.onCustomerAction(action); + this.config.onEntityAction = action => this.onCustomerAction(action, this.config); this.config.deleteEnabled = (customer) => customer && (!customer.additionalInfo || !customer.additionalInfo.isPublic); this.config.entitySelectionEnabled = (customer) => customer && (!customer.additionalInfo || !customer.additionalInfo.isPublic); this.config.detailsReadonly = (customer) => customer && customer.additionalInfo && customer.additionalInfo.isPublic; @@ -137,11 +137,12 @@ export class CustomersTableConfigResolver implements Resolve) { if ($event) { $event.stopPropagation(); } - this.router.navigateByUrl(`${this.router.url}/${customer.id.id}`); + const url = this.router.createUrlTree([customer.id.id], {relativeTo: config.table.route}) + this.router.navigateByUrl(url); } manageCustomerUsers($event: Event, customer: Customer) { @@ -179,10 +180,10 @@ export class CustomersTableConfigResolver implements Resolve): boolean { + onCustomerAction(action: EntityAction, config: EntityTableConfig): boolean { switch (action.action) { case 'open': - this.openCustomer(action.event, action.entity); + this.openCustomer(action.event, action.entity, config); return true; case 'manageUsers': this.manageCustomerUsers(action.event, action.entity); diff --git a/ui-ngx/src/app/modules/home/pages/device-profile/device-profiles-table-config.resolver.ts b/ui-ngx/src/app/modules/home/pages/device-profile/device-profiles-table-config.resolver.ts index 661adb9267..155c8174ce 100644 --- a/ui-ngx/src/app/modules/home/pages/device-profile/device-profiles-table-config.resolver.ts +++ b/ui-ngx/src/app/modules/home/pages/device-profile/device-profiles-table-config.resolver.ts @@ -183,7 +183,8 @@ export class DeviceProfilesTableConfigResolver implements Resolve this.deviceService.getDeviceInfo(savedDevice.id.id) )); }; - this.config.onEntityAction = action => this.onDeviceAction(action); + this.config.onEntityAction = action => this.onDeviceAction(action, this.config); this.config.detailsReadonly = () => (this.config.componentsData.deviceScope === 'customer_user' || this.config.componentsData.deviceScope === 'edge_customer_user'); @@ -371,11 +371,12 @@ export class DevicesTableConfigResolver implements Resolve) { if ($event) { $event.stopPropagation(); } - this.router.navigateByUrl(`${this.router.url}/${device.id.id}`); + const url = this.router.createUrlTree([device.id.id], {relativeTo: config.table.route}) + this.router.navigateByUrl(url); } importDevices($event: Event) { @@ -546,10 +547,10 @@ export class DevicesTableConfigResolver implements Resolve): boolean { + onDeviceAction(action: EntityAction, config: EntityTableConfig): boolean { switch (action.action) { case 'open': - this.openDevice(action.event, action.entity); + this.openDevice(action.event, action.entity, config); return true; case 'makePublic': this.makePublic(action.event, action.entity); diff --git a/ui-ngx/src/app/modules/home/pages/edge/edges-table-config.resolver.ts b/ui-ngx/src/app/modules/home/pages/edge/edges-table-config.resolver.ts index 41ce116ae7..00b1bf2f26 100644 --- a/ui-ngx/src/app/modules/home/pages/edge/edges-table-config.resolver.ts +++ b/ui-ngx/src/app/modules/home/pages/edge/edges-table-config.resolver.ts @@ -96,7 +96,7 @@ export class EdgesTableConfigResolver implements Resolve this.edgeService.getEdgeInfo(savedEdge.id.id) )); }; - this.config.onEntityAction = action => this.onEdgeAction(action); + this.config.onEntityAction = action => this.onEdgeAction(action, this.config); this.config.detailsReadonly = () => this.config.componentsData.edgeScope === 'customer_user'; this.config.headerComponent = EdgeTableHeaderComponent; } @@ -370,11 +370,12 @@ export class EdgesTableConfigResolver implements Resolve) { if ($event) { $event.stopPropagation(); } - this.router.navigateByUrl(`${this.router.url}/${edge.id.id}`); + const url = this.router.createUrlTree([edge.id.id], {relativeTo: config.table.route}) + this.router.navigateByUrl(url); } makePublic($event: Event, edge: Edge) { @@ -525,10 +526,10 @@ export class EdgesTableConfigResolver implements Resolve): boolean { + onEdgeAction(action: EntityAction, config: EntityTableConfig): boolean { switch (action.action) { case 'open': - this.openEdge(action.event, action.entity); + this.openEdge(action.event, action.entity, config); return true; case 'makePublic': this.makePublic(action.event, action.entity); 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 630f483918..e45370d257 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 @@ -103,7 +103,7 @@ export class EntityViewsTableConfigResolver implements Resolve this.entityViewService.getEntityViewInfo(savedEntityView.id.id) )); }; - this.config.onEntityAction = action => this.onEntityViewAction(action); + this.config.onEntityAction = action => this.onEntityViewAction(action, this.config); this.config.detailsReadonly = () => (this.config.componentsData.entityViewScope === 'customer_user' || this.config.componentsData.entityViewScope === 'edge_customer_user'); @@ -333,11 +333,12 @@ export class EntityViewsTableConfigResolver implements Resolve) { if ($event) { $event.stopPropagation(); } - this.router.navigateByUrl(`${this.router.url}/${entityView.id.id}`); + const url = this.router.createUrlTree([entityView.id.id], {relativeTo: config.table.route}) + this.router.navigateByUrl(url); } makePublic($event: Event, entityView: EntityView) { @@ -442,10 +443,10 @@ export class EntityViewsTableConfigResolver implements Resolve): boolean { + onEntityViewAction(action: EntityAction, config: EntityTableConfig): boolean { switch (action.action) { case 'open': - this.openEntityView(action.event, action.entity); + this.openEntityView(action.event, action.entity, config); return true; case 'makePublic': this.makePublic(action.event, action.entity); diff --git a/ui-ngx/src/app/modules/home/pages/ota-update/ota-update-table-config.resolve.ts b/ui-ngx/src/app/modules/home/pages/ota-update/ota-update-table-config.resolve.ts index 91556c73f5..0bea07784d 100644 --- a/ui-ngx/src/app/modules/home/pages/ota-update/ota-update-table-config.resolve.ts +++ b/ui-ngx/src/app/modules/home/pages/ota-update/ota-update-table-config.resolve.ts @@ -132,7 +132,8 @@ export class OtaUpdateTableConfigResolve implements Resolve this.tenantService.getTenantInfo(savedTenant.id.id)) ); this.config.deleteEntity = id => this.tenantService.deleteTenant(id.id); - this.config.onEntityAction = action => this.onTenantAction(action); + this.config.onEntityAction = action => this.onTenantAction(action, this.config); } resolve(): EntityTableConfig { @@ -87,11 +87,12 @@ export class TenantsTableConfigResolver implements Resolve) { if ($event) { $event.stopPropagation(); } - this.router.navigateByUrl(`${this.router.url}/${tenant.id.id}`); + const url = this.router.createUrlTree([tenant.id.id], {relativeTo: config.table.route}) + this.router.navigateByUrl(url); } manageTenantAdmins($event: Event, tenant: TenantInfo) { @@ -101,10 +102,10 @@ export class TenantsTableConfigResolver implements Resolve): boolean { + onTenantAction(action: EntityAction, config: EntityTableConfig): boolean { switch (action.action) { case 'open': - this.openTenant(action.event, action.entity); + this.openTenant(action.event, action.entity, config); return true; case 'manageTenantAdmins': this.manageTenantAdmins(action.event, action.entity); diff --git a/ui-ngx/src/app/modules/home/pages/user/users-table-config.resolver.ts b/ui-ngx/src/app/modules/home/pages/user/users-table-config.resolver.ts index 2e3148d7d8..3902b463c8 100644 --- a/ui-ngx/src/app/modules/home/pages/user/users-table-config.resolver.ts +++ b/ui-ngx/src/app/modules/home/pages/user/users-table-config.resolver.ts @@ -98,7 +98,7 @@ export class UsersTableConfigResolver implements Resolve this.config.loadEntity = id => this.userService.getUser(id.id); this.config.saveEntity = user => this.saveUser(user); this.config.deleteEntity = id => this.userService.deleteUser(id.id); - this.config.onEntityAction = action => this.onUserAction(action); + this.config.onEntityAction = action => this.onUserAction(action, this.config); this.config.addEntity = () => this.addUser(); } @@ -174,11 +174,12 @@ export class UsersTableConfigResolver implements Resolve }).afterClosed(); } - private openUser($event: Event, user: User) { + private openUser($event: Event, user: User, config: EntityTableConfig) { if ($event) { $event.stopPropagation(); } - this.router.navigateByUrl(`${this.router.url}/${user.id.id}`); + const url = this.router.createUrlTree([user.id.id], {relativeTo: config.table.route}) + this.router.navigateByUrl(url); } loginAsUser($event: Event, user: User) { @@ -236,10 +237,10 @@ export class UsersTableConfigResolver implements Resolve }); } - onUserAction(action: EntityAction): boolean { + onUserAction(action: EntityAction, config: EntityTableConfig): boolean { switch (action.action) { case 'open': - this.openUser(action.event, action.entity); + this.openUser(action.event, action.entity, config); return true; case 'loginAsUser': this.loginAsUser(action.event, action.entity);