Project

General

Profile

1
import {Injectable} from '@angular/core';
2
import {Http, Response, Headers} from '@angular/http';
3
import {Observable}     from 'rxjs/Observable';
4
import {OpenaireProperties} from '../utils/properties/openaireProperties';
5
import 'rxjs/add/observable/of';
6
import 'rxjs/add/operator/do';
7
import 'rxjs/add/operator/share';
8
import { CacheService  } from '../shared/cache.service';
9

    
10
@Injectable()
11
export class ReportsService {
12
    // 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";
13
    constructor(private http: Http) {}
14
//text/html
15
    //On the service:
16
   downloadCSVFile(url: string){
17
     var headers = new Headers();
18
     headers.append('responseType', 'arraybuffer');
19
     return this.http.get(url)
20
               .map(res => new Blob([res['_body']], { type: 'text/csv' }));
21
   }
22
   downloadHTMLFile(url: string){
23
     var headers = new Headers();
24
     headers.append('responseType', 'arraybuffer');
25
     return this.http.get(url).do(res => console.log(res['_body']))
26
               .map(res => new Blob([res['_body']], { type: 'text/html' }))
27
               .do(res => console.log(res))
28
   }
29

    
30
    private handleError (error: Response) {
31
    // in a real world app, we may send the error to some remote logging infrastructure
32
    // instead of just logging it to the console
33
        console.log(error);
34
        return Observable.throw(error  || 'Server error');
35
    }
36

    
37

    
38
}
(11-11/22)