add support for paginated properties on dspace objects

This commit is contained in:
Art Lowel
2018-10-24 13:03:03 +02:00
committed by Kristof De Langhe
parent 8c124f227d
commit 9aff1b6954
7 changed files with 1591 additions and 9 deletions

View File

@@ -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) });
}
});
}
}