141 lines
5.4 KiB
TypeScript
141 lines
5.4 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";
|
|
import {OrcidService} from "../../orcid/orcid.service";
|
|
import {Session} from "../../login/utils/helper.class";
|
|
import {properties} from "../../../../environments/environment";
|
|
|
|
@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;
|
|
@Input() showEnermaps: boolean;
|
|
|
|
constructor( private http: HttpClient/*ATHENA CODE*/
|
|
, private orcidService: OrcidService) {
|
|
}
|
|
|
|
ngOnInit() {}
|
|
sub;
|
|
ngOnDestroy() {
|
|
if(this.sub){
|
|
this.sub.unsubscribe();
|
|
}
|
|
}
|
|
initialize(){
|
|
this.previewResults = [];
|
|
for(let result of this.results){
|
|
this.previewResults.push(this.getResultPreview(result));
|
|
}
|
|
|
|
if((properties.adminToolsPortalType == "explore" || properties.adminToolsPortalType == "community")
|
|
&& Session.isLoggedIn() && this.results && this.results.length > 0) {
|
|
this.orcidService.getPutCodes(this.previewResults.map(
|
|
previewResult => {
|
|
if(previewResult.identifiers) {
|
|
let pidsArray: string[] = [];
|
|
for(let key of Array.from(previewResult.identifiers.keys())) {
|
|
pidsArray = pidsArray.concat(previewResult.identifiers.get(key));
|
|
}
|
|
return pidsArray;//.join();
|
|
}
|
|
})).subscribe(
|
|
putCodes => {
|
|
for (let i = 0; i < this.previewResults.length; i++) {
|
|
if(this.previewResults[i].identifiers) {
|
|
this.previewResults[i].orcidPutCodes = putCodes[i];
|
|
// console.debug(i, this.previewResults[i].orcidPutCodes);
|
|
}
|
|
}
|
|
}, error => {
|
|
|
|
}
|
|
);
|
|
}
|
|
|
|
/////////////////////// 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.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")) {
|
|
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 + '"';
|
|
}
|
|
}
|