1
|
import { Injectable } from '@angular/core';
|
2
|
import {
|
3
|
Router,
|
4
|
CanActivate,
|
5
|
ActivatedRouteSnapshot,
|
6
|
RouterStateSnapshot,
|
7
|
CanLoad, Route, UrlSegment
|
8
|
} from '@angular/router';
|
9
|
import {Observable} from 'rxjs';
|
10
|
|
11
|
import {ConnectHelper} from '../connectHelper';
|
12
|
|
13
|
@Injectable()
|
14
|
export class IsCommunity implements CanActivate, CanLoad {
|
15
|
|
16
|
constructor(private router: Router) {
|
17
|
}
|
18
|
|
19
|
check(community: string): Observable<boolean> | boolean {
|
20
|
if (community && community !== 'undefined') {
|
21
|
return true;
|
22
|
} else {
|
23
|
this.router.navigate(['errorcommunity']);
|
24
|
return false;
|
25
|
}
|
26
|
}
|
27
|
|
28
|
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean {
|
29
|
return this.check(route.queryParams['communityId']);
|
30
|
}
|
31
|
|
32
|
canLoad(route: Route, segments: UrlSegment[]): Observable<boolean> | Promise<boolean> | boolean {
|
33
|
const path = '/' + route.path + document.location.search;
|
34
|
return this.check(ConnectHelper.getCommunityFromPath(path));
|
35
|
}
|
36
|
}
|