mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ADF-2131] Search sorting (#3334)
* sorting configuration * detect primary sorting and use with document list * search results sorting * docs update * unit tests and code updates * update code * update code * generic sorting picker, test updates * ability to switch off client side sorting * update docs for document list
This commit is contained in:
committed by
Eugenio Romano
parent
73bc62ae8f
commit
07440731fa
@@ -18,12 +18,13 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Subject } from 'rxjs/Subject';
|
||||
import { AlfrescoApiService, AppConfigService } from '@alfresco/adf-core';
|
||||
import { QueryBody, RequestFacetFields, RequestFacetField } from 'alfresco-js-api';
|
||||
import { QueryBody, RequestFacetFields, RequestFacetField, RequestSortDefinitionInner } from 'alfresco-js-api';
|
||||
import { SearchCategory } from './search-category.interface';
|
||||
import { FilterQuery } from './filter-query.interface';
|
||||
import { SearchRange } from './search-range.interface';
|
||||
import { SearchConfiguration } from './search-configuration.interface';
|
||||
import { FacetQuery } from './facet-query.interface';
|
||||
import { SearchSortingDefinition } from './search-sorting-definition.interface';
|
||||
|
||||
@Injectable()
|
||||
export class SearchQueryBuilderService {
|
||||
@@ -34,17 +35,24 @@ export class SearchQueryBuilderService {
|
||||
categories: Array<SearchCategory> = [];
|
||||
queryFragments: { [id: string]: string } = {};
|
||||
filterQueries: FilterQuery[] = [];
|
||||
ranges: { [id: string]: SearchRange } = {};
|
||||
paging: { maxItems?: number; skipCount?: number } = null;
|
||||
sorting: Array<SearchSortingDefinition> = [];
|
||||
|
||||
config: SearchConfiguration;
|
||||
|
||||
// TODO: to be supported in future iterations
|
||||
ranges: { [id: string]: SearchRange } = {};
|
||||
|
||||
constructor(appConfig: AppConfigService, private alfrescoApiService: AlfrescoApiService) {
|
||||
this.config = appConfig.get<SearchConfiguration>('search');
|
||||
|
||||
if (this.config) {
|
||||
this.categories = (this.config.categories || []).filter(f => f.enabled);
|
||||
this.filterQueries = this.config.filterQueries || [];
|
||||
|
||||
if (this.config.sorting) {
|
||||
this.sorting = this.config.sorting.defaults || [];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,7 +120,8 @@ export class SearchQueryBuilderService {
|
||||
fields: this.config.fields,
|
||||
filterQueries: this.filterQueries,
|
||||
facetQueries: this.facetQueries,
|
||||
facetFields: this.facetFields
|
||||
facetFields: this.facetFields,
|
||||
sort: this.sort
|
||||
};
|
||||
|
||||
return result;
|
||||
@@ -121,6 +130,36 @@ export class SearchQueryBuilderService {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns primary sorting definition.
|
||||
*/
|
||||
getPrimarySorting(): SearchSortingDefinition {
|
||||
if (this.sorting && this.sorting.length > 0) {
|
||||
return this.sorting[0];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all pre-configured sorting options that users can choose from.
|
||||
*/
|
||||
getSortingOptions(): SearchSortingDefinition[] {
|
||||
if (this.config && this.config.sorting) {
|
||||
return this.config.sorting.options || [];
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
private get sort(): RequestSortDefinitionInner[] {
|
||||
return this.sorting.map(def => {
|
||||
return {
|
||||
type: def.type,
|
||||
field: def.field,
|
||||
ascending: def.ascending
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
private get facetQueries(): FacetQuery[] {
|
||||
const config = this.config.facetQueries;
|
||||
|
||||
|
Reference in New Issue
Block a user