openaire-library/searchPages/searchUtils/searchResult.component.ts

110 lines
4.2 KiB
TypeScript
Raw Normal View History

import {Component, Input, OnChanges, OnInit, SimpleChanges} from '@angular/core';
import {SearchResult} from '../../utils/entities/searchResult';
import {EnvProperties} from '../../utils/properties/env-properties';
import {ResultPreview} from "../../utils/result-preview/result-preview";
import {HttpClient} from "@angular/common/http";
@Component({
selector: 'search-result',
templateUrl: 'searchResult.component.html'
})
export class SearchResultComponent implements OnInit, OnChanges {
@Input() results: SearchResult[];
previewResults:ResultPreview[];
@Input() status: number;
@Input() type: string;
@Input() showLoading: boolean = false;
@Input() showSubjects: boolean = true;
@Input() showOrganizations: boolean = true;
@Input() custom_class: string = "search-results";
@Input() properties: EnvProperties;
@Input() showImpactFactors: boolean = false;
constructor( private http: HttpClient/*ATHENA CODE*/) {
}
ngOnInit() {}
sub;
ngOnDestroy() {
if(this.sub){
this.sub.unsubscribe();
}
}
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.DOIs).join(","));
// console.log(dois);
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.sub = this.http.get((this.properties.useCache?(this.properties.cacheUrl+(encodeURIComponent(url))):url)).subscribe((data_received:any[]) => {
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) {
if(result.identifiers) {
result.identifiers.get("doi").forEach(function (doi) {
if (impact[doi]) {
result.DOI = doi;
}
})
}
});
for (let i = 0; i < this.previewResults.length; i++) {
if (this.previewResults[i].DOI) {
this.previewResults[i].pop_inf = new Array<string>();
this.previewResults[i].pop_inf.push(impact[this.previewResults[i].DOI].pop_class, impact[this.previewResults[i].DOI].inf_class);
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");
}
}
}
}, 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();
}
}
public getResultPreview(result: SearchResult): ResultPreview {
return ResultPreview.searchResultConvert(result, (result.entityType)?result.entityType:this.type);
}
public quote(params: string): string {
return '"' + params + '"';
}
}