2021-04-13 16:25:51 +02:00
|
|
|
import {
|
2021-04-16 13:45:42 +02:00
|
|
|
AfterViewInit, ChangeDetectorRef,
|
2021-04-13 16:25:51 +02:00
|
|
|
Component,
|
|
|
|
Directive,
|
|
|
|
ElementRef,
|
|
|
|
HostListener,
|
|
|
|
Input,
|
|
|
|
OnInit, QueryList,
|
|
|
|
ViewChild,
|
|
|
|
ViewChildren, ViewContainerRef
|
|
|
|
} from '@angular/core';
|
2019-04-24 14:31:01 +02:00
|
|
|
import {HelperFunctions} from "../../utils/HelperFunctions.class";
|
2020-03-17 18:48:02 +01:00
|
|
|
import {EnvProperties} from "../../utils/properties/env-properties";
|
2021-02-10 10:33:36 +01:00
|
|
|
import {properties} from "../../../../environments/environment";
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
@Component({
|
2020-03-16 14:09:46 +01:00
|
|
|
selector: 'showIdentifiers',
|
|
|
|
template: `
|
2022-03-15 12:13:28 +01:00
|
|
|
<!-- <div class="uk-text-muted">Persistent Identifiers</div> -->
|
2021-04-13 14:33:40 +02:00
|
|
|
<div class="uk-height-max-medium uk-overflow-auto uk-margin-small-top">
|
|
|
|
<ng-container *ngFor="let key of keys let i=index">
|
2022-03-15 12:13:28 +01:00
|
|
|
<!-- <div [class.multi-line-ellipsis]="large.get(key) && !showAll" [class.lines-2]="keys.length === 1" [class.line-1]="keys.length > 1"> -->
|
|
|
|
<div *ngIf="!showAll" class="uk-flex-inline uk-flex-wrap uk-margin-medium-right">
|
|
|
|
<p class="uk-margin-remove">
|
|
|
|
<span #content [id]="key">
|
|
|
|
<span class="uk-text-muted uk-text-uppercase">{{key}}: </span>
|
|
|
|
<ng-container *ngFor="let item of identifiers.get(key) let j=index">
|
|
|
|
<!-- TODO: custom external link icons -->
|
|
|
|
<a *ngIf="key=='doi'" [href]="properties.doiURL + item" target="_blank" class="uk-display-inline">
|
|
|
|
{{item}} <span class="custom-external custom-icon"></span>
|
|
|
|
</a>
|
|
|
|
<a *ngIf="key=='pmc'" [href]="properties.pmcURL + item" target="_blank">
|
|
|
|
{{item}} <span class="custom-external custom-icon"></span>
|
|
|
|
</a>
|
|
|
|
<a *ngIf="key=='pmid'" [href]="properties.pmidURL + item" target="_blank">
|
|
|
|
{{item}} <span class="custom-external custom-icon"></span>
|
|
|
|
</a>
|
|
|
|
<a *ngIf="key=='handle'" [href]="properties.handleURL + item" target="_blank">
|
|
|
|
{{item}} <span class="custom-external custom-icon"></span>
|
|
|
|
</a>
|
|
|
|
<ng-container *ngIf="(j !== (identifiers.get(key).length - 1))">, </ng-container>
|
|
|
|
</ng-container>
|
|
|
|
</span>
|
2021-04-13 14:33:40 +02:00
|
|
|
</p>
|
2020-07-13 00:06:57 +02:00
|
|
|
</div>
|
2020-03-16 14:09:46 +01:00
|
|
|
</ng-container>
|
2021-04-13 14:33:40 +02:00
|
|
|
</div>
|
|
|
|
<div *ngIf="isLarge && showViewAll" class="uk-text-right uk-margin-small-top">
|
|
|
|
<a (click)="showAll = !showAll">View {{showAll?'less':'all'}}</a>
|
|
|
|
</div>
|
2020-03-16 14:09:46 +01:00
|
|
|
`
|
|
|
|
})
|
2021-04-13 16:25:51 +02:00
|
|
|
export class ShowIdentifiersComponent implements AfterViewInit {
|
2020-03-16 14:09:46 +01:00
|
|
|
@Input() identifiers: Map<string, string[]>;
|
2021-04-13 14:33:40 +02:00
|
|
|
@Input() showViewAll: boolean = false;
|
|
|
|
large: Map<string, boolean> = new Map<string, boolean>();
|
|
|
|
showAll: boolean = false;
|
|
|
|
properties: EnvProperties = properties;
|
2021-04-13 16:25:51 +02:00
|
|
|
@ViewChildren("content", { read: ElementRef }) types: QueryList<ElementRef>;
|
2020-03-16 14:09:46 +01:00
|
|
|
|
2021-04-16 13:45:42 +02:00
|
|
|
constructor(private cdr: ChangeDetectorRef) {
|
|
|
|
}
|
|
|
|
|
2021-04-13 14:33:40 +02:00
|
|
|
@HostListener('window:resize', ['$event'])
|
|
|
|
onResize(event) {
|
|
|
|
this.checkLarge();
|
|
|
|
}
|
2020-03-16 14:09:46 +01:00
|
|
|
|
2021-04-13 14:33:40 +02:00
|
|
|
ngAfterViewInit() {
|
|
|
|
this.checkLarge();
|
2020-03-16 14:09:46 +01:00
|
|
|
}
|
|
|
|
|
2021-04-13 14:33:40 +02:00
|
|
|
checkLarge() {
|
|
|
|
let overflow = (this.keys.length === 1?42:21);
|
|
|
|
if(typeof document !== "undefined") {
|
|
|
|
this.keys.forEach(key => {
|
2021-04-13 16:25:51 +02:00
|
|
|
let type = this.types.find(type => type.nativeElement.id === key);
|
2021-04-16 13:45:42 +02:00
|
|
|
this.large.set(key, type && type.nativeElement.offsetHeight > overflow);
|
2021-04-13 14:33:40 +02:00
|
|
|
});
|
2021-04-16 13:45:42 +02:00
|
|
|
this.cdr.detectChanges();
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
2020-03-16 14:09:46 +01:00
|
|
|
}
|
|
|
|
|
2021-04-13 14:33:40 +02:00
|
|
|
get isLarge() {
|
|
|
|
for(let key of this.keys) {
|
|
|
|
if (this.large.get(key)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2020-03-16 14:09:46 +01:00
|
|
|
}
|
|
|
|
|
2021-04-13 14:33:40 +02:00
|
|
|
public get keys(): string[] {
|
|
|
|
return Array.from(this.identifiers.keys()).sort((a: string, b: string) => {
|
|
|
|
if (a === 'doi') {
|
2020-03-16 14:09:46 +01:00
|
|
|
return -1;
|
2021-04-13 14:33:40 +02:00
|
|
|
} else if (b === 'doi') {
|
2020-03-16 14:09:46 +01:00
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|