2020-04-06 16:49:38 +02:00
|
|
|
import {Component, Input, OnChanges, OnInit, SimpleChanges} from '@angular/core';
|
2020-02-07 14:05:07 +01:00
|
|
|
import {SearchResult} from '../../utils/entities/searchResult';
|
|
|
|
import {EnvProperties} from '../../utils/properties/env-properties';
|
2020-03-12 14:49:10 +01:00
|
|
|
import {ResultPreview} from "../../utils/result-preview/result-preview";
|
2020-04-06 16:49:38 +02:00
|
|
|
import {HttpClient} from "@angular/common/http";
|
2020-02-07 14:05:07 +01:00
|
|
|
|
2017-12-19 13:53:46 +01:00
|
|
|
@Component({
|
2020-02-07 14:05:07 +01:00
|
|
|
selector: 'search-result',
|
|
|
|
templateUrl: 'searchResult.component.html'
|
2017-12-19 13:53:46 +01:00
|
|
|
})
|
2020-04-06 16:49:38 +02:00
|
|
|
export class SearchResultComponent implements OnInit, OnChanges {
|
2020-02-07 14:05:07 +01:00
|
|
|
@Input() results: SearchResult[];
|
2020-04-06 16:49:38 +02:00
|
|
|
previewResults:ResultPreview[];
|
2020-02-07 14:05:07 +01:00
|
|
|
@Input() status: number;
|
|
|
|
@Input() type: string;
|
|
|
|
@Input() showLoading: boolean = false;
|
2020-03-12 11:44:51 +01:00
|
|
|
@Input() showSubjects: boolean = true;
|
2020-02-07 14:05:07 +01:00
|
|
|
@Input() showOrganizations: boolean = true;
|
|
|
|
@Input() custom_class: string = "search-results";
|
|
|
|
@Input() properties: EnvProperties;
|
2020-04-06 16:49:38 +02:00
|
|
|
@Input() showImpactFactors: boolean = false;
|
2020-05-19 17:59:20 +02:00
|
|
|
|
2020-04-06 16:49:38 +02:00
|
|
|
constructor( private http: HttpClient/*ATHENA CODE*/) {
|
2020-02-07 14:05:07 +01:00
|
|
|
}
|
|
|
|
|
2020-03-12 14:49:10 +01:00
|
|
|
ngOnInit() {}
|
2020-11-11 15:43:13 +01:00
|
|
|
sub;
|
|
|
|
ngOnDestroy() {
|
|
|
|
if(this.sub){
|
|
|
|
this.sub.unsubscribe();
|
|
|
|
}
|
|
|
|
}
|
2020-04-06 16:49:38 +02:00
|
|
|
initialize(){
|
|
|
|
this.previewResults = [];
|
|
|
|
for(let result of this.results){
|
|
|
|
this.previewResults.push(this.getResultPreview(result));
|
|
|
|
}
|
|
|
|
/////////////////////// ATHENA CODE ///////////////////////
|
|
|
|
// console.log(data[1]);
|
2020-05-25 14:24:48 +02:00
|
|
|
let dois = encodeURIComponent(this.results.map((result) => result.DOIs).join(","));
|
2020-04-06 16:49:38 +02:00
|
|
|
// console.log(dois);
|
2020-12-15 18:08:31 +01:00
|
|
|
if(dois.length > 0 && this.showImpactFactors && (this.properties.impactFactorsAPIURL && this.properties.impactFactorsAPIURL.length > 0) ) {
|
2020-05-07 12:50:15 +02:00
|
|
|
let url = this.properties.impactFactorsAPIURL + dois;
|
2020-11-11 15:43:13 +01:00
|
|
|
this.sub = this.http.get((this.properties.useCache?(this.properties.cacheUrl+(encodeURIComponent(url))):url)).subscribe((data_received:any[]) => {
|
2020-05-25 14:24:48 +02:00
|
|
|
let impact =[];
|
|
|
|
data_received.forEach(function (result) {
|
|
|
|
if(result.doi && result.doi.length > 0 && result.pop_class!=null && result.inf_class!=null)
|
|
|
|
impact[result.doi]=result;
|
|
|
|
});
|
|
|
|
this.previewResults.forEach(function (result) {
|
2020-06-02 10:40:56 +02:00
|
|
|
if(result.identifiers) {
|
|
|
|
result.identifiers.get("doi").forEach(function (doi) {
|
|
|
|
if (impact[doi]) {
|
|
|
|
result.DOI = doi;
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
2020-05-25 14:24:48 +02:00
|
|
|
}
|
2020-06-02 10:40:56 +02:00
|
|
|
});
|
2020-04-06 16:49:38 +02:00
|
|
|
for (let i = 0; i < this.previewResults.length; i++) {
|
2020-05-25 14:24:48 +02:00
|
|
|
if (this.previewResults[i].DOI) {
|
2020-05-25 11:46:37 +02:00
|
|
|
this.previewResults[i].pop_inf = new Array<string>();
|
2020-05-25 14:24:48 +02:00
|
|
|
this.previewResults[i].pop_inf.push(impact[this.previewResults[i].DOI].pop_class, impact[this.previewResults[i].DOI].inf_class);
|
2020-05-05 18:21:31 +02:00
|
|
|
if(this.previewResults[i].pop_inf[0]=="A"){
|
|
|
|
// this.previewResults[i].pop_inf.push("High");
|
|
|
|
this.previewResults[i].pop_inf.push("Exceptional");
|
|
|
|
}else if(this.previewResults[i].pop_inf[0]=="B"){
|
|
|
|
// this.previewResults[i].pop_inf.push("Average");
|
|
|
|
this.previewResults[i].pop_inf.push("Substantial");
|
|
|
|
}else{
|
|
|
|
// this.previewResults[i].pop_inf.push("low");
|
|
|
|
this.previewResults[i].pop_inf.push("Average");
|
|
|
|
}
|
|
|
|
if(this.previewResults[i].pop_inf[1]=="A"){
|
|
|
|
// this.previewResults[i].pop_inf.push("Strong");
|
|
|
|
this.previewResults[i].pop_inf.push("Exceptional");
|
|
|
|
}else if(this.previewResults[i].pop_inf[1]=="B"){
|
|
|
|
// this.previewResults[i].pop_inf.push("Average");
|
|
|
|
this.previewResults[i].pop_inf.push("Substantial");
|
|
|
|
}else{
|
|
|
|
// this.previewResults[i].pop_inf.push("Weak");
|
|
|
|
this.previewResults[i].pop_inf.push("Average");
|
|
|
|
}
|
2020-04-06 16:49:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}, error1 => {
|
|
|
|
console.error("Failed to get Impact factors for elixir-gr")
|
|
|
|
});
|
|
|
|
// console.log(researchResults[1]);
|
|
|
|
|
|
|
|
}
|
|
|
|
/////////////////////// ATHENA CODE ///////////////////////
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnChanges(changes: SimpleChanges): void {
|
|
|
|
if (changes.results) {
|
|
|
|
this.initialize();
|
|
|
|
}
|
|
|
|
}
|
2020-03-12 14:49:10 +01:00
|
|
|
public getResultPreview(result: SearchResult): ResultPreview {
|
|
|
|
return ResultPreview.searchResultConvert(result, (result.entityType)?result.entityType:this.type);
|
2020-02-07 14:05:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public quote(params: string): string {
|
|
|
|
return '"' + params + '"';
|
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|