diff --git a/searchPages/searchUtils/searchDownload.component.ts b/searchPages/searchUtils/searchDownload.component.ts index e73e093e..7d768a0c 100644 --- a/searchPages/searchUtils/searchDownload.component.ts +++ b/searchPages/searchUtils/searchDownload.component.ts @@ -6,14 +6,17 @@ import {ReportsService} from '../../services/reports.service'; import {ModalLoading} from '../../utils/modal/loading.component'; import {PiwikService} from '../../utils/piwik/piwik.service'; import{EnvProperties} from '../../utils/properties/env-properties'; +import 'rxjs/Rx' ; @Component({ selector: 'search-download', template: ` + (CSV) + { - + this.properties = data.envSpecific; this.csvLimit = data.envSpecific.csvLimit; this.downloadURLAPI = data.envSpecific.csvAPIURL; this.isPiwikEnabled = data.envSpecific.enablePiwikTrack; @@ -77,6 +80,8 @@ export class SearchDownloadComponent { } downloadfile(url:string,filename:string){ + //var newWindow = window.open("", "_parent"); + //var newWindow = window.open(); console.log("Downloading file: "+ url); this.openLoading(); this.setMessageLoading("Downloading CSV file"); @@ -84,17 +89,37 @@ export class SearchDownloadComponent { this._reportsService.downloadCSVFile(url).subscribe( data => { this.closeLoading(); - window.open(window.URL.createObjectURL(data),filename+".csv"); + //window.open(window.URL.createObjectURL(data),filename+".csv"); + console.info("Fill window with data for csv"); + + var url = window.URL.createObjectURL(data); + var a = window.document.createElement('a'); + window.document.body.appendChild(a); + a.setAttribute('style', 'display: none'); + a.href = url; + a.download = filename+".csv"; + a.click(); + window.URL.revokeObjectURL(url); + a.remove(); // remove the element + + //newWindow.location.assign(window.URL.createObjectURL(data)); + + //window.location.href = window.URL.createObjectURL(data); + if(this.isPiwikEnabled && (typeof document !== 'undefined')){ this.downloadFilePiwikSub = this._piwikService.trackDownload(this.properties, url).subscribe(); } }, error => { console.log("Error downloading the file."); + //newWindow.close(); this.closeLoading(); this.confirmOpenCsvError(); }, - () => console.log('Completed file download.') + () => { + console.log('Completed file download.'); + //setTimeout(function(){ newWindow.close(); }, 500); + } ); } diff --git a/services/reports.service.ts b/services/reports.service.ts index ce1a3dd2..9ec08bd5 100644 --- a/services/reports.service.ts +++ b/services/reports.service.ts @@ -15,7 +15,7 @@ export class ReportsService { var headers = new Headers(); headers.append('responseType', 'arraybuffer'); return this.http.get(url) - .map(res => new Blob([res['_body']], { type: 'text/csv' })); + .map(res => new Blob([res['_body']], { type: 'text/csv' })); } getCSVResponse(url: string){ var headers = new Headers();