import { AfterViewInit, ChangeDetectorRef, Component, ElementRef, HostListener, Input, QueryList, ViewChild, ViewChildren } from '@angular/core'; import {EnvProperties} from "../../utils/properties/env-properties"; import {properties} from "../../../../environments/environment"; import {ParsingFunctions} from "./parsingFunctions.class"; @Component({ selector: 'showIdentifiers', template: `

{{key}}: {{item}} ,

View all
` }) export class ShowIdentifiersComponent implements AfterViewInit { @Input() isMobile: boolean = false; @Input() identifiers: Map; @Input() showViewAll: boolean = false; large: Map = new Map(); properties: EnvProperties = properties; @ViewChildren("content", { read: ElementRef }) types: QueryList; @ViewChild('identifiersModal') identifiersModal; public parsingFunctions: ParsingFunctions = new ParsingFunctions(); 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; } }); } public getUrl(key: string, value: string): string { if(value.includes("http://") || value.includes("https://")) { return ""; } if(key == "doi" || key == "Digital Object Identifier") { return properties.doiURL; } else if(key == "pmc") { return properties.pmcURL; } else if(key == "pmid") { return properties.pmidURL; } else if(key == "handle") { return properties.handleURL; } else if(key == "re3data") { return properties.r3DataURL; } else if(key == "swhid") { return properties.swhURL; } else if(key == "ROR") { return properties.rorURL; } else if(key == "ISNI") { return properties.isniURL; } else if(key == "Wikidata") { return properties.wikiDataURL; } else if(key == "FundRef") { return properties.fundRefURL; } } public openIdentifiersModal() { if(this.isMobile) { this.identifiersModal.okButton = false; this.identifiersModal.title = "Persistent Identifiers"; this.identifiersModal.open(); } else { this.identifiersModal.cancelButton = false; this.identifiersModal.okButton = false; this.identifiersModal.alertTitle = "Persistent Identifiers"; this.identifiersModal.open(); } } }