Project

General

Profile

1
import {Component, Input, OnChanges, OnInit, SimpleChanges} from "@angular/core";
2
import {ResultPreview} from "./result-preview";
3
import {EnvProperties} from "../properties/env-properties";
4
import {RouterHelper} from "../routerHelper.class";
5
import {AlertModal} from "../modal/alert";
6
import {properties} from "../../../../environments/environment";
7
import {Session} from "../../login/utils/helper.class";
8
import {Identifier} from "../string-utils.class";
9

    
10
@Component({
11
  selector: 'result-preview',
12
  templateUrl: 'result-preview.component.html'
13
})
14
export class ResultPreviewComponent implements OnInit, OnChanges {
15
  @Input() result: ResultPreview;
16
  @Input() properties: EnvProperties;
17
  @Input() showSubjects: boolean = true;
18
  @Input() showOrganizations: boolean = true;
19
  @Input() modal: AlertModal = null;
20
  @Input() promoteWebsiteURL: boolean = false;
21
  @Input() hasLink: boolean = true;
22
  public routerHelper: RouterHelper = new RouterHelper();
23
  public urlParam: string;
24
  public url: string;
25
  public type: string;
26
  public beforeTitle: string[] = [];
27
  public dataProviderUrl = properties.searchLinkToDataProvider.split('?')[0];
28
  @Input() showOrcid: boolean = true;
29

    
30
  ngOnInit(): void {
31
    if(this.hasLink) {
32
      if (this.result.resultType === "publication") {
33
        this.urlParam = "articleId";
34
        this.url = properties.searchLinkToPublication.split('?')[0];
35
      } else if (this.result.resultType === "dataset") {
36
        this.urlParam = "datasetId";
37
        this.url = properties.searchLinkToDataset.split('?')[0];
38
      } else if (this.result.resultType === "software") {
39
        this.urlParam = "softwareId";
40
        this.url = properties.searchLinkToSoftwareLanding.split('?')[0];
41
      } else if (this.result.resultType === "other") {
42
        this.urlParam = "orpId";
43
        this.url = properties.searchLinkToOrp.split('?')[0];
44
      } else if (this.result.resultType == "project") {
45
        this.urlParam = "projectId";
46
        this.url = properties.searchLinkToProject.split('?')[0];
47
      } else if (this.result.resultType == "organization") {
48
        this.urlParam = "organizationId";
49
        this.url = properties.searchLinkToOrganization.split('?')[0];
50
      } else if (this.result.resultType == "dataprovider") {
51
        this.urlParam = "datasourceId";
52
        this.url = properties.searchLinkToDataProvider.split('?')[0];
53
      } else {
54
        this.urlParam = "id";
55
        this.url = properties.searchLinkToResult.split('?')[0];
56
      }
57
      this.checkPID();
58
    }
59
    this.initBeforeTitle();
60
    if(this.result.languages) {
61
      this.result.languages = this.removeUnknown(this.result.languages);
62
    }
63
    if(this.result.countries) {
64
      this.result.countries = this.removeUnknown(this.result.countries);
65
    }
66
  }
67
  
68
  ngOnChanges(changes: SimpleChanges) {
69
    if(changes.result && this.hasLink) {
70
      this.checkPID();
71
    }
72
  }
73
  
74
  checkPID() {
75
    // if result has a pid use it as parameter instead of openaireId
76
    let pid:Identifier = Identifier.getResultPIDFromIdentifiers(this.result.identifiers);
77
    if(pid){
78
      this.urlParam = "pid";
79
      this.result.id = encodeURIComponent(pid.id);
80
    
81
    }
82
  }
83
  
84
  get isLoggedIn(): boolean {
85
    return Session.isLoggedIn();
86
  }
87
  
88
  public initBeforeTitle() {
89
    if(this.result.resultType && this.result.resultType !== 'dataprovider') {
90
      this.type = this.getTypeName(this.result.resultType);
91
    }
92
    if(this.result.types) {
93
      this.removeUnknown(this.removeDuplicates(this.result.types)).forEach(type => {
94
        this.beforeTitle.push(type);
95
      });
96
    }
97
    if(this.result.year) {
98
      this.beforeTitle.push(this.result.year.toString());
99
    }
100
    if(this.result.startYear && this.result.endYear) {
101
      this.beforeTitle.push(this.result.startYear.toString() + ' - ' + this.result.endYear.toString());
102
    }
103
    if(this.result.provenanceAction) {
104
      this.beforeTitle.push(this.result.provenanceAction);
105
    }
106
  }
107
  
108
  public getTypeName(type: string): string {
109
    if (type === "dataset") {
110
      return "research data";
111
    } else if (type === "other") {
112
      return "other research product";
113
    } else if (type === "dataprovider") {
114
      return "content provider";
115
    } else {
116
      return type;
117
    }
118
  }
119
  
120
  public removeUnknown(array: string[]): string[] {
121
    return array.filter(value => value.toLowerCase() !== 'unknown');
122
  }
123
  
124
  public removeDuplicates(array: string[]): string[] {
125
    return array.filter(value => value.toLowerCase() !== this.result.resultType);
126
  }
127
  
128
  public accessClass(accessMode: string): string {
129
    if(accessMode.toLowerCase().indexOf('open') !== -1) {
130
      return 'open';
131
    } else if(accessMode.toLowerCase() === 'not available') {
132
      return 'unknown';
133
    } else {
134
      return 'closed';
135
    }
136
  }
137
  
138
  public onClick() {
139
    if(this.modal) {
140
      this.modal.cancel();
141
    }
142
  }
143
}
(2-2/4)