2018-03-15 10:53:07 +01:00
|
|
|
import { Injectable } from '@angular/core';
|
2019-02-26 14:57:04 +01:00
|
|
|
import {
|
|
|
|
Router,
|
|
|
|
CanActivate,
|
|
|
|
ActivatedRouteSnapshot,
|
|
|
|
RouterStateSnapshot,
|
2019-06-03 15:20:36 +02:00
|
|
|
CanLoad, Route, UrlSegment
|
2019-02-26 14:57:04 +01:00
|
|
|
} from '@angular/router';
|
2019-06-03 15:20:36 +02:00
|
|
|
import {Observable} from 'rxjs';
|
|
|
|
|
2019-02-27 11:39:13 +01:00
|
|
|
import {ConnectHelper} from '../connectHelper';
|
2018-03-15 10:53:07 +01:00
|
|
|
|
|
|
|
@Injectable()
|
2019-02-26 14:57:04 +01:00
|
|
|
export class IsCommunity implements CanActivate, CanLoad {
|
2018-03-15 10:53:07 +01:00
|
|
|
|
2019-02-26 16:25:52 +01:00
|
|
|
constructor(private router: Router) {
|
|
|
|
}
|
2018-03-15 10:53:07 +01:00
|
|
|
|
2019-02-27 11:39:13 +01:00
|
|
|
check(community: string): Observable<boolean> | boolean {
|
2019-02-26 16:25:52 +01:00
|
|
|
if (community && community !== 'undefined') {
|
2019-02-26 14:57:04 +01:00
|
|
|
return true;
|
2019-02-26 16:25:52 +01:00
|
|
|
} else {
|
2019-02-26 14:57:04 +01:00
|
|
|
this.router.navigate(['errorcommunity']);
|
2019-02-26 16:25:52 +01:00
|
|
|
return false;
|
2018-03-15 10:53:07 +01:00
|
|
|
}
|
2019-02-26 14:57:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean {
|
2019-02-27 11:39:13 +01:00
|
|
|
return this.check(route.queryParams['communityId']);
|
2019-02-26 14:57:04 +01:00
|
|
|
}
|
|
|
|
|
2019-06-03 15:20:36 +02:00
|
|
|
canLoad(route: Route, segments: UrlSegment[]): Observable<boolean> | Promise<boolean> | boolean {
|
2019-03-04 14:23:01 +01:00
|
|
|
const path = '/' + route.path + document.location.search;
|
2019-02-27 11:39:13 +01:00
|
|
|
return this.check(ConnectHelper.getCommunityFromPath(path));
|
2018-03-15 10:53:07 +01:00
|
|
|
}
|
2019-02-26 14:57:04 +01:00
|
|
|
}
|