Showing
6 changed files
with
172 additions
and
48 deletions
... | ... | @@ -90,11 +90,13 @@ export class AssetService { |
90 | 90 | } |
91 | 91 | |
92 | 92 | public assignAssetToEdge(edgeId: string, assetId: string, config?: RequestConfig): Observable<Asset> { |
93 | - return this.http.post<Asset>(`/api/edge/${edgeId}/asset/${assetId}`, null, defaultHttpOptionsFromConfig(config)); | |
93 | + return this.http.post<Asset>(`/api/edge/${edgeId}/asset/${assetId}`, null, | |
94 | + defaultHttpOptionsFromConfig(config)); | |
94 | 95 | } |
95 | 96 | |
96 | - public unassignAssetFromEdge(assetId: string, config?: RequestConfig) { | |
97 | - return this.http.delete(`/api/edge/asset/${assetId}`, defaultHttpOptionsFromConfig(config)); | |
97 | + public unassignAssetFromEdge(edgeId: string, assetId: string, | |
98 | + config?: RequestConfig) { | |
99 | + return this.http.delete(`/api/edge/${edgeId}/asset/${assetId}`, defaultHttpOptionsFromConfig(config)); | |
98 | 100 | } |
99 | 101 | |
100 | 102 | public getEdgeAssets(edgeId, pageLink: PageLink, type: string = '', | ... | ... |
... | ... | @@ -76,23 +76,23 @@ export class AddEntitiesToEdgeDialogComponent extends |
76 | 76 | }); |
77 | 77 | switch (this.data.entityType) { |
78 | 78 | case EntityType.DEVICE: |
79 | - this.assignToEdgeTitle = 'device.assign-device-to-edge'; | |
79 | + this.assignToEdgeTitle = 'device.assign-device-to-edge-title'; | |
80 | 80 | this.assignToEdgeText = 'device.assign-device-to-edge-text'; |
81 | 81 | break; |
82 | 82 | case EntityType.RULE_CHAIN: |
83 | - this.assignToEdgeTitle = 'rulechain.assign-rulechain-to-edge'; | |
83 | + this.assignToEdgeTitle = 'rulechain.assign-rulechain-to-edge-title'; | |
84 | 84 | this.assignToEdgeText = 'rulechain.assign-rulechain-to-edge-text'; |
85 | 85 | break; |
86 | 86 | case EntityType.ASSET: |
87 | - this.assignToEdgeTitle = 'asset.assign-asset-to-edge'; | |
87 | + this.assignToEdgeTitle = 'asset.assign-asset-to-edge-title'; | |
88 | 88 | this.assignToEdgeText = 'asset.assign-asset-to-edge-text'; |
89 | 89 | break; |
90 | 90 | case EntityType.ENTITY_VIEW: |
91 | - this.assignToEdgeTitle = 'entity-view.assign-entity-view-to-edge'; | |
91 | + this.assignToEdgeTitle = 'entity-view.assign-entity-view-to-edge-title'; | |
92 | 92 | this.assignToEdgeText = 'entity-view.assign-entity-view-to-edge-text'; |
93 | 93 | break; |
94 | 94 | case EntityType.DASHBOARD: |
95 | - this.assignToEdgeTitle = 'dashboard.assign-dashboard-to-edge'; | |
95 | + this.assignToEdgeTitle = 'dashboard.assign-dashboard-to-edge-title'; | |
96 | 96 | this.assignToEdgeText = 'dashboard.assign-dashboard-to-edge-text'; |
97 | 97 | break; |
98 | 98 | } | ... | ... |
... | ... | @@ -136,13 +136,10 @@ export class AssetsTableConfigResolver implements Resolve<EntityTableConfig<Asse |
136 | 136 | } else { |
137 | 137 | this.config.tableTitle = parentCustomer.title + ': ' + this.translate.instant('asset.assets'); |
138 | 138 | } |
139 | - } else if (this.edgeId) { // TODO: deaflynx: find better way - out of parentCustomer map | |
140 | - this.edgeService.getEdge(this.edgeId) | |
141 | - .pipe(map(edge => | |
142 | - this.config.tableTitle = edge.name + ': ' + this.translate.instant('asset.assets') ), | |
143 | - ).subscribe(); | |
144 | - } | |
145 | - else { | |
139 | + } else if (this.config.componentsData.assetScope === 'edge') { | |
140 | + this.edgeService.getEdge(this.edgeId).pipe(map(edge => | |
141 | + this.config.tableTitle = edge.name + ': ' + this.translate.instant('asset.assets'))).subscribe(); | |
142 | + } else { | |
146 | 143 | this.config.tableTitle = this.translate.instant('asset.assets'); |
147 | 144 | } |
148 | 145 | this.config.columns = this.configureColumns(this.config.componentsData.assetScope); |
... | ... | @@ -242,9 +239,9 @@ export class AssetsTableConfigResolver implements Resolve<EntityTableConfig<Asse |
242 | 239 | if (assetScope === 'edge') { |
243 | 240 | actions.push( |
244 | 241 | { |
245 | - name: this.translate.instant('asset.unassign-from-edge'), | |
242 | + name: this.translate.instant('edge.unassign-from-edge'), | |
246 | 243 | icon: 'portable_wifi_off', |
247 | - isEnabled: (entity) => (entity.edgeId && entity.edgeId.id !== NULL_UUID), | |
244 | + isEnabled: (entity) => true, | |
248 | 245 | onAction: ($event, entity) => this.unassignFromEdge($event, entity) |
249 | 246 | } |
250 | 247 | ); |
... | ... | @@ -264,23 +261,23 @@ export class AssetsTableConfigResolver implements Resolve<EntityTableConfig<Asse |
264 | 261 | } |
265 | 262 | ); |
266 | 263 | } |
267 | - if (assetScope === 'edge') { | |
264 | + if (assetScope === 'customer') { | |
268 | 265 | actions.push( |
269 | 266 | { |
270 | - name: this.translate.instant('asset.unassign-assets-from-edge'), | |
271 | - icon: 'portable_wifi_off', | |
267 | + name: this.translate.instant('asset.unassign-assets'), | |
268 | + icon: 'assignment_return', | |
272 | 269 | isEnabled: true, |
273 | - onAction: ($event, entities) => this.unassignAssetsFromEdge($event, entities) | |
270 | + onAction: ($event, entities) => this.unassignAssetsFromCustomer($event, entities) | |
274 | 271 | } |
275 | 272 | ); |
276 | 273 | } |
277 | - if (assetScope === 'customer') { | |
274 | + if (assetScope === 'edge') { | |
278 | 275 | actions.push( |
279 | 276 | { |
280 | - name: this.translate.instant('asset.unassign-assets'), | |
281 | - icon: 'assignment_return', | |
277 | + name: this.translate.instant('asset.unassign-assets-from-edge'), | |
278 | + icon: 'portable_wifi_off', | |
282 | 279 | isEnabled: true, |
283 | - onAction: ($event, entities) => this.unassignAssetsFromCustomer($event, entities) | |
280 | + onAction: ($event, entities) => this.unassignAssetsFromEdge($event, entities) | |
284 | 281 | } |
285 | 282 | ); |
286 | 283 | } |
... | ... | @@ -357,26 +354,6 @@ export class AssetsTableConfigResolver implements Resolve<EntityTableConfig<Asse |
357 | 354 | }); |
358 | 355 | } |
359 | 356 | |
360 | - addAssetsToEdge($event: Event) { | |
361 | - if ($event) { | |
362 | - $event.stopPropagation(); | |
363 | - } | |
364 | - this.dialog.open<AddEntitiesToEdgeDialogComponent, AddEntitiesToEdgeDialogData, | |
365 | - boolean>(AddEntitiesToEdgeDialogComponent, { | |
366 | - disableClose: true, | |
367 | - panelClass: ['tb-dialog', 'tb-fullscreen-dialog'], | |
368 | - data: { | |
369 | - edgeId: this.edgeId, | |
370 | - entityType: EntityType.ASSET | |
371 | - } | |
372 | - }).afterClosed() | |
373 | - .subscribe((res) => { | |
374 | - if (res) { | |
375 | - this.config.table.updateData(); | |
376 | - } | |
377 | - }); | |
378 | - } | |
379 | - | |
380 | 357 | makePublic($event: Event, asset: Asset) { |
381 | 358 | if ($event) { |
382 | 359 | $event.stopPropagation(); |
... | ... | @@ -494,6 +471,26 @@ export class AssetsTableConfigResolver implements Resolve<EntityTableConfig<Asse |
494 | 471 | return false; |
495 | 472 | } |
496 | 473 | |
474 | + addAssetsToEdge($event: Event) { | |
475 | + if ($event) { | |
476 | + $event.stopPropagation(); | |
477 | + } | |
478 | + this.dialog.open<AddEntitiesToEdgeDialogComponent, AddEntitiesToEdgeDialogData, | |
479 | + boolean>(AddEntitiesToEdgeDialogComponent, { | |
480 | + disableClose: true, | |
481 | + panelClass: ['tb-dialog', 'tb-fullscreen-dialog'], | |
482 | + data: { | |
483 | + edgeId: this.edgeId, | |
484 | + entityType: EntityType.ASSET | |
485 | + } | |
486 | + }).afterClosed() | |
487 | + .subscribe((res) => { | |
488 | + if (res) { | |
489 | + this.config.table.updateData(); | |
490 | + } | |
491 | + }); | |
492 | + } | |
493 | + | |
497 | 494 | unassignFromEdge($event: Event, asset: AssetInfo) { |
498 | 495 | if ($event) { |
499 | 496 | $event.stopPropagation(); |
... | ... | @@ -506,7 +503,7 @@ export class AssetsTableConfigResolver implements Resolve<EntityTableConfig<Asse |
506 | 503 | true |
507 | 504 | ).subscribe((res) => { |
508 | 505 | if (res) { |
509 | - this.assetService.unassignAssetFromEdge(asset.id.id).subscribe( | |
506 | + this.assetService.unassignAssetFromEdge(this.edgeId, asset.id.id).subscribe( | |
510 | 507 | () => { |
511 | 508 | this.config.table.updateData(); |
512 | 509 | } |
... | ... | @@ -531,7 +528,7 @@ export class AssetsTableConfigResolver implements Resolve<EntityTableConfig<Asse |
531 | 528 | const tasks: Observable<any>[] = []; |
532 | 529 | assets.forEach( |
533 | 530 | (asset) => { |
534 | - tasks.push(this.assetService.unassignAssetFromEdge(asset.id.id)); | |
531 | + tasks.push(this.assetService.unassignAssetFromEdge(this.edgeId, asset.id.id)); | |
535 | 532 | } |
536 | 533 | ); |
537 | 534 | forkJoin(tasks).subscribe( | ... | ... |
... | ... | @@ -61,6 +61,11 @@ import { |
61 | 61 | } from '../../dialogs/add-entities-to-customer-dialog.component'; |
62 | 62 | import { DeviceTabsComponent } from '@home/pages/device/device-tabs.component'; |
63 | 63 | import { HomeDialogsService } from '@home/dialogs/home-dialogs.service'; |
64 | +import { EdgeService } from "@core/http/edge.service"; | |
65 | +import { | |
66 | + AddEntitiesToEdgeDialogComponent, | |
67 | + AddEntitiesToEdgeDialogData | |
68 | +} from "@home/dialogs/add-entities-to-edge-dialog.component"; | |
64 | 69 | |
65 | 70 | @Injectable() |
66 | 71 | export class DevicesTableConfigResolver implements Resolve<EntityTableConfig<DeviceInfo>> { |
... | ... | @@ -68,12 +73,14 @@ export class DevicesTableConfigResolver implements Resolve<EntityTableConfig<Dev |
68 | 73 | private readonly config: EntityTableConfig<DeviceInfo> = new EntityTableConfig<DeviceInfo>(); |
69 | 74 | |
70 | 75 | private customerId: string; |
76 | + private edgeId: string; | |
71 | 77 | |
72 | 78 | constructor(private store: Store<AppState>, |
73 | 79 | private broadcast: BroadcastService, |
74 | 80 | private deviceService: DeviceService, |
75 | 81 | private customerService: CustomerService, |
76 | 82 | private dialogService: DialogService, |
83 | + private edgeService: EdgeService, | |
77 | 84 | private homeDialogs: HomeDialogsService, |
78 | 85 | private translate: TranslateService, |
79 | 86 | private datePipe: DatePipe, |
... | ... | @@ -114,6 +121,7 @@ export class DevicesTableConfigResolver implements Resolve<EntityTableConfig<Dev |
114 | 121 | deviceType: '' |
115 | 122 | }; |
116 | 123 | this.customerId = routeParams.customerId; |
124 | + this.edgeId = routeParams.edgeId; | |
117 | 125 | return this.store.pipe(select(selectAuthUser), take(1)).pipe( |
118 | 126 | tap((authUser) => { |
119 | 127 | if (authUser.authority === Authority.CUSTOMER_USER) { |
... | ... | @@ -131,6 +139,9 @@ export class DevicesTableConfigResolver implements Resolve<EntityTableConfig<Dev |
131 | 139 | } else { |
132 | 140 | this.config.tableTitle = parentCustomer.title + ': ' + this.translate.instant('device.devices'); |
133 | 141 | } |
142 | + } else if (this.config.componentsData.deviceScope === 'edge') { | |
143 | + this.edgeService.getEdge(this.edgeId).pipe(map(edge => | |
144 | + this.config.tableTitle = edge.name + ': ' + this.translate.instant('device.devices'))).subscribe(); | |
134 | 145 | } else { |
135 | 146 | this.config.tableTitle = this.translate.instant('device.devices'); |
136 | 147 | } |
... | ... | @@ -177,6 +188,10 @@ export class DevicesTableConfigResolver implements Resolve<EntityTableConfig<Dev |
177 | 188 | this.config.entitiesFetchFunction = pageLink => |
178 | 189 | this.deviceService.getTenantDeviceInfos(pageLink, this.config.componentsData.deviceType); |
179 | 190 | this.config.deleteEntity = id => this.deviceService.deleteDevice(id.id); |
191 | + } else if (deviceScope === 'edge') { | |
192 | + this.config.entitiesFetchFunction = pageLink => | |
193 | + this.deviceService.getEdgeDevices(this.edgeId, pageLink, this.config.componentsData.edgeType); | |
194 | + this.config.deleteEntity = id => this.deviceService.deleteDevice(id.id); | |
180 | 195 | } else { |
181 | 196 | this.config.entitiesFetchFunction = pageLink => |
182 | 197 | this.deviceService.getCustomerDeviceInfos(this.customerId, pageLink, this.config.componentsData.deviceType); |
... | ... | @@ -252,6 +267,16 @@ export class DevicesTableConfigResolver implements Resolve<EntityTableConfig<Dev |
252 | 267 | } |
253 | 268 | ); |
254 | 269 | } |
270 | + if (deviceScope === 'edge') { | |
271 | + actions.push( | |
272 | + { | |
273 | + name: this.translate.instant('edge.unassign-from-edge'), | |
274 | + icon: 'portable_wifi_off', | |
275 | + isEnabled: (entity) => true, | |
276 | + onAction: ($event, entity) => this.unassignFromEdge($event, entity) | |
277 | + } | |
278 | + ); | |
279 | + } | |
255 | 280 | return actions; |
256 | 281 | } |
257 | 282 | |
... | ... | @@ -277,6 +302,16 @@ export class DevicesTableConfigResolver implements Resolve<EntityTableConfig<Dev |
277 | 302 | } |
278 | 303 | ); |
279 | 304 | } |
305 | + if (deviceScope === 'edge') { | |
306 | + actions.push( | |
307 | + { | |
308 | + name: this.translate.instant('asset.unassign-assets-from-edge'), | |
309 | + icon: 'portable_wifi_off', | |
310 | + isEnabled: true, | |
311 | + onAction: ($event, entities) => this.unassignDevicesFromCustomer($event, entities) | |
312 | + } | |
313 | + ); | |
314 | + } | |
280 | 315 | return actions; |
281 | 316 | } |
282 | 317 | |
... | ... | @@ -308,6 +343,16 @@ export class DevicesTableConfigResolver implements Resolve<EntityTableConfig<Dev |
308 | 343 | } |
309 | 344 | ); |
310 | 345 | } |
346 | + if (deviceScope === 'edge') { | |
347 | + actions.push( | |
348 | + { | |
349 | + name: this.translate.instant('device.assign-new-device'), | |
350 | + icon: 'add', | |
351 | + isEnabled: () => true, | |
352 | + onAction: ($event) => this.addDevicesToEdge($event) | |
353 | + } | |
354 | + ); | |
355 | + } | |
311 | 356 | return actions; |
312 | 357 | } |
313 | 358 | |
... | ... | @@ -475,4 +520,74 @@ export class DevicesTableConfigResolver implements Resolve<EntityTableConfig<Dev |
475 | 520 | return false; |
476 | 521 | } |
477 | 522 | |
523 | + addDevicesToEdge($event: Event) { | |
524 | + if ($event) { | |
525 | + $event.stopPropagation(); | |
526 | + } | |
527 | + this.dialog.open<AddEntitiesToEdgeDialogComponent, AddEntitiesToEdgeDialogData, | |
528 | + boolean>(AddEntitiesToEdgeDialogComponent, { | |
529 | + disableClose: true, | |
530 | + panelClass: ['tb-dialog', 'tb-fullscreen-dialog'], | |
531 | + data: { | |
532 | + edgeId: this.edgeId, | |
533 | + entityType: EntityType.DEVICE | |
534 | + } | |
535 | + }).afterClosed() | |
536 | + .subscribe((res) => { | |
537 | + if (res) { | |
538 | + this.config.table.updateData(); | |
539 | + } | |
540 | + }); | |
541 | + } | |
542 | + | |
543 | + unassignFromEdge($event: Event, device: DeviceInfo) { | |
544 | + if ($event) { | |
545 | + $event.stopPropagation(); | |
546 | + } | |
547 | + this.dialogService.confirm( | |
548 | + this.translate.instant('device.unassign-device-from-edge-title', {deviceName: device.name}), | |
549 | + this.translate.instant('device.unassign-device-from-edge-text'), | |
550 | + this.translate.instant('action.no'), | |
551 | + this.translate.instant('action.yes'), | |
552 | + true | |
553 | + ).subscribe((res) => { | |
554 | + if (res) { | |
555 | + this.deviceService.unassignDeviceFromEdge(device.id.id).subscribe( | |
556 | + () => { | |
557 | + this.config.table.updateData(); | |
558 | + } | |
559 | + ); | |
560 | + } | |
561 | + } | |
562 | + ); | |
563 | + } | |
564 | + | |
565 | + unassignDevicesFromEdge($event: Event, devices: Array<DeviceInfo>) { | |
566 | + if ($event) { | |
567 | + $event.stopPropagation(); | |
568 | + } | |
569 | + this.dialogService.confirm( | |
570 | + this.translate.instant('device.unassign-devices-from-edge-title', {count: devices.length}), | |
571 | + this.translate.instant('device.unassign-devices-from-edge-text'), | |
572 | + this.translate.instant('action.no'), | |
573 | + this.translate.instant('action.yes'), | |
574 | + true | |
575 | + ).subscribe((res) => { | |
576 | + if (res) { | |
577 | + const tasks: Observable<any>[] = []; | |
578 | + devices.forEach( | |
579 | + (device) => { | |
580 | + tasks.push(this.deviceService.unassignDeviceFromEdge(device.id.id)); | |
581 | + } | |
582 | + ); | |
583 | + forkJoin(tasks).subscribe( | |
584 | + () => { | |
585 | + this.config.table.updateData(); | |
586 | + } | |
587 | + ); | |
588 | + } | |
589 | + } | |
590 | + ); | |
591 | + } | |
592 | + | |
478 | 593 | } | ... | ... |
... | ... | @@ -24,7 +24,6 @@ import { EdgeId } from "@shared/models/id/edge-id"; |
24 | 24 | export interface Asset extends BaseData<AssetId> { |
25 | 25 | tenantId?: TenantId; |
26 | 26 | customerId?: CustomerId; |
27 | - edgeId?: EdgeId; //TODO: deaflynx: "edgeId?" ? | |
28 | 27 | name: string; |
29 | 28 | type: string; |
30 | 29 | label: string; | ... | ... |
... | ... | @@ -266,6 +266,8 @@ |
266 | 266 | "asset-details": "Asset details", |
267 | 267 | "assign-assets": "Assign assets", |
268 | 268 | "assign-assets-text": "Assign { count, plural, 1 {1 asset} other {# assets} } to customer", |
269 | + "assign-asset-to-edge-title": "Assign Asset(s) To Edge", | |
270 | + "assign-asset-to-edge-text":"Please select the assets to assign to the edge", | |
269 | 271 | "delete-assets": "Delete assets", |
270 | 272 | "unassign-assets": "Unassign assets", |
271 | 273 | "unassign-assets-action-title": "Unassign { count, plural, 1 {1 asset} other {# assets} } from customer", |
... | ... | @@ -284,6 +286,11 @@ |
284 | 286 | "unassign-asset": "Unassign asset", |
285 | 287 | "unassign-assets-title": "Are you sure you want to unassign { count, plural, 1 {1 asset} other {# assets} }?", |
286 | 288 | "unassign-assets-text": "After the confirmation all selected assets will be unassigned and won't be accessible by the customer.", |
289 | + "unassign-asset-from-edge-title": "Are you sure you want to unassign the asset '{{assetName}}'?", | |
290 | + "unassign-asset-from-edge-text": "After the confirmation the asset will be unassigned and won't be accessible by the edge.", | |
291 | + "unassign-assets-from-edge": "Unassign assets from edge", | |
292 | + "unassign-assets-from-edge-title": "Are you sure you want to unassign { count, plural, 1 {1 asset} other {# assets} }?", | |
293 | + "unassign-assets-from-edge-text": "After the confirmation all selected assets will be unassigned and won't be accessible by the edge.", | |
287 | 294 | "copyId": "Copy asset Id", |
288 | 295 | "idCopiedMessage": "Asset Id has been copied to clipboard", |
289 | 296 | "select-asset": "Select asset", |
... | ... | @@ -669,6 +676,8 @@ |
669 | 676 | "assign-to-customer": "Assign to customer", |
670 | 677 | "assign-device-to-customer": "Assign Device(s) To Customer", |
671 | 678 | "assign-device-to-customer-text": "Please select the devices to assign to the customer", |
679 | + "assign-device-to-edge-title": "Assign Device(s) To Edge", | |
680 | + "assign-device-to-edge-text":"Please select the devices to assign to the edge", | |
672 | 681 | "make-public": "Make device public", |
673 | 682 | "make-private": "Make device private", |
674 | 683 | "no-devices-text": "No devices found", |
... | ... | @@ -684,6 +693,8 @@ |
684 | 693 | "unassign-from-customer": "Unassign from customer", |
685 | 694 | "unassign-devices": "Unassign devices", |
686 | 695 | "unassign-devices-action-title": "Unassign { count, plural, 1 {1 device} other {# devices} } from customer", |
696 | + "unassign-device-from-edge-title": "Are you sure you want to unassign the device '{{deviceName}}'?", | |
697 | + "unassign-device-from-edge-text": "After the confirmation the device will be unassigned and won't be accessible by the edge.", | |
687 | 698 | "assign-new-device": "Assign new device", |
688 | 699 | "make-public-device-title": "Are you sure you want to make the device '{{deviceName}}' public?", |
689 | 700 | "make-public-device-text": "After the confirmation the device and all its data will be made public and accessible by others.", | ... | ... |