import {Component, ElementRef, EventEmitter, Input, Output, ViewChild} from '@angular/core'; import {HostedByCollectedFrom} from "../../utils/result-preview/result-preview"; import {properties} from "../../../../environments/environment"; import {StringUtils} from '../../utils/string-utils.class'; declare var UIkit; @Component({ selector: 'availableOn', template: `
Source: {{sliceString(availableOn[0].downloadNames.join("; "), 20)}}
{{instance.downloadNames.join("; ")}}
{{instance.types.join(" . ")}} . {{instance.years.join(" . ")}}
License: {{instance.license}} {{instance.license}}
` }) export class AvailableOnComponent { @Input() availableOn: HostedByCollectedFrom[]; @Input() viewAll: boolean = false; @Output() viewAllClicked = new EventEmitter(); @ViewChild("dropElement") dropElement: ElementRef; public lessBtn: boolean = false; public threshold: number = 1; public dataProviderUrl = properties.searchLinkToDataProvider.split('?')[0]; public title: string = "Download from"; constructor() { } ngOnInit() { } public removeUnknown(value: string): string { if (value.toLowerCase() === 'unknown') { return null; } return value; } public getKeys( map) { return Array.from(map.keys()); } public viewAllClick() { if(this.availableOn.length <= this.threshold*2) { this.viewAll = true; this.lessBtn = true; } else { this.viewAll = true; this.viewAllClicked.emit('availableOn'); } } public viewLessClick() { this.viewAll = false; this.viewAllClicked.emit(""); } public isUrl(str: string): boolean { return str.startsWith('http://') || str.startsWith('https://') || str.startsWith('//') || str.startsWith('www.'); } get isOpen() { return (typeof document !== 'undefined') && this.dropElement && UIkit.drop(this.dropElement.nativeElement).isActive(); } public sliceString(str: string, size: number) { return StringUtils.sliceString(str, size) } }