diff --git a/ui-ngx/src/app/core/http/device.service.ts b/ui-ngx/src/app/core/http/device.service.ts index 1055c1e53e..fb5af6639b 100644 --- a/ui-ngx/src/app/core/http/device.service.ts +++ b/ui-ngx/src/app/core/http/device.service.ts @@ -147,8 +147,9 @@ export class DeviceService { return this.http.post(`/api/edge/${edgeId}/device/${deviceId}`, defaultHttpOptionsFromConfig(config)); } - public unassignDeviceFromEdge(deviceId: string, config?: RequestConfig) { - return this.http.delete(`/api/edge/device/${deviceId}`, defaultHttpOptionsFromConfig(config)); + public unassignDeviceFromEdge(edgeId: string, deviceId: string, config?: RequestConfig) { + return this.http.delete(`/api/edge/${edgeId}/device/${deviceId}`, + defaultHttpOptionsFromConfig(config)); } public getEdgeDevices(edgeId: string, pageLink: PageLink, type: string = '', diff --git a/ui-ngx/src/app/core/http/entity-view.service.ts b/ui-ngx/src/app/core/http/entity-view.service.ts index 55ac1c6550..468ccca53d 100644 --- a/ui-ngx/src/app/core/http/entity-view.service.ts +++ b/ui-ngx/src/app/core/http/entity-view.service.ts @@ -88,8 +88,9 @@ export class EntityViewService { defaultHttpOptionsFromConfig(config)); } - public unassignEntityViewFromEdge(entityViewId: string, config?: RequestConfig) { - return this.http.delete(`/api/edge/entityView/${entityViewId}`, defaultHttpOptionsFromConfig(config)); + public unassignEntityViewFromEdge(edgeId: string, entityViewId: string, config?: RequestConfig) { + return this.http.delete(`/api/edge/${edgeId}/entityView/${entityViewId}`, + defaultHttpOptionsFromConfig(config)); } public getEdgeEntityViews(edgeId: string, pageLink: PageLink, type: string = '', 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 841822681a..5b48a5c36c 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 @@ -182,7 +182,6 @@ export class AssetsTableConfigResolver implements Resolve this.assetService.getEdgeAssets(this.edgeId, pageLink, this.config.componentsData.assetType); - this.config.deleteEntity = id => this.assetService.deleteAsset(id.id); } else { this.config.entitiesFetchFunction = pageLink => this.assetService.getCustomerAssetInfos(this.customerId, pageLink, this.config.componentsData.assetType); 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 814bc47374..b7467ac090 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 @@ -191,7 +191,6 @@ export class DevicesTableConfigResolver implements Resolve 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); @@ -552,7 +551,7 @@ export class DevicesTableConfigResolver implements Resolve { if (res) { - this.deviceService.unassignDeviceFromEdge(device.id.id).subscribe( + this.deviceService.unassignDeviceFromEdge(this.edgeId, device.id.id).subscribe( () => { this.config.table.updateData(); } @@ -577,7 +576,7 @@ export class DevicesTableConfigResolver implements Resolve[] = []; devices.forEach( (device) => { - tasks.push(this.deviceService.unassignDeviceFromEdge(device.id.id)); + tasks.push(this.deviceService.unassignDeviceFromEdge(this.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 755d5b37d9..d0c6102288 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 @@ -56,6 +56,11 @@ import { EntityViewComponent } from '@modules/home/pages/entity-view/entity-view import { EntityViewTableHeaderComponent } from '@modules/home/pages/entity-view/entity-view-table-header.component'; import { EntityViewId } from '@shared/models/id/entity-view-id'; import { EntityViewTabsComponent } from '@home/pages/entity-view/entity-view-tabs.component'; +import { EdgeService } from "@core/http/edge.service"; +import { + AddEntitiesToEdgeDialogComponent, + AddEntitiesToEdgeDialogData +} from "@home/dialogs/add-entities-to-edge-dialog.component"; @Injectable() export class EntityViewsTableConfigResolver implements Resolve> { @@ -63,11 +68,13 @@ export class EntityViewsTableConfigResolver implements Resolve = new EntityTableConfig(); private customerId: string; + private edgeId: string; constructor(private store: Store, private broadcast: BroadcastService, private entityViewService: EntityViewService, private customerService: CustomerService, + private edgeService: EdgeService, private dialogService: DialogService, private translate: TranslateService, private datePipe: DatePipe, @@ -111,6 +118,7 @@ export class EntityViewsTableConfigResolver implements Resolve { if (authUser.authority === Authority.CUSTOMER_USER) { @@ -128,7 +136,11 @@ export class EntityViewsTableConfigResolver implements Resolve + this.config.tableTitle = edge.name + ': ' + this.translate.instant('entity-view.entity-views'))).subscribe(); + } + else { this.config.tableTitle = this.translate.instant('entity-view.entity-views'); } this.config.columns = this.configureColumns(this.config.componentsData.entityViewScope); @@ -167,6 +179,9 @@ export class EntityViewsTableConfigResolver implements Resolve this.entityViewService.getTenantEntityViewInfos(pageLink, this.config.componentsData.entityViewType); this.config.deleteEntity = id => this.entityViewService.deleteEntityView(id.id); + } else if (entityViewScope === 'edge') { + this.config.entitiesFetchFunction = pageLink => + this.entityViewService.getEdgeEntityViews(this.edgeId, pageLink, this.config.componentsData.entityViewType); } else { this.config.entitiesFetchFunction = pageLink => this.entityViewService.getCustomerEntityViewInfos(this.customerId, pageLink, this.config.componentsData.entityViewType); @@ -220,6 +235,16 @@ export class EntityViewsTableConfigResolver implements Resolve true, + onAction: ($event, entity) => this.unassignFromEdge($event, entity) + } + ); + } return actions; } @@ -245,6 +270,16 @@ export class EntityViewsTableConfigResolver implements Resolve this.unassignEntityViewsFromEdge($event, entities) + } + ); + } return actions; } @@ -260,6 +295,16 @@ export class EntityViewsTableConfigResolver implements Resolve true, + onAction: ($event) => this.addEntityViewsToEdge($event) + } + ); + } return actions; } @@ -400,4 +445,74 @@ export class EntityViewsTableConfigResolver implements Resolve(AddEntitiesToEdgeDialogComponent, { + disableClose: true, + panelClass: ['tb-dialog', 'tb-fullscreen-dialog'], + data: { + edgeId: this.edgeId, + entityType: EntityType.ENTITY_VIEW + } + }).afterClosed() + .subscribe((res) => { + if (res) { + this.config.table.updateData(); + } + }); + } + + unassignFromEdge($event: Event, entityView: EntityViewInfo) { + if ($event) { + $event.stopPropagation(); + } + this.dialogService.confirm( + this.translate.instant('entity-view.unassign-entity-view-from-edge-title', {entityViewName: entityView.name}), + this.translate.instant('entity-view.unassign-entity-view-from-edge-text'), + this.translate.instant('action.no'), + this.translate.instant('action.yes'), + true + ).subscribe((res) => { + if (res) { + this.entityViewService.unassignEntityViewFromEdge(this.edgeId, entityView.id.id).subscribe( + () => { + this.config.table.updateData(); + } + ); + } + } + ); + } + + unassignEntityViewsFromEdge($event: Event, entityViews: Array) { + if ($event) { + $event.stopPropagation(); + } + this.dialogService.confirm( + this.translate.instant('entity-view.unassign-entity-views-from-edge-title', {count: entityViews.length}), + this.translate.instant('entity-view.unassign-entity-views-from-edge-text'), + this.translate.instant('action.no'), + this.translate.instant('action.yes'), + true + ).subscribe((res) => { + if (res) { + const tasks: Observable[] = []; + entityViews.forEach( + (entityView) => { + tasks.push(this.entityViewService.unassignEntityViewFromEdge(this.edgeId, entityView.id.id)); + } + ); + forkJoin(tasks).subscribe( + () => { + this.config.table.updateData(); + } + ); + } + } + ); + } + } 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 6351a2c9f5..6e8ea6f85e 100644 --- a/ui-ngx/src/assets/locale/locale.constant-en_US.json +++ b/ui-ngx/src/assets/locale/locale.constant-en_US.json @@ -984,6 +984,8 @@ "assign-to-customer": "Assign to customer", "assign-entity-view-to-customer": "Assign Entity View(s) To Customer", "assign-entity-view-to-customer-text": "Please select the entity views to assign to the customer", + "assign-entity-view-to-edge-title": "Assign Entity View(s) To Edge", + "assign-entity-view-to-edge-text":"Please select the entity views to assign to the edge", "no-entity-views-text": "No entity views found", "assign-to-customer-text": "Please select the customer to assign the entity view(s)", "entity-view-details": "Entity view details", @@ -995,6 +997,8 @@ "unassign-from-customer": "Unassign from customer", "unassign-entity-views": "Unassign entity views", "unassign-entity-views-action-title": "Unassign { count, plural, 1 {1 entity view} other {# entity views} } from customer", + "unassign-entity-view-from-edge-title": "Are you sure you want to unassign the entity view '{{entityViewName}}'?", + "unassign-entity-view-from-edge-text": "After the confirmation the entity view will be unassigned and won't be accessible by the edge.", "assign-new-entity-view": "Assign new entity view", "delete-entity-view-title": "Are you sure you want to delete the entity view '{{entityViewName}}'?", "delete-entity-view-text": "Be careful, after the confirmation the entity view and all related data will become unrecoverable.",