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
import {LocalStorageService} from "../../services/localStorage.service";
8

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

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

    
25

    
26
  public urlParam: string;
27
  public errorCodes: ErrorCodes = new ErrorCodes();
28
  public routerHelper: RouterHelper = new RouterHelper();
29
  public errorMessage: string = "No results found";
30
  public selectedCommunityId: string;
31
  public directLink: boolean = true;
32

    
33

    
34
  constructor(private router: Router,
35
              private localStorageService: LocalStorageService) {
36
  }
37

    
38
  ngOnInit() {
39
    this.localStorageService.get().subscribe(value => {
40
      this.directLink = value;
41
    });
42
  }
43

    
44
  getProductionPrefix(): string {
45
    return (this.properties.environment == "beta") ? "beta." : ""
46
  }
47

    
48
  isProduction(): boolean {
49
    return this.properties.environment != "development";
50

    
51
  }
52

    
53
  public _formatDescription(description) {
54
    return (((description).length > this.maxCharacters) ? (description.substring(0, (this.maxCharacters - ('...').length)) + "...") : description);
55
  }
56

    
57
  public confirmModalOpen(community: CommunityInfo) {
58
    this.selectedCommunityId = (this.type == 'community')? community.communityId:community['alias'];
59
    this.modal.cancelButton = true;
60
    this.modal.okButton = true;
61
    this.modal.alertTitle = 'You are going to visit ' +
62
      ((community.title) ? community.title : community.shortTitle)  + (this.type == 'community')? ' Gateway':' Monitor Dashboard';
63
    this.modal.alertMessage = false;
64
    this.modal.okButtonLeft = false;
65
    this.modal.okButtonText = 'Yes';
66
    this.modal.cancelButtonText = 'No';
67
    this.modal.choice = true;
68
    this.modal.open();
69
  }
70

    
71
  public getCommunityPageUrl(entity): string {
72
    let url = '';
73
    if (this.isProduction()) {
74
      url = 'https://' + this.getProductionPrefix() + entity.communityId + '.openaire.eu';
75
    } else {
76
      url = this.router.createUrlTree(['/'], {
77
        queryParams: {'communityId': entity.communityId}
78
      }).toString();
79
    }
80
    if(this.type == 'funder'){
81
      url = "http://dl170.madgik.di.uoa.gr/monitor/dashboard/"+entity.alias;
82
    }
83
    return url;
84
  }
85

    
86
  public goToCommunityPage(data: any) {
87
    if (data.value == true) {
88
      this.localStorageService.setCommunityDirectLink(data.choice);
89
      let url = '';
90
      if (this.isProduction()) {
91
        url = 'https://' + this.getProductionPrefix() + this.selectedCommunityId + '.openaire.eu';
92
      } else {
93
        url = this.router.createUrlTree(['/'], {
94
          queryParams: {'communityId': this.selectedCommunityId}
95
        }).toString();
96
      }
97
      if(this.type == 'funder'){
98
        url = "http://dl170.madgik.di.uoa.gr/monitor/dashboard/"+this.selectedCommunityId;
99
      }
100
      console.log(url)
101
      window.open(url, '_blank');
102
    }
103
  }
104
}
(12-12/54)