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