mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-16 22:43:03 +00:00
add support for paginated properties on dspace objects
This commit is contained in:

committed by
Kristof De Langhe

parent
8c124f227d
commit
9aff1b6954
@@ -1,6 +1,6 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Observable } from 'rxjs/Observable';
|
||||
import { distinctUntilChanged, flatMap, map, startWith } from 'rxjs/operators';
|
||||
import { distinctUntilChanged, filter, flatMap, map, startWith, switchMap } from 'rxjs/operators';
|
||||
import { hasValue, hasValueOperator, isEmpty, isNotEmpty } from '../../../shared/empty.util';
|
||||
import { PaginatedList } from '../../data/paginated-list';
|
||||
import { RemoteData } from '../../data/remote-data';
|
||||
@@ -190,7 +190,7 @@ export class RemoteDataBuildService {
|
||||
}
|
||||
|
||||
if (hasValue(normalized[relationship].page)) {
|
||||
links[relationship] = this.aggregatePaginatedList(result, normalized[relationship].pageInfo);
|
||||
links[relationship] = this.toPaginatedList(result, normalized[relationship].pageInfo);
|
||||
} else {
|
||||
links[relationship] = result;
|
||||
}
|
||||
@@ -254,8 +254,14 @@ export class RemoteDataBuildService {
|
||||
})
|
||||
}
|
||||
|
||||
aggregatePaginatedList<T>(input: Observable<RemoteData<T[]>>, pageInfo: PageInfo): Observable<RemoteData<PaginatedList<T>>> {
|
||||
return input.map((rd) => Object.assign(rd, {payload: new PaginatedList(pageInfo, rd.payload)}));
|
||||
private toPaginatedList<T>(input: Observable<RemoteData<T[] | PaginatedList<T>>>, pageInfo: PageInfo): Observable<RemoteData<PaginatedList<T>>> {
|
||||
return input.map((rd: RemoteData<T[] | PaginatedList<T>>) => {
|
||||
if (Array.isArray(rd.payload)) {
|
||||
return Object.assign(rd, { payload: new PaginatedList(pageInfo, rd.payload) })
|
||||
} else {
|
||||
return Object.assign(rd, { payload: new PaginatedList(pageInfo, rd.payload.page) });
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user