Project

General

Profile

1
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
        <search-result [properties]="properties"
27
                       [results]="fetch.results"
28
                       [status]="fetch.searchUtils.status"
29
                       [type]="resultType"  [showImpactFactors]="showImpactFactors" [showImage]="showImage">
30
        </search-result>
31

    
32
        <div *ngIf="searchLinkToAdvancedPage" class="uk-text-right">
33
<!--            {{getEntityName(resultType, true, true)}}-->
34
          <a class="el-content uk-button uk-button-text" [queryParams]="params" [routerLink]="searchLinkToAdvancedPage">
35
            View all
36
            <span *ngIf="fetch.searchUtils.totalResults <= searchNumber">in search page</span>
37
          </a>
38
        </div>
39
      </div>
40
    `
41
})
42

    
43
export class SearchTabComponent {
44
    @Input() public fetch;
45
    @Input() public resultType: string;
46
    @Input() public params: any;
47
    @Input() public searchNumber: number = 5;
48
    @Input() public searchLinkToAdvancedPage: string;
49
    @Input() properties: EnvProperties;
50
    @Input() showImpactFactors;
51
    @Input() customTitle;
52
    @Input() showImage: boolean;
53

    
54
    public errorCodes: ErrorCodes = new ErrorCodes();
55

    
56
    public getEntityName(entityType: string, plural: boolean, full: boolean): string {
57
      if (entityType == "publication") {
58
        return "publication" + (plural ? "s" : "");
59
      } else if (entityType == "dataset") {
60
        return (full ? "research data" : ("dataset" + (plural ? "s" : "")));
61
      } else if (entityType == "software") {
62
        return "software";
63
      } else if (entityType == "other") {
64
        return (full ? ("other research product" + (plural ? "s" : "")) : "other");
65
      } else if (entityType == "result") {
66
        return ((full ? "research outcome" : "result") + (plural ? "s" : ""));
67
      } else if (entityType == "project") {
68
        return "project" + (plural ? "s" : "");
69
      } else if (entityType == "dataprovider") {
70
        return ((full ? "content provider" : "dataprovider") + (plural ? "s" : ""));
71
      }
72
    }
73
}
(1-1/2)