2017-12-19 13:53:46 +01:00
|
|
|
import {Injectable} from '@angular/core';
|
2019-06-03 15:20:36 +02:00
|
|
|
import {HttpClient, HttpErrorResponse} from "@angular/common/http";
|
2020-11-11 15:43:13 +01:00
|
|
|
import {throwError} from 'rxjs';
|
2019-06-03 15:20:36 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2021-06-22 10:04:38 +02:00
|
|
|
import {map, tap, timeout} from "rxjs/operators";
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class ReportsService {
|
|
|
|
// url:string = "http://beta.services.openaire.eu:8480/search/rest/v2/api/publications?format=csv&page=0&size=3&q=(%22test%22)&fq=instancetypename%20exact%20%22Dataset%22";
|
2019-06-03 15:20:36 +02:00
|
|
|
constructor(private http: HttpClient) {}
|
2019-06-19 14:33:13 +02:00
|
|
|
|
2017-12-19 13:53:46 +01:00
|
|
|
//On the service:
|
|
|
|
downloadCSVFile(url: string){
|
2022-11-09 10:27:41 +01:00
|
|
|
return this.http.get(url, {responseType: 'text'}).pipe(map(res => new Blob([res], { type: 'text/csv' })));
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
2022-11-09 10:27:41 +01:00
|
|
|
|
2017-12-19 13:53:46 +01:00
|
|
|
getCSVResponse(url: string){
|
2021-06-22 10:04:38 +02:00
|
|
|
return this.http.get(url, {responseType: 'text'})
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
2019-06-19 14:33:13 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @deprecated not used
|
|
|
|
*/
|
2017-12-19 13:53:46 +01:00
|
|
|
downloadHTMLFile(url: string, info: string){
|
2019-06-03 15:20:36 +02:00
|
|
|
//var headers = new Headers();
|
|
|
|
//headers.append('responseType', 'arraybuffer');
|
2017-12-19 13:53:46 +01:00
|
|
|
return this.http.get(url)
|
2019-06-03 15:20:36 +02:00
|
|
|
.pipe(map(res => this.addInfo(res, info)))
|
|
|
|
.pipe(map(res => new Blob([res['_body']], { type: 'text/html' })))
|
|
|
|
.pipe(tap(res => console.log(res)))
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
|
|
|
|
2019-06-19 14:33:13 +02:00
|
|
|
/**
|
|
|
|
* @deprecated not used
|
|
|
|
*/
|
2017-12-19 13:53:46 +01:00
|
|
|
addInfo(res:any, info:string) {
|
|
|
|
/*
|
|
|
|
var para = res.document.createElement("P"); // Create a <p> element
|
|
|
|
var t = res.document.createTextNode("This is a paragraph"); // Create a text node
|
|
|
|
para.appendChild(t); // Append the text to <p>
|
|
|
|
res.document.body.appendChild(para);
|
|
|
|
*/
|
|
|
|
res['_body'] = info+res['_body'];
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2019-06-03 15:20:36 +02:00
|
|
|
private handleError (error: HttpErrorResponse) {
|
2017-12-19 13:53:46 +01:00
|
|
|
// in a real world app, we may send the error to some remote logging infrastructure
|
|
|
|
// instead of just logging it to the console
|
|
|
|
console.log(error);
|
2019-06-03 15:20:36 +02:00
|
|
|
return throwError(error || 'Server error');
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|