1 |
50988
|
argiro.kok
|
import { Injectable } from '@angular/core';
|
2 |
|
|
import { Http, Response, Headers, RequestOptions } from '@angular/http';
|
3 |
|
|
import { Observable } from 'rxjs/Rx';
|
4 |
51687
|
myrto.kouk
|
import {StatisticsDisplay, StatisticsSummary} from "../../openaireLibrary/connect/statistics/statisticsEntities";
|
5 |
50988
|
argiro.kok
|
|
6 |
|
|
|
7 |
|
|
@Injectable()
|
8 |
|
|
export class StatisticsService {
|
9 |
|
|
|
10 |
|
|
|
11 |
51322
|
myrto.kouk
|
constructor(private http:Http) { }
|
12 |
50988
|
argiro.kok
|
|
13 |
51322
|
myrto.kouk
|
getCommunityStatistics(apiUrl: string, communityId: string): Observable<StatisticsSummary> {
|
14 |
|
|
let url = `${apiUrl}communities/${communityId}`;
|
15 |
54781
|
konstantin
|
//console.log(`getting statistics summary from: ${url}`);
|
16 |
51322
|
myrto.kouk
|
return this.http.get(url)
|
17 |
|
|
.map(res => <any>res.json())
|
18 |
|
|
.map(res => res.statistics)
|
19 |
50988
|
argiro.kok
|
}
|
20 |
|
|
|
21 |
51322
|
myrto.kouk
|
getCommunityAdminStatisticsChoices(apiUrl: string, communityId: string): Observable<StatisticsDisplay> {
|
22 |
|
|
let url = `${apiUrl}/statistics/${communityId}`;
|
23 |
54781
|
konstantin
|
//console.log(`getting admin choices for statistics from: ${url}`);
|
24 |
51322
|
myrto.kouk
|
return this.http.get(url)
|
25 |
|
|
.map(stats => <StatisticsDisplay>stats.json())
|
26 |
|
|
.catch(this.handleError);
|
27 |
|
|
}
|
28 |
50988
|
argiro.kok
|
|
29 |
|
|
|
30 |
51322
|
myrto.kouk
|
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 |
50988
|
argiro.kok
|
}
|