Search pages: fix #6937- results per page change is not applied when the page or the keyword changes

This commit is contained in:
argirok 2021-08-13 12:42:50 +03:00
parent 01edbef93c
commit 725d2aa7e3
6 changed files with 33 additions and 43 deletions

View File

@ -23,7 +23,7 @@ import {properties} from "../../../environments/environment";
type="content providers" type="content providers"
[results]="results" [results]="results"
[searchUtils]="searchUtils" [searchUtils]="searchUtils"
[sortedByChanged]="searchUtils.sortBy" [resultsPerPageChanged]="searchUtils.size" [sortedByChanged]="searchUtils.sortBy"
[fieldIds]="fieldIds" [fieldIdsMap]="fieldIdsMap" [selectedFields]="selectedFields" [fieldIds]="fieldIds" [fieldIdsMap]="fieldIdsMap" [selectedFields]="selectedFields"
[csvParams]="csvParams" csvPath="datasources" [csvParams]="csvParams" csvPath="datasources"
[simpleSearchLink]="simpleSearchLink" [advancedSearchLink]="advancedSearchLink" [simpleSearchLink]="simpleSearchLink" [advancedSearchLink]="advancedSearchLink"
@ -133,11 +133,7 @@ export class SearchDataProvidersComponent {
let page = (params['page']=== undefined)?0:+params['page']; let page = (params['page']=== undefined)?0:+params['page'];
this.searchUtils.page = ( page < 1 ) ? 1 : page; this.searchUtils.page = ( page < 1 ) ? 1 : page;
this.searchUtils.size = (params['size']=== undefined)?10:+params['size']; this.searchUtils.validateSize(params['size']);
if(this.searchUtils.size != 5 && this.searchUtils.size != 10 && this.searchUtils.size != 20 && this.searchUtils.size != 50) {
this.searchUtils.size = 10;
}
this.searchPage.fieldIds = this.fieldIds; this.searchPage.fieldIds = this.fieldIds;
this.selectedFields =[]; this.selectedFields =[];
if(this.type == "deposit"){ if(this.type == "deposit"){

View File

@ -20,7 +20,7 @@ import {properties} from "../../../environments/environment";
type="organizations" type="organizations"
[results]="results" [results]="results"
[searchUtils]="searchUtils" [searchUtils]="searchUtils"
[sortedByChanged]="searchUtils.sortBy" [resultsPerPageChanged]="searchUtils.size" [sortedByChanged]="searchUtils.sortBy"
[fieldIds]="fieldIds" [fieldIdsMap]="fieldIdsMap" [selectedFields]="selectedFields" [fieldIds]="fieldIds" [fieldIdsMap]="fieldIdsMap" [selectedFields]="selectedFields"
[csvParams]="csvParams" csvPath="organizations" [csvParams]="csvParams" csvPath="organizations"
[simpleSearchLink]="simpleSearchLink" [advancedSearchLink]="advancedSearchLink" [simpleSearchLink]="simpleSearchLink" [advancedSearchLink]="advancedSearchLink"
@ -124,10 +124,7 @@ export class SearchOrganizationsComponent {
let page = (params['page']=== undefined)?1:+params['page']; let page = (params['page']=== undefined)?1:+params['page'];
this.searchUtils.page = ( page <= 0 ) ? 1 : page; this.searchUtils.page = ( page <= 0 ) ? 1 : page;
this.searchUtils.size = (params['size']=== undefined)?10:+params['size']; this.searchUtils.validateSize(params['size']);
if(this.searchUtils.size != 5 && this.searchUtils.size != 10 && this.searchUtils.size != 20 && this.searchUtils.size != 50) {
this.searchUtils.size = 10;
}
this.searchPage.fieldIds = this.fieldIds; this.searchPage.fieldIds = this.fieldIds;
this.selectedFields =[]; this.selectedFields =[];

View File

@ -20,7 +20,7 @@ import {properties} from "../../../environments/environment";
type="projects" type="projects"
[results]="results" [results]="results"
[searchUtils]="searchUtils" [searchUtils]="searchUtils"
[sortedByChanged]="searchUtils.sortBy" [resultsPerPageChanged]="searchUtils.size" [sortedByChanged]="searchUtils.sortBy"
[fieldIds]="fieldIds" [fieldIdsMap]="fieldIdsMap" [selectedFields]="selectedFields" [fieldIds]="fieldIds" [fieldIdsMap]="fieldIdsMap" [selectedFields]="selectedFields"
[csvParams]="csvParams" csvPath="projects" [csvParams]="csvParams" csvPath="projects"
[simpleSearchLink]="simpleSearchLink" [advancedSearchLink]="advancedSearchLink" [simpleSearchLink]="simpleSearchLink" [advancedSearchLink]="advancedSearchLink"
@ -125,10 +125,7 @@ export class SearchProjectsComponent {
let page = (params['page']=== undefined)?1:+params['page']; let page = (params['page']=== undefined)?1:+params['page'];
this.searchUtils.page = ( page <= 0 ) ? 1 : page; this.searchUtils.page = ( page <= 0 ) ? 1 : page;
this.searchUtils.size = (params['size']=== undefined)?10:+params['size']; this.searchUtils.validateSize(params['size']);
if(this.searchUtils.size != 5 && this.searchUtils.size != 10 && this.searchUtils.size != 20 && this.searchUtils.size != 50) {
this.searchUtils.size = 10;
}
this.searchPage.fieldIds = this.fieldIds; this.searchPage.fieldIds = this.fieldIds;
this.selectedFields = []; this.selectedFields = [];

View File

@ -21,7 +21,7 @@ import {ContextsService} from "../claims/claim-utils/service/contexts.service";
[type]="getEntityName(resultType, true, true)" [type]="getEntityName(resultType, true, true)"
[results]="results" [results]="results"
[searchUtils]="searchUtils" [searchUtils]="searchUtils"
[sortedByChanged]="searchUtils.sortBy" [resultsPerPageChanged]="searchUtils.size" [sortedByChanged]="searchUtils.sortBy"
[fieldIds]="fieldIds" [fieldIdsMap]="fieldIdsMap" [selectedFields]="selectedFields" [fieldIds]="fieldIds" [fieldIdsMap]="fieldIdsMap" [selectedFields]="selectedFields"
[csvParams]="csvParams" [csvPath]="getEntityName(resultType, true, false)" [csvParams]="csvParams" [csvPath]="getEntityName(resultType, true, false)"
[simpleSearchLink]="simpleSearchLink" [advancedSearchLink]="advancedSearchLink" [simpleSearchLink]="simpleSearchLink" [advancedSearchLink]="advancedSearchLink"
@ -46,10 +46,10 @@ import {ContextsService} from "../claims/claim-utils/service/contexts.service";
export class SearchResearchResultsComponent { export class SearchResearchResultsComponent {
@Input() resultType: string = "result"; @Input() resultType: string = "result";
@Input() simpleSearchLink: string = ""; @Input() simpleSearchLink: string = "";
advancedSearchLink: string = ""; advancedSearchLink: string = "";
private errorCodes: ErrorCodes; private errorCodes: ErrorCodes;
private errorMessages: ErrorMessagesComponent; private errorMessages: ErrorMessagesComponent;
@Input() piwikSiteId = properties.piwikSiteId; @Input() piwikSiteId = properties.piwikSiteId;
@ -57,10 +57,10 @@ export class SearchResearchResultsComponent {
public results = []; public results = [];
public filters = []; public filters = [];
public rangeFilters: RangeFilter[] = []; public rangeFilters: RangeFilter[] = [];
public searchUtils: SearchUtilsClass = new SearchUtilsClass(); public searchUtils: SearchUtilsClass = new SearchUtilsClass();
public searchFields: SearchFields = new SearchFields(); public searchFields: SearchFields = new SearchFields();
public fieldIds: string[] = this.searchFields.RESULT_ADVANCED_FIELDS; public fieldIds: string[] = this.searchFields.RESULT_ADVANCED_FIELDS;
public fieldIdsMap = this.searchFields.RESULT_FIELDS; public fieldIdsMap = this.searchFields.RESULT_FIELDS;
public rangeFields: string[][] = this.searchFields.RESULT_RANGE_FIELDS; public rangeFields: string[][] = this.searchFields.RESULT_RANGE_FIELDS;
@ -116,18 +116,18 @@ export class SearchResearchResultsComponent {
getRoute(){ getRoute(){
return this._router.url.split("?")[0]; return this._router.url.split("?")[0];
} }
ngOnInit() { ngOnInit() {
//TODO add checks about which result types are enabled! //TODO add checks about which result types are enabled!
this.pagingLimit = this.properties.pagingLimit; this.pagingLimit = this.properties.pagingLimit;
this.isPiwikEnabled = this.properties.enablePiwikTrack; this.isPiwikEnabled = this.properties.enablePiwikTrack;
if (!this.simpleSearchLink) { if (!this.simpleSearchLink) {
this.simpleSearchLink = this.properties.searchLinkToResults; this.simpleSearchLink = this.properties.searchLinkToResults;
} }
this.advancedSearchLink = this.properties.searchLinkToAdvancedResults; this.advancedSearchLink = this.properties.searchLinkToAdvancedResults;
this.searchUtils.baseUrl = this.getRoute();//(this.simpleView) ? this.simpleSearchLink : this.advancedSearchLink; this.searchUtils.baseUrl = this.getRoute();//(this.simpleView) ? this.simpleSearchLink : this.advancedSearchLink;
this.searchUtils.status = this.errorCodes.LOADING; this.searchUtils.status = this.errorCodes.LOADING;
var firstLoad = true; var firstLoad = true;
this.subs.push(this.route.queryParams.subscribe(params => { this.subs.push(this.route.queryParams.subscribe(params => {
@ -158,11 +158,8 @@ export class SearchResearchResultsComponent {
let page = (params['page'] === undefined) ? 1 : +params['page']; let page = (params['page'] === undefined) ? 1 : +params['page'];
this.searchUtils.page = (page <= 0) ? 1 : page; this.searchUtils.page = (page <= 0) ? 1 : page;
this.searchUtils.size = (params['size'] === undefined) ? 10 : +params['size']; this.searchUtils.validateSize(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.sortBy = (params['sortBy']) ? params['sortBy'] : ''; this.searchUtils.sortBy = (params['sortBy']) ? params['sortBy'] : '';
if (this.searchUtils.sortBy && this.searchUtils.sortBy != "resultdateofacceptance,descending" && this.searchUtils.sortBy != "resultdateofacceptance,ascending") { if (this.searchUtils.sortBy && this.searchUtils.sortBy != "resultdateofacceptance,descending" && this.searchUtils.sortBy != "resultdateofacceptance,ascending") {
this.searchUtils.sortBy = ""; this.searchUtils.sortBy = "";
@ -179,7 +176,7 @@ export class SearchResearchResultsComponent {
firstLoad = false; firstLoad = false;
})); }));
} }
ngOnDestroy() { ngOnDestroy() {
if(this.searchResultsSub) { if(this.searchResultsSub) {
this.searchResultsSub.unsubscribe(); this.searchResultsSub.unsubscribe();
@ -337,7 +334,7 @@ export class SearchResearchResultsComponent {
// } // }
this.csvParams = (parameters ? ("&fq=(" + parameters) : "") + (parameters ? ")" : ""); this.csvParams = (parameters ? ("&fq=(" + parameters) : "") + (parameters ? ")" : "");
this.csvParams += (refineFieldsFilterQuery ? refineFieldsFilterQuery : ""); this.csvParams += (refineFieldsFilterQuery ? refineFieldsFilterQuery : "");
this.searchUtils.status = this.errorCodes.LOADING; this.searchUtils.status = this.errorCodes.LOADING;
this.disableForms = true; this.disableForms = true;
this.searchPageUpdates.emit({disableForms: this.disableForms, disableRefineForms: this.disableRefineForms, searchUtils: this.searchUtils}); this.searchPageUpdates.emit({disableForms: this.disableForms, disableRefineForms: this.disableRefineForms, searchUtils: this.searchUtils});
@ -433,11 +430,11 @@ export class SearchResearchResultsComponent {
this.disableForms = false; this.disableForms = false;
this.searchPageUpdates.emit({disableForms: this.disableForms, disableRefineForms: this.disableRefineForms, searchUtils: this.searchUtils}); this.searchPageUpdates.emit({disableForms: this.disableForms, disableRefineForms: this.disableRefineForms, searchUtils: this.searchUtils});
} }
private handleError(message: string, error) { private handleError(message: string, error) {
console.error(this.getEntityName(this.resultType, true, true) + " advanced Search Page: " + message, error); console.error(this.getEntityName(this.resultType, true, true) + " advanced Search Page: " + message, error);
} }
public getEntityName(entityType: string, plural: boolean, full: boolean): string { public getEntityName(entityType: string, plural: boolean, full: boolean): string {
if (entityType == "publication") { if (entityType == "publication") {
return "publication" + (plural ? "s" : ""); return "publication" + (plural ? "s" : "");

View File

@ -58,7 +58,6 @@ export class NewSearchPageComponent {
@Input() customFilter: SearchCustomFilter; @Input() customFilter: SearchCustomFilter;
@Input() sort: boolean = true; @Input() sort: boolean = true;
@Input() sortedByChanged: string = ""; @Input() sortedByChanged: string = "";
@Input() resultsPerPageChanged: number;
@Input() searchFormClass: string = "searchForm"; @Input() searchFormClass: string = "searchForm";
//From simple: //From simple:
@Input() rangeFilters: RangeFilter[] = []; @Input() rangeFilters: RangeFilter[] = [];
@ -326,9 +325,7 @@ export class NewSearchPageComponent {
sizeChanged($event) { sizeChanged($event) {
//this.searchUtils.size = $event.value; this.searchUtils.size = $event;
this.resultsPerPageChanged = $event;
this.goTo(1); this.goTo(1);
} }
@ -1294,11 +1291,9 @@ public static createRangeFilterQuery(rangeField,selectedFromValue, selectedToVal
this.parameterValues.push("" + this.searchUtils.page); this.parameterValues.push("" + this.searchUtils.page);
} }
//if (this.searchUtils.size != this.resultsPerPage) { if (this.searchUtils.size != this.searchUtils.defaultSize) {
if (this.resultsPerPageChanged && this.searchUtils.size != this.resultsPerPageChanged) {
this.parameterNames.push("size"); this.parameterNames.push("size");
//this.parameterValues.push("" + this.searchUtils.size); this.parameterValues.push("" + this.searchUtils.size);
this.parameterValues.push("" + this.resultsPerPageChanged);
} }
//if (this.sort && this.searchUtils.sortBy) { //if (this.sort && this.searchUtils.sortBy) {
@ -1380,8 +1375,8 @@ public static createRangeFilterQuery(rangeField,selectedFromValue, selectedToVal
// this.parameterNames.push("sortBy"); // this.parameterNames.push("sortBy");
// this.parameterValues.push(this.searchUtils.sortBy); // this.parameterValues.push(this.searchUtils.sortBy);
// } // }
// console.log(this.parameterNames) console.log(this.parameterNames)
// console.log(this.parameterValues) console.log(this.parameterValues)
} }
/** /**

View File

@ -1,6 +1,7 @@
export class SearchUtilsClass{ export class SearchUtilsClass{
page:number = 1; page:number = 1;
size:number = 10; size:number = 10;
defaultSize:number = 10;
status:number = 1; status:number = 1;
refineStatus:number = 1; refineStatus:number = 1;
keyword:string = ""; keyword:string = "";
@ -8,6 +9,13 @@ export class SearchUtilsClass{
totalResults = null; totalResults = null;
totalResultsNoFilters:number; // for organization landing - tab with projects totalResultsNoFilters:number; // for organization landing - tab with projects
sortBy: string = ""; 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{ export class SearchCustomFilter{