openaire-library/utils/configuration/configuration.service.ts

71 lines
2.6 KiB
TypeScript

import {Injectable} from '@angular/core';
import {Http, Response, Headers} from '@angular/http';
import {HttpClient} from "@angular/common/http";
import {Observable} from 'rxjs';
// import 'rxjs/add/operator/do';
// import 'rxjs/add/operator/share';
import {map, mapTo} from 'rxjs/operators';
import {EnvProperties} from "../properties/env-properties";
@Injectable()
export class ConfigurationService {
constructor(private http: HttpClient ) {}
getCommunityInformation(properties:EnvProperties, community:string){
let url = properties.adminToolsAPIURL +"/communityFull/" + community;
return this.http.get((properties.useCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url);
//.map(res => res.json());
}
isEntityEnabled(APIUrl:string, community:string,entity: string){
//console.log("isEntityEnabled: "+entity);
let url = "isEntityEnabled-"+entity;
// if(entity == "publication" || entity == "dataset" || entity == "datasource"){
// return Observable.of(new Object()).mapTo(false);
// }
// return Observable.of(new Object()).mapTo(true);
return this.http.get(APIUrl + "/page")
.pipe(map(res => true));
}
isPageEnabled(properties:EnvProperties, community:string,router: string){
let url = properties.adminToolsAPIURL + "/community/" + community+"/pages?page_route="+router;
return this.http.get((properties.useCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url)
//.map(res => res.json())
.pipe(map(res => {
let result = false;
if(res['length'] >0 && res[0].route == router){
result = res[0].isEnabled;
}
return result;
}));//.do(res => {console.log("Route "+router +" is "+res)});
}
getMainPageContent(APIUrl:string, community:string,){
return this.http.get(APIUrl + "/page")
.pipe(map(res => true));
}
getSpecialAnouncementContent(APIUrl:string, community:string,){
return this.http.get(APIUrl + "/page")
.pipe(map(res => ""));
}
getHelpPageContent(APIUrl:string, community:string, router:string){
return this.http.get(APIUrl + "/page")
.pipe(map(res => true));
}
// 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 this.http.get(this.APIUrl + "/page")
// .map(res => true);
// }
}