Project

General

Profile

« Previous | Next » 

Revision 55964

[Library|Trunk]

Merge into trunk branch angular7 rev 55729

View differences:

connectCommunityGuard.guard.ts
1

  
2
import {filter, mergeMap} from 'rxjs/operators';
1 3
import { Injectable } from '@angular/core';
2 4
import {
3 5
  Router,
......
7 9
  CanLoad,
8 10
  Route
9 11
} from '@angular/router';
10
import {Observable} from 'rxjs/Observable';
12
import {Observable} from 'rxjs';
11 13
import {CommunityService} from '../community/community.service';
12 14
import { EnvironmentSpecificService} from '../../utils/properties/environment-specific.service';
13 15
import {ConnectHelper} from '../connectHelper';
14 16

  
15 17
@Injectable()
16
export class ConnectCommunityGuard implements  CanActivate, CanLoad {
18
export class ConnectCommunityGuard implements  CanActivate {
17 19

  
18 20
  constructor(private router: Router,
19 21
              private communityService: CommunityService,
......
21 23
  }
22 24

  
23 25
  check(community: string): Observable<boolean> | boolean {
24
    const obs = this.propertiesService.subscribeEnvironment().mergeMap(properties => {
26
    const obs = this.propertiesService.subscribeEnvironment().pipe(mergeMap(properties => {
25 27
      return this.communityService.isCommunityType(properties, properties['communityAPI'] + community);
26
    });
27
    obs.filter(enabled => !enabled)
28
    }));
29
    obs.pipe(filter(enabled => !enabled))
28 30
        .subscribe(() => this.router.navigate(['errorcommunity']));
29 31
    return obs;
30 32
  }
......
32 34
  canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean {
33 35
    return this.check(route.queryParams['communityId']);
34 36
  }
35

  
36
  canLoad(route: Route): Observable<boolean> | Promise<boolean> | boolean {
37
    const path = '/' + route.path + document.location.search;
38
    return this.check(ConnectHelper.getCommunityFromPath(path));
39
  }
40 37
}

Also available in: Unified diff