40416: small fixes and thumbnails

This commit is contained in:
Lotte Hofstede
2017-05-03 14:28:26 +02:00
parent b6fd84eb38
commit d932b44a77
23 changed files with 302 additions and 216 deletions

View File

@@ -14,80 +14,98 @@ import { NormalizedBitstream } from "./normalized-bitstream.model";
export class BundleBuilder {
constructor(
protected objectCache: ObjectCacheService,
protected responseCache: ResponseCacheService,
protected requestService: RequestService,
protected store: Store<CoreState>,
protected href: string,
protected normalized: NormalizedBundle
) {
}
build(): Bundle {
let links: any = {};
if (hasValue(this.normalized.bitstreams)) {
//for some reason the dispatches in the forEach don't
//fire without this timeout. A zone issue?
setTimeout(() => {
this.normalized.bitstreams.forEach((href: string) => {
const isCached = this.objectCache.hasBySelfLink(href);
const isPending = this.requestService.isPending(href);
if (!(isCached || isPending)) {
const request = new Request(href, NormalizedBitstream);
this.store.dispatch(new RequestConfigureAction(request));
this.store.dispatch(new RequestExecuteAction(href));
}
});
}, 0);
links.bitstreams = this.normalized.bitstreams.map((href: string) => {
return new BitstreamRDBuilder(
this.objectCache,
this.responseCache,
this.requestService,
this.store,
href
).build();
});
constructor(protected objectCache: ObjectCacheService,
protected responseCache: ResponseCacheService,
protected requestService: RequestService,
protected store: Store<CoreState>,
protected href: string,
protected normalized: NormalizedBundle) {
}
build(): Bundle {
let links: any = {};
if (hasValue(this.normalized.bitstreams)) {
//for some reason the dispatches in the forEach don't
//fire without this timeout. A zone issue?
setTimeout(() => {
this.normalized.bitstreams.forEach((href: string) => {
const isCached = this.objectCache.hasBySelfLink(href);
const isPending = this.requestService.isPending(href);
if (!(isCached || isPending)) {
const request = new Request(href, NormalizedBitstream);
this.store.dispatch(new RequestConfigureAction(request));
this.store.dispatch(new RequestExecuteAction(href));
}
});
}, 0);
links.bitstreams = this.normalized.bitstreams.map((href: string) => {
return new BitstreamRDBuilder(
this.objectCache,
this.responseCache,
this.requestService,
this.store,
href
).build();
});
}
if (hasValue(this.normalized.primaryBitstream)) {
const href = this.normalized.primaryBitstream;
//for some reason the dispatches in the forEach don't
//fire without this timeout. A zone issue?
setTimeout(() => {
const isCached = this.objectCache.hasBySelfLink(href);
const isPending = this.requestService.isPending(href);
if (!(isCached || isPending)) {
const request = new Request(href, NormalizedBitstream);
this.store.dispatch(new RequestConfigureAction(request));
this.store.dispatch(new RequestExecuteAction(href));
}
}, 0);
links.primaryBitstream =
new BitstreamRDBuilder(
this.objectCache,
this.responseCache,
this.requestService,
this.store,
href
).build();
}
return Object.assign(new Bundle(), this.normalized, links);
}
return Object.assign(new Bundle(), this.normalized, links);
}
}
export class BundleRDBuilder extends SingleRemoteDataBuilder<Bundle, NormalizedBundle> {
constructor(
objectCache: ObjectCacheService,
responseCache: ResponseCacheService,
requestService: RequestService,
store: Store<CoreState>,
href: string
) {
super(objectCache, responseCache, requestService, store, href, NormalizedBundle);
}
constructor(objectCache: ObjectCacheService,
responseCache: ResponseCacheService,
requestService: RequestService,
store: Store<CoreState>,
href: string) {
super(objectCache, responseCache, requestService, store, href, NormalizedBundle);
}
protected normalizedToDomain(normalized: NormalizedBundle): Bundle {
return new BundleBuilder(this.objectCache, this.responseCache, this.requestService, this.store, this.href, normalized).build();
}
protected normalizedToDomain(normalized: NormalizedBundle): Bundle {
return new BundleBuilder(this.objectCache, this.responseCache, this.requestService, this.store, this.href, normalized).build();
}
}
export class BundleListRDBuilder extends ListRemoteDataBuilder<Bundle, NormalizedBundle> {
constructor(
objectCache: ObjectCacheService,
responseCache: ResponseCacheService,
requestService: RequestService,
store: Store<CoreState>,
href: string
) {
super(objectCache, responseCache, requestService, store, href, NormalizedBundle);
}
constructor(objectCache: ObjectCacheService,
responseCache: ResponseCacheService,
requestService: RequestService,
store: Store<CoreState>,
href: string) {
super(objectCache, responseCache, requestService, store, href, NormalizedBundle);
}
protected normalizedToDomain(normalized: NormalizedBundle): Bundle {
return new BundleBuilder(this.objectCache, this.responseCache, this.requestService, this.store, this.href, normalized).build();
}
protected normalizedToDomain(normalized: NormalizedBundle): Bundle {
return new BundleBuilder(this.objectCache, this.responseCache, this.requestService, this.store, this.href, normalized).build();
}
}

View File

@@ -29,16 +29,18 @@ export class CollectionBuilder {
let links: any = {};
if (hasValue(this.normalized.items)) {
this.normalized.items.forEach((href: string) => {
const isCached = this.objectCache.hasBySelfLink(href);
const isPending = this.requestService.isPending(href);
setTimeout(() => {
this.normalized.items.forEach((href: string) => {
const isCached = this.objectCache.hasBySelfLink(href);
const isPending = this.requestService.isPending(href);
if (!(isCached || isPending)) {
const request = new Request(href, NormalizedItem);
this.store.dispatch(new RequestConfigureAction(request));
this.store.dispatch(new RequestExecuteAction(href));
}
});
if (!(isCached || isPending)) {
const request = new Request(href, NormalizedItem);
this.store.dispatch(new RequestConfigureAction(request));
this.store.dispatch(new RequestExecuteAction(href));
}
});
}, 0);
links.items = this.normalized.items.map((href: string) => {
return new ItemRDBuilder(

View File

@@ -28,16 +28,18 @@ export class ItemBuilder {
let links: any = {};
if (hasValue(this.normalized.bundles)) {
this.normalized.bundles.forEach((href: string) => {
const isCached = this.objectCache.hasBySelfLink(href);
const isPending = this.requestService.isPending(href);
setTimeout(() => {
this.normalized.bundles.forEach((href: string) => {
const isCached = this.objectCache.hasBySelfLink(href);
const isPending = this.requestService.isPending(href);
if (!(isCached || isPending)) {
const request = new Request(href, NormalizedBundle);
this.store.dispatch(new RequestConfigureAction(request));
this.store.dispatch(new RequestExecuteAction(href));
}
});
if (!(isCached || isPending)) {
const request = new Request(href, NormalizedBundle);
this.store.dispatch(new RequestConfigureAction(request));
this.store.dispatch(new RequestExecuteAction(href));
}
});
}, 0);
links.bundles = this.normalized.bundles.map((href: string) => {
return new BundleRDBuilder(

View File

@@ -1,4 +1,4 @@
import { inheritSerialization } from "cerialize";
import { inheritSerialization, autoserialize } from "cerialize";
import { NormalizedDSpaceObject } from "./normalized-dspace-object.model";
@inheritSerialization(NormalizedDSpaceObject)
@@ -33,4 +33,7 @@ export class NormalizedBitstream extends NormalizedDSpaceObject {
* The Bundle that owns this Bitstream
*/
owner: string;
@autoserialize
retrieve: string;
}

View File

@@ -8,77 +8,87 @@ import { CacheableObject } from "../cache/object-cache.reducer";
*/
export abstract class DSpaceObject implements CacheableObject {
@autoserialize
self: string;
@autoserialize
self: string;
/**
* The human-readable identifier of this DSpaceObject
*/
@autoserialize
id: string;
/**
* The human-readable identifier of this DSpaceObject
*/
@autoserialize
id: string;
/**
* The universally unique identifier of this DSpaceObject
*/
@autoserialize
uuid: string;
/**
* The universally unique identifier of this DSpaceObject
*/
@autoserialize
uuid: string;
/**
* A string representing the kind of DSpaceObject, e.g. community, item, …
*/
type: string;
/**
* A string representing the kind of DSpaceObject, e.g. community, item, …
*/
type: string;
/**
* The name for this DSpaceObject
*/
@autoserialize
name: string;
/**
* The name for this DSpaceObject
*/
@autoserialize
name: string;
/**
* An array containing all metadata of this DSpaceObject
*/
@autoserializeAs(Metadatum)
metadata: Array<Metadatum>;
/**
* An array containing all metadata of this DSpaceObject
*/
@autoserializeAs(Metadatum)
metadata: Array<Metadatum>;
/**
* An array of DSpaceObjects that are direct parents of this DSpaceObject
*/
parents: Array<DSpaceObject>;
/**
* An array of DSpaceObjects that are direct parents of this DSpaceObject
*/
parents: Array<DSpaceObject>;
/**
* The DSpaceObject that owns this DSpaceObject
*/
owner: DSpaceObject;
/**
* The DSpaceObject that owns this DSpaceObject
*/
owner: DSpaceObject;
/**
* Find a metadata field by key and language
*
* This method returns the value of the first element
* in the metadata array that matches the provided
* key and language
*
* @param key
* @param language
* @return string
*/
findMetadata(key: string, language?: string): string {
const metadatum = this.metadata
.find((metadatum: Metadatum) => {
return metadatum.key === key &&
(isEmpty(language) || metadatum.language === language)
});
if (isNotEmpty(metadatum)) {
return metadatum.value;
}
else {
return undefined;
}
}
/**
* Find a metadata field by key and language
*
* This method returns the value of the first element
* in the metadata array that matches the provided
* key and language
*
* @param key
* @param language
* @return string
*/
findMetadata(key: string, language?: string): string {
const metadatum = this.metadata
.find((metadatum: Metadatum) => {
return metadatum.key === key &&
(isEmpty(language) || metadatum.language === language)
});
if (isNotEmpty(metadatum)) {
return metadatum.value;
}
else {
return undefined;
}
}
filterMetadata(keys: string[]): Array<Metadatum> {
return this.metadata
.filter((metadatum: Metadatum) => {
return keys.some(key => key === metadatum.key);
});
}
/**
* Find metadata by an array of keys
*
* This method returns the values of the element
* in the metadata array that match the provided
* key(s)
*
* @param key(s)
* @return Array<Metadatum>
*/
filterMetadata(keys: string[]): Array<Metadatum> {
return this.metadata
.filter((metadatum: Metadatum) => {
return keys.some(key => key === metadatum.key);
});
}
}

View File

@@ -3,42 +3,62 @@ import { DSpaceObject } from "./dspace-object.model";
import { Collection } from "./collection.model";
import { RemoteData } from "../data/remote-data";
import { Bundle } from "./bundle.model";
import { Bitstream } from "./bitstream.model";
import { Observable } from "rxjs";
@inheritSerialization(DSpaceObject)
export class Item extends DSpaceObject {
/**
* A string representing the unique handle of this Item
*/
@autoserialize
handle: string;
/**
* A string representing the unique handle of this Item
*/
@autoserialize
handle: string;
/**
* The Date of the last modification of this Item
*/
lastModified: Date;
/**
* The Date of the last modification of this Item
*/
lastModified: Date;
/**
* A boolean representing if this Item is currently archived or not
*/
isArchived: boolean;
/**
* A boolean representing if this Item is currently archived or not
*/
isArchived: boolean;
/**
* A boolean representing if this Item is currently withdrawn or not
*/
isWithdrawn: boolean;
/**
* A boolean representing if this Item is currently withdrawn or not
*/
isWithdrawn: boolean;
/**
* An array of Collections that are direct parents of this Item
*/
@autoserializeAs(Collection)
parents: Array<Collection>;
/**
* An array of Collections that are direct parents of this Item
*/
@autoserializeAs(Collection)
parents: Array<Collection>;
/**
* The Collection that owns this Item
*/
owner: Collection;
/**
* The Collection that owns this Item
*/
owner: Collection;
bundles: Array<RemoteData<Bundle>>
bundles: Array<RemoteData<Bundle>>;
getThumbnail(): Observable<Bitstream> {
const bundle: Observable<Bundle> = this.getBundle("THUMBNAIL");
return bundle.flatMap(
b => b.primaryBitstream.payload
);
}
getBundle(name: String): Observable<Bundle> {
return Observable.combineLatest(
...this.bundles.map(b => b.payload),
(...bundles: Array<Bundle>) => bundles)
.map(bundles => {
return bundles.find((bundle: Bundle) => {
return bundle.name === name
});
});
}
}

View File

@@ -1,8 +1,9 @@
<div class="item-page" *ngIf="item.hasSucceeded | async">
Item page component
<ds-item-page-title-field [item]="item.payload"></ds-item-page-title-field>
<ds-item-page-date-field [item]="item.payload"></ds-item-page-date-field>
<ds-item-page-author-field [item]="item.payload"></ds-item-page-author-field>
<ds-item-page-abstract-field [item]="item.payload"></ds-item-page-abstract-field>
<ds-item-page-uri-field [item]="item.payload"></ds-item-page-uri-field>
<ds-thumbnail [thumbnail]="thumbnail | async"></ds-thumbnail>
<ds-item-page-title-field [item]="item.payload | async"></ds-item-page-title-field>
<ds-item-page-date-field [item]="item.payload | async"></ds-item-page-date-field>
<ds-item-page-author-field [item]="item.payload | async"></ds-item-page-author-field>
<ds-item-page-abstract-field [item]="item.payload | async"></ds-item-page-abstract-field>
<ds-item-page-uri-field [item]="item.payload | async"></ds-item-page-uri-field>
</div>

View File

@@ -1,35 +1,41 @@
import { Component, OnInit } from '@angular/core';
import { Component, OnInit, ChangeDetectionStrategy } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { Item } from "../core/shared/item.model";
import { ItemDataService } from "../core/data-services/item-data.service";
import { RemoteData } from "../core/data-services/remote-data";
import { ItemDataService } from "../core/data/item-data.service";
import { RemoteData } from "../core/data/remote-data";
import { Observable } from "rxjs";
import { Bitstream } from "../core/shared/bitstream.model";
@Component({
selector: 'ds-item-page',
styleUrls: ['./item-page.component.css'],
templateUrl: './item-page.component.html'
selector: 'ds-item-page',
styleUrls: ['./item-page.component.css'],
templateUrl: './item-page.component.html',
// changeDetection: ChangeDetectionStrategy.OnPush
})
export class ItemPageComponent implements OnInit {
id: number;
private sub: any;
item : RemoteData<Item>;
id: number;
private sub: any;
item: RemoteData<Item>;
thumbnail: Observable<Bitstream>;
constructor( private route: ActivatedRoute, private items : ItemDataService) {
this.universalInit();
}
constructor(private route: ActivatedRoute, private items: ItemDataService) {
this.universalInit();
}
universalInit() {
universalInit() {
}
}
ngOnInit(): void {
this.sub = this.route.params.subscribe(params => {
this.id = +params['id'];
this.item = this.items.findById(params['id']);
});
ngOnInit(): void {
this.sub = this.route.params.subscribe(params => {
this.id = +params['id'];
this.item = this.items.findById(params['id']);
this.thumbnail = this.item.payload.flatMap(i => i.getThumbnail());
});
}
}
}

View File

@@ -12,6 +12,7 @@ import { ItemPageUriFieldComponent } from './specific-field/uri/item-page-uri-fi
import { ItemPageTitleFieldComponent } from './specific-field/title/item-page-title-field.component';
import { ItemPageSpecificFieldComponent } from './specific-field/item-page-specific-field.component';
import { SharedModule } from './../shared/shared.module';
import { ThumbnailComponent } from "../thumbnail/thumbnail.component";
@NgModule({
declarations: [
@@ -25,6 +26,7 @@ import { SharedModule } from './../shared/shared.module';
ItemPageUriFieldComponent,
ItemPageTitleFieldComponent,
ItemPageSpecificFieldComponent,
ThumbnailComponent,
],
imports: [
ItemPageRoutingModule,

View File

@@ -1,6 +1,5 @@
import { Component, OnInit, Input } from '@angular/core';
import { Item } from "../../../core/shared/item.model";
import { Observable } from "rxjs";
import { ItemPageSpecificFieldComponent } from "../item-page-specific-field.component";
@Component({
@@ -9,7 +8,7 @@ import { ItemPageSpecificFieldComponent } from "../item-page-specific-field.comp
})
export class ItemPageAbstractFieldComponent extends ItemPageSpecificFieldComponent implements OnInit {
@Input() item: Observable<Item>;
@Input() item: Item;
fields : string[] = [
"dc.description.abstract"

View File

@@ -1,6 +1,5 @@
import { Component, OnInit, Input } from '@angular/core';
import { Item } from "../../../core/shared/item.model";
import { Observable } from "rxjs";
import { ItemPageSpecificFieldComponent } from "../item-page-specific-field.component";
@Component({
@@ -9,7 +8,7 @@ import { ItemPageSpecificFieldComponent } from "../item-page-specific-field.comp
})
export class ItemPageAuthorFieldComponent extends ItemPageSpecificFieldComponent implements OnInit {
@Input() item: Observable<Item>;
@Input() item: Item;
fields : string[] = [
"dc.contributor.author",

View File

@@ -1,6 +1,5 @@
import { Component, OnInit, Input } from '@angular/core';
import { Item } from "../../../core/shared/item.model";
import { Observable } from "rxjs";
import { ItemPageSpecificFieldComponent } from "../item-page-specific-field.component";
@Component({
@@ -9,7 +8,7 @@ import { ItemPageSpecificFieldComponent } from "../item-page-specific-field.comp
})
export class ItemPageDateFieldComponent extends ItemPageSpecificFieldComponent implements OnInit {
@Input() item: Observable<Item>;
@Input() item: Item;
fields : string[] = [
"dc.date.issued"

View File

@@ -1,3 +1,3 @@
<div class="item-page-specific-field">
<ds-metadata-values [values]="(item | async)?.filterMetadata(fields)" [separator]="separator" [label]="label"></ds-metadata-values>
<ds-metadata-values [values]="item?.filterMetadata(fields)" [separator]="separator" [label]="label"></ds-metadata-values>
</div>

View File

@@ -1,13 +1,12 @@
import { Component, OnInit, Input } from '@angular/core';
import { Item } from "../../core/shared/item.model";
import { Observable } from "rxjs";
@Component({
templateUrl: './item-page-specific-field.component.html'
})
export class ItemPageSpecificFieldComponent implements OnInit {
@Input() item: Observable<Item>;
@Input() item: Item;
fields : string[];
label : string;

View File

@@ -1,3 +1,3 @@
<h2 class="item-page-title-field">
<ds-metadata-values [values]="(item | async)?.filterMetadata(fields)"></ds-metadata-values>
<ds-metadata-values [values]="item?.filterMetadata(fields)"></ds-metadata-values>
</h2>

View File

@@ -1,6 +1,5 @@
import { Component, OnInit, Input } from '@angular/core';
import { Item } from "../../../core/shared/item.model";
import { Observable } from "rxjs";
import { ItemPageSpecificFieldComponent } from "../item-page-specific-field.component";
@Component({
@@ -9,7 +8,7 @@ import { ItemPageSpecificFieldComponent } from "../item-page-specific-field.comp
})
export class ItemPageTitleFieldComponent extends ItemPageSpecificFieldComponent implements OnInit {
@Input() item: Observable<Item>;
@Input() item: Item;
fields : string[] = [
"dc.title"

View File

@@ -1,3 +1,3 @@
<div class="item-page-specific-field">
<ds-metadata-uri-values [values]="(item | async)?.filterMetadata(fields)" [separator]="separator" [label]="label"></ds-metadata-uri-values>
<ds-metadata-uri-values [values]="item?.filterMetadata(fields)" [separator]="separator" [label]="label"></ds-metadata-uri-values>
</div>

View File

@@ -1,6 +1,5 @@
import { Component, OnInit, Input } from '@angular/core';
import { Item } from "../../../core/shared/item.model";
import { Observable } from "rxjs";
import { ItemPageSpecificFieldComponent } from "../item-page-specific-field.component";
@Component({
@@ -9,7 +8,7 @@ import { ItemPageSpecificFieldComponent } from "../item-page-specific-field.comp
})
export class ItemPageUriFieldComponent extends ItemPageSpecificFieldComponent implements OnInit {
@Input() item: Observable<Item>;
@Input() item: Item;
fields : string[] = [
"dc.identifier.uri"

View File

@@ -0,0 +1,3 @@
<div class="thumbnail">
<img [src]="thumbnail?.retrieve"/>
</div>

View File

@@ -0,0 +1 @@
@import '../../styles/variables.scss';

View File

@@ -0,0 +1,24 @@
import { Component, Input } from '@angular/core';
import { Bitstream } from "../core/shared/bitstream.model";
import { Observable } from "rxjs";
@Component({
selector: 'ds-thumbnail',
styleUrls: ['./thumbnail.component.css'],
templateUrl: './thumbnail.component.html'
})
export class ThumbnailComponent {
@Input() thumbnail : Observable<Bitstream>;
data: any = {};
constructor() {
this.universalInit();
}
universalInit() {
}
}

View File

@@ -8,7 +8,7 @@ export const BUNDLES = [
"bitstreams": [
{ "href": "/bitstreams/3678" },
],
"primaryBitstream": { "href": "/bitstreams/43c57c2b-206f-4645-8c8f-5f10c84b09fa" }
"primaryBitstream": { "href": "/bitstreams/3678" }
},
"id": "2355",
"uuid": "35e0606d-5e18-4f9c-aa61-74fc751cc3f9",
@@ -26,7 +26,7 @@ export const BUNDLES = [
"bitstreams": [
{ "href": "/bitstreams/8842" },
],
"primaryBitstream": { "href": "/bitstreams/1a013ecc-fb25-4689-a44f-f1383ad26632" }
"primaryBitstream": { "href": "/bitstreams/8842" }
},
"id": "5687",
"uuid": "a469c57a-abcf-45c3-83e4-b187ebd708fd",