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 {
|
2016-06-24 23:44:05 +02:00
|
|
|
|
|
|
|
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() {
|
2016-06-24 23:44:05 +02:00
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
2016-06-24 23:44:05 +02:00
|
|
|
return this.replacementSizeCache;
|
2016-06-23 22:43:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
isReplacementThumbnailAvailable() {
|
|
|
|
return this.getReplacementThumbnailSize() !== null;
|
|
|
|
}
|
2016-06-24 23:44:05 +02:00
|
|
|
|
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-24 23:44:05 +02:00
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|