1
|
import {Injectable} from '@angular/core';
|
2
|
import {HttpClient} from "@angular/common/http";
|
3
|
import {EnvironmentSpecificService} from "../../openaireLibrary/utils/properties/environment-specific.service";
|
4
|
import {Observable} from "rxjs";
|
5
|
|
6
|
|
7
|
@Injectable({
|
8
|
providedIn: 'root'
|
9
|
})
|
10
|
export class StatisticsService {
|
11
|
|
12
|
numberSources: Map<string, string> = new Map<string, string>();
|
13
|
chartSources: Map<string, string> = new Map<string, string>();
|
14
|
|
15
|
constructor(private http:HttpClient, private environmentSpecificService: EnvironmentSpecificService) {
|
16
|
this.environmentSpecificService.subscribeEnvironment().subscribe(properties => {
|
17
|
this.numberSources.set('statistics', properties.statisticsAPIURL);
|
18
|
this.numberSources.set('search', properties.searchAPIURLLAst);
|
19
|
this.numberSources.set('metrics', properties.metricsAPIURL);
|
20
|
this.chartSources.set('stats-tool', properties.statisticsFrameNewAPIURL);
|
21
|
this.chartSources.set('old', properties.statisticsFrameAPIURL);
|
22
|
this.chartSources.set('metrics', properties.metricsAPIURL);
|
23
|
this.chartSources.set('image', '');
|
24
|
})
|
25
|
}
|
26
|
|
27
|
getNumbers(source: string, url: string): Observable<any> {
|
28
|
return this.http.get<any>(this.numberSources.get(source) + url);
|
29
|
}
|
30
|
|
31
|
getChartUrl(source: string, url: string): string {
|
32
|
return this.chartSources.get(source) + url;
|
33
|
}
|
34
|
|
35
|
getChartSource(url: string): string {
|
36
|
let source = 'image';
|
37
|
this.chartSources.forEach((value, key) => {
|
38
|
if(value !== '' && url.indexOf(value) !== -1) {
|
39
|
source = key;
|
40
|
}
|
41
|
});
|
42
|
return source;
|
43
|
}
|
44
|
}
|