mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-17 06:53:03 +00:00
Merge remote-tracking branch 'remotes/origin/master' into submission
# Conflicts: # src/app/+search-page/search-service/search.service.spec.ts # src/app/app.component.spec.ts # src/app/app.component.ts # src/app/core/auth/auth-response-parsing.service.ts # src/app/core/cache/models/normalized-object-factory.ts # src/app/core/cache/models/normalized-resource-policy.model.ts # src/app/core/core.module.ts # src/app/core/data/base-response-parsing.service.ts # src/app/core/data/config-response-parsing.service.spec.ts # src/app/core/data/config-response-parsing.service.ts # src/app/core/data/dso-response-parsing.service.ts # src/app/core/data/request.models.ts # src/app/core/data/search-response-parsing.service.ts # src/app/core/integration/integration-response-parsing.service.spec.ts # src/app/core/integration/integration-response-parsing.service.ts # src/app/core/shared/item.model.ts # src/app/core/shared/resource-policy.model.ts # src/app/core/shared/resource-type.ts # src/app/shared/shared.module.ts # src/app/thumbnail/thumbnail.component.html
This commit is contained in:
@@ -8,12 +8,14 @@ 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 { NormalizedObject } from '../models/normalized-object.model';
|
||||
import { ObjectCacheService } from '../object-cache.service';
|
||||
import { DSOSuccessResponse, ErrorResponse } from '../response-cache.models';
|
||||
import { ResponseCacheEntry } from '../response-cache.reducer';
|
||||
import { ResponseCacheService } from '../response-cache.service';
|
||||
import { getMapsTo, getRelationMetadata, getRelationships } from './build-decorators';
|
||||
import { PageInfo } from '../../shared/page-info.model';
|
||||
import {
|
||||
getRequestFromSelflink,
|
||||
getResourceLinksFromResponse,
|
||||
@@ -96,7 +98,6 @@ export class RemoteDataBuildService {
|
||||
error = new RemoteDataError((resEntry.response as ErrorResponse).statusText, errorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
return new RemoteData(
|
||||
requestPending,
|
||||
responsePending,
|
||||
@@ -107,7 +108,7 @@ export class RemoteDataBuildService {
|
||||
});
|
||||
}
|
||||
|
||||
buildList<TNormalized extends NormalizedObject, TDomain>(href$: string | Observable<string>): Observable<RemoteData<TDomain[] | PaginatedList<TDomain>>> {
|
||||
buildList<TNormalized extends NormalizedObject, TDomain>(href$: string | Observable<string>): Observable<RemoteData<PaginatedList<TDomain>>> {
|
||||
if (typeof href$ === 'string') {
|
||||
href$ = Observable.of(href$);
|
||||
}
|
||||
@@ -144,11 +145,7 @@ export class RemoteDataBuildService {
|
||||
);
|
||||
|
||||
const payload$ = Observable.combineLatest(tDomainList$, pageInfo$, (tDomainList, pageInfo) => {
|
||||
if (hasValue(pageInfo)) {
|
||||
return new PaginatedList(pageInfo, tDomainList);
|
||||
} else {
|
||||
return tDomainList;
|
||||
}
|
||||
return new PaginatedList(pageInfo, tDomainList);
|
||||
});
|
||||
|
||||
return this.toRemoteDataObservable(requestEntry$, responseCache$, payload$);
|
||||
@@ -160,35 +157,43 @@ export class RemoteDataBuildService {
|
||||
const relationships = getRelationships(normalized.constructor) || [];
|
||||
|
||||
relationships.forEach((relationship: string) => {
|
||||
let result;
|
||||
if (hasValue(normalized[relationship])) {
|
||||
const { resourceType, isList } = getRelationMetadata(normalized, relationship);
|
||||
if (Array.isArray(normalized[relationship])) {
|
||||
normalized[relationship].forEach((href: string) => {
|
||||
const objectList = normalized[relationship].page || normalized[relationship];
|
||||
if (typeof objectList !== 'string') {
|
||||
objectList.forEach((href: string) => {
|
||||
this.requestService.configure(new GetRequest(this.requestService.generateRequestId(), href))
|
||||
});
|
||||
|
||||
const rdArr = [];
|
||||
normalized[relationship].forEach((href: string) => {
|
||||
objectList.forEach((href: string) => {
|
||||
rdArr.push(this.buildSingle(href));
|
||||
});
|
||||
|
||||
if (isList) {
|
||||
links[relationship] = this.aggregate(rdArr);
|
||||
result = this.aggregate(rdArr);
|
||||
} else if (rdArr.length === 1) {
|
||||
links[relationship] = rdArr[0];
|
||||
result = rdArr[0];
|
||||
}
|
||||
} else {
|
||||
this.requestService.configure(new GetRequest(this.requestService.generateRequestId(), normalized[relationship]));
|
||||
this.requestService.configure(new GetRequest(this.requestService.generateRequestId(), objectList));
|
||||
|
||||
// The rest API can return a single URL to represent a list of resources (e.g. /items/:id/bitstreams)
|
||||
// in that case only 1 href will be stored in the normalized obj (so the isArray above fails),
|
||||
// but it should still be built as a list
|
||||
if (isList) {
|
||||
links[relationship] = this.buildList(normalized[relationship]);
|
||||
result = this.buildList(objectList);
|
||||
} else {
|
||||
links[relationship] = this.buildSingle(normalized[relationship]);
|
||||
result = this.buildSingle(objectList);
|
||||
}
|
||||
}
|
||||
|
||||
if (hasValue(normalized[relationship].page)) {
|
||||
links[relationship] = this.aggregatePaginatedList(result, normalized[relationship].pageInfo);
|
||||
} else {
|
||||
links[relationship] = result;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -249,4 +254,8 @@ 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)}));
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user