1
0
mirror of https://github.com/bpatrik/pigallery2.git synced 2024-12-16 11:37:13 +02:00
pigallery2/frontend/app/gallery/grid/GridPhoto.ts

62 lines
2.0 KiB
TypeScript
Raw Normal View History

2016-05-12 11:00:46 +02:00
import {Photo} from "../../../../common/entities/Photo";
import {Config} from "../../config/Config";
import {Utils} from "../../../../common/Utils";
export class GridPhoto {
private replacementSizeCache:boolean|number = false;
2016-05-12 11:00:46 +02:00
constructor(public photo:Photo, public renderWidth:number, public renderHeight:number) {
}
2016-06-17 00:05:31 +02:00
thumbnailLoaded() {
if (!this.isThumbnailAvailable()) {
this.photo.readyThumbnails.push(this.getThumbnailSize());
}
}
getThumbnailSize() {
2016-05-12 11:00:46 +02:00
let renderSize = Math.sqrt(this.renderWidth * this.renderHeight);
2016-06-17 00:05:31 +02:00
return Utils.findClosest(renderSize, Config.Client.thumbnailSizes);
}
2016-06-23 22:43:23 +02:00
getReplacementThumbnailSize() {
if (this.replacementSizeCache === false) {
this.replacementSizeCache = null;
let size = this.getThumbnailSize();
for (let i = 0; i < this.photo.readyThumbnails.length; i++) {
if (this.photo.readyThumbnails[i] < size) {
this.replacementSizeCache = this.photo.readyThumbnails[i];
break;
}
2016-06-23 22:43:23 +02:00
}
}
return this.replacementSizeCache;
2016-06-23 22:43:23 +02:00
}
isReplacementThumbnailAvailable() {
return this.getReplacementThumbnailSize() !== null;
}
2016-06-17 00:05:31 +02:00
isThumbnailAvailable() {
return this.photo.readyThumbnails.indexOf(this.getThumbnailSize()) != -1;
}
2016-06-23 22:43:23 +02:00
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());
}
2016-06-17 00:05:31 +02:00
getThumbnailPath() {
let size = this.getThumbnailSize();
2016-05-12 11:00:46 +02:00
return Utils.concatUrls("/api/gallery/content/", this.photo.directory.path, this.photo.directory.name, this.photo.name, "thumbnail", size.toString());
}
getPhotoPath() {
return Utils.concatUrls("/api/gallery/content/", this.photo.directory.path, this.photo.directory.name, this.photo.name);
}
}