[develop-filters | DONE | ADDED]: Added structures for grouping and ordering search filters.

1. searchFields.base.ts: Added RESULT_FIELDS_ORDERED and PROJECT_FIELDS_ORDERED.
2. searchResearchResults.component.ts: Set and initialize orderedFields and orderedFilters and pass them to <new-search-page>.
3. newSearchPage.component.html: If there are orderedFilters, show filters from this structure.
This commit is contained in:
Konstantina Galouni 2023-12-14 18:23:28 +02:00
parent d9c7d35e57
commit afcbb07a24
3 changed files with 130 additions and 89 deletions

View File

@ -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;
}
}
}

View File

@ -123,43 +123,64 @@
<span *ngIf="searchUtils.refineStatus != errorCodes.NONE" class="uk-text-warning">Filters temporarily unavailable. Please try again later.</span>
</div>
<ul *ngIf="!showUnknownFilters" class="uk-list uk-list-xlarge">
<li *ngIf="filters.length > 0 && getFilterById('resultbestaccessright') && getFilterById('resultbestaccessright').values.length >0">
<ng-container *ngTemplateOutlet="search_filter; context: {filter: getFilterById('resultbestaccessright')}"></ng-container>
</li>
<li *ngIf="resultTypes && (filters.length > 0)">
<quick-selections [resultTypes]="resultTypes" (typeChange)="queryChanged($event)"
[isDisabled]="disabled" [vertical]="true"
[actionRoute]="true">
</quick-selections>
</li>
<li *ngIf="filters.length > 0 && getFilterById('instancetypename') && getFilterById('instancetypename').values.length >0">
<ng-container *ngTemplateOutlet="search_filter; context: {filter: getFilterById('instancetypename')}"></ng-container>
</li>
<ng-container *ngIf="entityType == 'result'">
<li *ngFor="let filter of rangeFilters">
<range-filter [isDisabled]="disabled" [filter]="filter"
(onFilterChange)="filterChanged($event)" [actionRoute]="true"></range-filter>
<ng-container *ngIf="orderedFilters && orderedFilters.length > 0">
<ng-container *ngFor="let group of orderedFilters">
<h5 *ngIf="group.title" class="uk-h5">{{group.title}}</h5>
<ng-container *ngFor="let filter of group.values">
<li *ngIf="filter.originalFilterIdFrom && filter.originalFilterIdTo; else refineBlock">
<range-filter [isDisabled]="disabled" [filter]="filter"
(onFilterChange)="filterChanged($event)" [actionRoute]="true"></range-filter>
</li>
<ng-template #refineBlock>
<li *ngIf="filter.values && filter.values.length > 0">
<ng-container *ngTemplateOutlet="search_filter; context: {filter: filter, showResultCount: filter.type!='static'}"></ng-container>
</li>
</ng-template>
</ng-container>
</ng-container>
</ng-container>
<ng-container *ngIf="!orderedFilters || orderedFilters.length == 0">
<ng-container *ngFor="let filter of staticFilters ">
<li *ngIf="filter.values && filter.values.length > 0">
<ng-container *ngTemplateOutlet="search_filter; context: {filter: filter, showResultCount: false}"></ng-container>
</li>
</ng-container>
<li *ngIf="resultTypes && (filters.length > 0)">
<quick-selections [resultTypes]="resultTypes" (typeChange)="queryChanged($event)"
[isDisabled]="disabled" [vertical]="true"
[actionRoute]="true">
</quick-selections>
</li>
<li *ngIf="filters.length > 0 && getFilterById('instancetypename') && getFilterById('instancetypename').values.length >0">
<ng-container *ngTemplateOutlet="search_filter; context: {filter: getFilterById('instancetypename'), showResultCount: showResultCount}"></ng-container>
</li>
<ng-container *ngIf="entityType == 'result'">
<li *ngFor="let filter of rangeFilters">
<range-filter [isDisabled]="disabled" [filter]="filter"
(onFilterChange)="filterChanged($event)" [actionRoute]="true"></range-filter>
</li>
</ng-container>
<ng-container *ngFor="let filter of filters ">
<li *ngIf="filter.values && filter.values.length > 0
&& filter.filterId != 'resultbestaccessright' && filter.filterId != 'instancetypename' && filter.filterId != 'projectoamandatepublications'">
<!-- <search-filter [filterValuesNum]="filterValuesNum" [showMoreInline]="showMoreFilterValuesInline"-->
<!-- [isDisabled]="disabled"-->
<!-- [filter]="filter" [showResultCount]=showResultCount-->
<!-- (onFilterChange)="filterChanged($event)" [actionRoute]="true"></search-filter>-->
<ng-container *ngTemplateOutlet="search_filter; context: {filter: filter, showResultCount: showResultCount}"></ng-container>
</li>
</ng-container>
<ng-container *ngIf="entityType == 'project'">
<li *ngFor="let filter of rangeFilters">
<range-filter [isDisabled]="disabled" [filter]="filter"
(onFilterChange)="filterChanged($event)" [actionRoute]="true"></range-filter>
</li>
</ng-container>
<li *ngIf="filters.length > 0 && getFilterById('projectoamandatepublications') && getFilterById('projectoamandatepublications').values.length >0">
<ng-container *ngTemplateOutlet="search_filter; context: {filter: getFilterById('projectoamandatepublications'), showResultCount: showResultCount}"></ng-container>
</li>
</ng-container>
<ng-container *ngFor="let filter of filters ">
<li *ngIf="filter.values && filter.values.length > 0
&& filter.filterId != 'resultbestaccessright' && filter.filterId != 'instancetypename' && filter.filterId != 'projectoamandatepublications'">
<!-- <search-filter [filterValuesNum]="filterValuesNum" [showMoreInline]="showMoreFilterValuesInline"-->
<!-- [isDisabled]="disabled"-->
<!-- [filter]="filter" [showResultCount]=showResultCount-->
<!-- (onFilterChange)="filterChanged($event)" [actionRoute]="true"></search-filter>-->
<ng-container *ngTemplateOutlet="search_filter; context: {filter: filter}"></ng-container>
</li>
</ng-container>
<ng-container *ngIf="entityType == 'project'">
<li *ngFor="let filter of rangeFilters">
<range-filter [isDisabled]="disabled" [filter]="filter"
(onFilterChange)="filterChanged($event)" [actionRoute]="true"></range-filter>
</li>
</ng-container>
<li *ngIf="filters.length > 0 && getFilterById('projectoamandatepublications') && getFilterById('projectoamandatepublications').values.length >0">
<ng-container *ngTemplateOutlet="search_filter; context: {filter: getFilterById('projectoamandatepublications')}"></ng-container>
</li>
</ul>
</div>
</ng-template>

View File

@ -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",