1
|
import {Component, Input, ElementRef} from '@angular/core';
|
2
|
import {OpenaireProperties} from '../utils/properties/openaireProperties';
|
3
|
|
4
|
@Component({
|
5
|
selector: 'showIdentifiers',
|
6
|
template: `
|
7
|
|
8
|
<span *ngIf="showAll && countIdentifiers() > 10">
|
9
|
<a class="uk-text-muted" (click)="showAll = !showAll;">View less identifiers</a>
|
10
|
</span>
|
11
|
|
12
|
<ng-container *ngFor="let key of identifiers.keys() let i=index">
|
13
|
<ng-container *ngFor="let item of identifiers.get(key) let j=index">
|
14
|
<span *ngIf="(i+j)<10 || showAll" class="custom-external custom-icon">
|
15
|
<a *ngIf="key=='doi'" href="{{doiURL}}{{item}}" target="_blank">{{key}}: {{item}}</a><a
|
16
|
*ngIf="key=='pmc'" href="{{pmcURL}}{{item}}" target="_blank">{{key}}: {{item}}</a></span><span
|
17
|
|
18
|
*ngIf="((i+j)<10 || showAll) && ((i+j) < countIdentifiers()-1)">{{", "}}</span>
|
19
|
<span *ngIf="!showAll && (i+j)==10"> ... </span>
|
20
|
</ng-container>
|
21
|
</ng-container>
|
22
|
|
23
|
<span *ngIf="!showAll && countIdentifiers() > 10">
|
24
|
<a class="uk-text-muted" (click)="showAll = !showAll;">
|
25
|
view all {{countIdentifiers()}} identifiers
|
26
|
</a>
|
27
|
</span>
|
28
|
<span *ngIf="showAll && countIdentifiers() > 10">
|
29
|
<a class="uk-text-muted" (click)="showAll = !showAll; scroll()">View less identifiers</a>
|
30
|
</span>
|
31
|
|
32
|
|
33
|
`
|
34
|
})
|
35
|
|
36
|
export class ShowIdentifiersComponent {
|
37
|
@Input() identifiers: Map<string, string[]>;
|
38
|
doiURL: string;
|
39
|
pmcURL: string;
|
40
|
public showAll: boolean = false;
|
41
|
public num: number = -1;
|
42
|
|
43
|
constructor (private element: ElementRef) {
|
44
|
this.doiURL = OpenaireProperties.getDoiURL();
|
45
|
this.pmcURL = OpenaireProperties.getPmcURL();
|
46
|
}
|
47
|
|
48
|
ngOnInit() {}
|
49
|
|
50
|
public countIdentifiers() {
|
51
|
if(this.num < 0) {
|
52
|
let num = 0;
|
53
|
if(this.identifiers != undefined) {
|
54
|
this.identifiers.forEach(function (value, key, map) {
|
55
|
num += value.length;
|
56
|
});
|
57
|
}
|
58
|
this.num = num;
|
59
|
}
|
60
|
return this.num;
|
61
|
}
|
62
|
|
63
|
public scroll() {
|
64
|
console.info("scroll into view");
|
65
|
if (typeof document !== 'undefined') {
|
66
|
this.element.nativeElement.scrollIntoView();
|
67
|
}
|
68
|
}
|
69
|
}
|