Project

General

Profile

1 61381 k.triantaf
import {Component, Input} from '@angular/core';
2
import {EnvProperties} from "../../properties/env-properties";
3
import {ErrorCodes} from "../../properties/errorCodes";
4
5
@Component({
6
    selector: 'search-tab',
7
    template: `
8
      <errorMessages *ngIf="resultType" [status]="[fetch.searchUtils.status]" [type]="getEntityName(resultType, true, true)"
9
                     tab_error_class=true></errorMessages>
10
11
      <div *ngIf="fetch.searchUtils.status == errorCodes.DONE">
12
        <div class="tab-header">
13
          <span *ngIf="!customTitle && resultType"><span *ngIf="resultType != 'organization' && resultType != 'dataprovider' && resultType != 'project'">Recent</span>
14
          {{getEntityName(resultType, true, true)}}
15
            </span>
16
          <span *ngIf="customTitle">{{customTitle}}</span>
17
        </div>
18
        <div *ngIf="searchLinkToAdvancedPage" class="uk-text-right">
19
<!--            {{getEntityName(resultType, true, true)}}-->
20
          <a class="el-content uk-button uk-button-text" [queryParams]="params" [routerLink]="searchLinkToAdvancedPage">
21
            View all
22
            <span *ngIf="fetch.searchUtils.totalResults <= searchNumber">in search page</span>
23
          </a>
24
        </div>
25
26
        <ng-content></ng-content>
27
28
        <search-result [properties]="properties"
29
                       [results]="fetch.results"
30
                       [status]="fetch.searchUtils.status"
31
                       [type]="resultType"  [showImpactFactors]="showImpactFactors" [showEnermaps]="showEnermaps">
32
        </search-result>
33
34
        <div *ngIf="searchLinkToAdvancedPage" class="uk-text-right">
35
<!--            {{getEntityName(resultType, true, true)}}-->
36
          <a class="el-content uk-button uk-button-text" [queryParams]="params" [routerLink]="searchLinkToAdvancedPage">
37
            View all
38
            <span *ngIf="fetch.searchUtils.totalResults <= searchNumber">in search page</span>
39
          </a>
40
        </div>
41
      </div>
42
    `
43
})
44
45
export class SearchTabComponent {
46
    @Input() public fetch;
47
    @Input() public resultType: string;
48
    @Input() public params: any;
49
    @Input() public searchNumber: number = 5;
50
    @Input() public searchLinkToAdvancedPage: string;
51
    @Input() properties: EnvProperties;
52
    @Input() showImpactFactors;
53
    @Input() customTitle;
54
    @Input() showEnermaps: boolean;
55
56
    public errorCodes: ErrorCodes = new ErrorCodes();
57
58
    public getEntityName(entityType: string, plural: boolean, full: boolean): string {
59
      if (entityType == "publication") {
60
        return "publication" + (plural ? "s" : "");
61
      } else if (entityType == "dataset") {
62
        return (full ? "research data" : ("dataset" + (plural ? "s" : "")));
63
      } else if (entityType == "software") {
64
        return "software";
65
      } else if (entityType == "other") {
66
        return (full ? ("other research product" + (plural ? "s" : "")) : "other");
67
      } else if (entityType == "result") {
68
        return ((full ? "research outcome" : "result") + (plural ? "s" : ""));
69
      } else if (entityType == "project") {
70
        return "project" + (plural ? "s" : "");
71
      } else if (entityType == "dataprovider") {
72
        return ((full ? "content provider" : "dataprovider") + (plural ? "s" : ""));
73
      }
74
    }
75
}