mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
Fix defaults in Pagination Service
This commit is contained in:
@@ -12,7 +12,7 @@ describe('PaginationService', () => {
|
|||||||
let routeService;
|
let routeService;
|
||||||
|
|
||||||
const defaultPagination = new PaginationComponentOptions();
|
const defaultPagination = new PaginationComponentOptions();
|
||||||
const defaultSort = new SortOptions('id', SortDirection.DESC);
|
const defaultSort = new SortOptions('dc.title', SortDirection.ASC);
|
||||||
const defaultFindListOptions = new FindListOptions();
|
const defaultFindListOptions = new FindListOptions();
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
@@ -39,7 +39,6 @@ describe('PaginationService', () => {
|
|||||||
service = new PaginationService(routeService, router);
|
service = new PaginationService(routeService, router);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
describe('getCurrentPagination', () => {
|
describe('getCurrentPagination', () => {
|
||||||
it('should retrieve the current pagination info from the routerService', () => {
|
it('should retrieve the current pagination info from the routerService', () => {
|
||||||
service.getCurrentPagination('test-id', defaultPagination).subscribe((currentPagination) => {
|
service.getCurrentPagination('test-id', defaultPagination).subscribe((currentPagination) => {
|
||||||
@@ -56,6 +55,26 @@ describe('PaginationService', () => {
|
|||||||
expect(currentSort).toEqual(Object.assign(new SortOptions('score', SortDirection.ASC )));
|
expect(currentSort).toEqual(Object.assign(new SortOptions('score', SortDirection.ASC )));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
it('should return default sort when no sort specified', () => {
|
||||||
|
// This is same as routeService (defined above), but returns no sort field or direction
|
||||||
|
routeService = {
|
||||||
|
getQueryParameterValue: (param) => {
|
||||||
|
let value;
|
||||||
|
if (param.endsWith('.page')) {
|
||||||
|
value = 5;
|
||||||
|
}
|
||||||
|
if (param.endsWith('.rpp')) {
|
||||||
|
value = 10;
|
||||||
|
}
|
||||||
|
return observableOf(value);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
service = new PaginationService(routeService, router);
|
||||||
|
|
||||||
|
service.getCurrentSort('test-id', defaultSort).subscribe((currentSort) => {
|
||||||
|
expect(currentSort).toEqual(defaultSort);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
describe('getFindListOptions', () => {
|
describe('getFindListOptions', () => {
|
||||||
it('should retrieve the current findListOptions info from the routerService', () => {
|
it('should retrieve the current findListOptions info from the routerService', () => {
|
||||||
|
@@ -24,7 +24,11 @@ import { isNumeric } from '../../shared/numeric.util';
|
|||||||
*/
|
*/
|
||||||
export class PaginationService {
|
export class PaginationService {
|
||||||
|
|
||||||
private defaultSortOptions = new SortOptions('id', SortDirection.ASC);
|
/**
|
||||||
|
* Sort on title ASC by default
|
||||||
|
* @type {SortOptions}
|
||||||
|
*/
|
||||||
|
private defaultSortOptions = new SortOptions('dc.title', SortDirection.ASC);
|
||||||
|
|
||||||
private clearParams = {};
|
private clearParams = {};
|
||||||
|
|
||||||
|
@@ -28,7 +28,6 @@ import { SearchConfigurationService } from '../../../core/shared/search/search-c
|
|||||||
import { SearchService } from '../../../core/shared/search/search.service';
|
import { SearchService } from '../../../core/shared/search/search.service';
|
||||||
import { NoContent } from '../../../core/shared/NoContent.model';
|
import { NoContent } from '../../../core/shared/NoContent.model';
|
||||||
import { getItemPageRoute } from '../../item-page-routing-paths';
|
import { getItemPageRoute } from '../../item-page-routing-paths';
|
||||||
import { SortDirection, SortOptions } from '../../../core/cache/models/sort-options.model';
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'ds-item-collection-mapper',
|
selector: 'ds-item-collection-mapper',
|
||||||
@@ -74,12 +73,6 @@ export class ItemCollectionMapperComponent implements OnInit {
|
|||||||
*/
|
*/
|
||||||
mappedCollectionsRD$: Observable<RemoteData<PaginatedList<Collection>>>;
|
mappedCollectionsRD$: Observable<RemoteData<PaginatedList<Collection>>>;
|
||||||
|
|
||||||
/**
|
|
||||||
* Sort on title ASC by default
|
|
||||||
* @type {SortOptions}
|
|
||||||
*/
|
|
||||||
defaultSortOptions: SortOptions = new SortOptions('dc.title', SortDirection.ASC);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Firing this observable (shouldUpdate$.next(true)) forces the two lists to reload themselves
|
* Firing this observable (shouldUpdate$.next(true)) forces the two lists to reload themselves
|
||||||
* Usually fired after the lists their cache is cleared (to force a new request to the REST API)
|
* Usually fired after the lists their cache is cleared (to force a new request to the REST API)
|
||||||
@@ -156,8 +149,7 @@ export class ItemCollectionMapperComponent implements OnInit {
|
|||||||
switchMap(([itemCollectionsRD, owningCollectionRD, searchOptions]) => {
|
switchMap(([itemCollectionsRD, owningCollectionRD, searchOptions]) => {
|
||||||
return this.searchService.search(Object.assign(new PaginatedSearchOptions(searchOptions), {
|
return this.searchService.search(Object.assign(new PaginatedSearchOptions(searchOptions), {
|
||||||
query: this.buildQuery([...itemCollectionsRD.payload.page, owningCollectionRD.payload], searchOptions.query),
|
query: this.buildQuery([...itemCollectionsRD.payload.page, owningCollectionRD.payload], searchOptions.query),
|
||||||
dsoTypes: [DSpaceObjectType.COLLECTION],
|
dsoTypes: [DSpaceObjectType.COLLECTION]
|
||||||
sort: this.defaultSortOptions
|
|
||||||
}), 10000).pipe(
|
}), 10000).pipe(
|
||||||
toDSpaceObjectListRD(),
|
toDSpaceObjectListRD(),
|
||||||
startWith(undefined)
|
startWith(undefined)
|
||||||
|
Reference in New Issue
Block a user