40416: Thumbnail fix + clean up

This commit is contained in:
Lotte Hofstede
2017-05-10 13:03:53 +02:00
parent 6652f61770
commit 9906dd59e3
21 changed files with 103 additions and 47 deletions

View File

@@ -33,4 +33,10 @@ export class Bitstream extends DSpaceObject {
* The Bundle that owns this Bitstream * The Bundle that owns this Bitstream
*/ */
owner: Bundle; owner: Bundle;
/**
* The Bundle that owns this Bitstream
*/
retrieve: string;
} }

View File

@@ -42,12 +42,24 @@ export class Item extends DSpaceObject {
getThumbnail(): Observable<Bitstream> { getThumbnail(): Observable<Bitstream> {
const bundle: Observable<Bundle> = this.getBundle("THUMBNAIL"); const bundle: Observable<Bundle> = this.getBundle("THUMBNAIL");
return bundle.flatMap( return bundle.flatMap(
b => b.primaryBitstream.payload bundle => {
if (bundle != null) {
return bundle.primaryBitstream.payload;
}
else {
return Observable.of(undefined);
}
}
); );
} }
getFiles(): Observable<Array<Observable<Bitstream>>> { getFiles(): Observable<Array<Observable<Bitstream>>> {
return this.getBundle("ORIGINAL").map(bundle => bundle.bitstreams.map(bitstream => bitstream.payload)); const bundle: Observable <Bundle> = this.getBundle("ORIGINAL");
return bundle.map(bundle => {
if (bundle != null) {
return bundle.bitstreams.map(bitstream => bitstream.payload)
}
});
} }
getBundle(name: String): Observable<Bundle> { getBundle(name: String): Observable<Bundle> {
@@ -62,7 +74,7 @@ export class Item extends DSpaceObject {
} }
getCollections(): Array<Observable<Collection>> { getCollections(): Array<Observable<Collection>> {
return this.parents.map(c => c.payload.map(p => p)); return this.parents.map(collection => collection.payload.map(parent => parent));
} }
} }

View File

