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
            .map(res => res.statistics)
19
    }
20

    
21
    getCommunityAdminStatisticsChoices(apiUrl: string, communityId: string): Observable<StatisticsDisplay> {
22
        let url = `${apiUrl}/statistics/${communityId}`;
23
        //console.log(`getting admin choices for statistics from: ${url}`);
24
        return this.http.get(url)
25
            .map(stats => <StatisticsDisplay>stats.json())
26
            .catch(this.handleError);
27
    }
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
}
    (1-1/1)