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
import {StringUtils} from "../../utils/string-utils.class";
10

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

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

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

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