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, prodReadyCommunities} from "../../connect/community/communityInfo";
6
import {Router} from "@angular/router";
7
import {LocalStorageService} from "../../services/localStorage.service";
8
import {Stakeholder, StakeholderInfo, Visibility} from "../../monitor/entities/stakeholder";
9
import {Subscriber} from "rxjs";
10

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

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

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