From 12c8c912f1059d4b35bb8be969e2f64dc2bcc0ef Mon Sep 17 00:00:00 2001 From: Braun Patrik Date: Thu, 23 Jun 2016 22:43:23 +0200 Subject: [PATCH] improving thumbnail loading --- frontend/app/gallery/grid/GridPhoto.ts | 20 +++++++++++++++++++ .../photo/photo.grid.gallery.component.ts | 18 ++++++++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/frontend/app/gallery/grid/GridPhoto.ts b/frontend/app/gallery/grid/GridPhoto.ts index 49449210..d4c56b22 100644 --- a/frontend/app/gallery/grid/GridPhoto.ts +++ b/frontend/app/gallery/grid/GridPhoto.ts @@ -18,9 +18,29 @@ export class GridPhoto { return Utils.findClosest(renderSize, Config.Client.thumbnailSizes); } + getReplacementThumbnailSize() { + let size = this.getThumbnailSize(); + for (let i = 0; i < this.photo.readyThumbnails.length; i++) { + if (this.photo.readyThumbnails[i] < size) { + return this.photo.readyThumbnails[i]; + } + } + return null; + } + + isReplacementThumbnailAvailable() { + return this.getReplacementThumbnailSize() !== null; + } + isThumbnailAvailable() { return this.photo.readyThumbnails.indexOf(this.getThumbnailSize()) != -1; } + + getReplacementThumbnailPath() { + let size = this.getReplacementThumbnailSize(); + return Utils.concatUrls("/api/gallery/content/", this.photo.directory.path, this.photo.directory.name, this.photo.name, "thumbnail", size.toString()); + + } getThumbnailPath() { let size = this.getThumbnailSize(); diff --git a/frontend/app/gallery/grid/photo/photo.grid.gallery.component.ts b/frontend/app/gallery/grid/photo/photo.grid.gallery.component.ts index faa70d8b..418875ec 100644 --- a/frontend/app/gallery/grid/photo/photo.grid.gallery.component.ts +++ b/frontend/app/gallery/grid/photo/photo.grid.gallery.component.ts @@ -22,7 +22,7 @@ export class GalleryPhotoComponent implements IRenderable, AfterViewInit { image = { - src: "#", + src: '', show: false }; @@ -51,6 +51,22 @@ export class GalleryPhotoComponent implements IRenderable, AfterViewInit { this.image.src = this.gridPhoto.getThumbnailPath(); this.image.show = true; this.loading.show = false; + } else if (this.gridPhoto.isReplacementThumbnailAvailable()) { + + this.image.src = this.gridPhoto.getReplacementThumbnailPath(); + this.image.show = true; + this.loading.show = false; + this.thumbnailService.loadImage(this.gridPhoto, + ()=> { //onLoadStarted + }, + ()=> {//onLoaded + this.image.src = this.gridPhoto.getThumbnailPath(); + }, + (error)=> {//onError + //TODO: handle error + console.error("something bad happened"); + console.error(error); + }); } else { this.loading.show = true; this.thumbnailService.loadImage(this.gridPhoto,