1 |
61381
|
k.triantaf
|
import {
|
2 |
|
|
AfterViewInit, ChangeDetectorRef,
|
3 |
|
|
Component,
|
4 |
|
|
Directive,
|
5 |
|
|
ElementRef,
|
6 |
|
|
HostListener,
|
7 |
|
|
Input,
|
8 |
|
|
OnInit, QueryList,
|
9 |
|
|
ViewChild,
|
10 |
|
|
ViewChildren, ViewContainerRef
|
11 |
|
|
} from '@angular/core';
|
12 |
|
|
import {HelperFunctions} from "../../utils/HelperFunctions.class";
|
13 |
|
|
import {EnvProperties} from "../../utils/properties/env-properties";
|
14 |
|
|
import {properties} from "../../../../environments/environment";
|
15 |
|
|
|
16 |
|
|
@Component({
|
17 |
|
|
selector: 'showIdentifiers',
|
18 |
|
|
template: `
|
19 |
|
|
<div class="uk-text-muted">Persistent Identifiers</div>
|
20 |
|
|
<div class="uk-height-max-medium uk-overflow-auto uk-margin-small-top">
|
21 |
|
|
<ng-container *ngFor="let key of keys let i=index">
|
22 |
|
|
<div [class.multi-line-ellipsis]="large.get(key) && !showAll" [class.lines-2]="keys.length === 1" [class.line-1]="keys.length > 1">
|
23 |
|
|
<p class="custom-break uk-margin-remove">
|
24 |
|
|
<span #content [id]="key">
|
25 |
|
|
<span class="uk-text-bold uk-text-uppercase">{{key}}: </span>
|
26 |
|
|
<ng-container *ngFor="let item of identifiers.get(key) let j=index">
|
27 |
|
|
<a *ngIf="key=='doi'" [href]="properties.doiURL + item" target="_blank" class="uk-display-inline">
|
28 |
|
|
{{item}} <span class="custom-external custom-icon space"></span>
|
29 |
|
|
</a>
|
30 |
|
|
<a *ngIf="key=='pmc'" [href]="properties.pmcURL + item" target="_blank">
|
31 |
|
|
{{item}} <span class="custom-external custom-icon space"></span>
|
32 |
|
|
</a>
|
33 |
|
|
<a *ngIf="key=='pmid'" [href]="properties.pmidURL + item" target="_blank">
|
34 |
|
|
{{item}} <span class="custom-external custom-icon space"></span>
|
35 |
|
|
</a>
|
36 |
|
|
<a *ngIf="key=='handle'" [href]="properties.handleURL + item" target="_blank">
|
37 |
|
|
{{item}} <span class="custom-external custom-icon space"></span>
|
38 |
|
|
</a>
|
39 |
|
|
<ng-container *ngIf="(j !== (identifiers.get(key).length - 1))">, </ng-container>
|
40 |
|
|
</ng-container>
|
41 |
|
|
</span>
|
42 |
|
|
</p>
|
43 |
|
|
</div>
|
44 |
|
|
</ng-container>
|
45 |
|
|
</div>
|
46 |
|
|
<div *ngIf="isLarge && showViewAll" class="uk-text-right uk-margin-small-top">
|
47 |
|
|
<a (click)="showAll = !showAll">View {{showAll?'less':'all'}}</a>
|
48 |
|
|
</div>
|
49 |
|
|
`
|
50 |
|
|
})
|
51 |
|
|
export class ShowIdentifiersComponent implements AfterViewInit {
|
52 |
|
|
@Input() identifiers: Map<string, string[]>;
|
53 |
|
|
@Input() showViewAll: boolean = false;
|
54 |
|
|
large: Map<string, boolean> = new Map<string, boolean>();
|
55 |
|
|
showAll: boolean = false;
|
56 |
|
|
properties: EnvProperties = properties;
|
57 |
|
|
@ViewChildren("content", { read: ElementRef }) types: QueryList<ElementRef>;
|
58 |
|
|
|
59 |
|
|
constructor(private cdr: ChangeDetectorRef) {
|
60 |
|
|
}
|
61 |
|
|
|
62 |
|
|
@HostListener('window:resize', ['$event'])
|
63 |
|
|
onResize(event) {
|
64 |
|
|
this.checkLarge();
|
65 |
|
|
}
|
66 |
|
|
|
67 |
|
|
ngAfterViewInit() {
|
68 |
|
|
this.checkLarge();
|
69 |
|
|
}
|
70 |
|
|
|
71 |
|
|
checkLarge() {
|
72 |
|
|
let overflow = (this.keys.length === 1?42:21);
|
73 |
|
|
if(typeof document !== "undefined") {
|
74 |
|
|
this.keys.forEach(key => {
|
75 |
|
|
let type = this.types.find(type => type.nativeElement.id === key);
|
76 |
|
|
this.large.set(key, type && type.nativeElement.offsetHeight > overflow);
|
77 |
|
|
});
|
78 |
|
|
this.cdr.detectChanges();
|
79 |
|
|
}
|
80 |
|
|
}
|
81 |
|
|
|
82 |
|
|
get isLarge() {
|
83 |
|
|
for(let key of this.keys) {
|
84 |
|
|
if (this.large.get(key)) {
|
85 |
|
|
return true;
|
86 |
|
|
}
|
87 |
|
|
}
|
88 |
|
|
return false;
|
89 |
|
|
}
|
90 |
|
|
|
91 |
|
|
public get keys(): string[] {
|
92 |
|
|
return Array.from(this.identifiers.keys()).sort((a: string, b: string) => {
|
93 |
|
|
if (a === 'doi') {
|
94 |
|
|
return -1;
|
95 |
|
|
} else if (b === 'doi') {
|
96 |
|
|
return 1;
|
97 |
|
|
} else {
|
98 |
|
|
return 0;
|
99 |
|
|
}
|
100 |
|
|
});
|
101 |
|
|
}
|
102 |
|
|
}
|