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