import {Component, EventEmitter, Input, Output} from '@angular/core';
import {Project} from "../../utils/result-preview/result-preview";
import {properties} from "../../../../environments/environment";
import {HelperFunctions} from '../../utils/HelperFunctions.class';
import {RouterHelper} from "../../utils/routerHelper.class";
@Component({
selector: 'fundedBy',
template: `
`
})
export class FundedByComponent {
@Input() prevPath: string = "";
@Input() fundedByProjects: Project[];
@Input() viewAll: boolean = false;
@Output() viewAllClicked = new EventEmitter();
public lessBtn: boolean = false;
public threshold: number = 4;
public url = properties.searchLinkToProject.split('?')[0];
public title: string = "Funded by";
@Input() provenanceActionVocabulary = null;
public provenancesCalculated: boolean[] = [];
public routerHelper:RouterHelper = new RouterHelper();
public viewAllClick() {
if(this.fundedByProjects.length <= this.threshold*2) {
this.viewAll = true;
this.lessBtn = true;
} else {
this.viewAll = true;
this.viewAllClicked.emit('fundedBy');
}
}
public viewLessClick() {
this.viewAll = false;
this.viewAllClicked.emit("");
}
public getVocabularyLabel(item: any, vocabulary: any, index: number) {
if(!this.provenancesCalculated[index]) {
this.provenancesCalculated[index] = true;
item.provenanceAction = HelperFunctions.getVocabularyLabel(item.provenanceAction, vocabulary, false);
}
return item.provenanceAction;
}
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;
}
}