mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
94242: Add optional NavigationExtras to PaginationService.updateRoute
This commit is contained in:
@@ -101,6 +101,17 @@ describe('PaginationService', () => {
|
||||
|
||||
expect(router.navigate).toHaveBeenCalledWith([], {queryParams: navigateParams, queryParamsHandling: 'merge'});
|
||||
});
|
||||
it('should pass on navigationExtras to router.navigate', () => {
|
||||
service.updateRoute('test', {page: 2}, undefined, undefined, { queryParamsHandling: 'preserve', replaceUrl: true, preserveFragment: true });
|
||||
|
||||
const navigateParams = {};
|
||||
navigateParams[`test.page`] = `2`;
|
||||
navigateParams[`test.rpp`] = `10`;
|
||||
navigateParams[`test.sf`] = `score`;
|
||||
navigateParams[`test.sd`] = `ASC`;
|
||||
|
||||
expect(router.navigate).toHaveBeenCalledWith([], {queryParams: navigateParams, queryParamsHandling: 'preserve', replaceUrl: true, preserveFragment: true });
|
||||
});
|
||||
});
|
||||
describe('updateRouteWithUrl', () => {
|
||||
it('should update the route with the provided page params and url', () => {
|
||||
@@ -125,7 +136,17 @@ describe('PaginationService', () => {
|
||||
|
||||
expect(router.navigate).toHaveBeenCalledWith(['someUrl'], {queryParams: navigateParams, queryParamsHandling: 'merge'});
|
||||
});
|
||||
it('should pass on navigationExtras to router.navigate', () => {
|
||||
service.updateRouteWithUrl('test',['someUrl'], {page: 2}, undefined, undefined, { queryParamsHandling: 'preserve', replaceUrl: true, preserveFragment: true });
|
||||
|
||||
const navigateParams = {};
|
||||
navigateParams[`test.page`] = `2`;
|
||||
navigateParams[`test.rpp`] = `10`;
|
||||
navigateParams[`test.sf`] = `score`;
|
||||
navigateParams[`test.sd`] = `ASC`;
|
||||
|
||||
expect(router.navigate).toHaveBeenCalledWith(['someUrl'], {queryParams: navigateParams, queryParamsHandling: 'preserve', replaceUrl: true, preserveFragment: true });
|
||||
});
|
||||
});
|
||||
describe('clearPagination', () => {
|
||||
it('should clear the pagination next time the updateRoute/updateRouteWithUrl method is called', () => {
|
||||
|
@@ -1,5 +1,5 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Router } from '@angular/router';
|
||||
import { NavigationExtras, Router } from '@angular/router';
|
||||
import { RouteService } from '../services/route.service';
|
||||
import { PaginationComponentOptions } from '../../shared/pagination/pagination-component-options.model';
|
||||
import { combineLatest as observableCombineLatest, Observable } from 'rxjs';
|
||||
@@ -114,15 +114,22 @@ export class PaginationService {
|
||||
* @param params - The page related params to update in the route
|
||||
* @param extraParams - Addition params unrelated to the pagination that need to be added to the route
|
||||
* @param retainScrollPosition - Scroll to the pagination component after updating the route instead of the top of the page
|
||||
* @param navigationExtras - Extra parameters to pass on to `router.navigate`. Can be used to override values set by this service.
|
||||
*/
|
||||
updateRoute(paginationId: string, params: {
|
||||
updateRoute(
|
||||
paginationId: string,
|
||||
params: {
|
||||
page?: number
|
||||
pageSize?: number
|
||||
sortField?: string
|
||||
sortDirection?: SortDirection
|
||||
}, extraParams?, retainScrollPosition?: boolean) {
|
||||
},
|
||||
extraParams?,
|
||||
retainScrollPosition?: boolean,
|
||||
navigationExtras?: NavigationExtras,
|
||||
) {
|
||||
|
||||
this.updateRouteWithUrl(paginationId, [], params, extraParams, retainScrollPosition);
|
||||
this.updateRouteWithUrl(paginationId, [], params, extraParams, retainScrollPosition, navigationExtras);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -132,13 +139,21 @@ export class PaginationService {
|
||||
* @param params - The page related params to update in the route
|
||||
* @param extraParams - Addition params unrelated to the pagination that need to be added to the route
|
||||
* @param retainScrollPosition - Scroll to the pagination component after updating the route instead of the top of the page
|
||||
* @param navigationExtras - Extra parameters to pass on to `router.navigate`. Can be used to override values set by this service.
|
||||
*/
|
||||
updateRouteWithUrl(paginationId: string, url: string[], params: {
|
||||
updateRouteWithUrl(
|
||||
paginationId: string,
|
||||
url: string[],
|
||||
params: {
|
||||
page?: number
|
||||
pageSize?: number
|
||||
sortField?: string
|
||||
sortDirection?: SortDirection
|
||||
}, extraParams?, retainScrollPosition?: boolean) {
|
||||
},
|
||||
extraParams?,
|
||||
retainScrollPosition?: boolean,
|
||||
navigationExtras?: NavigationExtras,
|
||||
) {
|
||||
this.getCurrentRouting(paginationId).subscribe((currentFindListOptions) => {
|
||||
const currentParametersWithIdName = this.getParametersWithIdName(paginationId, currentFindListOptions);
|
||||
const parametersWithIdName = this.getParametersWithIdName(paginationId, params);
|
||||
@@ -149,12 +164,14 @@ export class PaginationService {
|
||||
this.router.navigate(url, {
|
||||
queryParams: queryParams,
|
||||
queryParamsHandling: 'merge',
|
||||
fragment: `p-${paginationId}`
|
||||
fragment: `p-${paginationId}`,
|
||||
...navigationExtras,
|
||||
});
|
||||
} else {
|
||||
this.router.navigate(url, {
|
||||
queryParams: queryParams,
|
||||
queryParamsHandling: 'merge'
|
||||
queryParamsHandling: 'merge',
|
||||
...navigationExtras,
|
||||
});
|
||||
}
|
||||
this.clearParams = {};
|
||||
|
Reference in New Issue
Block a user