mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-18 07:23:03 +00:00
Merge branch 'master' into live-rest-backend
This commit is contained in:
@@ -26,53 +26,46 @@ export class RemoteDataBuildService {
|
||||
) {
|
||||
}
|
||||
|
||||
//TODO refactor, nearly identical to buildList, only payload differs
|
||||
buildSingle<TNormalized extends CacheableObject, TDomain>(
|
||||
href: string,
|
||||
normalizedType: GenericConstructor<TNormalized>
|
||||
): RemoteData<TDomain> {
|
||||
const requestObs = this.store.select<RequestEntry>('core', 'data', 'request', href);
|
||||
const responseCacheObs = this.responseCache.get(href);
|
||||
const requestHrefObs = this.objectCache.getRequestHrefBySelfLink(href);
|
||||
|
||||
const requestPending = requestObs.map((entry: RequestEntry) => hasValue(entry) && entry.requestPending).distinctUntilChanged();
|
||||
const requestObs = Observable.race(
|
||||
this.store.select<RequestEntry>('core', 'data', 'request', href).filter(entry => hasValue(entry)),
|
||||
requestHrefObs.flatMap(requestHref =>
|
||||
this.store.select<RequestEntry>('core', 'data', 'request', requestHref)).filter(entry => hasValue(entry))
|
||||
);
|
||||
|
||||
const responsePending = requestObs.map((entry: RequestEntry) => hasValue(entry) && entry.responsePending).distinctUntilChanged();
|
||||
const responseCacheObs = Observable.race(
|
||||
this.responseCache.get(href).filter(entry => hasValue(entry)),
|
||||
requestHrefObs.flatMap(requestHref => this.responseCache.get(requestHref)).filter(entry => hasValue(entry))
|
||||
);
|
||||
|
||||
const requestPending = requestObs.map((entry: RequestEntry) => entry.requestPending).distinctUntilChanged();
|
||||
|
||||
const responsePending = requestObs.map((entry: RequestEntry) => entry.responsePending).distinctUntilChanged();
|
||||
|
||||
const isSuccessFul = responseCacheObs
|
||||
.map((entry: ResponseCacheEntry) => hasValue(entry) && entry.response.isSuccessful).distinctUntilChanged();
|
||||
.map((entry: ResponseCacheEntry) => entry.response.isSuccessful).distinctUntilChanged();
|
||||
|
||||
const errorMessage = responseCacheObs
|
||||
.filter((entry: ResponseCacheEntry) => hasValue(entry) && !entry.response.isSuccessful)
|
||||
.filter((entry: ResponseCacheEntry) => !entry.response.isSuccessful)
|
||||
.map((entry: ResponseCacheEntry) => (<ErrorResponse> entry.response).errorMessage)
|
||||
.distinctUntilChanged();
|
||||
|
||||
const statusCode = responseCacheObs
|
||||
.filter((entry: ResponseCacheEntry) => hasValue(entry))
|
||||
.map((entry: ResponseCacheEntry) => entry.response.statusCode)
|
||||
.distinctUntilChanged();
|
||||
|
||||
const pageInfo = responseCacheObs
|
||||
.filter((entry: ResponseCacheEntry) => hasValue(entry)
|
||||
&& hasValue(entry.response) && hasValue(entry.response['pageInfo']))
|
||||
.filter((entry: ResponseCacheEntry) => hasValue(entry.response) && hasValue(entry.response['pageInfo']))
|
||||
.map((entry: ResponseCacheEntry) => (<SuccessResponse> entry.response).pageInfo)
|
||||
.distinctUntilChanged();
|
||||
|
||||
const payload =
|
||||
Observable.race(
|
||||
this.objectCache.getBySelfLink<TNormalized>(href, normalizedType),
|
||||
responseCacheObs
|
||||
.filter((entry: ResponseCacheEntry) => hasValue(entry) && entry.response.isSuccessful)
|
||||
.map((entry: ResponseCacheEntry) => (<SuccessResponse> entry.response).resourceUUIDs)
|
||||
.flatMap((resourceUUIDs: Array<string>) => {
|
||||
if (isNotEmpty(resourceUUIDs)) {
|
||||
return this.objectCache.get(resourceUUIDs[0], normalizedType);
|
||||
}
|
||||
else {
|
||||
return Observable.of(undefined);
|
||||
}
|
||||
})
|
||||
.distinctUntilChanged()
|
||||
).map((normalized: TNormalized) => {
|
||||
const payload = this.objectCache.getBySelfLink<TNormalized>(href, normalizedType)
|
||||
.map((normalized: TNormalized) => {
|
||||
return this.build<TNormalized, TDomain>(normalized);
|
||||
});
|
||||
|
||||
@@ -88,39 +81,37 @@ export class RemoteDataBuildService {
|
||||
);
|
||||
}
|
||||
|
||||
//TODO refactor, nearly identical to buildSingle, only payload differs
|
||||
buildList<TNormalized extends CacheableObject, TDomain>(
|
||||
href: string,
|
||||
normalizedType: GenericConstructor<TNormalized>
|
||||
): RemoteData<TDomain[]> {
|
||||
const requestObs = this.store.select<RequestEntry>('core', 'data', 'request', href);
|
||||
const responseCacheObs = this.responseCache.get(href);
|
||||
const requestObs = this.store.select<RequestEntry>('core', 'data', 'request', href)
|
||||
.filter(entry => hasValue(entry));
|
||||
const responseCacheObs = this.responseCache.get(href).filter(entry => hasValue(entry));
|
||||
|
||||
const requestPending = requestObs.map((entry: RequestEntry) => hasValue(entry) && entry.requestPending).distinctUntilChanged();
|
||||
const requestPending = requestObs.map((entry: RequestEntry) => entry.requestPending).distinctUntilChanged();
|
||||
|
||||
const responsePending = requestObs.map((entry: RequestEntry) => hasValue(entry) && entry.responsePending).distinctUntilChanged();
|
||||
const responsePending = requestObs.map((entry: RequestEntry) => entry.responsePending).distinctUntilChanged();
|
||||
|
||||
const isSuccessFul = responseCacheObs
|
||||
.map((entry: ResponseCacheEntry) => hasValue(entry) && entry.response.isSuccessful).distinctUntilChanged();
|
||||
.map((entry: ResponseCacheEntry) => entry.response.isSuccessful).distinctUntilChanged();
|
||||
|
||||
const errorMessage = responseCacheObs
|
||||
.filter((entry: ResponseCacheEntry) => hasValue(entry) && !entry.response.isSuccessful)
|
||||
.filter((entry: ResponseCacheEntry) => !entry.response.isSuccessful)
|
||||
.map((entry: ResponseCacheEntry) => (<ErrorResponse> entry.response).errorMessage)
|
||||
.distinctUntilChanged();
|
||||
|
||||
const statusCode = responseCacheObs
|
||||
.filter((entry: ResponseCacheEntry) => hasValue(entry))
|
||||
.map((entry: ResponseCacheEntry) => entry.response.statusCode)
|
||||
.distinctUntilChanged();
|
||||
|
||||
const pageInfo = responseCacheObs
|
||||
.filter((entry: ResponseCacheEntry) => hasValue(entry)
|
||||
&& hasValue(entry.response) && hasValue(entry.response['pageInfo']))
|
||||
.filter((entry: ResponseCacheEntry) => hasValue(entry.response) && hasValue(entry.response['pageInfo']))
|
||||
.map((entry: ResponseCacheEntry) => (<SuccessResponse> entry.response).pageInfo)
|
||||
.distinctUntilChanged();
|
||||
|
||||
const payload = responseCacheObs
|
||||
.filter((entry: ResponseCacheEntry) => hasValue(entry) && entry.response.isSuccessful)
|
||||
.filter((entry: ResponseCacheEntry) => entry.response.isSuccessful)
|
||||
.map((entry: ResponseCacheEntry) => (<SuccessResponse> entry.response).resourceUUIDs)
|
||||
.flatMap((resourceUUIDs: Array<string>) => {
|
||||
return this.objectCache.getList(resourceUUIDs, normalizedType)
|
||||
|
Reference in New Issue
Block a user