import { AfterViewInit, ChangeDetectorRef, Component, ElementRef, HostListener, Input, QueryList, ViewChildren } from '@angular/core'; import {EnvProperties} from "../../utils/properties/env-properties"; import {properties} from "../../../../environments/environment"; @Component({ selector: 'showIdentifiers', template: `
View {{showAll?'less':'all'}}
` }) export class ShowIdentifiersComponent implements AfterViewInit { @Input() identifiers: Map; @Input() showViewAll: boolean = false; large: Map = new Map(); showAll: boolean = false; properties: EnvProperties = properties; @ViewChildren("content", { read: ElementRef }) types: QueryList; constructor(private cdr: ChangeDetectorRef) { } @HostListener('window:resize', ['$event']) onResize(event) { this.checkLarge(); } ngAfterViewInit() { this.checkLarge(); } checkLarge() { let overflow = (this.keys.length === 1?42:21); if(typeof document !== "undefined") { this.keys.forEach(key => { let type = this.types.find(type => type.nativeElement.id === key); this.large.set(key, type && type.nativeElement.offsetHeight > overflow); }); this.cdr.detectChanges(); } } get isLarge() { for(let key of this.keys) { if (this.large.get(key)) { return true; } } return false; } public get keys(): string[] { return Array.from(this.identifiers.keys()).sort((a: string, b: string) => { if (a === 'doi') { return -1; } else if (b === 'doi') { return 1; } else { return 0; } }); } }