@@ -10,8 +10,11 @@ import { Item } from "../../core/shared/item.model";
export class CollectionsComponent implements OnInit { export class CollectionsComponent implements OnInit {
@Input() item: Item; @Input() item: Item;
label : string = "item.page.collections"; label : string = "item.page.collections";
separator: string = "<br/>" separator: string = "<br/>"
collections: Array<Observable<Collection>>; collections: Array<Observable<Collection>>;
constructor() { constructor() {

View File

@@ -10,8 +10,11 @@ import { Observable } from "rxjs";
export class FileSectionComponent implements OnInit { export class FileSectionComponent implements OnInit {
@Input() item: Item; @Input() item: Item;
label : string = "item.page.files"; label : string = "item.page.files";
separator: string = "<br/>" separator: string = "<br/>"
files: Observable<Array<Observable<Bitstream>>>; files: Observable<Array<Observable<Bitstream>>>;
constructor() { constructor() {

View File

@@ -2,7 +2,9 @@
<ds-item-page-title-field [item]="item.payload | async"></ds-item-page-title-field> <ds-item-page-title-field [item]="item.payload | async"></ds-item-page-title-field>
<div class="row"> <div class="row">
<div class="col-xs-12 col-md-4"> <div class="col-xs-12 col-md-4">
<ds-metadata-field-wrapper>
<ds-thumbnail [thumbnail]="thumbnail | async"></ds-thumbnail> <ds-thumbnail [thumbnail]="thumbnail | async"></ds-thumbnail>
</ds-metadata-field-wrapper>
<ds-item-page-file-section [item]="item.payload | async"></ds-item-page-file-section> <ds-item-page-file-section [item]="item.payload | async"></ds-item-page-file-section>
<ds-item-page-date-field [item]="item.payload | async"></ds-item-page-date-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-author-field [item]="item.payload | async"></ds-item-page-author-field>

View File

@@ -14,8 +14,11 @@ import { Bitstream } from "../core/shared/bitstream.model";
export class ItemPageComponent implements OnInit { export class ItemPageComponent implements OnInit {
id: number; id: number;
private sub: any; private sub: any;
item: RemoteData<Item>; item: RemoteData<Item>;
thumbnail: Observable<Bitstream>; thumbnail: Observable<Bitstream>;
constructor(private route: ActivatedRoute, private items: ItemDataService) { constructor(private route: ActivatedRoute, private items: ItemDataService) {
@@ -32,8 +35,6 @@ export class ItemPageComponent implements OnInit {
this.item = this.items.findById(params['id']); this.item = this.items.findById(params['id']);
this.thumbnail = this.item.payload.flatMap(i => i.getThumbnail()); this.thumbnail = this.item.payload.flatMap(i => i.getThumbnail());
}); });
} }

View File

@@ -12,7 +12,6 @@ import { ItemPageUriFieldComponent } from './specific-field/uri/item-page-uri-fi
import { ItemPageTitleFieldComponent } from './specific-field/title/item-page-title-field.component'; import { ItemPageTitleFieldComponent } from './specific-field/title/item-page-title-field.component';
import { ItemPageSpecificFieldComponent } from './specific-field/item-page-specific-field.component'; import { ItemPageSpecificFieldComponent } from './specific-field/item-page-specific-field.component';
import { SharedModule } from './../shared/shared.module'; import { SharedModule } from './../shared/shared.module';
import { ThumbnailComponent } from "../thumbnail/thumbnail.component";
import { FileSectionComponent } from "./file-section/file-section.component"; import { FileSectionComponent } from "./file-section/file-section.component";
import { CollectionsComponent } from "./collections/collections.component"; import { CollectionsComponent } from "./collections/collections.component";
@@ -28,7 +27,6 @@ import { CollectionsComponent } from "./collections/collections.component";
ItemPageUriFieldComponent, ItemPageUriFieldComponent,
ItemPageTitleFieldComponent, ItemPageTitleFieldComponent,
ItemPageSpecificFieldComponent, ItemPageSpecificFieldComponent,
ThumbnailComponent,
FileSectionComponent, FileSectionComponent,
CollectionsComponent CollectionsComponent
], ],

View File

@@ -8,6 +8,7 @@ import { Component, Input } from '@angular/core';
export class MetadataFieldWrapperComponent { export class MetadataFieldWrapperComponent {
@Input() label: string; @Input() label: string;
constructor() { constructor() {
this.universalInit(); this.universalInit();

View File

@@ -7,8 +7,12 @@ import { MetadataValuesComponent } from "../metadata-values/metadata-values.comp
templateUrl: './metadata-uri-values.component.html' templateUrl: './metadata-uri-values.component.html'
}) })
export class MetadataUriValuesComponent extends MetadataValuesComponent { export class MetadataUriValuesComponent extends MetadataValuesComponent {
@Input() linktext: any; @Input() linktext: any;
@Input() values: any; @Input() values: any;
@Input() separator: string; @Input() separator: string;
@Input() label: string; @Input() label: string;
} }

View File

@@ -8,7 +8,9 @@ import { Component, Input } from '@angular/core';
export class MetadataValuesComponent { export class MetadataValuesComponent {
@Input() values: any; @Input() values: any;
@Input() separator: string; @Input() separator: string;
@Input() label: string; @Input() label: string;
constructor() { constructor() {

View File

@@ -6,14 +6,16 @@ import { ItemPageSpecificFieldComponent } from "../item-page-specific-field.comp
selector: 'ds-item-page-abstract-field', selector: 'ds-item-page-abstract-field',
templateUrl: './../item-page-specific-field.component.html' templateUrl: './../item-page-specific-field.component.html'
}) })
export class ItemPageAbstractFieldComponent extends ItemPageSpecificFieldComponent implements OnInit { export class ItemPageAbstractFieldComponent extends ItemPageSpecificFieldComponent {
@Input() item: Item; @Input() item: Item;
separator : string; separator : string;
fields : string[] = [ fields : string[] = [
"dc.description.abstract" "dc.description.abstract"
]; ];
label : string = "item.page.abstract"; label : string = "item.page.abstract";
} }

View File

@@ -6,9 +6,10 @@ import { ItemPageSpecificFieldComponent } from "../item-page-specific-field.comp
selector: 'ds-item-page-author-field', selector: 'ds-item-page-author-field',
templateUrl: './../item-page-specific-field.component.html' templateUrl: './../item-page-specific-field.component.html'
}) })
export class ItemPageAuthorFieldComponent extends ItemPageSpecificFieldComponent implements OnInit { export class ItemPageAuthorFieldComponent extends ItemPageSpecificFieldComponent {
@Input() item: Item; @Input() item: Item;
separator : string; separator : string;
fields : string[] = [ fields : string[] = [
@@ -16,6 +17,7 @@ export class ItemPageAuthorFieldComponent extends ItemPageSpecificFieldComponent
"dc.creator", "dc.creator",
"dc.contributor" "dc.contributor"
]; ];
label : string = "item.page.author"; label : string = "item.page.author";
} }

View File

@@ -6,14 +6,16 @@ import { ItemPageSpecificFieldComponent } from "../item-page-specific-field.comp
selector: 'ds-item-page-date-field', selector: 'ds-item-page-date-field',
templateUrl: './../item-page-specific-field.component.html' templateUrl: './../item-page-specific-field.component.html'
}) })
export class ItemPageDateFieldComponent extends ItemPageSpecificFieldComponent implements OnInit { export class ItemPageDateFieldComponent extends ItemPageSpecificFieldComponent {
@Input() item: Item; @Input() item: Item;
separator : string = ", "; separator : string = ", ";
fields : string[] = [ fields : string[] = [
"dc.date.issued" "dc.date.issued"
]; ];
label : string = "item.page.date"; label : string = "item.page.date";
} }

