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-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]);
|
|
|
|
let dois = encodeURIComponent(this.results.map((result) => result.DOI).join(","));
|
|
|
|
// console.log(dois);
|
2020-05-07 12:50:15 +02:00
|
|
|
if(dois.length > 0 && this.showImpactFactors && this.properties.environment != "production" && (this.properties.impactFactorsAPIURL && this.properties.impactFactorsAPIURL.length > 0) ) {
|
|
|
|
let url = this.properties.impactFactorsAPIURL + dois;
|
|
|
|
this.http.get((this.properties.useCache?(this.properties.cacheUrl+(encodeURIComponent(url))):url)).subscribe((data_received) => {
|
2020-04-06 16:49:38 +02:00
|
|
|
for (let i = 0; i < this.previewResults.length; i++) {
|
2020-05-25 11:46:37 +02:00
|
|
|
if (this.previewResults[i].DOI != '' && this.previewResults[i].DOI != null && data_received[i].pop_class!=null && data_received[i].inf_class!=null) {
|
|
|
|
this.previewResults[i].pop_inf = new Array<string>();
|
2020-04-06 16:49:38 +02:00
|
|
|
this.previewResults[i].pop_inf.push(data_received[i].pop_class, data_received[i].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
|
|
|
}
|