1
0
mirror of https://github.com/bpatrik/pigallery2.git synced 2024-11-24 08:42:24 +02:00

improving thumbnail loading

This commit is contained in:
Braun Patrik 2016-06-23 22:43:23 +02:00
parent 1de7dabe52
commit 12c8c912f1
2 changed files with 37 additions and 1 deletions

View File

@ -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();

View File

@ -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,