39 lines
1.4 KiB
TypeScript
39 lines
1.4 KiB
TypeScript
import { Injectable } from '@angular/core';
|
|
import { Http, Response, Headers, RequestOptions } from '@angular/http';
|
|
import { Observable } from 'rxjs/Rx';
|
|
import {StatisticsDisplay, StatisticsSummary} from "../../openaireLibrary/connect/statistics/statisticsEntities";
|
|
|
|
|
|
@Injectable()
|
|
export class StatisticsService {
|
|
|
|
|
|
constructor(private http:Http) { }
|
|
|
|
getCommunityStatistics(apiUrl: string, communityId: string): Observable<StatisticsSummary> {
|
|
let url = `${apiUrl}communities/${communityId}`;
|
|
console.log(`getting statistics summary from: ${url}`);
|
|
return this.http.get(url)
|
|
.map(res => <any>res.json())
|
|
.do(res => {console.log(res)})
|
|
.map(res => res.statistics)
|
|
.do(res => {console.log(res)});
|
|
}
|
|
|
|
getCommunityAdminStatisticsChoices(apiUrl: string, communityId: string): Observable<StatisticsDisplay> {
|
|
let url = `${apiUrl}/statistics/${communityId}`;
|
|
console.log(`getting admin choices for statistics from: ${url}`);
|
|
return this.http.get(url)
|
|
.map(stats => <StatisticsDisplay>stats.json())
|
|
.catch(this.handleError);
|
|
}
|
|
|
|
|
|
private handleError (error: Response) {
|
|
// 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);
|
|
return Observable.throw(error || 'Server error');
|
|
}
|
|
}
|