Project

General

Profile

1
import {HttpParams} from '@angular/common/http';
2
import {properties} from "../../../environments/environment";
3

    
4
export class ConnectHelper {
5

    
6
  public static  getCommunityFromDomain(domain: string): string{
7
    if(properties.environment == "development") {
8
      domain = "beta.egi.openaire.eu"; //for testing
9
    }
10
    domain = domain.indexOf("//") != -1? domain.split("//")[1]:domain; //remove https:// prefix
11
    if (domain.indexOf('openaire.eu') === -1) {
12
      return null;
13
    }
14
    if ( domain.indexOf('beta') !== -1) {
15
      domain = domain.substr(domain.indexOf('.') + 1, domain.length);
16
      domain = domain.substr(0, domain.indexOf('.'));
17
    } else if (domain.indexOf('test.') !== -1) {
18
      return null;
19
    } else {
20
      domain = domain.substr(0, domain.indexOf('.'));
21
    }
22
    if (domain === 'connect' || domain === 'explore' || domain === 'monitor' || domain === 'admin'){
23
      return null;
24
    }
25
    return domain;
26
  }
27

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

    
37
  public static setPortalTypeFromPid(pid: string): void {
38
    if(pid == "openaire") {
39
      properties.adminToolsPortalType = "explore";
40
    } else if(pid == "connect") {
41
      properties.adminToolsPortalType = "connect";
42
    } else if(pid == "monitor") {
43
      properties.adminToolsPortalType = "monitor";
44
    } else {
45
      properties.adminToolsPortalType = "community";
46
    }
47
  }
48
}
    (1-1/1)