View File

@@ -4,12 +4,14 @@ import { Item } from "../../core/shared/item.model";
@Component({ @Component({
templateUrl: './item-page-specific-field.component.html' templateUrl: './item-page-specific-field.component.html'
}) })
export class ItemPageSpecificFieldComponent implements OnInit { export class ItemPageSpecificFieldComponent {
@Input() item: Item; @Input() item: Item;
fields : string[]; fields : string[];
label : string; label : string;
separator : string = "<br/>"; separator : string = "<br/>";
constructor() { constructor() {
@@ -19,9 +21,4 @@ export class ItemPageSpecificFieldComponent implements OnInit {
universalInit() { universalInit() {
} }
ngOnInit(): void {
}
} }

View File

@@ -6,9 +6,10 @@ import { ItemPageSpecificFieldComponent } from "../item-page-specific-field.comp
selector: 'ds-item-page-title-field', selector: 'ds-item-page-title-field',
templateUrl: './item-page-title-field.component.html' templateUrl: './item-page-title-field.component.html'
}) })
export class ItemPageTitleFieldComponent extends ItemPageSpecificFieldComponent implements OnInit { export class ItemPageTitleFieldComponent extends ItemPageSpecificFieldComponent {
@Input() item: Item; @Input() item: Item;
separator : string; separator : string;
fields : string[] = [ fields : string[] = [

View File

@@ -6,15 +6,16 @@ import { ItemPageSpecificFieldComponent } from "../item-page-specific-field.comp
selector: 'ds-item-page-uri-field', selector: 'ds-item-page-uri-field',
templateUrl: './item-page-uri-field.component.html' templateUrl: './item-page-uri-field.component.html'
}) })
export class ItemPageUriFieldComponent extends ItemPageSpecificFieldComponent implements OnInit { export class ItemPageUriFieldComponent extends ItemPageSpecificFieldComponent {
@Input() item: Item; @Input() item: Item;
separator : string;
separator : string;
fields : string[] = [ fields : string[] = [
"dc.identifier.uri" "dc.identifier.uri"
]; ];
label : string = "item.page.uri"; label : string = "item.page.uri";
} }

View File

