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
    return "beta.";
47
  }
48

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

    
52
  }
53

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

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

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

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