Project

General

Profile

1
import {Component, Input, OnChanges, OnInit, SimpleChanges} from '@angular/core';
2
import {SearchResult} from '../../utils/entities/searchResult';
3
import {EnvProperties} from '../../utils/properties/env-properties';
4
import {ResultPreview} from "../../utils/result-preview/result-preview";
5
import {HttpClient} from "@angular/common/http";
6

    
7
@Component({
8
  selector: 'search-result',
9
  templateUrl: 'searchResult.component.html'
10
})
11
export class SearchResultComponent implements OnInit, OnChanges  {
12
  @Input() results: SearchResult[];
13
  previewResults:ResultPreview[];
14
  @Input() status: number;
15
  @Input() type: string;
16
  @Input() showLoading: boolean = false;
17
  @Input() showSubjects: boolean = true;
18
  @Input() showOrganizations: boolean = true;
19
  @Input() custom_class: string = "search-results";
20
  @Input() properties: EnvProperties;
21
  @Input() showImpactFactors: boolean = false;
22

    
23
  constructor( private http: HttpClient/*ATHENA CODE*/) {
24
  }
25
  
26
  ngOnInit() {}
27

    
28
  initialize(){
29
    this.previewResults = [];
30
    for(let result of this.results){
31
      this.previewResults.push(this.getResultPreview(result));
32
    }
33
    /////////////////////// ATHENA CODE ///////////////////////
34
    // console.log(data[1]);
35
    let dois = encodeURIComponent(this.results.map((result) => result.DOIs).join(","));
36
    // console.log(dois);
37
    if(dois.length > 0 && this.showImpactFactors && this.properties.environment != "production" &&  (this.properties.impactFactorsAPIURL &&  this.properties.impactFactorsAPIURL.length > 0) ) {
38
      let url = this.properties.impactFactorsAPIURL + dois;
39
      this.http.get((this.properties.useCache?(this.properties.cacheUrl+(encodeURIComponent(url))):url)).subscribe((data_received:any[]) => {
40
        let impact =[];
41
        data_received.forEach(function (result) {
42
          if(result.doi && result.doi.length > 0 && result.pop_class!=null && result.inf_class!=null)
43
          impact[result.doi]=result;
44
        });
45
        this.previewResults.forEach(function (result) {
46
          if(result.identifiers) {
47
            result.identifiers.get("doi").forEach(function (doi) {
48
              if (impact[doi]) {
49
                result.DOI = doi;
50
              }
51

    
52
            })
53
          }
54
         });
55
        for (let i = 0; i < this.previewResults.length; i++) {
56
          if (this.previewResults[i].DOI) {
57
            this.previewResults[i].pop_inf = new Array<string>();
58
            this.previewResults[i].pop_inf.push(impact[this.previewResults[i].DOI].pop_class, impact[this.previewResults[i].DOI].inf_class);
59
            if(this.previewResults[i].pop_inf[0]=="A"){
60
              // this.previewResults[i].pop_inf.push("High");
61
              this.previewResults[i].pop_inf.push("Exceptional");
62
            }else if(this.previewResults[i].pop_inf[0]=="B"){
63
              // this.previewResults[i].pop_inf.push("Average");
64
              this.previewResults[i].pop_inf.push("Substantial");
65
            }else{
66
              // this.previewResults[i].pop_inf.push("low");
67
              this.previewResults[i].pop_inf.push("Average");
68
            }
69
            if(this.previewResults[i].pop_inf[1]=="A"){
70
              // this.previewResults[i].pop_inf.push("Strong");
71
              this.previewResults[i].pop_inf.push("Exceptional");
72
            }else if(this.previewResults[i].pop_inf[1]=="B"){
73
              // this.previewResults[i].pop_inf.push("Average");
74
              this.previewResults[i].pop_inf.push("Substantial");
75
            }else{
76
              // this.previewResults[i].pop_inf.push("Weak");
77
              this.previewResults[i].pop_inf.push("Average");
78
            }
79
          }
80
        }
81

    
82
      }, error1 => {
83
        console.error("Failed to get Impact factors for elixir-gr")
84
      });
85
      // console.log(researchResults[1]);
86

    
87
    }
88
    /////////////////////// ATHENA CODE ///////////////////////
89
  }
90

    
91
  ngOnChanges(changes: SimpleChanges): void {
92
     if (changes.results) {
93
      this.initialize();
94
    }
95
  }
96
  public getResultPreview(result: SearchResult): ResultPreview {
97
    return ResultPreview.searchResultConvert(result, (result.entityType)?result.entityType:this.type);
98
  }
99
  
100
  
101
  public quote(params: string): string {
102
    return '"' + params + '"';
103
  }
104
}
(46-46/55)