1
0
mirror of https://github.com/xuthus83/pigallery2.git synced 2024-11-03 21:04:03 +08:00
pigallery2/frontend/app/gallery/Photo.ts

63 lines
2.1 KiB
TypeScript
Raw Normal View History

2017-03-18 07:11:53 +08:00
import {PhotoDTO} from "../../../common/entities/PhotoDTO";
import {Utils} from "../../../common/Utils";
import {IconPhoto} from "./IconPhoto";
2017-06-04 21:25:08 +08:00
import {Config} from "../../../common/config/public/Config";
export class Photo extends IconPhoto {
2017-03-18 07:11:53 +08:00
constructor(photo: PhotoDTO, public renderWidth: number, public renderHeight: number) {
super(photo);
2017-03-18 07:11:53 +08:00
}
thumbnailLoaded() {
if (!this.isThumbnailAvailable()) {
this.photo.readyThumbnails = this.photo.readyThumbnails || [];
this.photo.readyThumbnails.push(this.getThumbnailSize());
}
}
getThumbnailSize() {
let renderSize = Math.sqrt(this.renderWidth * this.renderHeight);
return Utils.findClosest(renderSize, Config.Client.thumbnailSizes);
}
getReplacementThumbnailSize(): number {
2017-03-18 07:11:53 +08:00
if (this.replacementSizeCache === false) {
this.replacementSizeCache = null;
let size = this.getThumbnailSize();
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;
}
}
}
}
return <number>this.replacementSizeCache;
2017-03-18 07:11:53 +08:00
}
isReplacementThumbnailAvailable() {
return this.getReplacementThumbnailSize() !== null;
}
isThumbnailAvailable() {
return this.photo.readyThumbnails && 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();
return Utils.concatUrls("/api/gallery/content/", this.photo.directory.path, this.photo.directory.name, this.photo.name, "thumbnail", size.toString());
}
}