[Trunk|Library]: isRouteEnabled
git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@54913 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
parent
75533e17bf
commit
bc9801aeb0
|
@ -1,6 +1,5 @@
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import {
|
import {
|
||||||
ActivatedRoute,
|
|
||||||
Router,
|
Router,
|
||||||
CanActivate,
|
CanActivate,
|
||||||
CanLoad,
|
CanLoad,
|
||||||
|
@ -17,33 +16,36 @@ import {ConnectHelper} from '../connect/connectHelper';
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class IsRouteEnabled implements CanActivate, CanLoad {
|
export class IsRouteEnabled implements CanActivate, CanLoad {
|
||||||
|
|
||||||
constructor(private route: ActivatedRoute,private router: Router, private config: ConfigurationService, private propertiesService:EnvironmentSpecificService ) {}
|
constructor(private router: Router,
|
||||||
|
private config: ConfigurationService,
|
||||||
|
private propertiesService: EnvironmentSpecificService ) {}
|
||||||
|
|
||||||
check(path: string): Observable<boolean> | boolean {
|
check(route: ActivatedRouteSnapshot, path: string): Observable<boolean> | boolean {
|
||||||
let customRedirect = this.route.data['redirect'];
|
const customRedirect = route.data['redirect'];
|
||||||
let community = this.route.queryParams["communityId"];
|
let community = route.queryParams['communityId'];
|
||||||
if(!community && this.route.data['community']){ // for openaire
|
if (!community && route.data['community']) { // for openaire
|
||||||
community = this.route.data['community'];
|
community = route.data['community'];
|
||||||
}
|
}
|
||||||
if(!community && typeof document != 'undefined'){
|
if (!community && typeof document !== 'undefined') {
|
||||||
community = ConnectHelper.getCommunityFromDomain(document.location.hostname);
|
community = ConnectHelper.getCommunityFromDomain(document.location.hostname);
|
||||||
}
|
}
|
||||||
if(community){
|
if (community) {
|
||||||
let redirect = customRedirect ? customRedirect : '/error';
|
const redirect = customRedirect ? customRedirect : '/error';
|
||||||
let obs = this.propertiesService.subscribeEnvironment().map(res=>res["adminToolsAPIURL"]).mergeMap(url => {
|
const obs = this.propertiesService.subscribeEnvironment().map(res => res['adminToolsAPIURL']).mergeMap(url => {
|
||||||
return this.config.isPageEnabled(url, community,"/" + path.split("?")[0].substring(1))});
|
return this.config.isPageEnabled(url, community, '/' + path.split('?')[0].substring(1));
|
||||||
|
});
|
||||||
obs.filter(enabled => !enabled)
|
obs.filter(enabled => !enabled)
|
||||||
.subscribe(() => this.router.navigate([redirect], { queryParams: { "page": path } }));
|
.subscribe(() => this.router.navigate([redirect], {queryParams: {'page': path}}));
|
||||||
return obs;
|
return obs;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean {
|
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean {
|
||||||
return this.check(state.url);
|
return this.check(route, state.url);
|
||||||
}
|
}
|
||||||
|
|
||||||
canLoad(route: Route): Observable<boolean> | Promise<boolean> | boolean {
|
canLoad(route: Route): Observable<boolean> | Promise<boolean> | boolean {
|
||||||
return this.check('/' + route.path);
|
return this.check(null, '/' + route.path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue