Project

General

Profile

1
import {Component, Input, OnChanges, OnInit, SimpleChanges, ViewChild} from '@angular/core';
2
import {ErrorCodes} from '../../utils/properties/errorCodes';
3
import {RouterHelper} from '../../utils/routerHelper.class';
4
import {EnvProperties} from '../../utils/properties/env-properties';
5
import {CommunityInfo} from "../../connect/community/communityInfo";
6
import {Router} from "@angular/router";
7
import {LocalStorageService} from "../../services/localStorage.service";
8
import {Stakeholder, StakeholderInfo} from "../../monitor/entities/stakeholder";
9

    
10
@Component({
11
  selector: 'portal-search-result',
12
  templateUrl: 'portal-search-result.component.html'
13
})
14

    
15
export class PortalSearchResultComponent implements OnInit{
16
  @Input() results: (CommunityInfo & StakeholderInfo)[];
17
  @Input() status: number;
18
  @Input() type: string;
19
  @Input() showType = false;
20
  @Input() showLoading: boolean = false;
21
  @Input() custom_class: string = "search-results";
22
  @Input() properties: EnvProperties;
23
  @Input() maxCharacters: number = 150;
24
  @ViewChild('AlertModal') modal;
25
  /*visibilityIcon: Map<Visibility, string> = new Map<Visibility, string> ([
26
    ["PUBLIC", 'earth'],
27
    ["PRIVATE", 'lock'],
28
    ["RESTRICTED", 'group']
29
  ]);*/
30
  
31
  public urlParam: string;
32
  public errorCodes: ErrorCodes = new ErrorCodes();
33
  public routerHelper: RouterHelper = new RouterHelper();
34
  public errorMessage: string = "No results found";
35
  public selected: CommunityInfo & Stakeholder;
36
  public directLink: boolean = true;
37
  sub;
38
  
39
  constructor(private router: Router,
40
              private localStorageService: LocalStorageService) {
41
  }
42
  ngOnDestroy() {
43
    if(this.sub){
44
      this.sub.unsubscribe();
45
    }
46
  }
47
  ngOnInit() {
48
    this.sub = this.localStorageService.get().subscribe(value => {
49
      this.directLink = value;
50
    });
51
  }
52

    
53
  
54
  getProductionPrefix(id:string): string {
55
    return (this.properties.environment == "production") ? "" : "beta.";
56
  }
57
  
58
  isProduction(): boolean {
59
    return this.properties.environment != "development";
60
    
61
  }
62
  
63
  public _formatDescription(description) {
64
    return (((description).length > this.maxCharacters) ? (description.substring(0, (this.maxCharacters - ('...').length)) + "...") : description);
65
  }
66
  
67
  public confirmModalOpen(result: CommunityInfo & Stakeholder) {
68
    this.selected = result;
69
    this.modal.cancelButton = true;
70
    this.modal.okButton = true;
71
    if(this.type === 'stakeholder') {
72
      this.modal.alertTitle = 'You are going to visit ' + result.name + ' Monitor Dashboard';
73
    } else if (this.type === 'community') {
74
      this.modal.alertTitle = 'You are going to visit ' + ((result.title) ? result.title : result.shortTitle) +' Gateway';
75
    }
76
    this.modal.alertMessage = false;
77
    this.modal.okButtonLeft = false;
78
    this.modal.okButtonText = 'Yes';
79
    this.modal.cancelButtonText = 'No';
80
    this.modal.choice = true;
81
    this.modal.open();
82
  }
83
  
84
  public getCommunityPageUrl(communityInfo: CommunityInfo): string {
85
    let url = '';
86
    if (this.isProduction()) {
87
      url = 'https://' + this.getProductionPrefix(communityInfo.communityId ) + communityInfo.communityId + '.openaire.eu';
88
    } else {
89
      url = this.router.createUrlTree(['/'], {
90
        queryParams: {'communityId': communityInfo.communityId}
91
      }).toString();
92
    }
93
    return url;
94
  }
95

    
96
  public getStakeholderPageUrl(stakeholder: Stakeholder) {
97
    return this.properties.domain + this.properties.baseLink +"/dashboard/" + stakeholder.alias;
98
  }
99
  
100
  public goToPage(data: any) {
101
    if (data.value == true) {
102
      let url = '';
103
      if (this.type === 'stakeholder') {
104
        url = this.getStakeholderPageUrl(this.selected);
105
      } else if (this.type === 'community') {
106
        url = this.getCommunityPageUrl(this.selected);
107
      }
108
      this.localStorageService.setCommunityDirectLink(data.choice);
109
      window.open(url, '_blank');
110
    }
111
  }
112
}
(19-19/47)