Project

General

Profile

1
import {Component, Input} from '@angular/core';
2
import {SearchResult}     from '../utils/entities/searchResult';
3
import {ErrorCodes} from '../utils/properties/errorCodes';
4
import {RouterHelper} from '../utils/routerHelper.class';
5
import {EnvProperties} from '../utils/properties/env-properties';
6
import {ZenodoInformationClass} from "./utils/zenodoInformation.class";
7
import {ActivatedRoute} from "@angular/router";
8
import {ResultPreview} from "../utils/result-preview/result-preview";
9
import {Subscriber} from "rxjs";
10

    
11
@Component({
12
  selector: 'deposit-result',
13
  templateUrl:'searchResultsInDeposit.component.html'
14
})
15

    
16
export class SearchResultsInDepositComponent {
17
  @Input() results: SearchResult[];
18
  @Input() status: number;
19
  @Input() type: string;
20
  @Input() properties:EnvProperties;
21

    
22

    
23
  public urlParam: string;
24
  public linkToAdvancedSearchPage: string;
25
  public errorCodes:ErrorCodes = new ErrorCodes();
26
  public routerHelper:RouterHelper = new RouterHelper();
27
  public errorMessage: string = "No results found";
28

    
29
  @Input() public zenodoInformation: ZenodoInformationClass = new ZenodoInformationClass();
30
  sub;
31
  constructor (private  route: ActivatedRoute) {}
32
  ngOnDestroy() {
33
    if (this.sub instanceof Subscriber) {
34
      this.sub.unsubscribe();
35
    }
36
  }
37
  ngOnInit() {
38
    if(this.type == "publication") {
39
      this.linkToAdvancedSearchPage = this.properties.searchLinkToAdvancedPublications;
40
      this.urlParam = "articleId";
41
    } else if(this.type == "dataset") {
42
      this.linkToAdvancedSearchPage = this.properties.searchLinkToAdvancedDatasets;
43
      this.urlParam = "datasetId";
44
    } else if(this.type == "software") {
45
      this.linkToAdvancedSearchPage = this.properties.searchLinkToAdvancedSoftware;
46
      this.urlParam = "softwareId";
47
    } else if(this.type == "other") {
48
      this.linkToAdvancedSearchPage = this.properties.searchLinkToAdvancedOrps;
49
      this.urlParam = "orpId";
50
    } else if(this.type == "project") {
51
      this.linkToAdvancedSearchPage = this.properties.searchLinkToAdvancedProjects;
52
      this.urlParam = "projectId";
53
    } else if(this.type == "organization") {
54
      this.linkToAdvancedSearchPage = this.properties.searchLinkToAdvancedOrganizations;
55
      this.urlParam = "organizationId";
56
    } else if(this.type == "dataprovider") {
57
      this.linkToAdvancedSearchPage = this.properties.searchLinkToAdvancedDataProviders;
58
      this.urlParam = "datasourceId";
59
    }
60

    
61
    this.sub = this.route.data
62
      .subscribe((data: { envSpecific: EnvProperties }) => {
63
        this.properties = data.envSpecific;
64

    
65
        if (!this.zenodoInformation) {
66
          this.zenodoInformation = new ZenodoInformationClass();
67
        }
68
        if (!this.zenodoInformation.shareInZenodoUrl) {
69
          this.zenodoInformation.url = this.properties.zenodo;
70
        }
71
        if (!this.zenodoInformation.name) {
72
          this.zenodoInformation.name = "Zenodo";
73
        }
74
      });
75
  }
76

    
77
  public  quote(params: string):string {
78
    return '"'+params+'"';
79
  }
80
  public getResultPreview(result: SearchResult): ResultPreview {
81
    return ResultPreview.searchResultConvert(result, (result.entityType)?result.entityType:this.type);
82
  }
83

    
84
}
(6-6/7)