mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-18 15:42:54 +00:00
refactor: enable full sort capabilites on search
This commit is contained in:
committed by
Jovan Krunić
parent
03084b1c96
commit
a1bf950c88
@@ -27,24 +27,28 @@ export class FoodDataListComponent extends SearchPageComponent {
|
||||
*/
|
||||
initialize() {
|
||||
if (this.positionService.position) {
|
||||
this.sortQuery = {
|
||||
type: 'distance',
|
||||
order: 'asc',
|
||||
arguments: {
|
||||
field: 'geo.point.coordinates',
|
||||
position: [
|
||||
this.positionService.position.longitude,
|
||||
this.positionService.position.latitude,
|
||||
],
|
||||
this.sortQuery = [
|
||||
{
|
||||
type: 'distance',
|
||||
order: 'asc',
|
||||
arguments: {
|
||||
field: 'geo.point.coordinates',
|
||||
position: [
|
||||
this.positionService.position.longitude,
|
||||
this.positionService.position.latitude,
|
||||
],
|
||||
},
|
||||
},
|
||||
};
|
||||
];
|
||||
}
|
||||
|
||||
this.sortQuery = {
|
||||
arguments: {field: 'name'},
|
||||
order: 'asc',
|
||||
type: 'ducet',
|
||||
};
|
||||
this.sortQuery = [
|
||||
{
|
||||
arguments: {field: 'name'},
|
||||
order: 'asc',
|
||||
type: 'ducet',
|
||||
},
|
||||
];
|
||||
|
||||
this.forcedFilter = {
|
||||
arguments: {
|
||||
|
||||
@@ -98,7 +98,7 @@ export class SearchPageComponent implements OnInit, OnDestroy {
|
||||
/**
|
||||
* Api query sorting
|
||||
*/
|
||||
sortQuery: SCSearchSort | undefined;
|
||||
sortQuery: SCSearchSort[] | undefined;
|
||||
|
||||
/**
|
||||
* Array of all subscriptions to Observables
|
||||
@@ -148,7 +148,7 @@ export class SearchPageComponent implements OnInit, OnDestroy {
|
||||
|
||||
if (this.sortQuery) {
|
||||
// add query sorting
|
||||
searchOptions.sort = [this.sortQuery];
|
||||
searchOptions.sort = this.sortQuery;
|
||||
}
|
||||
|
||||
for (const filter of [this.forcedFilter, this.filterQuery]) {
|
||||
|
||||
@@ -22,7 +22,7 @@ import {
|
||||
OnDestroy,
|
||||
OnChanges,
|
||||
} from '@angular/core';
|
||||
import {SCCatalog, SCSearchBooleanFilter} from '@openstapps/core';
|
||||
import {SCCatalog, SCSearchBooleanFilter, SCDucetSort} from '@openstapps/core';
|
||||
import {SearchPageComponent} from '../../list/search-page.component';
|
||||
|
||||
enum AccordionButtonState {
|
||||
@@ -72,12 +72,21 @@ export class CatalogDetailContentComponent
|
||||
|
||||
initialize() {
|
||||
this.pageSize = 100;
|
||||
this.sortQuery = {
|
||||
|
||||
const nameSort: SCDucetSort = {
|
||||
arguments: {field: 'name'},
|
||||
order: 'asc',
|
||||
type: 'ducet',
|
||||
};
|
||||
|
||||
const typeSort: SCDucetSort = {
|
||||
arguments: {field: 'type'},
|
||||
order: 'desc',
|
||||
type: 'ducet',
|
||||
};
|
||||
|
||||
this.sortQuery = [typeSort, nameSort];
|
||||
|
||||
const subCatalogFilter: SCSearchBooleanFilter = {
|
||||
arguments: {
|
||||
operation: 'and',
|
||||
|
||||
@@ -193,7 +193,7 @@ export class FavoritesService {
|
||||
search(
|
||||
queryText?: string,
|
||||
filterQuery?: SCSearchFilter,
|
||||
sortQuery?: SCSearchSort,
|
||||
sortQuery?: SCSearchSort[],
|
||||
): Observable<{data: SCThings[]; facets: SCFacet[]}> {
|
||||
return this.favoritesChanged$.pipe(
|
||||
map(favoritesMap => {
|
||||
@@ -229,8 +229,8 @@ export class FavoritesService {
|
||||
if (typeof sortQuery !== 'undefined') {
|
||||
items = this.sortItems(
|
||||
items,
|
||||
sortQuery.arguments.field as 'name' | 'type',
|
||||
sortQuery.order,
|
||||
sortQuery[0].arguments.field as 'name' | 'type',
|
||||
sortQuery[0].order,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -75,7 +75,7 @@ export class ContextMenuService {
|
||||
/**
|
||||
* Container for the sort query
|
||||
*/
|
||||
sortQuery = new Subject<SCSearchSort>();
|
||||
sortQuery = new Subject<SCSearchSort[]>();
|
||||
|
||||
/**
|
||||
* Observable SortContext streams
|
||||
@@ -144,20 +144,22 @@ export class ContextMenuService {
|
||||
*
|
||||
* @param sortContext SortContext to build SCSearchSort from
|
||||
*/
|
||||
buildSortQuery = (sortContext: SortContext): SCSearchSort | undefined => {
|
||||
buildSortQuery = (sortContext: SortContext): SCSearchSort[] | undefined => {
|
||||
if (
|
||||
sortContext.value &&
|
||||
sortContext.value.length > 0 &&
|
||||
(sortContext.value === 'name' || sortContext.value === 'type')
|
||||
) {
|
||||
return {
|
||||
arguments: {
|
||||
field: sortContext.value,
|
||||
position: 0,
|
||||
return [
|
||||
{
|
||||
arguments: {
|
||||
field: sortContext.value,
|
||||
position: 0,
|
||||
},
|
||||
order: sortContext.reversed ? 'desc' : 'asc',
|
||||
type: 'ducet',
|
||||
},
|
||||
order: sortContext.reversed ? 'desc' : 'asc',
|
||||
type: 'ducet',
|
||||
};
|
||||
];
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user