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

77 lines
2.5 KiB
TypeScript
Raw Normal View History

2016-05-12 17:00:46 +08: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-06-26 17:08:05 +08:00
constructor(public photo:Photo, public renderWidth:number, public renderHeight:number, public rowId:number) {
2016-05-12 17:00:46 +08:00
}
2016-06-17 06:05:31 +08:00
thumbnailLoaded() {
if (!this.isThumbnailAvailable()) {
this.photo.readyThumbnails.push(this.getThumbnailSize());
}
}
getThumbnailSize() {
2016-05-12 17:00:46 +08:00
let renderSize = Math.sqrt(this.renderWidth * this.renderHeight);
2016-06-17 06:05:31 +08:00
return Utils.findClosest(renderSize, Config.Client.thumbnailSizes);
}
2016-06-24 04:43:23 +08: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-24 04:43:23 +08:00
}
}
return this.replacementSizeCache;
2016-06-24 04:43:23 +08:00
}
isReplacementThumbnailAvailable() {
return this.getReplacementThumbnailSize() !== null;
}
2016-06-17 06:05:31 +08:00
isThumbnailAvailable() {
return this.photo.readyThumbnails.indexOf(this.getThumbnailSize()) != -1;
}
2016-06-24 04:43:23 +08: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 06:05:31 +08:00
getThumbnailPath() {
let size = this.getThumbnailSize();
2016-05-12 17:00:46 +08: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 17:08:05 +08: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 17:00:46 +08:00
}