import {Component, EventEmitter, Input, Output} from '@angular/core'; import {HostedByCollectedFrom} from "../../utils/result-preview/result-preview"; import {properties} from "../../../../environments/environment"; @Component({ selector: 'availableOn', template: `
{{title}} Download from View less View all {{availableOn.length}} sources
{{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(); 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.'); } }