diff --git a/searchPages/searchResearchResults.component.ts b/searchPages/searchResearchResults.component.ts index 01433b9b..d8e78fe6 100644 --- a/searchPages/searchResearchResults.component.ts +++ b/searchPages/searchResearchResults.component.ts @@ -38,6 +38,7 @@ import {RefineFieldResultsService} from "../services/refineFieldResults.service" [searchForm]="searchForm" [filters]="filters" [quickFilter]="quickFilter" [rangeFilters]="rangeFilters" [rangeFields]="rangeFields" + [orderedFilters]="orderedFilters" [simpleView]="simpleView" formPlaceholderText="Search by title, author, abstract, DOI, orcid..." [includeOnlyResultsAndFilter]="includeOnlyResultsAndFilter" [showBreadcrumb]="showBreadcrumb" [showSwitchSearchLink]="showSwitchSearchLink" @@ -73,7 +74,7 @@ export class SearchResearchResultsComponent { public staticFields: string[] = this.searchFields.RESULT_STATIC_FIELDS; public staticFieldValues = this.searchFields.RESULT_STATIC_FIELD_VALUES; public staticFilters = RefineResultsUtils.parse(this.staticFieldValues, this.staticFields, this.resultType, "search", true); - // public orderedFilters; + public orderedFilters; public resourcesQuery = "((oaftype exact result) and (resulttypeid exact " + this.resultType + "))"; public csvParams: string; @@ -87,6 +88,7 @@ export class SearchResearchResultsComponent { properties: EnvProperties = properties; public openaireEntities = OpenaireEntities; public refineFields: string[] = this.searchFields.RESULT_REFINE_FIELDS; + public orderedFields = this.searchFields.RESULT_FIELDS_ORDERED; @ViewChild(NewSearchPageComponent, { static: true }) searchPage: NewSearchPageComponent; @Input() simpleView: boolean = true; quickFilter: { filter: Filter, selected: boolean, filterId: string, value: string } = { @@ -311,43 +313,43 @@ export class SearchResearchResultsComponent { this.rangeFilters = this.searchPage.prepareRangeFiltersToShow(); this.staticFilters = this.searchPage.prepareStaticFiltersToShow(); - // if(this.orderedFields) { - // this.orderedFilters = []; - // for(let group of this.orderedFields) { - // if (group.type == "refine") { - // let groupedFilters = {title: group.title, values: []}; - // for (let field of group.values) { - // let index = this.filters.findIndex(filter => filter.filterId == field); - // if (index > -1) { - // groupedFilters.values.push(this.filters[index]); - // } - // } - // if (groupedFilters.values.length > 0) { - // this.orderedFilters.push(groupedFilters); - // } - // } else if (group.type == "range") { - // let groupedFilters = {title: group.title, values: []}; - // let from = group.values[0]; - // let to = group.values[1]; - // let index = this.rangeFilters.findIndex(filter => filter.originalFilterIdFrom == from && filter.originalFilterIdTo == to); - // if (index > -1) { - // groupedFilters.values.push(this.rangeFilters[index]); - // this.orderedFilters.push(groupedFilters); - // } - // } else if (group.type == "static") { - // let groupedFilters = {title: group.title, values: []}; - // for (let field of group.values) { - // let index = this.staticFilters.findIndex(filter => filter.filterId == field); - // if (index > -1) { - // groupedFilters.values.push(this.staticFilters[index]); - // } - // } - // if (groupedFilters.values.length > 0) { - // this.orderedFilters.push(groupedFilters); - // } - // } - // } - // } + if(this.orderedFields) { + this.orderedFilters = []; + for(let group of this.orderedFields) { + if (group.type == "refine") { + let groupedFilters = {title: group.title, values: []}; + for (let field of group.values) { + let index = this.filters.findIndex(filter => filter.filterId == field); + if (index > -1) { + groupedFilters.values.push(this.filters[index]); + } + } + if (groupedFilters.values.length > 0) { + this.orderedFilters.push(groupedFilters); + } + } else if (group.type == "range") { + let groupedFilters = {title: group.title, values: []}; + let from = group.values[0]; + let to = group.values[1]; + let index = this.rangeFilters.findIndex(filter => filter.originalFilterIdFrom == from && filter.originalFilterIdTo == to); + if (index > -1) { + groupedFilters.values.push(this.rangeFilters[index]); + this.orderedFilters.push(groupedFilters); + } + } else if (group.type == "static") { + let groupedFilters = {title: group.title, values: []}; + for (let field of group.values) { + let index = this.staticFilters.findIndex(filter => filter.filterId == field); + if (index > -1) { + groupedFilters.values.push(this.staticFilters[index]); + } + } + if (groupedFilters.values.length > 0) { + this.orderedFilters.push(groupedFilters); + } + } + } + } } this.searchUtils.refineStatus = this.errorCodes.DONE; @@ -528,7 +530,7 @@ export class SearchResearchResultsComponent { filter.countSelectedValues = oldFilter.countSelectedValues; filter.radioValue = oldFilter.radioValue; this.filters[index] = filter; - // this.updateOrderedFilter(filter); + this.updateOrderedFilter(filter); this.cdr.detectChanges(); }, @@ -536,25 +538,25 @@ export class SearchResearchResultsComponent { let index: number = this.filters.findIndex((fltr: Filter) => fltr.filterId == oldFilter.filterId); oldFilter.countAllValues = 0; this.filters[index] = oldFilter; - // this.updateOrderedFilter(oldFilter); + this.updateOrderedFilter(oldFilter); this.cdr.detectChanges(); } ) } - // public updateOrderedFilter(filter: Filter) { - // if(this.orderedFilters) { - // let groupIndex = 0; - // let index; - // for(let group of this.orderedFilters) { - // index = group.values.findIndex((fltr: Filter) => fltr.filterId == filter.filterId); - // if(index != -1) { - // break; - // } - // groupIndex++; - // } - // this.orderedFilters[groupIndex].values[index] = filter; - // } - // } + public updateOrderedFilter(filter: Filter) { + if(this.orderedFilters) { + let groupIndex = 0; + let index; + for(let group of this.orderedFilters) { + index = group.values.findIndex((fltr: Filter) => fltr.filterId == filter.filterId); + if(index != -1) { + break; + } + groupIndex++; + } + this.orderedFilters[groupIndex].values[index] = filter; + } + } } diff --git a/searchPages/searchUtils/newSearchPage.component.html b/searchPages/searchUtils/newSearchPage.component.html index dcc2398b..ce07b7af 100644 --- a/searchPages/searchUtils/newSearchPage.component.html +++ b/searchPages/searchUtils/newSearchPage.component.html @@ -123,43 +123,64 @@ Filters temporarily unavailable. Please try again later. diff --git a/utils/properties/searchFields.base.ts b/utils/properties/searchFields.base.ts index 6c183db7..67152fe6 100644 --- a/utils/properties/searchFields.base.ts +++ b/utils/properties/searchFields.base.ts @@ -20,6 +20,17 @@ export class SearchFieldsBase { "relfundinglevel0_id", "relfundinglevel1_id", "relfundinglevel2_id", "relproject", "sdg", "country", "resultlanguagename", "resulthostingdatasource", "community"]; + RESULT_FIELDS_ORDERED = [ + {type: "static", title: "", values: ["resultbestaccessright", "type"]}, + {type: "refine", title: "", values: ["instancetypename"]}, + {type: "range", title: "", values: ["resultacceptanceyear", "resultacceptanceyear"]}, + {type: "refine", title: "", values: [ + properties.environment!='production'?"foslabel":'fos', "relfunder", + "relfundinglevel0_id", "relfundinglevel1_id", "relfundinglevel2_id", + "relproject", "sdg", "country", "resultlanguagename", "resulthostingdatasource", "community" + ]} + ]; + public RESULT_ADVANCED_FIELDS: string[] = ["q", "resulttitle", "resultauthor", "authorid", "resultdescription", "resultsubject", "eoscifguidelines", "resultpublisher", "resultbestaccessright", "community", "collectedfromdatasourceid", "resulthostingdatasourceid", "resultdateofacceptance", "relfunder", @@ -307,6 +318,13 @@ export class SearchFieldsBase { ]; public PROJECT_REFINE_FIELDS: string[] = ["funder", "fundinglevel0_id", "fundinglevel1_id", "fundinglevel2_id", "projectoamandatepublications", "projectstartyear", "projectendyear"]; + + public PROJECT_FIELDS_ORDERED = [ + {type: "refine", title: "", values: ["funder", "fundinglevel0_id", "fundinglevel1_id", "fundinglevel2_id"]}, + {type: "range", title: "", values: ["projectstartyear", "projectendyear"]}, + {type: "refine", title: "", values: ["projectoamandatepublications"]} + ]; + public PROJECT_ADVANCED_FIELDS: string[] = ["q", "projectacronym", "projecttitle", "projectkeywords", "funder", "fundinglevel0_id", "fundinglevel1_id", "fundinglevel2_id", "projectstartdate", "projectenddate",