Project

General

Profile

« Previous | Next » 

Revision 54915

[Trunk|Library]: 1. Add static function to find community from url path. 2. Community guards can now be used as CanLoad guards using functionality of getCommunityFromPath(look at 1).

View differences:

connectHelper.ts
1
export class ConnectHelper{
1
import {HttpParams} from '@angular/common/http';
2 2

  
3
  public static  getCommunityFromDomain(domain:string):string{
3
export class ConnectHelper {
4

  
5
  public static  getCommunityFromDomain(domain: string): string{
4 6
    // domain = "beta.egi.openaire.eu"; for testing
5
    if(domain.indexOf("openaire.eu") == -1){
7
    if (domain.indexOf('openaire.eu') === -1) {
6 8
      return null;
7 9
    }
8
    if(domain.indexOf("beta")!=-1){
9
      domain = domain.substr(domain.indexOf(".")+1,domain.length);
10
      domain = domain.substr(0,domain.indexOf("."));
11
    }else if(domain.indexOf("test.")!=-1){
10
    if ( domain.indexOf('beta') !== -1) {
11
      domain = domain.substr(domain.indexOf('.') + 1, domain.length);
12
      domain = domain.substr(0, domain.indexOf('.'));
13
    } else if (domain.indexOf('test.') !== -1) {
12 14
      return null;
13
    }else{
14
      domain = domain.substr(0,domain.indexOf("."));
15
    } else {
16
      domain = domain.substr(0, domain.indexOf('.'));
15 17
    }
16
    if(domain == "connect" || domain == "explore"){
18
    if (domain === 'connect' || domain === 'explore') {
17 19
      return null;
18 20
    }
19 21
    return domain;
20 22
  }
23

  
24
  public static getCommunityFromPath(path: string): string {
25
    if (path.includes('?')) {
26
      const httpParams = new HttpParams({ fromString: path.split('?')[1] });
27
      return httpParams.get('communityId');
28
    } else {
29
      return null;
30
    }
31
  }
21 32
}

Also available in: Unified diff