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