From 428a48223aa5066fc2161aef0b7c858c0439c9fb Mon Sep 17 00:00:00 2001 From: "konstantina.galouni" Date: Thu, 23 Jun 2022 17:30:45 +0300 Subject: [PATCH] [Library | new-theme]: Sorted Advanced filters alphabetically | Added "pid" in advanced filters for Datasource | Organization lannding: projects tab: Added number of selected values in funder filter. 1. projects-in-modal.component.ts: Added the missing number of selected values next to the filter name - on updateFilters() method, update filter.countSelectedValues. 2. searchFields.ts: a. Added pid in DATASOURCE_ADVANCED_FIELDS. b. Added method "sortFieldsByName()" to sort fields by name and leave "q" filter (Any field) first. 3. searchAll.component.ts & searchDataProviders.component.ts & searchResearchResults.component.ts & searchProjects.component.ts & searchOrganizations.component.ts: Added "this.searchFields.sortFieldsByName(this.fieldIds, this.fieldIdsMap);" to sort advanced fields alphabetically. --- .../projects-in-modal.component.ts | 4 +++- searchPages/find/searchAll.component.ts | 1 + searchPages/searchDataProviders.component.ts | 2 ++ searchPages/searchOrganizations.component.ts | 3 +-- searchPages/searchProjects.component.ts | 2 ++ .../searchResearchResults.component.ts | 2 ++ utils/properties/searchFields.ts | 20 ++++++++++++++++--- 7 files changed, 28 insertions(+), 6 deletions(-) diff --git a/landingPages/landing-utils/projects-in-modal.component.ts b/landingPages/landing-utils/projects-in-modal.component.ts index a0d8a1c7..088d68c1 100644 --- a/landingPages/landing-utils/projects-in-modal.component.ts +++ b/landingPages/landing-utils/projects-in-modal.component.ts @@ -18,7 +18,7 @@ import {OpenaireEntities} from '../../utils/properties/searchFields';
@@ -111,12 +111,14 @@ export class ProjectsInModalComponent { 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) { diff --git a/searchPages/find/searchAll.component.ts b/searchPages/find/searchAll.component.ts index 1857bb44..bc8f5a0d 100644 --- a/searchPages/find/searchAll.component.ts +++ b/searchPages/find/searchAll.component.ts @@ -136,6 +136,7 @@ export class SearchAllComponent { this.fetchSoftware = new FetchResearchResults(this._searchResearchResultsService); this.fetchOrps = new FetchResearchResults(this._searchResearchResultsService); this.fetchOrganizations = new FetchOrganizations(this._searchOrganizationsService); + this.searchFields.sortFieldsByName(this.fieldIds, this.fieldIdsMap); this.selectedFields.push(new AdvancedField(this.fieldIds[0], this.fieldIdsMap[this.fieldIds[0]].param, this.fieldIdsMap[this.fieldIds[0]].name, this.fieldIdsMap[this.fieldIds[0]].type, '', "and")); } diff --git a/searchPages/searchDataProviders.component.ts b/searchPages/searchDataProviders.component.ts index 95f053dc..78e2e2fd 100644 --- a/searchPages/searchDataProviders.component.ts +++ b/searchPages/searchDataProviders.component.ts @@ -99,6 +99,8 @@ export class SearchDataProvidersComponent { this.errorCodes = new ErrorCodes(); this.errorMessages = new ErrorMessagesComponent(); this.searchUtils.status = this.errorCodes.LOADING; + + this.searchFields.sortFieldsByName(this.fieldIds, this.fieldIdsMap); } ngOnInit() { this.refineFields = DatasourcesHelperClass.getrefineFields(this.type); diff --git a/searchPages/searchOrganizations.component.ts b/searchPages/searchOrganizations.component.ts index a0b05f56..943f9ccb 100644 --- a/searchPages/searchOrganizations.component.ts +++ b/searchPages/searchOrganizations.component.ts @@ -89,8 +89,7 @@ export class SearchOrganizationsComponent { this.errorMessages = new ErrorMessagesComponent(); this.searchUtils.status = this.errorCodes.LOADING; - - + this.searchFields.sortFieldsByName(this.fieldIds, this.fieldIdsMap); } ngOnInit() { diff --git a/searchPages/searchProjects.component.ts b/searchPages/searchProjects.component.ts index efe6153b..7f8a90ac 100644 --- a/searchPages/searchProjects.component.ts +++ b/searchPages/searchProjects.component.ts @@ -92,6 +92,8 @@ export class SearchProjectsComponent { this.errorMessages = new ErrorMessagesComponent(); this.searchUtils.status = this.errorCodes.LOADING; this.searchUtils.refineStatus = this.errorCodes.LOADING; + + this.searchFields.sortFieldsByName(this.fieldIds, this.fieldIdsMap); } ngOnInit() { diff --git a/searchPages/searchResearchResults.component.ts b/searchPages/searchResearchResults.component.ts index d07c7bcb..ada82d40 100644 --- a/searchPages/searchResearchResults.component.ts +++ b/searchPages/searchResearchResults.component.ts @@ -113,6 +113,8 @@ export class SearchResearchResultsComponent { this.searchUtils.status = this.errorCodes.LOADING; this.searchUtils.refineStatus = this.errorCodes.LOADING; this.getPublicCommunities(); + + this.searchFields.sortFieldsByName(this.fieldIds, this.fieldIdsMap); } getRoute(){ diff --git a/utils/properties/searchFields.ts b/utils/properties/searchFields.ts index fcd79467..3f1e9d60 100644 --- a/utils/properties/searchFields.ts +++ b/utils/properties/searchFields.ts @@ -418,7 +418,7 @@ export class SearchFields { "datasourcejurisdiction"]; public DATASOURCE_ADVANCED_FIELDS: string[] = ["q", "datasourceofficialname", "datasourceenglishname", "datasourceodsubjects", "datasourcetypename", "datasourceodlanguages", - "datasourceodcontenttypes", "datasourcecompatibilityname", "relorganizationid", "collectedfromdatasourceid"]; + "datasourceodcontenttypes", "datasourcecompatibilityname", "relorganizationid", "collectedfromdatasourceid", "pid"]; public DATASOURCE_FIELDS: { [key: string]: FieldDetails } = { ["q"]: {name: "Any field", type: "keyword", param: "q", operator: "op", equalityOperator: "=", filterType: null}, @@ -549,7 +549,8 @@ export class SearchFields { operator: "ju", equalityOperator: " exact ", filterType: "checkbox" - } + }, + ["pid"]: {name: "PID", type: "keyword", param: "pid", operator: "pd", equalityOperator: " exact ", filterType: null} }; public DEPOSIT_DATASOURCE_KEYWORD_FIELDS: { "name": string, "equalityOperator": string } [] = [ @@ -698,7 +699,20 @@ export class SearchFields { let field = this.getField(fieldId, fieldType); return field?field.name:"UNDEFINED"; } - + + sortFieldsByName(fieldIds: string[], fieldIdsMap: { [key: string]: FieldDetails }) { + fieldIds.sort((a: string, b: string) => { + if(a == "q") { + return -1; + } else if(b == "q") { + return 1; + } + let nameA: string = fieldIdsMap[a].name; + let nameB: string = fieldIdsMap[b].name; + return nameA.localeCompare(nameB); + }) + } + getFieldFilterType(fieldId: string, fieldType: string, usedBy: string = "search"): string { let field = this.getField(fieldId, fieldType); return field?field.filterType:"checkbox";