import {Component, Input} from '@angular/core';
import {HelperFunctions} from "../../utils/HelperFunctions.class";
import {EnvProperties} from "../../utils/properties/env-properties";
import {properties} from "../../../../environments/environment";
@Component({
selector: 'showIdentifiers',
template: `
`
})
export class ShowIdentifiersComponent {
@Input() identifiers: Map;
@Input() properties: EnvProperties = properties;
public showAll: boolean = false;
public sizeOfIdentifiers: number = -1;
public sizeOfPreviousIdentifiers: number = -1;
public pageSize: number = 3;
constructor() {}
ngOnInit() {}
public countIdentifiers(): number {
if (this.sizeOfIdentifiers < 0) {
let num: number = 0;
if (this.identifiers != undefined) {
this.identifiers.forEach((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) {
let self = this;
this.getKeys(this.identifiers).forEach(function(key: string) {
// console.debug("value:", self.identifiers.get(key));
if (i < index) {
num += self.identifiers.get(key).length;
}
i++;
})
// this.identifiers.forEach(function (value, key, map) {
// console.debug("value:", value);
// if (i < index) {
// num += value.length;
// }
// i++;
// });
}
this.sizeOfPreviousIdentifiers = num;
return num;
}
public scroll() {
HelperFunctions.scroll();
}
public getKeys(map) {
return Array.from(map.keys()).sort((a: string, b: string) => {
if(a === 'doi') {
return -1;
} else if(b === 'doi') {
return 1;
} else {
return 0;
}
});
}
}