2018-03-31 03:30:30 +08:00
|
|
|
import {Component, ElementRef, Input, OnChanges} from '@angular/core';
|
|
|
|
import {GridPhoto} from '../../grid/GridPhoto';
|
2018-11-02 17:40:09 +08:00
|
|
|
import {PhotoDTO} from '../../../../../common/entities/PhotoDTO';
|
|
|
|
import {FixOrientationPipe} from '../../FixOrientationPipe';
|
2016-05-13 20:27:00 +08:00
|
|
|
|
|
|
|
@Component({
|
2018-05-04 07:17:08 +08:00
|
|
|
selector: 'app-gallery-lightbox-photo',
|
2017-06-11 04:32:56 +08:00
|
|
|
styleUrls: ['./photo.lightbox.gallery.component.css'],
|
|
|
|
templateUrl: './photo.lightbox.gallery.component.html'
|
2016-05-13 20:27:00 +08:00
|
|
|
})
|
|
|
|
export class GalleryLightboxPhotoComponent implements OnChanges {
|
|
|
|
|
2017-06-11 04:32:56 +08:00
|
|
|
@Input() gridPhoto: GridPhoto;
|
2018-05-04 06:23:48 +08:00
|
|
|
@Input() loadImage = false;
|
|
|
|
@Input() windowAspect = 1;
|
2018-11-02 17:40:09 +08:00
|
|
|
prevGirdPhoto = null;
|
2016-05-13 20:27:00 +08:00
|
|
|
|
2018-03-31 03:30:30 +08:00
|
|
|
public imageSize = {width: 'auto', height: '100'};
|
2016-05-13 20:27:00 +08:00
|
|
|
|
2018-11-02 17:40:09 +08:00
|
|
|
private imageLoaded = false;
|
2018-05-04 06:23:48 +08:00
|
|
|
public imageLoadFinished = false;
|
2016-05-13 20:27:00 +08:00
|
|
|
|
2018-11-02 17:40:09 +08:00
|
|
|
thumbnailSrc: string = null;
|
|
|
|
photoSrc: string = null;
|
|
|
|
|
2017-07-16 16:59:28 +08:00
|
|
|
constructor(public elementRef: ElementRef) {
|
2017-06-11 04:32:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ngOnChanges() {
|
|
|
|
this.imageLoaded = false;
|
2017-07-28 06:04:19 +08:00
|
|
|
this.imageLoadFinished = false;
|
2017-06-11 04:32:56 +08:00
|
|
|
this.setImageSize();
|
2018-11-02 17:40:09 +08:00
|
|
|
if (this.prevGirdPhoto !== this.gridPhoto) {
|
|
|
|
this.prevGirdPhoto = this.gridPhoto;
|
|
|
|
this.thumbnailSrc = null;
|
|
|
|
this.photoSrc = null;
|
|
|
|
}
|
|
|
|
if (this.thumbnailSrc == null && this.gridPhoto && this.ThumbnailUrl !== null) {
|
|
|
|
FixOrientationPipe.transform(this.ThumbnailUrl, this.gridPhoto.photo.metadata.orientation)
|
|
|
|
.then((src) => this.thumbnailSrc = src);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.photoSrc == null && this.gridPhoto && this.loadImage) {
|
|
|
|
FixOrientationPipe.transform(this.gridPhoto.getPhotoPath(), this.gridPhoto.photo.metadata.orientation)
|
|
|
|
.then((src) => this.thumbnailSrc = src);
|
|
|
|
}
|
2017-06-11 04:32:56 +08:00
|
|
|
}
|
2016-07-04 22:58:10 +08:00
|
|
|
|
2018-03-31 03:30:30 +08:00
|
|
|
onImageError() {
|
2018-05-04 06:23:48 +08:00
|
|
|
// TODO:handle error
|
2018-03-31 03:30:30 +08:00
|
|
|
this.imageLoadFinished = true;
|
2018-11-02 17:40:09 +08:00
|
|
|
console.error('Error: cannot load image for lightbox url: ' + this.gridPhoto.getPhotoPath());
|
2017-06-11 04:32:56 +08:00
|
|
|
}
|
2016-05-13 20:27:00 +08:00
|
|
|
|
2016-07-04 22:58:10 +08:00
|
|
|
|
2017-06-11 04:32:56 +08:00
|
|
|
onImageLoad() {
|
2017-07-28 06:04:19 +08:00
|
|
|
this.imageLoadFinished = true;
|
2017-06-11 04:32:56 +08:00
|
|
|
this.imageLoaded = true;
|
|
|
|
}
|
2016-07-04 22:58:10 +08:00
|
|
|
|
2018-11-02 17:40:09 +08:00
|
|
|
private get ThumbnailUrl(): string {
|
2018-05-04 06:23:48 +08:00
|
|
|
if (this.gridPhoto.isThumbnailAvailable() === true) {
|
2018-03-31 03:30:30 +08:00
|
|
|
return this.gridPhoto.getThumbnailPath();
|
2018-05-04 06:23:48 +08:00
|
|
|
}
|
2018-03-31 03:30:30 +08:00
|
|
|
|
2018-05-04 06:23:48 +08:00
|
|
|
if (this.gridPhoto.isReplacementThumbnailAvailable() === true) {
|
2018-03-31 03:30:30 +08:00
|
|
|
return this.gridPhoto.getReplacementThumbnailPath();
|
2018-05-04 06:23:48 +08:00
|
|
|
}
|
2018-03-31 03:30:30 +08:00
|
|
|
return null;
|
2017-06-11 04:32:56 +08:00
|
|
|
}
|
2016-07-04 22:58:10 +08:00
|
|
|
|
2018-11-02 17:40:09 +08:00
|
|
|
public get PhotoSrc(): string {
|
|
|
|
return this.gridPhoto.getPhotoPath();
|
|
|
|
}
|
|
|
|
|
2017-06-11 04:32:56 +08:00
|
|
|
public showThumbnail(): boolean {
|
2018-11-02 17:40:09 +08:00
|
|
|
return this.gridPhoto &&
|
|
|
|
!this.imageLoaded &&
|
|
|
|
this.thumbnailSrc !== null &&
|
2017-06-11 04:32:56 +08:00
|
|
|
(this.gridPhoto.isThumbnailAvailable() || this.gridPhoto.isReplacementThumbnailAvailable());
|
|
|
|
}
|
2016-07-04 22:58:10 +08:00
|
|
|
|
2018-03-31 03:30:30 +08:00
|
|
|
private setImageSize() {
|
|
|
|
if (!this.gridPhoto) {
|
|
|
|
return;
|
|
|
|
}
|
2016-07-04 22:58:10 +08:00
|
|
|
|
2018-03-31 03:30:30 +08:00
|
|
|
|
2018-11-02 17:40:09 +08:00
|
|
|
const photoAspect = PhotoDTO.calcRotatedAspectRatio(this.gridPhoto.photo);
|
2018-03-31 03:30:30 +08:00
|
|
|
|
|
|
|
if (photoAspect < this.windowAspect) {
|
|
|
|
this.imageSize.height = '100';
|
|
|
|
this.imageSize.width = null;
|
|
|
|
} else {
|
|
|
|
this.imageSize.height = null;
|
|
|
|
this.imageSize.width = '100';
|
|
|
|
}
|
2017-06-11 04:32:56 +08:00
|
|
|
}
|
2016-07-04 22:58:10 +08:00
|
|
|
|
2016-05-13 20:27:00 +08:00
|
|
|
}
|
|
|
|
|