Project

General

Profile

1
import {Component, Input, 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
@Component({
8
  selector: 'community-search-result',
9
  templateUrl:'communitySearchResults.component.html'
10
})
11

    
12
export class CommunitySearchResultsComponent {
13
  @Input() results: CommunityInfo[];
14
  @Input() status: number;
15
  @Input() type: string;
16
  @Input() showLoading: boolean = false;
17
  @Input() custom_class: string = "search-results";
18
  @Input() properties: EnvProperties;
19
  @Input() maxCharacters: number = 150;
20
  @ViewChild('AlertModal') modal;
21

    
22

    
23
  public urlParam: string;
24
  public errorCodes:ErrorCodes = new ErrorCodes();
25
  public routerHelper:RouterHelper = new RouterHelper();
26
  public errorMessage: string = "No results found";
27
  public selectedCommunityId: string;
28
  constructor(private router: Router) {}
29

    
30
  ngOnInit() {
31

    
32
  }
33

    
34
  getProductionPrefix():string{
35
    return (this.properties.environment == "beta")?"beta.":""
36
  }
37

    
38
  isProduction():boolean{
39
    return this.properties.environment!="development";
40

    
41
  }
42

    
43
  public _formatDescription(description){
44
    return (((description).length > this.maxCharacters)?(description.substring(0,(this.maxCharacters - ('...').length))+"..."):description);
45
  }
46

    
47
  public confirmModalOpen(community: CommunityInfo) {
48
      this.selectedCommunityId = community.communityId;
49
      this.modal.cancelButton = true;
50
      this.modal.okButton = true;
51
      this.modal.alertTitle = 'You have selected ' + community.title;
52
      this.modal.alertMessage = false;
53
      this.modal.okButtonLeft = false;
54
      this.modal.okButtonText = 'Yes';
55
      this.modal.cancelButtonText = 'No';
56
      this.modal.open();
57
  }
58

    
59
  public goToCommunityPage(data: any) {
60
    let url = '';
61
    if(this.isProduction()) {
62
      url = 'https://'+ this.getProductionPrefix() + this.selectedCommunityId +'.openaire.eu';
63
    } else {
64
      url = this.router.createUrlTree(['/'], {
65
        queryParams: { 'communityId': this.selectedCommunityId} }).toString();
66
    }
67
    window.open(url, '_blank');
68
  }
69
}
(12-12/45)