From 5679464561dca508d908f489123e0555fa1b7c2e Mon Sep 17 00:00:00 2001 From: argirok Date: Wed, 16 Feb 2022 16:03:14 +0200 Subject: [PATCH] fix issue with filters not applied in search projects --- .../simple/searchProjects.component.ts | 51 +++++++++---------- 1 file changed, 23 insertions(+), 28 deletions(-) diff --git a/src/app/searchPages/simple/searchProjects.component.ts b/src/app/searchPages/simple/searchProjects.component.ts index e1626e3..7bba317 100644 --- a/src/app/searchPages/simple/searchProjects.component.ts +++ b/src/app/searchPages/simple/searchProjects.component.ts @@ -97,13 +97,11 @@ export class OpenaireSearchProjectsComponent { this.keyword = decodeURIComponent(params['fv0']?params['fv0']:(params['keyword']?params['keyword']:'')); this.selectedFields = []; this.searchPage.prepareSearchPage(this.fieldIds, this.selectedFields, this.refineFields, [], this.fieldIdsMap, this.customFilter, params, "project"); - this.filters = []; - this.searchPage.prepareFiltersToShow(this.filters, 0); if(this.initialLoad) { this.initialLoad = false; this._getResults(); }else{ - this.filterResults(); + this._getResults(); } })); } @@ -118,25 +116,31 @@ export class OpenaireSearchProjectsComponent { }); } private _getResults(){ - this.searchUtils.status = this.errorCodes.LOADING; - this.disableForms = true; - this.enableSearchView = false; this.results = []; this.searchUtils.totalResults = 0; - this.subscriptions.push(this._searchProjectsService.searchProjects(this.properties, this.communityId).subscribe( + this.searchUtils.refineStatus = this.errorCodes.LOADING; + this.searchUtils.status = this.errorCodes.LOADING; + this.disableForms = true; + this.disableRefineForms = true; + this.enableSearchView = false; + if(this.allResults) { + this.subscriptions.push(this._searchProjectsService.searchProjects(this.properties, this.communityId).subscribe( data => { - this.originalFilters = this.createFilters(data); + this.originalFilters = this.createFilters(data).slice(); //copy array this.allResults = this.parseResults(data); + this.filters = this.searchPage.prepareFiltersToShow(this.originalFilters, this.allResults.length); this.filterResults(); }, err => { - - this.handleError("Error getting projects for community with id: "+this.communityId, err); + this.handleError("Error getting projects for community with id: " + this.communityId, err); this.searchUtils.status = this.errorMessages.getErrorCode(err.status); - this.enableSearchView = true; } - )); + )); + }else{ + this.filters = this.searchPage.prepareFiltersToShow(this.originalFilters, this.allResults.length); + this.filterResults(); + } } @@ -204,11 +208,6 @@ export class OpenaireSearchProjectsComponent { return results; } filterResults(){ - this.searchUtils.refineStatus = this.errorCodes.LOADING; - this.searchUtils.status = this.errorCodes.LOADING; - this.disableForms = true; - this.disableRefineForms = true; - this.enableSearchView = false; let results = this.allResults.filter(value => { return value.title.name && value.title.name.toLowerCase().indexOf(this.keyword.toLowerCase()) !=-1 || value.acronym && value.acronym.toLowerCase().indexOf(this.keyword.toLowerCase()) !=-1}); let funderFilterValues = []; for(let filter of this.filters){ @@ -226,17 +225,13 @@ export class OpenaireSearchProjectsComponent { }); } this.oldTotalResults = results.length; - this.searchUtils.totalResults = results.length; - this.subscriptions.push(setTimeout(() => { - this.filters = this.searchPage.prepareFiltersToShow(this.originalFilters, this.allResults.length); - this.results = results.slice((this.searchUtils.page - 1) * this.searchUtils.size, this.searchUtils.page *this.searchUtils.size ); - this.searchUtils.status = this.results.length == 0 ? this.errorCodes.NONE: this.errorCodes.DONE; - this.disableForms = false; - this.disableRefineForms = false; - this.enableSearchView = true; - this.searchUtils.refineStatus = this.errorCodes.DONE; - }, 300)); - + this.searchUtils.totalResults = results.length; + this.results = results.slice((this.searchUtils.page - 1) * this.searchUtils.size, this.searchUtils.page *this.searchUtils.size ); + this.searchUtils.status = this.results.length == 0 ? this.errorCodes.NONE: this.errorCodes.DONE; + this.disableForms = false; + this.disableRefineForms = false; + this.enableSearchView = true; + this.searchUtils.refineStatus = this.errorCodes.DONE; } private handleError(message: string, error) { console.error("Projects simple Search Page: "+message, error);