import {Component, Input} from '@angular/core'; import {HelperFunctions} from "../../utils/HelperFunctions.class"; @Component({ selector: 'showIdentifiers', template: ` Identifiers: View less identifiers {{key}}: {{item}}{{key}}: {{item}}{{key}}: {{item}}{{", "}} ... view all {{countIdentifiers() | number}} identifiers View less identifiers ` }) export class ShowIdentifiersComponent { @Input() identifiers: Map; public doiURL: string; public pmcURL: string; public handleURL: string; public showAll: boolean = false; public sizeOfIdentifiers: number = -1; public sizeOfPreviousIdentifiers: number = -1; public pageSize: number = 10; constructor () { this.doiURL = "https://dx.doi.org/"; this.pmcURL = "http://europepmc.org/articles/"; this.handleURL = "http://hdl.handle.net/"; } ngOnInit() {} public countIdentifiers(): number { if(this.sizeOfIdentifiers < 0) { let num: number = 0; if(this.identifiers != undefined) { this.identifiers.forEach(function (value, key, map) { num += value.length; }); } this.sizeOfIdentifiers = num; } return this.sizeOfIdentifiers; } public countSizeOfPreviousIdentifiers(index: number): number { let num: number = 0; let i: number = 0; if(this.identifiers != undefined) { this.identifiers.forEach(function (value, key, map) { if(i < index) { num += value.length; } i++; }); } this.sizeOfPreviousIdentifiers= num; return num; } public scroll() { HelperFunctions.scroll(); } public getKeys( map) { return Array.from(map.keys()); } }