Project

General

Profile

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