From 3a48b90d84cebe5f9d0a6a789e13beebeeffce28 Mon Sep 17 00:00:00 2001 From: deaflynx Date: Mon, 22 Jun 2020 12:08:31 +0300 Subject: [PATCH] Fixed Edge devices page --- ui-ngx/src/app/core/http/asset.service.ts | 8 +- .../add-entities-to-edge-dialog.component.ts | 10 +- .../asset/assets-table-config.resolver.ts | 75 ++++++------ .../device/devices-table-config.resolver.ts | 115 ++++++++++++++++++ ui-ngx/src/app/shared/models/asset.models.ts | 1 - .../assets/locale/locale.constant-en_US.json | 11 ++ 6 files changed, 172 insertions(+), 48 deletions(-) diff --git a/ui-ngx/src/app/core/http/asset.service.ts b/ui-ngx/src/app/core/http/asset.service.ts index b3f5f86c10..7935abad4e 100644 --- a/ui-ngx/src/app/core/http/asset.service.ts +++ b/ui-ngx/src/app/core/http/asset.service.ts @@ -90,11 +90,13 @@ export class AssetService { } public assignAssetToEdge(edgeId: string, assetId: string, config?: RequestConfig): Observable { - return this.http.post(`/api/edge/${edgeId}/asset/${assetId}`, null, defaultHttpOptionsFromConfig(config)); + return this.http.post(`/api/edge/${edgeId}/asset/${assetId}`, null, + defaultHttpOptionsFromConfig(config)); } - public unassignAssetFromEdge(assetId: string, config?: RequestConfig) { - return this.http.delete(`/api/edge/asset/${assetId}`, defaultHttpOptionsFromConfig(config)); + public unassignAssetFromEdge(edgeId: string, assetId: string, + config?: RequestConfig) { + return this.http.delete(`/api/edge/${edgeId}/asset/${assetId}`, defaultHttpOptionsFromConfig(config)); } public getEdgeAssets(edgeId, pageLink: PageLink, type: string = '', diff --git a/ui-ngx/src/app/modules/home/dialogs/add-entities-to-edge-dialog.component.ts b/ui-ngx/src/app/modules/home/dialogs/add-entities-to-edge-dialog.component.ts index cba40c88d9..a179c05286 100644 --- a/ui-ngx/src/app/modules/home/dialogs/add-entities-to-edge-dialog.component.ts +++ b/ui-ngx/src/app/modules/home/dialogs/add-entities-to-edge-dialog.component.ts @@ -76,23 +76,23 @@ export class AddEntitiesToEdgeDialogComponent extends }); switch (this.data.entityType) { case EntityType.DEVICE: - this.assignToEdgeTitle = 'device.assign-device-to-edge'; + this.assignToEdgeTitle = 'device.assign-device-to-edge-title'; this.assignToEdgeText = 'device.assign-device-to-edge-text'; break; case EntityType.RULE_CHAIN: - this.assignToEdgeTitle = 'rulechain.assign-rulechain-to-edge'; + this.assignToEdgeTitle = 'rulechain.assign-rulechain-to-edge-title'; this.assignToEdgeText = 'rulechain.assign-rulechain-to-edge-text'; break; case EntityType.ASSET: - this.assignToEdgeTitle = 'asset.assign-asset-to-edge'; + this.assignToEdgeTitle = 'asset.assign-asset-to-edge-title'; this.assignToEdgeText = 'asset.assign-asset-to-edge-text'; break; case EntityType.ENTITY_VIEW: - this.assignToEdgeTitle = 'entity-view.assign-entity-view-to-edge'; + this.assignToEdgeTitle = 'entity-view.assign-entity-view-to-edge-title'; this.assignToEdgeText = 'entity-view.assign-entity-view-to-edge-text'; break; case EntityType.DASHBOARD: - this.assignToEdgeTitle = 'dashboard.assign-dashboard-to-edge'; + this.assignToEdgeTitle = 'dashboard.assign-dashboard-to-edge-title'; this.assignToEdgeText = 'dashboard.assign-dashboard-to-edge-text'; break; } 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 3ca3adfe3e..841822681a 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 @@ -136,13 +136,10 @@ export class AssetsTableConfigResolver implements Resolve - this.config.tableTitle = edge.name + ': ' + this.translate.instant('asset.assets') ), - ).subscribe(); - } - else { + } else if (this.config.componentsData.assetScope === 'edge') { + this.edgeService.getEdge(this.edgeId).pipe(map(edge => + this.config.tableTitle = edge.name + ': ' + this.translate.instant('asset.assets'))).subscribe(); + } else { this.config.tableTitle = this.translate.instant('asset.assets'); } this.config.columns = this.configureColumns(this.config.componentsData.assetScope); @@ -242,9 +239,9 @@ export class AssetsTableConfigResolver implements Resolve (entity.edgeId && entity.edgeId.id !== NULL_UUID), + isEnabled: (entity) => true, onAction: ($event, entity) => this.unassignFromEdge($event, entity) } ); @@ -264,23 +261,23 @@ export class AssetsTableConfigResolver implements Resolve this.unassignAssetsFromEdge($event, entities) + onAction: ($event, entities) => this.unassignAssetsFromCustomer($event, entities) } ); } - if (assetScope === 'customer') { + if (assetScope === 'edge') { actions.push( { - name: this.translate.instant('asset.unassign-assets'), - icon: 'assignment_return', + name: this.translate.instant('asset.unassign-assets-from-edge'), + icon: 'portable_wifi_off', isEnabled: true, - onAction: ($event, entities) => this.unassignAssetsFromCustomer($event, entities) + onAction: ($event, entities) => this.unassignAssetsFromEdge($event, entities) } ); } @@ -357,26 +354,6 @@ export class AssetsTableConfigResolver implements Resolve(AddEntitiesToEdgeDialogComponent, { - disableClose: true, - panelClass: ['tb-dialog', 'tb-fullscreen-dialog'], - data: { - edgeId: this.edgeId, - entityType: EntityType.ASSET - } - }).afterClosed() - .subscribe((res) => { - if (res) { - this.config.table.updateData(); - } - }); - } - makePublic($event: Event, asset: Asset) { if ($event) { $event.stopPropagation(); @@ -494,6 +471,26 @@ export class AssetsTableConfigResolver implements Resolve(AddEntitiesToEdgeDialogComponent, { + disableClose: true, + panelClass: ['tb-dialog', 'tb-fullscreen-dialog'], + data: { + edgeId: this.edgeId, + entityType: EntityType.ASSET + } + }).afterClosed() + .subscribe((res) => { + if (res) { + this.config.table.updateData(); + } + }); + } + unassignFromEdge($event: Event, asset: AssetInfo) { if ($event) { $event.stopPropagation(); @@ -506,7 +503,7 @@ export class AssetsTableConfigResolver implements Resolve { if (res) { - this.assetService.unassignAssetFromEdge(asset.id.id).subscribe( + this.assetService.unassignAssetFromEdge(this.edgeId, asset.id.id).subscribe( () => { this.config.table.updateData(); } @@ -531,7 +528,7 @@ export class AssetsTableConfigResolver implements Resolve[] = []; assets.forEach( (asset) => { - tasks.push(this.assetService.unassignAssetFromEdge(asset.id.id)); + tasks.push(this.assetService.unassignAssetFromEdge(this.edgeId, asset.id.id)); } ); forkJoin(tasks).subscribe( 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 3216e776dd..814bc47374 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 @@ -61,6 +61,11 @@ import { } from '../../dialogs/add-entities-to-customer-dialog.component'; import { DeviceTabsComponent } from '@home/pages/device/device-tabs.component'; import { HomeDialogsService } from '@home/dialogs/home-dialogs.service'; +import { EdgeService } from "@core/http/edge.service"; +import { + AddEntitiesToEdgeDialogComponent, + AddEntitiesToEdgeDialogData +} from "@home/dialogs/add-entities-to-edge-dialog.component"; @Injectable() export class DevicesTableConfigResolver implements Resolve> { @@ -68,12 +73,14 @@ export class DevicesTableConfigResolver implements Resolve = new EntityTableConfig(); private customerId: string; + private edgeId: string; constructor(private store: Store, private broadcast: BroadcastService, private deviceService: DeviceService, private customerService: CustomerService, private dialogService: DialogService, + private edgeService: EdgeService, private homeDialogs: HomeDialogsService, private translate: TranslateService, private datePipe: DatePipe, @@ -114,6 +121,7 @@ export class DevicesTableConfigResolver implements Resolve { if (authUser.authority === Authority.CUSTOMER_USER) { @@ -131,6 +139,9 @@ export class DevicesTableConfigResolver implements Resolve + this.config.tableTitle = edge.name + ': ' + this.translate.instant('device.devices'))).subscribe(); } else { this.config.tableTitle = this.translate.instant('device.devices'); } @@ -177,6 +188,10 @@ export class DevicesTableConfigResolver implements Resolve this.deviceService.getTenantDeviceInfos(pageLink, this.config.componentsData.deviceType); this.config.deleteEntity = id => this.deviceService.deleteDevice(id.id); + } else if (deviceScope === 'edge') { + this.config.entitiesFetchFunction = pageLink => + this.deviceService.getEdgeDevices(this.edgeId, pageLink, this.config.componentsData.edgeType); + this.config.deleteEntity = id => this.deviceService.deleteDevice(id.id); } else { this.config.entitiesFetchFunction = pageLink => this.deviceService.getCustomerDeviceInfos(this.customerId, pageLink, this.config.componentsData.deviceType); @@ -252,6 +267,16 @@ export class DevicesTableConfigResolver implements Resolve true, + onAction: ($event, entity) => this.unassignFromEdge($event, entity) + } + ); + } return actions; } @@ -277,6 +302,16 @@ export class DevicesTableConfigResolver implements Resolve this.unassignDevicesFromCustomer($event, entities) + } + ); + } return actions; } @@ -308,6 +343,16 @@ export class DevicesTableConfigResolver implements Resolve true, + onAction: ($event) => this.addDevicesToEdge($event) + } + ); + } return actions; } @@ -475,4 +520,74 @@ export class DevicesTableConfigResolver implements Resolve(AddEntitiesToEdgeDialogComponent, { + disableClose: true, + panelClass: ['tb-dialog', 'tb-fullscreen-dialog'], + data: { + edgeId: this.edgeId, + entityType: EntityType.DEVICE + } + }).afterClosed() + .subscribe((res) => { + if (res) { + this.config.table.updateData(); + } + }); + } + + unassignFromEdge($event: Event, device: DeviceInfo) { + if ($event) { + $event.stopPropagation(); + } + this.dialogService.confirm( + this.translate.instant('device.unassign-device-from-edge-title', {deviceName: device.name}), + this.translate.instant('device.unassign-device-from-edge-text'), + this.translate.instant('action.no'), + this.translate.instant('action.yes'), + true + ).subscribe((res) => { + if (res) { + this.deviceService.unassignDeviceFromEdge(device.id.id).subscribe( + () => { + this.config.table.updateData(); + } + ); + } + } + ); + } + + unassignDevicesFromEdge($event: Event, devices: Array) { + if ($event) { + $event.stopPropagation(); + } + this.dialogService.confirm( + this.translate.instant('device.unassign-devices-from-edge-title', {count: devices.length}), + this.translate.instant('device.unassign-devices-from-edge-text'), + this.translate.instant('action.no'), + this.translate.instant('action.yes'), + true + ).subscribe((res) => { + if (res) { + const tasks: Observable[] = []; + devices.forEach( + (device) => { + tasks.push(this.deviceService.unassignDeviceFromEdge(device.id.id)); + } + ); + forkJoin(tasks).subscribe( + () => { + this.config.table.updateData(); + } + ); + } + } + ); + } + } diff --git a/ui-ngx/src/app/shared/models/asset.models.ts b/ui-ngx/src/app/shared/models/asset.models.ts index 69ce01b6af..d1e64c06d7 100644 --- a/ui-ngx/src/app/shared/models/asset.models.ts +++ b/ui-ngx/src/app/shared/models/asset.models.ts @@ -24,7 +24,6 @@ import { EdgeId } from "@shared/models/id/edge-id"; export interface Asset extends BaseData { tenantId?: TenantId; customerId?: CustomerId; - edgeId?: EdgeId; //TODO: deaflynx: "edgeId?" ? name: string; type: string; label: string; diff --git a/ui-ngx/src/assets/locale/locale.constant-en_US.json b/ui-ngx/src/assets/locale/locale.constant-en_US.json index 28bdc53e99..6351a2c9f5 100644 --- a/ui-ngx/src/assets/locale/locale.constant-en_US.json +++ b/ui-ngx/src/assets/locale/locale.constant-en_US.json @@ -266,6 +266,8 @@ "asset-details": "Asset details", "assign-assets": "Assign assets", "assign-assets-text": "Assign { count, plural, 1 {1 asset} other {# assets} } to customer", + "assign-asset-to-edge-title": "Assign Asset(s) To Edge", + "assign-asset-to-edge-text":"Please select the assets to assign to the edge", "delete-assets": "Delete assets", "unassign-assets": "Unassign assets", "unassign-assets-action-title": "Unassign { count, plural, 1 {1 asset} other {# assets} } from customer", @@ -284,6 +286,11 @@ "unassign-asset": "Unassign asset", "unassign-assets-title": "Are you sure you want to unassign { count, plural, 1 {1 asset} other {# assets} }?", "unassign-assets-text": "After the confirmation all selected assets will be unassigned and won't be accessible by the customer.", + "unassign-asset-from-edge-title": "Are you sure you want to unassign the asset '{{assetName}}'?", + "unassign-asset-from-edge-text": "After the confirmation the asset will be unassigned and won't be accessible by the edge.", + "unassign-assets-from-edge": "Unassign assets from edge", + "unassign-assets-from-edge-title": "Are you sure you want to unassign { count, plural, 1 {1 asset} other {# assets} }?", + "unassign-assets-from-edge-text": "After the confirmation all selected assets will be unassigned and won't be accessible by the edge.", "copyId": "Copy asset Id", "idCopiedMessage": "Asset Id has been copied to clipboard", "select-asset": "Select asset", @@ -669,6 +676,8 @@ "assign-to-customer": "Assign to customer", "assign-device-to-customer": "Assign Device(s) To Customer", "assign-device-to-customer-text": "Please select the devices to assign to the customer", + "assign-device-to-edge-title": "Assign Device(s) To Edge", + "assign-device-to-edge-text":"Please select the devices to assign to the edge", "make-public": "Make device public", "make-private": "Make device private", "no-devices-text": "No devices found", @@ -684,6 +693,8 @@ "unassign-from-customer": "Unassign from customer", "unassign-devices": "Unassign devices", "unassign-devices-action-title": "Unassign { count, plural, 1 {1 device} other {# devices} } from customer", + "unassign-device-from-edge-title": "Are you sure you want to unassign the device '{{deviceName}}'?", + "unassign-device-from-edge-text": "After the confirmation the device will be unassigned and won't be accessible by the edge.", "assign-new-device": "Assign new device", "make-public-device-title": "Are you sure you want to make the device '{{deviceName}}' public?", "make-public-device-text": "After the confirmation the device and all its data will be made public and accessible by others.",