mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
[CST-4009] Retrieve sort options also for search page
This commit is contained in:
@@ -31,11 +31,14 @@
|
||||
<ng-template #sidebarContent>
|
||||
<ds-search-sidebar id="search-sidebar" *ngIf="!(isXsOrSm$ | async)"
|
||||
[resultCount]="(resultsRD$ | async)?.payload?.totalElements"
|
||||
[searchOptions]="(searchOptions$ | async)"
|
||||
[sortOptions]="(sortOptions$ | async)"
|
||||
[inPlaceSearch]="inPlaceSearch"></ds-search-sidebar>
|
||||
<ds-search-sidebar id="search-sidebar-sm" *ngIf="(isXsOrSm$ | async)"
|
||||
[resultCount]="(resultsRD$ | async)?.payload.totalElements"
|
||||
(toggleSidebar)="closeSidebar()"
|
||||
>
|
||||
[searchOptions]="(searchOptions$ | async)"
|
||||
[sortOptions]="(sortOptions$ | async)"
|
||||
(toggleSidebar)="closeSidebar()">
|
||||
</ds-search-sidebar>
|
||||
</ng-template>
|
||||
|
||||
|
@@ -40,12 +40,14 @@ const pagination: PaginationComponentOptions = new PaginationComponentOptions();
|
||||
pagination.id = 'search-results-pagination';
|
||||
pagination.currentPage = 1;
|
||||
pagination.pageSize = 10;
|
||||
const sortOption = { name: 'score', metadata: null };
|
||||
const sort: SortOptions = new SortOptions('score', SortDirection.DESC);
|
||||
const mockResults = createSuccessfulRemoteDataObject$(['test', 'data']);
|
||||
const searchServiceStub = jasmine.createSpyObj('SearchService', {
|
||||
search: mockResults,
|
||||
getSearchLink: '/search',
|
||||
getScopes: observableOf(['test-scope'])
|
||||
getScopes: observableOf(['test-scope']),
|
||||
getSearchConfigurationFor: createSuccessfulRemoteDataObject$({ sortOptions: [sortOption]})
|
||||
});
|
||||
const configurationParam = 'default';
|
||||
const queryParam = 'test query';
|
||||
@@ -181,4 +183,24 @@ describe('SearchComponent', () => {
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('when stable', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should have initialized the sortOptions$ observable', (done) => {
|
||||
|
||||
comp.sortOptions$.subscribe((sortOptions) => {
|
||||
|
||||
expect(sortOptions.length).toEqual(2);
|
||||
expect(sortOptions[0]).toEqual(new SortOptions('score', SortDirection.ASC));
|
||||
expect(sortOptions[1]).toEqual(new SortOptions('score', SortDirection.DESC));
|
||||
done();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
@@ -1,14 +1,14 @@
|
||||
import { ChangeDetectionStrategy, Component, Inject, Input, OnInit } from '@angular/core';
|
||||
import { BehaviorSubject, Observable, Subscription } from 'rxjs';
|
||||
import { startWith, switchMap, } from 'rxjs/operators';
|
||||
import { BehaviorSubject, combineLatest, Observable, Subscription } from 'rxjs';
|
||||
import { map, startWith, switchMap, take, } from 'rxjs/operators';
|
||||
import { PaginatedList } from '../core/data/paginated-list.model';
|
||||
import { RemoteData } from '../core/data/remote-data';
|
||||
import { DSpaceObject } from '../core/shared/dspace-object.model';
|
||||
import { pushInOut } from '../shared/animations/push';
|
||||
import { HostWindowService } from '../shared/host-window.service';
|
||||
import { SidebarService } from '../shared/sidebar/sidebar.service';
|
||||
import { hasValue, isNotEmpty } from '../shared/empty.util';
|
||||
import { getFirstSucceededRemoteData } from '../core/shared/operators';
|
||||
import { hasValue, isEmpty } from '../shared/empty.util';
|
||||
import { getFirstSucceededRemoteData, getFirstSucceededRemoteDataPayload } from '../core/shared/operators';
|
||||
import { RouteService } from '../core/services/route.service';
|
||||
import { SEARCH_CONFIG_SERVICE } from '../+my-dspace-page/my-dspace-page.component';
|
||||
import { PaginatedSearchOptions } from '../shared/search/paginated-search-options.model';
|
||||
@@ -18,6 +18,8 @@ import { SearchService } from '../core/shared/search/search.service';
|
||||
import { currentPath } from '../shared/utils/route.utils';
|
||||
import { Router } from '@angular/router';
|
||||
import { Context } from '../core/shared/context.model';
|
||||
import { SortDirection, SortOptions } from '../core/cache/models/sort-options.model';
|
||||
import { SearchConfig } from '../core/shared/search/search-filters/search-config.model';
|
||||
|
||||
@Component({
|
||||
selector: 'ds-search',
|
||||
@@ -47,6 +49,11 @@ export class SearchComponent implements OnInit {
|
||||
*/
|
||||
searchOptions$: Observable<PaginatedSearchOptions>;
|
||||
|
||||
/**
|
||||
* The current available sort options
|
||||
*/
|
||||
sortOptions$: Observable<SortOptions[]>;
|
||||
|
||||
/**
|
||||
* The current relevant scopes
|
||||
*/
|
||||
@@ -129,9 +136,32 @@ export class SearchComponent implements OnInit {
|
||||
this.scopeListRD$ = this.searchConfigService.getCurrentScope('').pipe(
|
||||
switchMap((scopeId) => this.service.getScopes(scopeId))
|
||||
);
|
||||
if (!isNotEmpty(this.configuration$)) {
|
||||
if (isEmpty(this.configuration$)) {
|
||||
this.configuration$ = this.routeService.getRouteParameterValue('configuration');
|
||||
}
|
||||
|
||||
this.sortOptions$ = this.configuration$.pipe(
|
||||
switchMap((configuration) => this.service.getSearchConfigurationFor(null, configuration)),
|
||||
getFirstSucceededRemoteDataPayload(),
|
||||
map((searchConfig: SearchConfig) => {
|
||||
const sortOptions = [];
|
||||
searchConfig.sortOptions.forEach(sortOption => {
|
||||
sortOptions.push(new SortOptions(sortOption.name, SortDirection.ASC));
|
||||
sortOptions.push(new SortOptions(sortOption.name, SortDirection.DESC));
|
||||
});
|
||||
console.log(searchConfig, sortOptions);
|
||||
return sortOptions;
|
||||
}));
|
||||
|
||||
combineLatest([
|
||||
this.sortOptions$,
|
||||
this.searchConfigService.paginatedSearchOptions
|
||||
]).pipe(take(1))
|
||||
.subscribe(([sortOptions, searchOptions]) => {
|
||||
const updateValue = Object.assign(new PaginatedSearchOptions({}), searchOptions, { sort: sortOptions[0]});
|
||||
console.log(updateValue);
|
||||
this.searchConfigService.paginatedSearchOptions.next(updateValue);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user