Organization & Project landing page: change how CSV buttons/links work to set filename and avoid browser popup blocker.

git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@53731 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
konstantina.galouni 2018-11-13 10:28:27 +00:00
parent f86a8891df
commit 7d6f6f5297
4 changed files with 56 additions and 10 deletions

View File

@ -231,7 +231,7 @@
<!--a href="{{downloadURLAPI}}resources?size={{organizationInfo.projects.get(key).length}}&{{csvProjectParamsHead}}{{organizationInfo.projects.get(key)[0]['funderId']}}{{csvParamsTail}}">
Download projects report (CSV) for {{key}}
</a-->
<a class="clickable" (click)="downloadFile(downloadURLAPI+'?'+csvProjectParamsHead+encodeURI(funder.id)+csvParamsTail)">
<a class="clickable" (click)="downloadFile(downloadURLAPI+'?'+csvProjectParamsHead+encodeURI(funder.id)+csvParamsTail, 'funder-projects-report')">
<!--span class="clickable" (click)="downloadProjectsFile(downloadURLAPI+'organizations/'+organizationId+'/projects?fq=(funderid exact '+funder.id+')&size='+funder.number)"-->
<span class="uk-icon"><svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" icon="download" ratio="1"><polyline fill="none" stroke="#000" points="14,10 9.5,14.5 5,10"></polyline><rect x="3" y="17" width="13" height="1"></rect><line fill="none" stroke="#000" x1="9.5" y1="13.91" x2="9.5" y2="3"></line></svg></span>
<span class="uk-icon-download"> Project list for {{funder.name}} (CSV)</span>
@ -249,7 +249,7 @@
<!-- url = this.downloadURLAPI+"format=csv-special&type=publications&fq=(((oaftype exact result) and (resulttypeid exact publication)) and (relprojectid exact '"+projects[index].id+"'))"-->
<!-- <a class="clickable" (click)="downloadFile(downloadURLAPI+'/organizations/'+organizationId+'?type=publications&format=csv')"> -->
<a class="clickable" (click)="downloadFile(downloadURLAPI+'?format=csv&type=publications&fq=(((oaftype exact result) and (resulttypeid exact publication)) and (relorganizationid exact '+organizationId+'))')">
<a class="clickable" (click)="downloadFile(downloadURLAPI+'?format=csv&type=publications&fq=(((oaftype exact result) and (resulttypeid exact publication)) and (relorganizationid exact '+organizationId+'))', 'organization-publications-report')">
<span class="uk-icon"><svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" icon="download" ratio="1"><polyline fill="none" stroke="#000" points="14,10 9.5,14.5 5,10"></polyline><rect x="3" y="17" width="13" height="1"></rect><line fill="none" stroke="#000" x1="9.5" y1="13.91" x2="9.5" y2="3"></line></svg></span>
<span class="uk-icon-download"> Publications of organization (CSV) - based on the affiliation information.</span>
</a>

View File

@ -314,7 +314,7 @@ export class OrganizationComponent {
}
}
public downloadFile(url:string){
public downloadFile(url:string, filename: string){
console.log("Downloading file: "+ url);
this.openLoading();
@ -323,7 +323,18 @@ export class OrganizationComponent {
this.downloadFileSub = this._reportsService.downloadCSVFile(url).subscribe(
data => {
this.closeLoading();
window.open(window.URL.createObjectURL(data));
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
//window.open(window.URL.createObjectURL(data));
if(this.properties.enablePiwikTrack && (typeof document !== 'undefined')){
this.downloadFilePiwikSub = this._piwikService.trackDownload(this.properties, url, this.piwikSiteId).subscribe();
}
@ -348,6 +359,8 @@ export class OrganizationComponent {
let counter: number = count;
let title: boolean = false;
let filename: string = 'funder-project-publications-report';
this.countProjectsSub = this._searchProjectsService.getProjectsForOrganizations(this.organizationId,' and (funder exact "'+ funderId + '" ) ',1,count,[], this.properties).subscribe(
data =>
{
@ -378,7 +391,18 @@ export class OrganizationComponent {
}
}
this.closeLoading();
window.open(window.URL.createObjectURL(new Blob([totalResponse], { type: 'text/csv' })));
var csvurl = window.URL.createObjectURL(new Blob([totalResponse], { type: 'text/csv' }));
var a = window.document.createElement('a');
window.document.body.appendChild(a);
a.setAttribute('style', 'display: none');
a.href = csvurl;
a.download = filename+".csv";
a.click();
window.URL.revokeObjectURL(csvurl);
a.remove(); // remove the element
//window.open(window.URL.createObjectURL(new Blob([totalResponse], { type: 'text/csv' })));
// if(this.properties.enablePiwikTrack && (typeof document !== 'undefined')){
// this._piwikService.trackDownload(this.properties, url).subscribe();
// }
@ -399,7 +423,18 @@ export class OrganizationComponent {
}
}
this.closeLoading();
window.open(window.URL.createObjectURL(new Blob([totalResponse], { type: 'text/csv' })));
var csvurl = window.URL.createObjectURL(new Blob([totalResponse], { type: 'text/csv' }));
var a = window.document.createElement('a');
window.document.body.appendChild(a);
a.setAttribute('style', 'display: none');
a.href = csvurl;
a.download = filename+".csv";
a.click();
window.URL.revokeObjectURL(csvurl);
a.remove(); // remove the element
//window.open(window.URL.createObjectURL(new Blob([totalResponse], { type: 'text/csv' })));
// if(this.properties.enablePiwikTrack && (typeof document !== 'undefined')){
// this._piwikService.trackDownload(this.properties, url).subscribe();
// }

View File

@ -449,7 +449,7 @@
</a>
</li>
<li>
<a class="clickable" (click)="downloadfile(downloadURLAPI+csvParams)">
<a class="clickable" (click)="downloadfile(downloadURLAPI+csvParams, 'funder-publications-report')">
<span class="uk-icon"><svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" icon="download" ratio="1"><polyline fill="none" stroke="#000" points="14,10 9.5,14.5 5,10"></polyline><rect x="3" y="17" width="13" height="1"></rect><line fill="none" stroke="#000" x1="9.5" y1="13.91" x2="9.5" y2="3"></line></svg></span> Get {{projectInfo.funder}} report (CSV)
</a>
</li>
@ -486,7 +486,7 @@
</a>
</li>
<li>
<a class="clickable" (click)="downloadfile(downloadURLAPI+csvParamsDatasets)">
<a class="clickable" (click)="downloadfile(downloadURLAPI+csvParamsDatasets, 'funder-research-data-report')">
<span class="uk-icon"><svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" icon="download" ratio="1"><polyline fill="none" stroke="#000" points="14,10 9.5,14.5 5,10"></polyline><rect x="3" y="17" width="13" height="1"></rect><line fill="none" stroke="#000" x1="9.5" y1="13.91" x2="9.5" y2="3"></line></svg></span> Get {{projectInfo.funder}} report (CSV)
</a>
</li>

View File

@ -373,14 +373,25 @@ actionsAfterGettingProjectInfo(){
this.showLoading = false;
}
public downloadfile(url:string){
public downloadfile(url:string, filename: string){
this.openLoading();
this.setMessageLoading("Downloading CSV file");
this._reportsService.downloadCSVFile(url).subscribe(
data => {
this.closeLoading();
window.open(window.URL.createObjectURL(data));
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
//window.open(window.URL.createObjectURL(data));
if(this.properties.enablePiwikTrack && (typeof document !== 'undefined')){
this.downloadFilePiwikSub = this._piwikService.trackDownload(this.properties, url).subscribe();
}