Revision 59816
Added by Argiro Kokogiannaki over 3 years ago
isRouteEnabled.guard.ts | ||
---|---|---|
1 |
|
|
2 |
import {of as observableOf, Observable, Subject, Subscription} from 'rxjs'; |
|
3 |
|
|
4 |
import {map, filter, mergeMap, tap} from 'rxjs/operators'; |
|
1 |
import {Observable, Subscription} from 'rxjs'; |
|
2 |
import {tap, take} from 'rxjs/operators'; |
|
5 | 3 |
import { Injectable } from '@angular/core'; |
6 | 4 |
import { |
7 | 5 |
Router, |
8 | 6 |
CanActivate, |
9 |
CanLoad, |
|
10 | 7 |
ActivatedRouteSnapshot, |
11 | 8 |
RouterStateSnapshot, |
12 |
Route, Data
|
|
9 |
Data |
|
13 | 10 |
} from '@angular/router'; |
14 | 11 |
|
15 | 12 |
import { ConfigurationService } from '../utils/configuration/configuration.service'; |
16 |
import { EnvironmentSpecificService} from '../utils/properties/environment-specific.service'; |
|
17 | 13 |
import {ConnectHelper} from '../connect/connectHelper'; |
18 | 14 |
import {properties} from "../../../environments/environment"; |
19 |
import {LoginErrorCodes} from "../login/utils/guardHelper.class"; |
|
20 |
import {of} from 'rxjs'; |
|
21 |
import {Page} from "../utils/entities/adminTool/page"; |
|
22 | 15 |
|
23 | 16 |
@Injectable() |
24 | 17 |
export class IsRouteEnabled implements CanActivate { |
25 | 18 |
sub: Subscription = null; |
26 | 19 |
|
27 | 20 |
constructor(private router: Router, |
28 |
private config: ConfigurationService, |
|
29 |
private propertiesService: EnvironmentSpecificService) {} |
|
21 |
private config: ConfigurationService) {} |
|
30 | 22 |
|
31 | 23 |
// check(data: Data, community: string, path: string): Observable<boolean> | boolean { |
32 | 24 |
// const customRedirect = data['redirect']; |
... | ... | |
72 | 64 |
community = properties.adminToolsCommunity; |
73 | 65 |
} |
74 | 66 |
|
75 |
const obs = |
|
76 |
//this.config.isPageEnabled(properties, community, '/' + path); |
|
77 |
this.config.isPageEnabledByState(properties, community, '/'+path); |
|
78 |
this.sub = obs |
|
79 |
//.pipe(tap((enabled) => console.log("aaa: "+enabled))) |
|
80 |
.pipe(filter(enabled => !enabled)) |
|
81 |
.subscribe(() => { |
|
82 |
this.router.navigate([redirect], {queryParams: {'page': path}}); |
|
83 |
}); |
|
67 |
return this.config.isPageEnabledByState(properties, community, '/'+path).pipe(take(1),tap((enabled) => { |
|
68 |
if(!enabled){ |
|
69 |
this.router.navigate([redirect], {queryParams: {'page': path}}); |
|
70 |
} |
|
71 |
})); |
|
84 | 72 |
|
85 |
return obs; |
|
86 | 73 |
} |
87 | 74 |
|
88 | 75 |
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean { |
89 | 76 |
return this.check(route.data, route.queryParams['communityId'], state.url); |
90 | 77 |
} |
91 | 78 |
|
92 |
canDeactivate() { |
|
93 |
if(this.sub) { |
|
94 |
this.sub.unsubscribe(); |
|
95 |
} |
|
96 |
return true; |
|
97 |
} |
|
98 | 79 |
} |
Also available in: Unified diff
[Library|Trunk]
code clean up:
-remove app.* files from library
-remove unused imports, code, files (Old search pages for results, dataproviders, map search page, etc)
-remove Freeguard from modules
-unsubscribe all subscriptions
-Services: configuration, isvocabularies, user management: unsubscribe from app component or the component that uses them (clearSubscriptions())
-Fetchers: unsubscribe from the component that uses them (clearSubscriptions())