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