forked from hazza/dspace-angular
add support for paginated properties on dspace objects
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { Observable } from 'rxjs/Observable';
|
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 { hasValue, hasValueOperator, isEmpty, isNotEmpty } from '../../../shared/empty.util';
|
||||||
import { PaginatedList } from '../../data/paginated-list';
|
import { PaginatedList } from '../../data/paginated-list';
|
||||||
import { RemoteData } from '../../data/remote-data';
|
import { RemoteData } from '../../data/remote-data';
|
||||||
@@ -8,6 +8,8 @@ import { RemoteDataError } from '../../data/remote-data-error';
|
|||||||
import { GetRequest } from '../../data/request.models';
|
import { GetRequest } from '../../data/request.models';
|
||||||
import { RequestEntry } from '../../data/request.reducer';
|
import { RequestEntry } from '../../data/request.reducer';
|
||||||
import { RequestService } from '../../data/request.service';
|
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 { NormalizedObject } from '../models/normalized-object.model';
|
||||||
import { ObjectCacheService } from '../object-cache.service';
|
import { ObjectCacheService } from '../object-cache.service';
|
||||||
@@ -190,7 +192,7 @@ export class RemoteDataBuildService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (hasValue(normalized[relationship].page)) {
|
if (hasValue(normalized[relationship].page)) {
|
||||||
links[relationship] = this.aggregatePaginatedList(result, normalized[relationship].pageInfo);
|
links[relationship] = this.toPaginatedList(result, normalized[relationship].pageInfo);
|
||||||
} else {
|
} else {
|
||||||
links[relationship] = result;
|
links[relationship] = result;
|
||||||
}
|
}
|
||||||
@@ -254,8 +256,14 @@ export class RemoteDataBuildService {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
aggregatePaginatedList<T>(input: Observable<RemoteData<T[]>>, pageInfo: PageInfo): Observable<RemoteData<PaginatedList<T>>> {
|
private toPaginatedList<T>(input: Observable<RemoteData<T[] | PaginatedList<T>>>, pageInfo: PageInfo): Observable<RemoteData<PaginatedList<T>>> {
|
||||||
return input.map((rd) => Object.assign(rd, {payload: new PaginatedList(pageInfo, rd.payload)}));
|
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) });
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -6,7 +6,6 @@ import { ObjectCacheService } from '../cache/object-cache.service';
|
|||||||
import { GlobalConfig } from '../../../config/global-config.interface';
|
import { GlobalConfig } from '../../../config/global-config.interface';
|
||||||
import { GenericConstructor } from '../shared/generic-constructor';
|
import { GenericConstructor } from '../shared/generic-constructor';
|
||||||
import { PaginatedList } from './paginated-list';
|
import { PaginatedList } from './paginated-list';
|
||||||
import { NormalizedObject } from '../cache/models/normalized-object.model';
|
|
||||||
import { ResourceType } from '../shared/resource-type';
|
import { ResourceType } from '../shared/resource-type';
|
||||||
import { RESTURLCombiner } from '../url-combiner/rest-url-combiner';
|
import { RESTURLCombiner } from '../url-combiner/rest-url-combiner';
|
||||||
|
|
||||||
@@ -15,7 +14,7 @@ function isObjectLevel(halObj: any) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function isPaginatedResponse(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 */
|
/* tslint:disable:max-classes-per-file */
|
||||||
@@ -130,7 +129,7 @@ export abstract class BaseResponseParsingService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
processPageInfo(payload: any): PageInfo {
|
processPageInfo(payload: any): PageInfo {
|
||||||
if (isNotEmpty(payload.page)) {
|
if (hasValue(payload.page)) {
|
||||||
const pageObj = Object.assign({}, payload.page, { _links: payload._links });
|
const pageObj = Object.assign({}, payload.page, { _links: payload._links });
|
||||||
const pageInfoObject = new DSpaceRESTv2Serializer(PageInfo).deserialize(pageObj);
|
const pageInfoObject = new DSpaceRESTv2Serializer(PageInfo).deserialize(pageObj);
|
||||||
if (pageInfoObject.currentPage >= 0) {
|
if (pageInfoObject.currentPage >= 0) {
|
||||||
|
@@ -1,4 +1,5 @@
|
|||||||
import { Observable } from 'rxjs/Observable';
|
import { Observable } from 'rxjs/Observable';
|
||||||
|
import { filter, map, startWith, tap } from 'rxjs/operators';
|
||||||
|
|
||||||
import { DSpaceObject } from './dspace-object.model';
|
import { DSpaceObject } from './dspace-object.model';
|
||||||
import { Collection } from './collection.model';
|
import { Collection } from './collection.model';
|
||||||
@@ -86,6 +87,7 @@ export class Item extends DSpaceObject {
|
|||||||
* Retrieves bitstreams by bundle name
|
* Retrieves bitstreams by bundle name
|
||||||
* @param bundleName The name of the Bundle that should be returned
|
* @param bundleName The name of the Bundle that should be returned
|
||||||
* @returns {Observable<Bitstream[]>} the bitstreams with the given bundleName
|
* @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[]> {
|
getBitstreamsByBundleName(bundleName: string): Observable<Bitstream[]> {
|
||||||
return this.bitstreams
|
return this.bitstreams
|
||||||
|
@@ -59,7 +59,7 @@ export const toDSpaceObjectListRD = () =>
|
|||||||
source.pipe(
|
source.pipe(
|
||||||
map((rd: RemoteData<PaginatedList<SearchResult<T>>>) => {
|
map((rd: RemoteData<PaginatedList<SearchResult<T>>>) => {
|
||||||
const dsoPage: T[] = rd.payload.page.map((searchResult: SearchResult<T>) => searchResult.dspaceObject);
|
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});
|
return Object.assign(rd, {payload: payload});
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
@@ -3,6 +3,7 @@ import { Component, Input, OnDestroy, OnInit } from '@angular/core';
|
|||||||
import { TranslateService } from '@ngx-translate/core';
|
import { TranslateService } from '@ngx-translate/core';
|
||||||
|
|
||||||
import { Subscription } from 'rxjs/Subscription';
|
import { Subscription } from 'rxjs/Subscription';
|
||||||
|
import { hasValue } from '../empty.util';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'ds-loading',
|
selector: 'ds-loading',
|
||||||
@@ -28,7 +29,7 @@ export class LoadingComponent implements OnDestroy, OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ngOnDestroy() {
|
ngOnDestroy() {
|
||||||
if (this.subscription !== undefined) {
|
if (hasValue(this.subscription)) {
|
||||||
this.subscription.unsubscribe();
|
this.subscription.unsubscribe();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user