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

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

    
87
      }, error1 => {
88
        console.error("Failed to get Impact factors for elixir-gr")
89
      });
90
      // console.log(researchResults[1]);
91

    
92
    }
93
    /////////////////////// ATHENA CODE ///////////////////////
94
  }
95

    
96
  ngOnChanges(changes: SimpleChanges): void {
97
     if (changes.results) {
98
      this.initialize();
99
    }
100
  }
101
  public getResultPreview(result: SearchResult): ResultPreview {
102
    return ResultPreview.searchResultConvert(result, (result.entityType)?result.entityType:this.type);
103
  }
104
  
105
  
106
  public quote(params: string): string {
107
    return '"' + params + '"';
108
  }
109
}
(38-38/47)