fix issue with filters not applied in search projects

This commit is contained in:
argirok 2022-02-16 16:03:14 +02:00
parent 8b11478f20
commit 5679464561
1 changed files with 23 additions and 28 deletions

View File

@ -97,13 +97,11 @@ export class OpenaireSearchProjectsComponent {
this.keyword = decodeURIComponent(params['fv0']?params['fv0']:(params['keyword']?params['keyword']:'')); this.keyword = decodeURIComponent(params['fv0']?params['fv0']:(params['keyword']?params['keyword']:''));
this.selectedFields = []; this.selectedFields = [];
this.searchPage.prepareSearchPage(this.fieldIds, this.selectedFields, this.refineFields, [], this.fieldIdsMap, this.customFilter, params, "project"); 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) { if(this.initialLoad) {
this.initialLoad = false; this.initialLoad = false;
this._getResults(); this._getResults();
}else{ }else{
this.filterResults(); this._getResults();
} }
})); }));
} }
@ -118,25 +116,31 @@ export class OpenaireSearchProjectsComponent {
}); });
} }
private _getResults(){ private _getResults(){
this.searchUtils.status = this.errorCodes.LOADING;
this.disableForms = true;
this.enableSearchView = false;
this.results = []; this.results = [];
this.searchUtils.totalResults = 0; 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 => { data => {
this.originalFilters = this.createFilters(data); this.originalFilters = this.createFilters(data).slice(); //copy array
this.allResults = this.parseResults(data); this.allResults = this.parseResults(data);
this.filters = this.searchPage.prepareFiltersToShow(this.originalFilters, this.allResults.length);
this.filterResults(); this.filterResults();
}, },
err => { 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.searchUtils.status = this.errorMessages.getErrorCode(err.status);
this.enableSearchView = true; 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; return results;
} }
filterResults(){ 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 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 = []; let funderFilterValues = [];
for(let filter of this.filters){ for(let filter of this.filters){
@ -227,16 +226,12 @@ export class OpenaireSearchProjectsComponent {
} }
this.oldTotalResults = results.length; this.oldTotalResults = results.length;
this.searchUtils.totalResults = results.length; this.searchUtils.totalResults = results.length;
this.subscriptions.push(setTimeout(() => { this.results = results.slice((this.searchUtils.page - 1) * this.searchUtils.size, this.searchUtils.page *this.searchUtils.size );
this.filters = this.searchPage.prepareFiltersToShow(this.originalFilters, this.allResults.length); this.searchUtils.status = this.results.length == 0 ? this.errorCodes.NONE: this.errorCodes.DONE;
this.results = results.slice((this.searchUtils.page - 1) * this.searchUtils.size, this.searchUtils.page *this.searchUtils.size ); this.disableForms = false;
this.searchUtils.status = this.results.length == 0 ? this.errorCodes.NONE: this.errorCodes.DONE; this.disableRefineForms = false;
this.disableForms = false; this.enableSearchView = true;
this.disableRefineForms = false; this.searchUtils.refineStatus = this.errorCodes.DONE;
this.enableSearchView = true;
this.searchUtils.refineStatus = this.errorCodes.DONE;
}, 300));
} }
private handleError(message: string, error) { private handleError(message: string, error) {
console.error("Projects simple Search Page: "+message, error); console.error("Projects simple Search Page: "+message, error);