From 725d2aa7e3ca6e396c0174985ef2e80c189dd52d Mon Sep 17 00:00:00 2001 From: argirok Date: Fri, 13 Aug 2021 12:42:50 +0300 Subject: [PATCH] Search pages: fix #6937- results per page change is not applied when the page or the keyword changes --- searchPages/searchDataProviders.component.ts | 8 ++--- searchPages/searchOrganizations.component.ts | 7 ++--- searchPages/searchProjects.component.ts | 7 ++--- .../searchResearchResults.component.ts | 31 +++++++++---------- .../searchUtils/newSearchPage.component.ts | 15 +++------ searchPages/searchUtils/searchUtils.class.ts | 8 +++++ 6 files changed, 33 insertions(+), 43 deletions(-) diff --git a/searchPages/searchDataProviders.component.ts b/searchPages/searchDataProviders.component.ts index b3c4bffd..704ba1a0 100644 --- a/searchPages/searchDataProviders.component.ts +++ b/searchPages/searchDataProviders.component.ts @@ -23,7 +23,7 @@ import {properties} from "../../../environments/environment"; type="content providers" [results]="results" [searchUtils]="searchUtils" - [sortedByChanged]="searchUtils.sortBy" [resultsPerPageChanged]="searchUtils.size" + [sortedByChanged]="searchUtils.sortBy" [fieldIds]="fieldIds" [fieldIdsMap]="fieldIdsMap" [selectedFields]="selectedFields" [csvParams]="csvParams" csvPath="datasources" [simpleSearchLink]="simpleSearchLink" [advancedSearchLink]="advancedSearchLink" @@ -133,11 +133,7 @@ export class SearchDataProvidersComponent { let page = (params['page']=== undefined)?0:+params['page']; this.searchUtils.page = ( page < 1 ) ? 1 : page; - this.searchUtils.size = (params['size']=== undefined)?10:+params['size']; - if(this.searchUtils.size != 5 && this.searchUtils.size != 10 && this.searchUtils.size != 20 && this.searchUtils.size != 50) { - this.searchUtils.size = 10; - } - + this.searchUtils.validateSize(params['size']); this.searchPage.fieldIds = this.fieldIds; this.selectedFields =[]; if(this.type == "deposit"){ diff --git a/searchPages/searchOrganizations.component.ts b/searchPages/searchOrganizations.component.ts index 68c83d9d..70d5d697 100644 --- a/searchPages/searchOrganizations.component.ts +++ b/searchPages/searchOrganizations.component.ts @@ -20,7 +20,7 @@ import {properties} from "../../../environments/environment"; type="organizations" [results]="results" [searchUtils]="searchUtils" - [sortedByChanged]="searchUtils.sortBy" [resultsPerPageChanged]="searchUtils.size" + [sortedByChanged]="searchUtils.sortBy" [fieldIds]="fieldIds" [fieldIdsMap]="fieldIdsMap" [selectedFields]="selectedFields" [csvParams]="csvParams" csvPath="organizations" [simpleSearchLink]="simpleSearchLink" [advancedSearchLink]="advancedSearchLink" @@ -124,10 +124,7 @@ export class SearchOrganizationsComponent { let page = (params['page']=== undefined)?1:+params['page']; this.searchUtils.page = ( page <= 0 ) ? 1 : page; - this.searchUtils.size = (params['size']=== undefined)?10:+params['size']; - if(this.searchUtils.size != 5 && this.searchUtils.size != 10 && this.searchUtils.size != 20 && this.searchUtils.size != 50) { - this.searchUtils.size = 10; - } + this.searchUtils.validateSize(params['size']); this.searchPage.fieldIds = this.fieldIds; this.selectedFields =[]; diff --git a/searchPages/searchProjects.component.ts b/searchPages/searchProjects.component.ts index b5d15890..d91913c2 100644 --- a/searchPages/searchProjects.component.ts +++ b/searchPages/searchProjects.component.ts @@ -20,7 +20,7 @@ import {properties} from "../../../environments/environment"; type="projects" [results]="results" [searchUtils]="searchUtils" - [sortedByChanged]="searchUtils.sortBy" [resultsPerPageChanged]="searchUtils.size" + [sortedByChanged]="searchUtils.sortBy" [fieldIds]="fieldIds" [fieldIdsMap]="fieldIdsMap" [selectedFields]="selectedFields" [csvParams]="csvParams" csvPath="projects" [simpleSearchLink]="simpleSearchLink" [advancedSearchLink]="advancedSearchLink" @@ -125,10 +125,7 @@ export class SearchProjectsComponent { let page = (params['page']=== undefined)?1:+params['page']; this.searchUtils.page = ( page <= 0 ) ? 1 : page; - this.searchUtils.size = (params['size']=== undefined)?10:+params['size']; - if(this.searchUtils.size != 5 && this.searchUtils.size != 10 && this.searchUtils.size != 20 && this.searchUtils.size != 50) { - this.searchUtils.size = 10; - } + this.searchUtils.validateSize(params['size']); this.searchPage.fieldIds = this.fieldIds; this.selectedFields = []; diff --git a/searchPages/searchResearchResults.component.ts b/searchPages/searchResearchResults.component.ts index 0b586a91..59c3bd8c 100644 --- a/searchPages/searchResearchResults.component.ts +++ b/searchPages/searchResearchResults.component.ts @@ -21,7 +21,7 @@ import {ContextsService} from "../claims/claim-utils/service/contexts.service"; [type]="getEntityName(resultType, true, true)" [results]="results" [searchUtils]="searchUtils" - [sortedByChanged]="searchUtils.sortBy" [resultsPerPageChanged]="searchUtils.size" + [sortedByChanged]="searchUtils.sortBy" [fieldIds]="fieldIds" [fieldIdsMap]="fieldIdsMap" [selectedFields]="selectedFields" [csvParams]="csvParams" [csvPath]="getEntityName(resultType, true, false)" [simpleSearchLink]="simpleSearchLink" [advancedSearchLink]="advancedSearchLink" @@ -46,10 +46,10 @@ import {ContextsService} from "../claims/claim-utils/service/contexts.service"; export class SearchResearchResultsComponent { @Input() resultType: string = "result"; - + @Input() simpleSearchLink: string = ""; advancedSearchLink: string = ""; - + private errorCodes: ErrorCodes; private errorMessages: ErrorMessagesComponent; @Input() piwikSiteId = properties.piwikSiteId; @@ -57,10 +57,10 @@ export class SearchResearchResultsComponent { public results = []; public filters = []; public rangeFilters: RangeFilter[] = []; - + public searchUtils: SearchUtilsClass = new SearchUtilsClass(); public searchFields: SearchFields = new SearchFields(); - + public fieldIds: string[] = this.searchFields.RESULT_ADVANCED_FIELDS; public fieldIdsMap = this.searchFields.RESULT_FIELDS; public rangeFields: string[][] = this.searchFields.RESULT_RANGE_FIELDS; @@ -116,18 +116,18 @@ export class SearchResearchResultsComponent { getRoute(){ return this._router.url.split("?")[0]; } - + ngOnInit() { //TODO add checks about which result types are enabled! this.pagingLimit = this.properties.pagingLimit; this.isPiwikEnabled = this.properties.enablePiwikTrack; - + if (!this.simpleSearchLink) { this.simpleSearchLink = this.properties.searchLinkToResults; } this.advancedSearchLink = this.properties.searchLinkToAdvancedResults; this.searchUtils.baseUrl = this.getRoute();//(this.simpleView) ? this.simpleSearchLink : this.advancedSearchLink; - + this.searchUtils.status = this.errorCodes.LOADING; var firstLoad = true; this.subs.push(this.route.queryParams.subscribe(params => { @@ -158,11 +158,8 @@ export class SearchResearchResultsComponent { let page = (params['page'] === undefined) ? 1 : +params['page']; this.searchUtils.page = (page <= 0) ? 1 : page; - - this.searchUtils.size = (params['size'] === undefined) ? 10 : +params['size']; - if (this.searchUtils.size != 5 && this.searchUtils.size != 10 && this.searchUtils.size != 20 && this.searchUtils.size != 50) { - this.searchUtils.size = 10; - } + + this.searchUtils.validateSize(params['size']); this.searchUtils.sortBy = (params['sortBy']) ? params['sortBy'] : ''; if (this.searchUtils.sortBy && this.searchUtils.sortBy != "resultdateofacceptance,descending" && this.searchUtils.sortBy != "resultdateofacceptance,ascending") { this.searchUtils.sortBy = ""; @@ -179,7 +176,7 @@ export class SearchResearchResultsComponent { firstLoad = false; })); } - + ngOnDestroy() { if(this.searchResultsSub) { this.searchResultsSub.unsubscribe(); @@ -337,7 +334,7 @@ export class SearchResearchResultsComponent { // } this.csvParams = (parameters ? ("&fq=(" + parameters) : "") + (parameters ? ")" : ""); this.csvParams += (refineFieldsFilterQuery ? refineFieldsFilterQuery : ""); - + this.searchUtils.status = this.errorCodes.LOADING; this.disableForms = true; this.searchPageUpdates.emit({disableForms: this.disableForms, disableRefineForms: this.disableRefineForms, searchUtils: this.searchUtils}); @@ -433,11 +430,11 @@ export class SearchResearchResultsComponent { this.disableForms = false; this.searchPageUpdates.emit({disableForms: this.disableForms, disableRefineForms: this.disableRefineForms, searchUtils: this.searchUtils}); } - + private handleError(message: string, error) { console.error(this.getEntityName(this.resultType, true, true) + " advanced Search Page: " + message, error); } - + public getEntityName(entityType: string, plural: boolean, full: boolean): string { if (entityType == "publication") { return "publication" + (plural ? "s" : ""); diff --git a/searchPages/searchUtils/newSearchPage.component.ts b/searchPages/searchUtils/newSearchPage.component.ts index c86bb164..f6d7d4e1 100644 --- a/searchPages/searchUtils/newSearchPage.component.ts +++ b/searchPages/searchUtils/newSearchPage.component.ts @@ -58,7 +58,6 @@ export class NewSearchPageComponent { @Input() customFilter: SearchCustomFilter; @Input() sort: boolean = true; @Input() sortedByChanged: string = ""; - @Input() resultsPerPageChanged: number; @Input() searchFormClass: string = "searchForm"; //From simple: @Input() rangeFilters: RangeFilter[] = []; @@ -326,9 +325,7 @@ export class NewSearchPageComponent { sizeChanged($event) { - //this.searchUtils.size = $event.value; - this.resultsPerPageChanged = $event; - + this.searchUtils.size = $event; this.goTo(1); } @@ -1294,11 +1291,9 @@ public static createRangeFilterQuery(rangeField,selectedFromValue, selectedToVal this.parameterValues.push("" + this.searchUtils.page); } - //if (this.searchUtils.size != this.resultsPerPage) { - if (this.resultsPerPageChanged && this.searchUtils.size != this.resultsPerPageChanged) { + if (this.searchUtils.size != this.searchUtils.defaultSize) { this.parameterNames.push("size"); - //this.parameterValues.push("" + this.searchUtils.size); - this.parameterValues.push("" + this.resultsPerPageChanged); + this.parameterValues.push("" + this.searchUtils.size); } //if (this.sort && this.searchUtils.sortBy) { @@ -1380,8 +1375,8 @@ public static createRangeFilterQuery(rangeField,selectedFromValue, selectedToVal // this.parameterNames.push("sortBy"); // this.parameterValues.push(this.searchUtils.sortBy); // } - // console.log(this.parameterNames) - // console.log(this.parameterValues) + console.log(this.parameterNames) + console.log(this.parameterValues) } /** diff --git a/searchPages/searchUtils/searchUtils.class.ts b/searchPages/searchUtils/searchUtils.class.ts index 7692528a..2f687806 100644 --- a/searchPages/searchUtils/searchUtils.class.ts +++ b/searchPages/searchUtils/searchUtils.class.ts @@ -1,6 +1,7 @@ export class SearchUtilsClass{ page:number = 1; size:number = 10; + defaultSize:number = 10; status:number = 1; refineStatus:number = 1; keyword:string = ""; @@ -8,6 +9,13 @@ export class SearchUtilsClass{ totalResults = null; totalResultsNoFilters:number; // for organization landing - tab with projects sortBy: string = ""; + + validateSize(sizeFromParams){ + this.size = (sizeFromParams=== undefined)?this.defaultSize:+sizeFromParams; + if(this.size != 5 && this.size != 10 && this.size != 20 && this.size != 50) { + this.size = this.defaultSize; + } + } } export class SearchCustomFilter{