@@ -8,6 +8,8 @@ import { TranslateModule } from 'ng2-translate/ng2-translate';
import { ApiService } from './api.service'; import { ApiService } from './api.service';
import { FileSizePipe } from "./utils/file-size-pipe"; import { FileSizePipe } from "./utils/file-size-pipe";
import { ThumbnailComponent } from "../thumbnail/thumbnail.component";
import { SafeUrlPipe } from "./utils/safe-url-pipe";
const MODULES = [ const MODULES = [
// Do NOT include UniversalModule, HttpModule, or JsonpModule here // Do NOT include UniversalModule, HttpModule, or JsonpModule here
@@ -20,11 +22,13 @@ const MODULES = [
]; ];
const PIPES = [ const PIPES = [
FileSizePipe FileSizePipe,
SafeUrlPipe
// put pipes here // put pipes here
]; ];
const COMPONENTS = [ const COMPONENTS = [
ThumbnailComponent
// put shared components here // put shared components here
]; ];

View File

@@ -0,0 +1,10 @@
import { Pipe, PipeTransform } from '@angular/core';
import { DomSanitizer } from '@angular/platform-browser';
@Pipe({name: 'dsSafeUrl'})
export class SafeUrlPipe implements PipeTransform {
constructor(private domSanitizer: DomSanitizer) {}
transform(url) {
return this.domSanitizer.bypassSecurityTrustResourceUrl(url);
}
}

View File

@@ -1,3 +1,4 @@
<div class="thumbnail"> <div class="thumbnail">
<img [src]="thumbnail?.retrieve"/> <img *ngIf="thumbnail" [src]="thumbnail.retrieve"/>
<img *ngIf="!thumbnail" [src]="holderSource | dsSafeUrl"/>
</div> </div>

View File

@@ -1,6 +1,5 @@
import { Component, Input } from '@angular/core'; import { Component, Input, OnInit } from '@angular/core';
import { Bitstream } from "../core/shared/bitstream.model"; import { Bitstream } from "../core/shared/bitstream.model";
import { Observable } from "rxjs";
@Component({ @Component({
selector: 'ds-thumbnail', selector: 'ds-thumbnail',
@@ -9,12 +8,17 @@ import { Observable } from "rxjs";
}) })
export class ThumbnailComponent { export class ThumbnailComponent {
@Input() thumbnail : Observable<Bitstream>; @Input() thumbnail: Bitstream;
data: any = {}; data: any = {};
/**
* The default 'holder.js' image
*/
holderSource: string = "data:image/svg+xml;charset=UTF-8,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%2293%22%20height%3D%22120%22%20viewBox%3D%220%200%2093%20120%22%20preserveAspectRatio%3D%22none%22%3E%3C!--%0ASource%20URL%3A%20holder.js%2F93x120%3Ftext%3DNo%20Thumbnail%0ACreated%20with%20Holder.js%202.8.2.%0ALearn%20more%20at%20http%3A%2F%2Fholderjs.com%0A(c)%202012-2015%20Ivan%20Malopinsky%20-%20http%3A%2F%2Fimsky.co%0A--%3E%3Cdefs%3E%3Cstyle%20type%3D%22text%2Fcss%22%3E%3C!%5BCDATA%5B%23holder_1543e460b05%20text%20%7B%20fill%3A%23AAAAAA%3Bfont-weight%3Abold%3Bfont-family%3AArial%2C%20Helvetica%2C%20Open%20Sans%2C%20sans-serif%2C%20monospace%3Bfont-size%3A10pt%20%7D%20%5D%5D%3E%3C%2Fstyle%3E%3C%2Fdefs%3E%3Cg%20id%3D%22holder_1543e460b05%22%3E%3Crect%20width%3D%2293%22%20height%3D%22120%22%20fill%3D%22%23EEEEEE%22%2F%3E%3Cg%3E%3Ctext%20x%3D%2235.6171875%22%20y%3D%2257%22%3ENo%3C%2Ftext%3E%3Ctext%20x%3D%2210.8125%22%20y%3D%2272%22%3EThumbnail%3C%2Ftext%3E%3C%2Fg%3E%3C%2Fg%3E%3C%2Fsvg%3E";
constructor() { constructor() {
this.universalInit(); this.universalInit();
} }
universalInit() { universalInit() {