mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 18:14:17 +00:00
adapted remote data build method to aggregate relation remotedata arrays
This commit is contained in:

committed by
Lotte Hofstede

parent
2b74c3034a
commit
fbb64a6031
@@ -134,9 +134,12 @@ export class RemoteDataBuildService {
|
||||
});
|
||||
}, 0);
|
||||
|
||||
links[relationship] = normalized[relationship].map((href: string) => {
|
||||
return this.buildSingle(href, resourceConstructor);
|
||||
let rdArr = [];
|
||||
normalized[relationship].forEach((href: string) => {
|
||||
rdArr.push(this.buildSingle(href, resourceConstructor));
|
||||
});
|
||||
|
||||
links[relationship] = this.aggregate(rdArr);
|
||||
}
|
||||
else {
|
||||
// without the setTimeout, the actions inside requestService.configure
|
||||
@@ -155,29 +158,33 @@ export class RemoteDataBuildService {
|
||||
}
|
||||
|
||||
aggregate<T>(input: RemoteData<T>[]): RemoteData<T[]> {
|
||||
const requestPending: Observable<boolean> = <Observable<boolean>> Observable.combineLatest(
|
||||
const requestPending = Observable.combineLatest(
|
||||
...input.map(rd => rd.isRequestPending),
|
||||
(...pendingArray) => pendingArray.every(e => e === true)
|
||||
).distinctUntilChanged();
|
||||
const responsePending: Observable<boolean> = <Observable<boolean>> Observable.combineLatest(
|
||||
).map((...pendingArray) => pendingArray.every(e => e === true))
|
||||
.distinctUntilChanged();
|
||||
|
||||
const responsePending = Observable.combineLatest(
|
||||
...input.map(rd => rd.isResponsePending),
|
||||
(...pendingArray) => pendingArray.every(e => e === true)
|
||||
).distinctUntilChanged();
|
||||
const isSuccessFul: Observable<boolean> = <Observable<boolean>> Observable.combineLatest(
|
||||
).map((...pendingArray) => pendingArray.every(e => e === true))
|
||||
.distinctUntilChanged();
|
||||
|
||||
const isSuccessFul = Observable.combineLatest(
|
||||
...input.map(rd => rd.hasSucceeded),
|
||||
(...successArray) => successArray.every(e => e === true)
|
||||
).distinctUntilChanged();
|
||||
const errorMessage: Observable<string> = <Observable<string>> Observable.combineLatest(
|
||||
).map((...successArray) => successArray.every(e => e === true))
|
||||
.distinctUntilChanged();
|
||||
|
||||
const errorMessage = Observable.combineLatest(
|
||||
...input.map(rd => rd.errorMessage),
|
||||
(...errors) => errors
|
||||
.map((e, idx) => {
|
||||
if (hasValue(e)) {
|
||||
return `[${idx}]: ${e}`;
|
||||
}
|
||||
})
|
||||
.filter(e => hasValue(e))
|
||||
.join(", ")
|
||||
).map((...errors) => errors
|
||||
.map((e, idx) => {
|
||||
if (hasValue(e)) {
|
||||
return `[${idx}]: ${e}`;
|
||||
}
|
||||
})
|
||||
.filter(e => hasValue(e))
|
||||
.join(", ")
|
||||
);
|
||||
|
||||
const payload = <Observable<T[]>> Observable.combineLatest(
|
||||
...input.map(rd => rd.payload)
|
||||
);
|
||||
|
@@ -27,7 +27,7 @@ export class Bitstream extends DSpaceObject {
|
||||
/**
|
||||
* An array of Bundles that are direct parents of this Bitstream
|
||||
*/
|
||||
parents: Array<RemoteData<Bundle>>;
|
||||
parents: RemoteData<Bundle[]>;
|
||||
|
||||
/**
|
||||
* The Bundle that owns this Bitstream
|
||||
|
@@ -12,13 +12,13 @@ export class Bundle extends DSpaceObject {
|
||||
/**
|
||||
* An array of Items that are direct parents of this Bundle
|
||||
*/
|
||||
parents: Array<RemoteData<Item>>;
|
||||
parents: RemoteData<Item[]>;
|
||||
|
||||
/**
|
||||
* The Item that owns this Bundle
|
||||
*/
|
||||
owner: Item;
|
||||
|
||||
bitstreams: Array<RemoteData<Bitstream>>
|
||||
bitstreams: RemoteData<Bitstream[]>
|
||||
|
||||
}
|
||||
|
@@ -58,13 +58,13 @@ export class Collection extends DSpaceObject {
|
||||
/**
|
||||
* An array of Collections that are direct parents of this Collection
|
||||
*/
|
||||
parents: Array<RemoteData<Collection>>;
|
||||
parents: RemoteData<Collection[]>;
|
||||
|
||||
/**
|
||||
* The Collection that owns this Collection
|
||||
*/
|
||||
owner: Collection;
|
||||
|
||||
items: Array<RemoteData<Item>>;
|
||||
items: RemoteData<Item[]>;
|
||||
|
||||
}
|
||||
|
@@ -50,13 +50,13 @@ export class Community extends DSpaceObject {
|
||||
/**
|
||||
* An array of Communities that are direct parents of this Community
|
||||
*/
|
||||
parents: Array<RemoteData<DSpaceObject>>;
|
||||
parents: RemoteData<DSpaceObject[]>;
|
||||
|
||||
/**
|
||||
* The Community that owns this Community
|
||||
*/
|
||||
owner: Community;
|
||||
|
||||
collections: Array<RemoteData<Collection>>;
|
||||
collections: RemoteData<Collection[]>;
|
||||
|
||||
}
|
||||
|
@@ -38,7 +38,7 @@ export abstract class DSpaceObject implements CacheableObject {
|
||||
/**
|
||||
* An array of DSpaceObjects that are direct parents of this DSpaceObject
|
||||
*/
|
||||
parents: Array<RemoteData<DSpaceObject>>;
|
||||
parents: RemoteData<DSpaceObject[]>;
|
||||
|
||||
/**
|
||||
* The DSpaceObject that owns this DSpaceObject
|
||||
|
@@ -31,14 +31,14 @@ export class Item extends DSpaceObject {
|
||||
/**
|
||||
* An array of Collections that are direct parents of this Item
|
||||
*/
|
||||
parents: Array<RemoteData<Collection>>;
|
||||
parents: RemoteData<Collection[]>;
|
||||
|
||||
/**
|
||||
* The Collection that owns this Item
|
||||
*/
|
||||
owner: Collection;
|
||||
|
||||
bundles: Array<RemoteData<Bundle>>;
|
||||
bundles: RemoteData<Bundle[]>;
|
||||
|
||||
|
||||
/**
|
||||
@@ -63,13 +63,11 @@ export class Item extends DSpaceObject {
|
||||
* Retrieves all files that should be displayed on the item page of this item
|
||||
* @returns {Observable<Array<Observable<Bitstream>>>} an array of all Bitstreams in the "ORIGINAL" bundle
|
||||
*/
|
||||
getFiles(): Observable<Array<Observable<Bitstream>>> {
|
||||
getFiles(): Observable<Bitstream[]> {
|
||||
const bundle: Observable <Bundle> = this.getBundle("ORIGINAL");
|
||||
return bundle.map(bundle => {
|
||||
if (hasValue(bundle) && Array.isArray(bundle.bitstreams)) {
|
||||
return bundle.bitstreams.map(bitstream => bitstream.payload)
|
||||
}
|
||||
});
|
||||
return bundle
|
||||
.filter(bundle => hasValue(bundle))
|
||||
.flatMap(bundle => bundle.bitstreams.payload);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -78,9 +76,8 @@ export class Item extends DSpaceObject {
|
||||
* @returns {Observable<Bundle>} the Bundle that belongs to this item with the given name
|
||||
*/
|
||||
getBundle(name: String): Observable<Bundle> {
|
||||
return Observable.combineLatest(
|
||||
...this.bundles.map(b => b.payload),
|
||||
(...bundles: Array<Bundle>) => bundles)
|
||||
return this.bundles.payload
|
||||
.filter(bundles => hasValue(bundles))
|
||||
.map(bundles => {
|
||||
return bundles.find((bundle: Bundle) => {
|
||||
return bundle.name === name
|
||||
@@ -88,12 +85,4 @@ export class Item extends DSpaceObject {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves all direct parent collections of this item
|
||||
* @returns {Array<Observable<Collection>>} an array of all Collections that contain this item
|
||||
*/
|
||||
getCollections(): Array<Observable<Collection>> {
|
||||
return this.parents.map(collection => collection.payload.map(parent => parent));
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,7 +1,7 @@
|
||||
<ds-metadata-field-wrapper [label]="label | translate">
|
||||
<div class="collections">
|
||||
<a *ngFor="let collection of collections; let last=last;" [href]="(collection | async)?.self">
|
||||
<span>{{(collection | async)?.name}}</span><span *ngIf="!last" [innerHTML]="separator"></span>
|
||||
<a *ngFor="let collection of (collections | async); let last=last;" [href]="collection?.self">
|
||||
<span>{{collection?.name}}</span><span *ngIf="!last" [innerHTML]="separator"></span>
|
||||
</a>
|
||||
</div>
|
||||
</ds-metadata-field-wrapper>
|
||||
|
@@ -20,7 +20,7 @@ export class CollectionsComponent implements OnInit {
|
||||
|
||||
separator: string = "<br/>"
|
||||
|
||||
collections: Array<Observable<Collection>>;
|
||||
collections: Observable<Collection[]>;
|
||||
|
||||
constructor() {
|
||||
this.universalInit();
|
||||
@@ -31,7 +31,7 @@ export class CollectionsComponent implements OnInit {
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.collections = this.item.getCollections();
|
||||
this.collections = this.item.parents.payload;
|
||||
}
|
||||
|
||||
|
||||
|
@@ -1,8 +1,8 @@
|
||||
<ds-metadata-field-wrapper [label]="label | translate">
|
||||
<div class="file-section">
|
||||
<a *ngFor="let file of (files | async); let last=last;" [href]="(file | async)?.retrieve">
|
||||
<span>{{(file | async)?.name}}</span>
|
||||
<span>({{((file | async)?.size) | dsFileSize }})</span>
|
||||
<a *ngFor="let file of (files | async); let last=last;" [href]="file?.retrieve">
|
||||
<span>{{file?.name}}</span>
|
||||
<span>({{(file?.size) | dsFileSize }})</span>
|
||||
<span *ngIf="!last" innerHTML="{{separator}}"></span>
|
||||
</a>
|
||||
</div>
|
||||
|
@@ -20,7 +20,7 @@ export class FileSectionComponent implements OnInit {
|
||||
|
||||
separator: string = "<br/>"
|
||||
|
||||
files: Observable<Array<Observable<Bitstream>>>;
|
||||
files: Observable<Bitstream[]>;
|
||||
|
||||
constructor() {
|
||||
this.universalInit();
|
||||
|
@@ -82,22 +82,25 @@ function ngApp(req, res) {
|
||||
function onHandleError(parentZoneDelegate, currentZone, targetZone, error) {
|
||||
console.warn('Error in SSR, serving for direct CSR');
|
||||
res.sendFile('index.html', { root: './src' });
|
||||
return false;
|
||||
}
|
||||
|
||||
Zone.current.fork({ name: 'CSR fallback', onHandleError }).run(() => {
|
||||
res.render('index', {
|
||||
req,
|
||||
res,
|
||||
// time: true, // use this to determine what part of your app is slow only in development
|
||||
async: EnvConfig.universal.async,
|
||||
preboot: EnvConfig.universal.preboot,
|
||||
baseUrl: EnvConfig.ui.nameSpace,
|
||||
requestUrl: req.originalUrl,
|
||||
originUrl: EnvConfig.ui.baseUrl
|
||||
if (EnvConfig.universal.preboot) {
|
||||
Zone.current.fork({ name: 'CSR fallback', onHandleError }).run(() => {
|
||||
res.render('index', {
|
||||
req,
|
||||
res,
|
||||
// time: true, // use this to determine what part of your app is slow only in development
|
||||
async: EnvConfig.universal.async,
|
||||
preboot: EnvConfig.universal.preboot,
|
||||
baseUrl: EnvConfig.ui.nameSpace,
|
||||
requestUrl: req.originalUrl,
|
||||
originUrl: EnvConfig.ui.baseUrl
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
else {
|
||||
res.sendFile('index.html', { root: './src' });
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user