openaire-library/utils/tabs/contents/search-tab.component.ts

78 lines
3.4 KiB
TypeScript

import {Component, Input} from '@angular/core';
import {EnvProperties} from "../../properties/env-properties";
import {ErrorCodes} from "../../properties/errorCodes";
@Component({
selector: 'search-tab',
template: `
<errorMessages *ngIf="resultType" [status]="[fetch.searchUtils.status]" [type]="getEntityName(resultType, true, true)"
tab_error_class=true></errorMessages>
<a *ngIf="fetch.searchUtils.status == errorCodes.LOADING" class="uk-invisible"
[queryParams]="params" [routerLink]="searchLinkToAdvancedPage"></a>
<div *ngIf="fetch.searchUtils.status == errorCodes.DONE">
<div class="tab-header">
<span *ngIf="!customTitle && resultType"><span *ngIf="resultType != 'organization' && resultType != 'dataprovider' && resultType != 'project'">Recent</span>
{{getEntityName(resultType, true, true)}}
</span>
<span *ngIf="customTitle">{{customTitle}}</span>
</div>
<div *ngIf="searchLinkToAdvancedPage" class="uk-text-right">
<!-- {{getEntityName(resultType, true, true)}}-->
<a class="el-content uk-button uk-button-text" [queryParams]="params" [routerLink]="searchLinkToAdvancedPage">
View all
<span *ngIf="fetch.searchUtils.totalResults <= searchNumber">in search page</span>
</a>
</div>
<ng-content></ng-content>
<search-result [properties]="properties"
[results]="fetch.results"
[status]="fetch.searchUtils.status"
[type]="resultType" [showImpactFactors]="showImpactFactors" [showEnermaps]="showEnermaps">
</search-result>
<div *ngIf="searchLinkToAdvancedPage" class="uk-text-right">
<!-- {{getEntityName(resultType, true, true)}}-->
<a class="el-content uk-button uk-button-text" [queryParams]="params" [routerLink]="searchLinkToAdvancedPage">
View all
<span *ngIf="fetch.searchUtils.totalResults <= searchNumber">in search page</span>
</a>
</div>
</div>
`
})
export class SearchTabComponent {
@Input() public fetch;
@Input() public resultType: string;
@Input() public params: any;
@Input() public searchNumber: number = 5;
@Input() public searchLinkToAdvancedPage: string;
@Input() properties: EnvProperties;
@Input() showImpactFactors;
@Input() customTitle;
@Input() showEnermaps: boolean;
public errorCodes: ErrorCodes = new ErrorCodes();
public getEntityName(entityType: string, plural: boolean, full: boolean): string {
if (entityType == "publication") {
return "publication" + (plural ? "s" : "");
} else if (entityType == "dataset") {
return (full ? "research data" : ("dataset" + (plural ? "s" : "")));
} else if (entityType == "software") {
return "software";
} else if (entityType == "other") {
return (full ? ("other research product" + (plural ? "s" : "")) : "other");
} else if (entityType == "result") {
return ((full ? "research outcome" : "result") + (plural ? "s" : ""));
} else if (entityType == "project") {
return "project" + (plural ? "s" : "");
} else if (entityType == "dataprovider") {
return ((full ? "content provider" : "dataprovider") + (plural ? "s" : ""));
}
}
}