1
|
import {Component, Input, OnChanges, OnInit, SimpleChanges} from '@angular/core';
|
2
|
import {SearchResult} from '../../utils/entities/searchResult';
|
3
|
import {EnvProperties} from '../../utils/properties/env-properties';
|
4
|
import {ResultPreview} from "../../utils/result-preview/result-preview";
|
5
|
import {HttpClient} from "@angular/common/http";
|
6
|
import {OrcidService} from "../../orcid/orcid.service";
|
7
|
import {Session} from "../../login/utils/helper.class";
|
8
|
import {properties} from "../../../../environments/environment";
|
9
|
|
10
|
@Component({
|
11
|
selector: 'search-result',
|
12
|
templateUrl: 'searchResult.component.html'
|
13
|
})
|
14
|
export class SearchResultComponent implements OnInit, OnChanges {
|
15
|
@Input() results: SearchResult[];
|
16
|
previewResults:ResultPreview[];
|
17
|
@Input() status: number;
|
18
|
@Input() type: string;
|
19
|
@Input() showLoading: boolean = false;
|
20
|
@Input() showSubjects: boolean = true;
|
21
|
@Input() showOrganizations: boolean = true;
|
22
|
@Input() custom_class: string = "search-results";
|
23
|
@Input() properties: EnvProperties;
|
24
|
@Input() showImpactFactors: boolean = false;
|
25
|
@Input() showEnermaps: boolean;
|
26
|
|
27
|
constructor( private http: HttpClient/*ATHENA CODE*/
|
28
|
, private orcidService: OrcidService) {
|
29
|
}
|
30
|
|
31
|
ngOnInit() {}
|
32
|
sub;
|
33
|
ngOnDestroy() {
|
34
|
if(this.sub){
|
35
|
this.sub.unsubscribe();
|
36
|
}
|
37
|
}
|
38
|
initialize(){
|
39
|
this.previewResults = [];
|
40
|
for(let result of this.results){
|
41
|
this.previewResults.push(this.getResultPreview(result));
|
42
|
}
|
43
|
|
44
|
if((properties.adminToolsPortalType == "explore" || properties.adminToolsPortalType == "community")
|
45
|
&& Session.isLoggedIn() && this.results && this.results.length > 0) {
|
46
|
this.orcidService.getPutCodes(this.previewResults.map(
|
47
|
previewResult => {
|
48
|
if(previewResult.identifiers) {
|
49
|
let pidsArray: string[] = [];
|
50
|
for(let key of Array.from(previewResult.identifiers.keys())) {
|
51
|
pidsArray = pidsArray.concat(previewResult.identifiers.get(key));
|
52
|
}
|
53
|
return pidsArray;//.join();
|
54
|
}
|
55
|
})).subscribe(
|
56
|
putCodes => {
|
57
|
for (let i = 0; i < this.previewResults.length; i++) {
|
58
|
if(this.previewResults[i].identifiers) {
|
59
|
this.previewResults[i].orcidPutCodes = putCodes[i];
|
60
|
// console.debug(i, this.previewResults[i].orcidPutCodes);
|
61
|
}
|
62
|
}
|
63
|
}, error => {
|
64
|
|
65
|
}
|
66
|
);
|
67
|
}
|
68
|
|
69
|
/////////////////////// ATHENA CODE ///////////////////////
|
70
|
// console.log(data[1]);
|
71
|
let dois = encodeURIComponent(this.results.map((result) => result.DOIs).join(","));
|
72
|
// console.log(dois);
|
73
|
if(dois.length > 0 && this.showImpactFactors && (this.properties.impactFactorsAPIURL && this.properties.impactFactorsAPIURL.length > 0) ) {
|
74
|
let url = this.properties.impactFactorsAPIURL + dois;
|
75
|
this.sub = this.http.get((this.properties.useCache?(this.properties.cacheUrl+(encodeURIComponent(url))):url)).subscribe((data_received:any[]) => {
|
76
|
let impact =[];
|
77
|
data_received.forEach(function (result) {
|
78
|
if(result.doi && result.doi.length > 0 && result.pop_class!=null && result.inf_class!=null)
|
79
|
impact[result.doi]=result;
|
80
|
});
|
81
|
this.previewResults.forEach(function (result) {
|
82
|
if(result.identifiers && result.identifiers.get("doi")) {
|
83
|
result.identifiers.get("doi").forEach(function (doi) {
|
84
|
if (impact[doi]) {
|
85
|
result.DOI = doi;
|
86
|
}
|
87
|
|
88
|
})
|
89
|
}
|
90
|
});
|
91
|
for (let i = 0; i < this.previewResults.length; i++) {
|
92
|
if (this.previewResults[i].DOI) {
|
93
|
this.previewResults[i].pop_inf = new Array<string>();
|
94
|
this.previewResults[i].pop_inf.push(impact[this.previewResults[i].DOI].pop_class, impact[this.previewResults[i].DOI].inf_class);
|
95
|
if(this.previewResults[i].pop_inf[0]=="A"){
|
96
|
// this.previewResults[i].pop_inf.push("High");
|
97
|
this.previewResults[i].pop_inf.push("Exceptional");
|
98
|
}else if(this.previewResults[i].pop_inf[0]=="B"){
|
99
|
// this.previewResults[i].pop_inf.push("Average");
|
100
|
this.previewResults[i].pop_inf.push("Substantial");
|
101
|
}else{
|
102
|
// this.previewResults[i].pop_inf.push("low");
|
103
|
this.previewResults[i].pop_inf.push("Average");
|
104
|
}
|
105
|
if(this.previewResults[i].pop_inf[1]=="A"){
|
106
|
// this.previewResults[i].pop_inf.push("Strong");
|
107
|
this.previewResults[i].pop_inf.push("Exceptional");
|
108
|
}else if(this.previewResults[i].pop_inf[1]=="B"){
|
109
|
// this.previewResults[i].pop_inf.push("Average");
|
110
|
this.previewResults[i].pop_inf.push("Substantial");
|
111
|
}else{
|
112
|
// this.previewResults[i].pop_inf.push("Weak");
|
113
|
this.previewResults[i].pop_inf.push("Average");
|
114
|
}
|
115
|
}
|
116
|
}
|
117
|
|
118
|
}, error1 => {
|
119
|
console.error("Failed to get Impact factors for elixir-gr")
|
120
|
});
|
121
|
// console.log(researchResults[1]);
|
122
|
|
123
|
}
|
124
|
/////////////////////// ATHENA CODE ///////////////////////
|
125
|
}
|
126
|
|
127
|
ngOnChanges(changes: SimpleChanges): void {
|
128
|
if (changes.results) {
|
129
|
this.initialize();
|
130
|
}
|
131
|
}
|
132
|
public getResultPreview(result: SearchResult): ResultPreview {
|
133
|
return ResultPreview.searchResultConvert(result, (result.entityType)?result.entityType:this.type);
|
134
|
}
|
135
|
|
136
|
|
137
|
public quote(params: string): string {
|
138
|
return '"' + params + '"';
|
139
|
}
|
140
|
}
|