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.DOI).join(","));
36
    // console.log(dois);
37
    if(dois.length > 0 && this.showImpactFactors && this.properties.environment != "production") {
38
      let url = 'http://bip.imis.athena-innovation.gr:4000/paper/scores/batch/' + dois;
39
      this.http.get(url).subscribe((data_received) => {
40
        for (let i = 0; i < this.previewResults.length; i++) {
41
          this.previewResults[i].pop_inf = new Array<string>();
42
          // console.log(data[1][i].DOI,'inf: ',data_received[i].pop_class,'and pop: ',data_received[i].inf_class);
43
          // researchResults[1].pop_inf[i].push(data[i].inf_class,data[i].pop_class);
44
          console.log(this.previewResults[i].DOI)
45
          if (this.previewResults[i].DOI != '' && this.previewResults[i].DOI != null) {
46
            this.previewResults[i].pop_inf.push(data_received[i].pop_class, data_received[i].inf_class);
47
          }
48
        }
49
        console.log(this.previewResults)
50

    
51
      }, error1 => {
52
        console.error("Failed to get Impact factors for elixir-gr")
53
      });
54
      // console.log(researchResults[1]);
55

    
56
    }
57
    /////////////////////// ATHENA CODE ///////////////////////
58
  }
59

    
60
  ngOnChanges(changes: SimpleChanges): void {
61
     if (changes.results) {
62
      this.initialize();
63
    }
64
  }
65
  public getResultPreview(result: SearchResult): ResultPreview {
66
    return ResultPreview.searchResultConvert(result, (result.entityType)?result.entityType:this.type);
67
  }
68
  
69
  
70
  public quote(params: string): string {
71
    return '"' + params + '"';
72
  }
73
}
(46-46/55)