import {Component, EventEmitter, Input, Output} from '@angular/core';
import {HostedByCollectedFrom} from "../../utils/result-preview/result-preview";
import {properties} from "../../../../environments/environment";
import {RouterHelper} from "../../utils/routerHelper.class";
@Component({
selector: 'availableOn',
template: `
{{instance.downloadNames.join("; ")}}
0 || instance.years?.length > 0" class="uk-text-meta">
0" class="uk-text-capitalize">{{instance.types.join(" . ")}}
0 && instance.years?.length > 0"> .
0">{{instance.years.join(" . ")}}
`
})
export class AvailableOnComponent {
@Input() prevPath: string = "";
@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";
public routerHelper:RouterHelper = new RouterHelper();
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.');
}
public addEoscPrevInParams(obj) {
if(properties.adminToolsPortalType == "eosc" && this.prevPath) {
let splitted: string[] = this.prevPath.split("?");
obj = this.routerHelper.addQueryParam("return_path", splitted[0], obj);
if(splitted.length > 0) {
obj = this.routerHelper.addQueryParam("search_params", splitted[1], obj);
}
}
return obj;
}
}