1
|
import {Component, Input} from '@angular/core';
|
2
|
import {HelperFunctions} from "../../utils/HelperFunctions.class";
|
3
|
import {EnvProperties} from "../../utils/properties/env-properties";
|
4
|
|
5
|
@Component({
|
6
|
selector: 'showIdentifiers',
|
7
|
template: `
|
8
|
<ng-container *ngFor="let key of getKeys(identifiers) let i=index">
|
9
|
<li>
|
10
|
<span *ngIf="countSizeOfPreviousIdentifiers(i) < pageSize || showAll" class="uk-margin-right">
|
11
|
<span class="uk-text-muted uk-text-uppercase">{{key}}: </span>
|
12
|
<ng-container *ngFor="let item of identifiers.get(key) let j=index">
|
13
|
<span *ngIf="(sizeOfPreviousIdentifiers + j) < pageSize || showAll">
|
14
|
<span class="uk-display-inline-block">
|
15
|
<a *ngIf="key=='doi'" [href]="properties.doiURL + item" target="_blank">
|
16
|
{{item}} <span class="custom-external custom-icon space"></span>
|
17
|
</a>
|
18
|
<a *ngIf="key=='pmc'" [href]="properties.pmcURL + item" target="_blank">
|
19
|
{{item}} <span class="custom-external custom-icon space"></span>
|
20
|
</a>
|
21
|
<a *ngIf="key=='pmid'" [href]="properties.pmidURL + item" target="_blank">
|
22
|
{{item}} <span class="custom-external custom-icon space"></span>
|
23
|
</a>
|
24
|
<a *ngIf="key=='handle'" [href]="properties.handleURL + item" target="_blank">
|
25
|
{{item}} <span class="custom-external custom-icon space"></span>
|
26
|
</a>
|
27
|
</span>
|
28
|
<span *ngIf="j !== (identifiers.get(key).length - 1)">, </span>
|
29
|
</span>
|
30
|
</ng-container>
|
31
|
</span>
|
32
|
</li>
|
33
|
</ng-container>
|
34
|
<div *ngIf="!showAll && countIdentifiers() > pageSize" class="uk-text-right">
|
35
|
<a (click)="showAll = !showAll;">
|
36
|
View all {{countIdentifiers() | number}} identifiers
|
37
|
</a>
|
38
|
</div>
|
39
|
<div *ngIf="showAll && countIdentifiers() > pageSize" class="uk-text-right">
|
40
|
<a (click)="showAll = !showAll; scroll()">View less identifiers</a>
|
41
|
</div>
|
42
|
`
|
43
|
})
|
44
|
|
45
|
export class ShowIdentifiersComponent {
|
46
|
@Input() identifiers: Map<string, string[]>;
|
47
|
@Input() properties: EnvProperties;
|
48
|
public showAll: boolean = false;
|
49
|
public sizeOfIdentifiers: number = -1;
|
50
|
public sizeOfPreviousIdentifiers: number = -1;
|
51
|
public pageSize: number = 3;
|
52
|
|
53
|
constructor() {}
|
54
|
|
55
|
ngOnInit() {}
|
56
|
|
57
|
public countIdentifiers(): number {
|
58
|
if (this.sizeOfIdentifiers < 0) {
|
59
|
let num: number = 0;
|
60
|
if (this.identifiers != undefined) {
|
61
|
this.identifiers.forEach((value, key, map) => {
|
62
|
num += value.length;
|
63
|
});
|
64
|
}
|
65
|
this.sizeOfIdentifiers = num;
|
66
|
}
|
67
|
return this.sizeOfIdentifiers;
|
68
|
}
|
69
|
|
70
|
public countSizeOfPreviousIdentifiers(index: number): number {
|
71
|
let num: number = 0;
|
72
|
let i: number = 0;
|
73
|
if (this.identifiers != undefined) {
|
74
|
this.identifiers.forEach(function (value, key, map) {
|
75
|
if (i < index) {
|
76
|
num += value.length;
|
77
|
}
|
78
|
i++;
|
79
|
});
|
80
|
}
|
81
|
this.sizeOfPreviousIdentifiers = num;
|
82
|
return num;
|
83
|
}
|
84
|
|
85
|
public scroll() {
|
86
|
HelperFunctions.scroll();
|
87
|
}
|
88
|
|
89
|
public getKeys(map) {
|
90
|
return Array.from(map.keys()).sort((a: string, b: string) => {
|
91
|
if(a === 'doi') {
|
92
|
return -1;
|
93
|
} else if(b === 'doi') {
|
94
|
return 1;
|
95
|
} else {
|
96
|
return 0;
|
97
|
}
|
98
|
});
|
99
|
}
|
100
|
}
|