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

86 lines
2.8 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());
}
/**
* @deprecated
*/
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 page_route: string = router.split('?')[0].substring(1);
let url = properties.adminToolsAPIURL + "/community/" + community+"/pages?page_route="+page_route;
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 == page_route){
result = res[0].isEnabled;
}
return result;
}));//.do(res => {console.log("Route "+page_route +" is "+res)});
}
/**
* @deprecated
*/
getMainPageContent(APIUrl:string, community:string,){
return this.http.get(APIUrl + "/page")
.pipe(map(res => true));
}
/**
* @deprecated
*/
getSpecialAnouncementContent(APIUrl:string, community:string,){
return this.http.get(APIUrl + "/page")
.pipe(map(res => ""));
}
/**
* @deprecated
*/
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);
// }
}