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
    domain = "beta.covid-19.openaire.eu"; //for testing
8
    domain = domain.indexOf("//") != -1? domain.split("//")[1]:domain; //remove https:// prefix
9
    if (domain.indexOf('openaire.eu') === -1) {
10
      return null;
11
    }
12
    if ( domain.indexOf('beta') !== -1) {
13
      domain = domain.substr(domain.indexOf('.') + 1, domain.length);
14
      domain = domain.substr(0, domain.indexOf('.'));
15
    } else if (domain.indexOf('test.') !== -1) {
16
      return null;
17
    } else {
18
      domain = domain.substr(0, domain.indexOf('.'));
19
    }
20
    if (domain === 'connect' || domain === 'explore' || domain === 'monitor' || domain === 'admin'){
21
      return null;
22
    }
23
    return domain;
24
  }
25

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

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