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

74 lines
2.7 KiB
TypeScript

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() {}
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);
if(dois.length > 0 && this.showImpactFactors && this.properties.environment == "development") {
let url = 'http://bip.imis.athena-innovation.gr:4000/paper/scores/batch/' + dois;
this.http.get(url).subscribe((data_received) => {
for (let i = 0; i < this.previewResults.length; i++) {
this.previewResults[i].pop_inf = new Array<string>();
// console.log(data[1][i].DOI,'inf: ',data_received[i].pop_class,'and pop: ',data_received[i].inf_class);
// researchResults[1].pop_inf[i].push(data[i].inf_class,data[i].pop_class);
console.log(this.previewResults[i].DOI)
if (this.previewResults[i].DOI != '' && this.previewResults[i].DOI != null) {
this.previewResults[i].pop_inf.push(data_received[i].pop_class, data_received[i].inf_class);
}
}
console.log(this.previewResults)
}, 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 + '"';
}
}