1 |
59816
|
argiro.kok
|
import {Injectable, OnDestroy} from '@angular/core';
|
2 |
55964
|
argiro.kok
|
import {HttpClient} from "@angular/common/http";
|
3 |
59966
|
argiro.kok
|
import {BehaviorSubject, from, Observable, of, Subscription} from 'rxjs';
|
4 |
59816
|
argiro.kok
|
import {map} from 'rxjs/operators';
|
5 |
55995
|
argiro.kok
|
import {EnvProperties} from "../properties/env-properties";
|
6 |
59465
|
konstantin
|
import {Portal} from "../entities/adminTool/portal";
|
7 |
59074
|
konstantin
|
import {Page} from "../entities/adminTool/page";
|
8 |
50169
|
argiro.kok
|
|
9 |
59074
|
konstantin
|
@Injectable({ providedIn: 'root' })
|
10 |
59816
|
argiro.kok
|
export class ConfigurationService{
|
11 |
59465
|
konstantin
|
private communityInformation: BehaviorSubject<Portal> = new BehaviorSubject(null);
|
12 |
59074
|
konstantin
|
private sub: Subscription = null;
|
13 |
59465
|
konstantin
|
private source: Observable<Portal> = null;
|
14 |
59074
|
konstantin
|
private promise: Promise<boolean> = null;
|
15 |
50169
|
argiro.kok
|
|
16 |
59074
|
konstantin
|
constructor(private http: HttpClient ) {}
|
17 |
54775
|
konstantin
|
|
18 |
59074
|
konstantin
|
ngOnDestroy() {
|
19 |
59816
|
argiro.kok
|
this.clearSubscriptions();
|
20 |
|
|
}
|
21 |
|
|
|
22 |
|
|
clearSubscriptions() {
|
23 |
59074
|
konstantin
|
if(this.sub) {
|
24 |
|
|
this.sub.unsubscribe();
|
25 |
|
|
}
|
26 |
|
|
}
|
27 |
|
|
|
28 |
|
|
/**
|
29 |
|
|
* @deprecated
|
30 |
|
|
*/
|
31 |
55995
|
argiro.kok
|
getCommunityInformation(properties:EnvProperties, community:string){
|
32 |
59465
|
konstantin
|
let url = properties.adminToolsAPIURL +"/"+properties.adminToolsPortalType+"/" + community + '/full';
|
33 |
59074
|
konstantin
|
return this.http.get((properties.useLongCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url);
|
34 |
55964
|
argiro.kok
|
//.map(res => res.json());
|
35 |
50586
|
argiro.kok
|
}
|
36 |
|
|
|
37 |
59966
|
argiro.kok
|
public initStaticCommunityInformation(communityInformation: Portal) {
|
38 |
|
|
this.promise = new Promise<any>((resolve => {
|
39 |
|
|
this.communityInformation.next(communityInformation);
|
40 |
|
|
resolve();
|
41 |
|
|
}));
|
42 |
|
|
}
|
43 |
59074
|
konstantin
|
public initCommunityInformation(properties:EnvProperties, community:string) {
|
44 |
59137
|
konstantin
|
if(community == null) return;
|
45 |
|
|
|
46 |
59465
|
konstantin
|
let url = properties.adminToolsAPIURL +"/" + properties.adminToolsPortalType + "/" + community + "/full";
|
47 |
59074
|
konstantin
|
this.promise = new Promise<any>((resolve => {
|
48 |
59465
|
konstantin
|
this.source = this.http.get<Portal>((properties.useLongCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url);
|
49 |
59074
|
konstantin
|
|
50 |
|
|
this.sub = this.source
|
51 |
|
|
.subscribe(
|
52 |
59465
|
konstantin
|
(communityInformation: Portal) => {
|
53 |
59074
|
konstantin
|
this.communityInformation.next(communityInformation);
|
54 |
|
|
resolve();
|
55 |
59085
|
konstantin
|
},
|
56 |
|
|
error => {
|
57 |
59245
|
k.triantaf
|
this.communityInformation.error(error);
|
58 |
59085
|
konstantin
|
resolve();
|
59 |
59074
|
konstantin
|
});
|
60 |
|
|
}));
|
61 |
|
|
|
62 |
|
|
}
|
63 |
|
|
|
64 |
59465
|
konstantin
|
public get communityInformationState(): Observable<Portal> {
|
65 |
59074
|
konstantin
|
return this.communityInformation.asObservable();
|
66 |
|
|
}
|
67 |
|
|
|
68 |
58417
|
konstantin
|
/**
|
69 |
|
|
* @deprecated
|
70 |
|
|
*/
|
71 |
50586
|
argiro.kok
|
isEntityEnabled(APIUrl:string, community:string,entity: string){
|
72 |
54775
|
konstantin
|
//console.log("isEntityEnabled: "+entity);
|
73 |
50169
|
argiro.kok
|
let url = "isEntityEnabled-"+entity;
|
74 |
|
|
|
75 |
|
|
// if(entity == "publication" || entity == "dataset" || entity == "datasource"){
|
76 |
|
|
// return Observable.of(new Object()).mapTo(false);
|
77 |
|
|
// }
|
78 |
|
|
// return Observable.of(new Object()).mapTo(true);
|
79 |
50586
|
argiro.kok
|
return this.http.get(APIUrl + "/page")
|
80 |
55964
|
argiro.kok
|
.pipe(map(res => true));
|
81 |
50169
|
argiro.kok
|
}
|
82 |
|
|
|
83 |
59074
|
konstantin
|
/**
|
84 |
|
|
* @deprecated
|
85 |
|
|
*/
|
86 |
55995
|
argiro.kok
|
isPageEnabled(properties:EnvProperties, community:string,router: string){
|
87 |
58417
|
konstantin
|
let page_route: string = router.split('?')[0].substring(1);
|
88 |
59074
|
konstantin
|
|
89 |
59465
|
konstantin
|
let url = properties.adminToolsAPIURL + "/"+properties.adminToolsPortalType+"/" + community+"/pages?page_route="+page_route;
|
90 |
59074
|
konstantin
|
return this.http.get((properties.useLongCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url)
|
91 |
55964
|
argiro.kok
|
//.map(res => res.json())
|
92 |
|
|
.pipe(map(res => {
|
93 |
54906
|
k.triantaf
|
let result = false;
|
94 |
58417
|
konstantin
|
if(res['length'] >0 && res[0].route == page_route){
|
95 |
50586
|
argiro.kok
|
result = res[0].isEnabled;
|
96 |
|
|
}
|
97 |
|
|
|
98 |
|
|
return result;
|
99 |
58417
|
konstantin
|
}));//.do(res => {console.log("Route "+page_route +" is "+res)});
|
100 |
50169
|
argiro.kok
|
}
|
101 |
50586
|
argiro.kok
|
|
102 |
59074
|
konstantin
|
async isPageEnabledByStateAsync(properties: EnvProperties, community:string, page_route: string) {
|
103 |
|
|
if(!this.promise) {
|
104 |
|
|
this.initCommunityInformation(properties, community);
|
105 |
|
|
}
|
106 |
|
|
|
107 |
|
|
await this.promise;
|
108 |
59816
|
argiro.kok
|
if(this.sub){
|
109 |
|
|
this.sub.unsubscribe();
|
110 |
|
|
}
|
111 |
59074
|
konstantin
|
return this.filtering(page_route);
|
112 |
|
|
}
|
113 |
|
|
|
114 |
|
|
isPageEnabledByState(properties: EnvProperties, community:string, router: string): Observable<boolean> {
|
115 |
|
|
let page_route: string = router.split('?')[0].substring(1);
|
116 |
|
|
return from(this.isPageEnabledByStateAsync(properties, community, page_route));
|
117 |
|
|
}
|
118 |
|
|
|
119 |
|
|
filtering(page_route: string) {
|
120 |
59465
|
konstantin
|
let community: Portal = this.communityInformation.getValue();
|
121 |
59074
|
konstantin
|
|
122 |
|
|
let pages: Page[] = <Page[]>community.pages;
|
123 |
|
|
pages = pages.filter(function (page: Page) {
|
124 |
|
|
return page.route == page_route;
|
125 |
|
|
});
|
126 |
|
|
|
127 |
|
|
if (pages) {
|
128 |
|
|
let result = false;
|
129 |
|
|
if (pages['length'] > 0 && pages[0].route == page_route) {
|
130 |
|
|
result = pages[0].isEnabled;
|
131 |
|
|
}
|
132 |
|
|
return result;
|
133 |
|
|
}
|
134 |
|
|
}
|
135 |
|
|
|
136 |
58417
|
konstantin
|
/**
|
137 |
|
|
* @deprecated
|
138 |
|
|
*/
|
139 |
|
|
getMainPageContent(APIUrl:string, community:string,){
|
140 |
50586
|
argiro.kok
|
return this.http.get(APIUrl + "/page")
|
141 |
55964
|
argiro.kok
|
.pipe(map(res => true));
|
142 |
50169
|
argiro.kok
|
}
|
143 |
58417
|
konstantin
|
|
144 |
|
|
/**
|
145 |
|
|
* @deprecated
|
146 |
|
|
*/
|
147 |
|
|
getSpecialAnouncementContent(APIUrl:string, community:string,){
|
148 |
50586
|
argiro.kok
|
return this.http.get(APIUrl + "/page")
|
149 |
55964
|
argiro.kok
|
.pipe(map(res => ""));
|
150 |
50169
|
argiro.kok
|
}
|
151 |
58417
|
konstantin
|
|
152 |
|
|
/**
|
153 |
|
|
* @deprecated
|
154 |
|
|
*/
|
155 |
|
|
getHelpPageContent(APIUrl:string, community:string, router:string){
|
156 |
50586
|
argiro.kok
|
return this.http.get(APIUrl + "/page")
|
157 |
55964
|
argiro.kok
|
.pipe(map(res => true));
|
158 |
50169
|
argiro.kok
|
}
|
159 |
50586
|
argiro.kok
|
// private handleError (error: Response) {
|
160 |
|
|
// // in a real world app, we may send the error to some remote logging infrastructure
|
161 |
|
|
// // instead of just logging it to the console
|
162 |
|
|
// console.log(error);
|
163 |
|
|
// return this.http.get(this.APIUrl + "/page")
|
164 |
|
|
// .map(res => true);
|
165 |
|
|
// }
|
166 |
50169
|
argiro.kok
|
|
167 |
|
|
|
168 |
|
|
}
|