import {Component, Input} from '@angular/core'; import {ActivatedRoute} from '@angular/router'; import {FetchProjects} from '../../utils/fetchEntitiesClasses/fetchProjects.class'; import {SearchProjectsService} from '../../services/searchProjects.service'; import {ErrorCodes} from '../../utils/properties/errorCodes'; import {StringUtils} from '../../utils/string-utils.class'; import {RouterHelper} from '../../utils/routerHelper.class'; import {EnvProperties} from '../../utils/properties/env-properties'; import {AlertModal} from "../../utils/modal/alert"; import {OpenaireEntities} from '../../utils/properties/searchFields'; @Component({ selector: 'projectsInModal', template: `
` }) export class ProjectsInModalComponent { @Input() fetchProjects: FetchProjects; @Input() organizationId: string = ""; @Input() properties: EnvProperties; @Input() modal: AlertModal; public page: number = 1; public size: number = 5; public routerHelper: RouterHelper = new RouterHelper(); public errorCodes: ErrorCodes = new ErrorCodes(); private filterQuery: string = ""; public openaireEntities = OpenaireEntities; constructor(private route: ActivatedRoute, private _searchProjectsService: SearchProjectsService) { } ngOnInit() { if (this.organizationId) { if (this.fetchProjects.searchUtils.totalResults > 0) { this.search(false, ""); } } } private search(refine: boolean, filterQuery: string) { var refineFields: string [] = ["funder"]; this.fetchProjects.getResultsForOrganizations(this.organizationId, filterQuery, this.page, this.size, (refine) ? refineFields : [], this.properties); this.scrollToTabTop("projects"); } public pageChange($event) { this.page = $event.value; this.search(false, this.filterQuery); } scrollToTabTop(tabId:string){ setTimeout(() => { window.scrollTo({ top: document.getElementById(tabId) ? document.getElementById(tabId).offsetTop - 250 : 250, behavior: 'smooth' }); }, 200); } public filterChange($event) { this.page = 1; this.updateFilters(); //this.search(true, this.filterQuery); this.search(false, this.filterQuery); } private updateFilters() { this.filterQuery = ""; for (let filter of this.fetchProjects.filters) { filter.countSelectedValues = 0; var filterLimits = ""; for (let value of filter.values) { if (value.selected == true) { //filterLimits+=((filterLimits.length == 0)?'':',') +'"'+ StringUtils.URIEncode(value.id)+'"'; filterLimits += ((filterLimits.length == 0) ? '' : ' or ') + filter.filterId + ' exact '; filterLimits += '"' + StringUtils.URIEncode(value.id) + '"'; filter.countSelectedValues++; } } if (filterLimits.length > 0) { //this.filterQuery+=' and '+filter.filterId + ' exact '+ filterLimits + ' '; this.filterQuery += ' and ( ' + filterLimits + ' ) '; } } //console.log("Filter Changed"+this.filterQuery); } }