Project

General

Profile

« Previous | Next » 

Revision 55964

[Library|Trunk]

Merge into trunk branch angular7 rev 55729

View differences:

isRouteEnabled.guard.ts
1

  
2
import {of as observableOf, Observable} from 'rxjs';
3

  
4
import {map, filter, mergeMap} from 'rxjs/operators';
1 5
import { Injectable } from '@angular/core';
2 6
import {
3 7
  Router,
......
7 11
  RouterStateSnapshot,
8 12
  Route, Data
9 13
} from '@angular/router';
10
import {Observable} from 'rxjs/Observable';
11
import 'rxjs/add/operator/filter';
14

  
12 15
import { ConfigurationService } from '../utils/configuration/configuration.service';
13 16
import { EnvironmentSpecificService} from '../utils/properties/environment-specific.service';
14 17
import {ConnectHelper} from '../connect/connectHelper';
15 18

  
16 19
@Injectable()
17
export class IsRouteEnabled implements CanActivate, CanLoad {
20
export class IsRouteEnabled implements CanActivate {
18 21

  
19 22
  constructor(private router: Router,
20 23
              private config: ConfigurationService,
......
26 29
      community = data['community'];
27 30
    }
28 31
      const redirect = customRedirect ? customRedirect : '/error';
29
      const obs = this.propertiesService.subscribeEnvironment().map(res => {
32
      const obs = this.propertiesService.subscribeEnvironment().pipe(map(res => {
30 33
        if (!community) {
31 34
          community  = ConnectHelper.getCommunityFromDomain(res.domain);
32 35
        }
33 36
       return  res['adminToolsAPIURL'];
34
      }).mergeMap(url => {
37
      }),mergeMap(url => {
35 38
        if (!community) { // no community to check - return true
36
          return Observable.of(true);
39
          return observableOf(true);
37 40
        }
38 41
        return this.config.isPageEnabled(url, community, '/' + path.split('?')[0].substring(1));
39
      });
40
      obs.filter(enabled => !enabled)
42
      }),);
43
      obs.pipe(filter(enabled => !enabled))
41 44
          .subscribe(() => this.router.navigate([redirect], {queryParams: {'page': path}}));
42 45
      return obs;
43 46
  }
......
45 48
  canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean {
46 49
    return this.check(route.data, route.queryParams['communityId'], state.url);
47 50
  }
48
  canLoad(route: Route): Observable<boolean> | Promise<boolean> | boolean {
49
    const path = '/' + route.path + document.location.search;
50
    return this.check(route.data, ConnectHelper.getCommunityFromPath(path), path);
51
  }
52 51
}

Also available in: Unified diff