Skip to content

Commit

Permalink
Merge pull request primefaces#272 from Nanitor/fixing-broken-blob
Browse files Browse the repository at this point in the history
CSV functionality was not working
  • Loading branch information
Alfred Hall authored Jul 31, 2019
2 parents 11942cb + 8a609fe commit 9ab120a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
18 changes: 18 additions & 0 deletions src/account/account.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,24 @@ export class AccountService {
);
}

executePostBlob(path: string, payload: any, doAuth: boolean = true): Observable<Object> {
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<Object> {
let headers = new HttpHeaders();
headers = headers.append('Content-Type', 'application/json');
Expand Down
2 changes: 1 addition & 1 deletion src/organization/device/device.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
4 changes: 2 additions & 2 deletions src/organization/device/device_list.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down

0 comments on commit 9ab120a

Please sign in to comment.