add support for paginated properties on dspace objects

This commit is contained in:
Art Lowel
2018-10-24 13:03:03 +02:00
parent 8c124f227d
commit c1eab402e8
6 changed files with 1535 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';
@@ -8,6 +8,8 @@ import { RemoteDataError } from '../../data/remote-data-error';
import { GetRequest } from '../../data/request.models';
import { RequestEntry } from '../../data/request.reducer';
import { RequestService } from '../../data/request.service';
import { Bitstream } from '../../shared/bitstream.model';
import { Item } from '../../shared/item.model';
import { NormalizedObject } from '../models/normalized-object.model';
import { ObjectCacheService } from '../object-cache.service';
@@ -190,7 +192,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 +256,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) });
}
});
}
}

View File

@@ -6,7 +6,6 @@ import { ObjectCacheService } from '../cache/object-cache.service';
import { GlobalConfig } from '../../../config/global-config.interface';
import { GenericConstructor } from '../shared/generic-constructor';
import { PaginatedList } from './paginated-list';
import { NormalizedObject } from '../cache/models/normalized-object.model';
import { ResourceType } from '../shared/resource-type';
import { RESTURLCombiner } from '../url-combiner/rest-url-combiner';
@@ -15,7 +14,7 @@ function isObjectLevel(halObj: any) {
}
function isPaginatedResponse(halObj: any) {
return isNotEmpty(halObj.page) && hasValue(halObj._embedded);
return hasValue(halObj.page) && hasValue(halObj._embedded);
}
/* tslint:disable:max-classes-per-file */
@@ -130,7 +129,7 @@ export abstract class BaseResponseParsingService {
}
processPageInfo(payload: any): PageInfo {
if (isNotEmpty(payload.page)) {
if (hasValue(payload.page)) {
const pageObj = Object.assign({}, payload.page, { _links: payload._links });
const pageInfoObject = new DSpaceRESTv2Serializer(PageInfo).deserialize(pageObj);
if (pageInfoObject.currentPage >= 0) {

View File

@@ -1,4 +1,5 @@
import { Observable } from 'rxjs/Observable';
import { filter, map, startWith, tap } from 'rxjs/operators';
import { DSpaceObject } from './dspace-object.model';
import { Collection } from './collection.model';
@@ -86,6 +87,7 @@ export class Item extends DSpaceObject {
* Retrieves bitstreams by bundle name
* @param bundleName The name of the Bundle that should be returned
* @returns {Observable<Bitstream[]>} the bitstreams with the given bundleName
* TODO now that bitstreams can be paginated this should move to the server
*/
getBitstreamsByBundleName(bundleName: string): Observable<Bitstream[]> {
return this.bitstreams

View File

@@ -59,7 +59,7 @@ export const toDSpaceObjectListRD = () =>
source.pipe(
map((rd: RemoteData<PaginatedList<SearchResult<T>>>) => {
const dsoPage: T[] = rd.payload.page.map((searchResult: SearchResult<T>) => searchResult.dspaceObject);
const payload = Object.assign(rd.payload, { page: dsoPage }) as PaginatedList<T>;
const payload = Object.assign(rd.payload, { page: dsoPage }) as any;
return Object.assign(rd, {payload: payload});
})
);

View File

@@ -3,6 +3,7 @@ import { Component, Input, OnDestroy, OnInit } from '@angular/core';
import { TranslateService } from '@ngx-translate/core';
import { Subscription } from 'rxjs/Subscription';
import { hasValue } from '../empty.util';
@Component({
selector: 'ds-loading',
@@ -28,7 +29,7 @@ export class LoadingComponent implements OnDestroy, OnInit {
}
ngOnDestroy() {
if (this.subscription !== undefined) {
if (hasValue(this.subscription)) {
this.subscription.unsubscribe();
}
}

1516
yarn.lock

File diff suppressed because it is too large Load Diff