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} 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, OnChanges{
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
  
26
  
27
  public urlParam: string;
28
  public errorCodes: ErrorCodes = new ErrorCodes();
29
  public routerHelper: RouterHelper = new RouterHelper();
30
  public errorMessage: string = "No results found";
31
  public selected: CommunityInfo & Stakeholder;
32
  public directLink: boolean = true;
33
  
34
  
35
  constructor(private router: Router,
36
              private localStorageService: LocalStorageService) {
37
  }
38
  
39
  ngOnInit() {
40
    this.localStorageService.get().subscribe(value => {
41
      this.directLink = value;
42
    });
43
  }
44
  
45
  ngOnChanges(changes: SimpleChanges) {
46
    console.log(changes);
47
  }
48
  
49
  getProductionPrefix(id:string): string {
50
    return (this.properties.environment == "production" &&  prodReadyCommunities.indexOf(id)!=-1) ? "" : "beta.";
51
  }
52
  
53
  isProduction(): boolean {
54
    return this.properties.environment != "development";
55
    
56
  }
57
  
58
  public _formatDescription(description) {
59
    return (((description).length > this.maxCharacters) ? (description.substring(0, (this.maxCharacters - ('...').length)) + "...") : description);
60
  }
61
  
62
  public confirmModalOpen(result: CommunityInfo & Stakeholder) {
63
    this.selected = result;
64
    this.modal.cancelButton = true;
65
    this.modal.okButton = true;
66
    if(this.type === 'stakeholder') {
67
      this.modal.alertTitle = 'You are going to visit ' + result.name + ' Monitor Dashboard';
68
    } else if (this.type === 'community') {
69
      this.modal.alertTitle = 'You are going to visit ' + ((result.title) ? result.title : result.shortTitle) +' Gateway';
70
    }
71
    this.modal.alertMessage = false;
72
    this.modal.okButtonLeft = false;
73
    this.modal.okButtonText = 'Yes';
74
    this.modal.cancelButtonText = 'No';
75
    this.modal.choice = true;
76
    this.modal.open();
77
  }
78
  
79
  public getCommunityPageUrl(communityInfo: CommunityInfo): string {
80
    let url = '';
81
    if (this.isProduction()) {
82
      url = 'https://' + this.getProductionPrefix(communityInfo.communityId ) + communityInfo.communityId + '.openaire.eu';
83
    } else {
84
      url = this.router.createUrlTree(['/'], {
85
        queryParams: {'communityId': communityInfo.communityId}
86
      }).toString();
87
    }
88
    return url;
89
  }
90

    
91
  public getStakeholderPageUrl(stakeholder: Stakeholder) {
92
    return this.properties.domain + this.properties.baseLink +"/" + stakeholder.alias;
93
  }
94
  
95
  public goToPage(data: any) {
96
    if (data.value == true) {
97
      let url = '';
98
      if (this.type === 'stakeholder') {
99
        url = this.getStakeholderPageUrl(this.selected);
100
      } else if (this.type === 'community') {
101
        url = this.getCommunityPageUrl(this.selected);
102
      }
103
      this.localStorageService.setCommunityDirectLink(data.choice);
104
      window.open(url, '_blank');
105
    }
106
  }
107
}
(22-22/55)