Project

General

Profile

1
import { Injectable } from '@angular/core';
2
import { Http, Response, Headers, RequestOptions } from '@angular/http';
3
import { Observable } from 'rxjs/Rx';
4
import {StatisticsDisplay, StatisticsSummary} from "../../openaireLibrary/connect/statistics/statisticsEntities";
5

    
6

    
7
@Injectable()
8
export class StatisticsService {
9

    
10

    
11
    constructor(private http:Http) { }
12

    
13
    getCommunityStatistics(apiUrl: string, communityId: string): Observable<StatisticsSummary> {
14
        let url = `${apiUrl}communities/${communityId}`;
15
        console.log(`getting statistics summary from: ${url}`);
16
        return this.http.get(url)
17
            .map(res => <any>res.json())
18
            .do(res => {console.log(res)})
19
            .map(res => res.statistics)
20
            .do(res => {console.log(res)});
21
    }
22

    
23
    getCommunityAdminStatisticsChoices(apiUrl: string, communityId: string): Observable<StatisticsDisplay> {
24
        let url = `${apiUrl}/statistics/${communityId}`;
25
        console.log(`getting admin choices for statistics from: ${url}`);
26
        return this.http.get(url)
27
            .map(stats => <StatisticsDisplay>stats.json())
28
            .catch(this.handleError);
29
    }
30

    
31

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