first tests and docs

This commit is contained in:
Lotte Hofstede
2017-05-23 10:21:26 +02:00
parent 0f472fb06b
commit 6aff818dcd
8 changed files with 255 additions and 1 deletions

View File

@@ -4,6 +4,7 @@ import { RemoteData } from "../data/remote-data";
import { Bundle } from "./bundle.model";
import { Bitstream } from "./bitstream.model";
import { Observable } from "rxjs";
import { hasValue } from "../../shared/empty.util";
export class Item extends DSpaceObject {
@@ -39,6 +40,11 @@ export class Item extends DSpaceObject {
bundles: Array<RemoteData<Bundle>>;
/**
* Retrieves the thumbnail of this item
* @returns {Observable<Bitstream>} the primaryBitstream of the "THUMBNAIL" bundle
*/
getThumbnail(): Observable<Bitstream> {
const bundle: Observable<Bundle> = this.getBundle("THUMBNAIL");
return bundle.flatMap(
@@ -53,15 +59,24 @@ 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>>> {
const bundle: Observable <Bundle> = this.getBundle("ORIGINAL");
return bundle.map(bundle => {
if (bundle != null) {
if (hasValue(bundle) && Array.isArray(bundle.bitstreams)) {
return bundle.bitstreams.map(bitstream => bitstream.payload)
}
});
}
/**
* Retrieves the bundle of this item by its name
* @param name The name of the Bundle that should be returned
* @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),
@@ -73,6 +88,10 @@ 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));
}