From 8a609fee49c4569177c570073a4d543066914be4 Mon Sep 17 00:00:00 2001 From: Alfred Hall Date: Tue, 30 Jul 2019 18:05:13 +0000 Subject: [PATCH] CSV functionality was not working Fixed, works now. --- src/account/account.service.ts | 18 ++++++++++++++++++ src/organization/device/device.service.ts | 2 +- .../device/device_list.component.ts | 4 ++-- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/account/account.service.ts b/src/account/account.service.ts index 549b45d14ce..2321bd3da9d 100755 --- a/src/account/account.service.ts +++ b/src/account/account.service.ts @@ -93,6 +93,24 @@ export class AccountService { ); } + executePostBlob(path: string, payload: any, doAuth: boolean = true): Observable { + let headers = new HttpHeaders(); + headers = headers.append('Content-Type', 'application/json'); + + if (doAuth) { + headers = headers.append('Authorization', 'Bearer ' + this.getToken()); + } + + return this.http.post( + this.basicUrl + path, + JSON.stringify(payload), + { + headers: headers, + responseType: 'blob' + } + ); + } + executeGet(path: string, doAuth: boolean = true): Observable { let headers = new HttpHeaders(); headers = headers.append('Content-Type', 'application/json'); diff --git a/src/organization/device/device.service.ts b/src/organization/device/device.service.ts index 83d88cf7982..6153dd41446 100755 --- a/src/organization/device/device.service.ts +++ b/src/organization/device/device.service.ts @@ -66,6 +66,6 @@ export class DeviceService extends BaseListService { filters: this.getFilters(), sort: this.listSorting }; - return this.accountService.executePost(`/organization/${this.accountService.getOrganizationId()}/device/export_list`, data); + return this.accountService.executePostBlob(`/organization/${this.accountService.getOrganizationId()}/device/export_list`, data); } } diff --git a/src/organization/device/device_list.component.ts b/src/organization/device/device_list.component.ts index 6cc35b60484..d14178cf5c1 100755 --- a/src/organization/device/device_list.component.ts +++ b/src/organization/device/device_list.component.ts @@ -279,8 +279,8 @@ export class DeviceListComponent extends BaseDevice implements OnInit { const filename = 'nanitor_device_list.csv'; this.service.spinnerService.setState(true); this.service.getAllDevicesInCsv(selectedItemIds).subscribe( - (data: any) => { - FileSaver.saveAs(data, filename); + (blob: Blob) => { + FileSaver.saveAs(blob, filename); this.service.spinnerService.setState(false); }, err => {