2016-12-27 21:55:51 +02:00
|
|
|
import {PhotoDTO} from "../../../../common/entities/PhotoDTO";
|
2016-05-12 11:00:46 +02:00
|
|
|
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-12-27 21:55:51 +02:00
|
|
|
constructor(public photo: PhotoDTO, public renderWidth: number, public renderHeight: number, public rowId: number) {
|
2016-05-12 11:00:46 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-06-17 00:05:31 +02:00
|
|
|
|
|
|
|
thumbnailLoaded() {
|
|
|
|
if (!this.isThumbnailAvailable()) {
|
2016-12-30 12:58:04 +02:00
|
|
|
this.photo.readyThumbnails = this.photo.readyThumbnails || [];
|
2016-06-17 00:05:31 +02:00
|
|
|
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();
|
2016-12-28 16:52:27 +02:00
|
|
|
if (!!this.photo.readyThumbnails) {
|
|
|
|
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-24 23:44:05 +02:00
|
|
|
}
|
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() {
|
2016-12-28 16:52:27 +02:00
|
|
|
return this.photo.readyThumbnails && this.photo.readyThumbnails.indexOf(this.getThumbnailSize()) != -1;
|
2016-06-17 00:05:31 +02:00
|
|
|
}
|
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);
|
|
|
|
}
|
2016-06-26 11:08:05 +02:00
|
|
|
|
|
|
|
|
|
|
|
equals(other:any) {
|
|
|
|
//is gridphoto
|
|
|
|
if (other.photo) {
|
|
|
|
return this.photo.directory.path === other.photo.directory.path && this.photo.directory.name === other.photo.directory.name && this.photo.name === other.photo.name
|
|
|
|
}
|
|
|
|
|
|
|
|
//is photo
|
|
|
|
if (other.directory) {
|
|
|
|
return this.photo.directory.path === other.directory.path && this.photo.directory.name === other.directory.name && this.photo.name === other.name
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2016-05-12 11:00:46 +02:00
|
|
|
}
|