openaire-library/landingPages/landing-utils/availableOn.component.ts

73 lines
3.0 KiB
TypeScript

import {Component, Input, ElementRef} from '@angular/core';
@Component({
selector: 'availableOn',
template: `
<dl class="uk-description-list-line">
<dt class="title">Available On</dt>
<dd class="line" *ngFor="let available of availableOn let i=index" >
<div *ngIf="i<5 || showAll">
<div class="{{available['bestAccessMode']}}">
<span *ngIf="available.downloadUrl.length > 1"
class="custom-external custom-icon">
{{available.downloadName}}
<span *ngFor="let url of available.downloadUrl; let i=index;">
<a href="{{url}}" target="_blank"
[attr.uk-tooltip]="available.accessMode[i] ? 'pos:right; delay:10' : 'cls: uk-invisible'"
[title]="available.accessMode[i]">
[{{i+1}}]
</a>
</span>
</span>
<a class="custom-external custom-icon"
*ngIf="available['downloadUrl'].length == 1"
href="{{available['downloadUrl']}}"
target="_blank"
[attr.uk-tooltip]="available['bestAccessMode'] ? 'pos:right; delay:10' : 'cls: uk-invisible'"
[title]="available['bestAccessMode']">
{{available.downloadName}}
</a>
<span *ngIf="available.collectedName" class="uk-text-bold">via</span>
<a *ngIf="available.collectedName"
[queryParams]="{datasourceId: available.collectedId}" routerLinkActive="router-link-active" routerLink="/search/dataprovider">
{{available.collectedName}}
</a>
<span *ngIf="available.type || available.year">(<span *ngIf="available.type">{{available.type}}, </span><span *ngIf="available.year">{{available.year}}</span>)</span>
</div>
</div>
</dd>
<dd *ngIf="showAll" class="uk-text-right">
<a (click)="showAll = !showAll; scroll()">
View less
</a>
</dd>
<dd *ngIf="!showAll && availableOn.length > 5">...</dd>
<dd *ngIf="!showAll && availableOn.length > 5" class="uk-text-right">
<a (click)="showAll = !showAll;">
View more
</a>
</dd>
</dl>
`
})
export class AvailableOnComponent {
@Input() availableOn: { "downloadName": string, "downloadUrl": string[],
"collectedName": string, "collectedId": string,
"accessMode": string[], "bestAccessMode": string,
"type": string, "year":string }[];
public showAll: boolean = false;
constructor (private element: ElementRef) {}
ngOnInit() {}
public scroll() {
console.info("scroll into view");
if (typeof document !== 'undefined') {
this.element.nativeElement.scrollIntoView();
}
}
}