[Library | Trunk]: Fix load environment on properties
git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@58907 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
parent
1044737f9d
commit
b7e29a6139
|
@ -10,60 +10,61 @@ import {properties} from "../../../../environments/environment";
|
|||
|
||||
@Injectable()
|
||||
export class EnvironmentSpecificService {
|
||||
|
||||
|
||||
public envSpecific: EnvProperties;
|
||||
public domain: string;
|
||||
private envSpecificSubject: BehaviorSubject<EnvProperties> = new BehaviorSubject<EnvProperties>(null);
|
||||
private propertiesPath = "/assets/env-properties.json?v=2";
|
||||
|
||||
|
||||
constructor(private http: HttpClient, @Optional() @Inject(REQUEST) private request: Request) {
|
||||
properties.domain = this.getDomain();
|
||||
}
|
||||
|
||||
public loadEnvironment() {
|
||||
return Promise.resolve(this.envSpecific);
|
||||
this.envSpecific = properties;
|
||||
return Promise.resolve(this.envSpecific);
|
||||
}
|
||||
|
||||
|
||||
public subscribeEnvironment() {
|
||||
// Only want to do this once - if root page is revisited, it calls this again.
|
||||
if (this.envSpecific === null || this.envSpecific === undefined) {
|
||||
this.envSpecific = properties;
|
||||
}
|
||||
// console.log('subscribeEnvironment: already loaded ');
|
||||
return of(this.envSpecific);
|
||||
// Only want to do this once - if root page is revisited, it calls this again.
|
||||
if (this.envSpecific === null || this.envSpecific === undefined) {
|
||||
this.envSpecific = properties;
|
||||
}
|
||||
// console.log('subscribeEnvironment: already loaded ');
|
||||
return of(this.envSpecific);
|
||||
}
|
||||
|
||||
getDomain(){
|
||||
var domain = "";
|
||||
|
||||
getDomain() {
|
||||
var domain = "";
|
||||
if (typeof document == 'undefined') {
|
||||
domain = this.request.get('host').split(":")[0];
|
||||
}else{
|
||||
} else {
|
||||
domain = document.location.hostname;
|
||||
}
|
||||
return domain;
|
||||
}
|
||||
return domain;
|
||||
}
|
||||
|
||||
|
||||
public setEnvProperties(es: EnvProperties) {
|
||||
// This has already been set so bail out.
|
||||
if (es === null || es === undefined) {
|
||||
return;
|
||||
return;
|
||||
}
|
||||
this.envSpecific = es;
|
||||
if (this.envSpecificSubject) {
|
||||
this.envSpecificSubject.next(this.envSpecific);
|
||||
this.envSpecificSubject.next(this.envSpecific);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Call this if you want to know when EnvProperties is set.
|
||||
*/
|
||||
public subscribe(caller: any, callback: (caller: any, es: EnvProperties) => void) {
|
||||
this.envSpecificSubject
|
||||
.subscribe((es) => {
|
||||
if (es === null) {
|
||||
return;
|
||||
}
|
||||
callback(caller, es);
|
||||
});
|
||||
this.envSpecificSubject
|
||||
.subscribe((es) => {
|
||||
if (es === null) {
|
||||
return;
|
||||
}
|
||||
callback(caller, es);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue