2018-03-31 03:30:30 +08:00
|
|
|
import {Component, ElementRef, Input, OnDestroy, OnInit, ViewChild} from '@angular/core';
|
|
|
|
import {Dimension, IRenderable} from '../../../model/IRenderable';
|
2018-11-05 02:28:32 +08:00
|
|
|
import {GridMedia} from '../GridMedia';
|
2018-03-31 03:30:30 +08:00
|
|
|
import {SearchTypes} from '../../../../../common/entities/AutoCompleteItem';
|
|
|
|
import {RouterLink} from '@angular/router';
|
|
|
|
import {Thumbnail, ThumbnailManagerService} from '../../thumnailManager.service';
|
|
|
|
import {Config} from '../../../../../common/config/public/Config';
|
|
|
|
import {AnimationBuilder} from '@angular/animations';
|
2018-05-17 06:52:08 +08:00
|
|
|
import {PageHelper} from '../../../model/page.helper';
|
2018-11-18 02:32:31 +08:00
|
|
|
import {PhotoDTO} from '../../../../../common/entities/PhotoDTO';
|
2017-07-20 04:40:27 +08:00
|
|
|
|
2016-05-12 17:00:46 +08:00
|
|
|
@Component({
|
2018-05-04 07:17:08 +08:00
|
|
|
selector: 'app-gallery-grid-photo',
|
2017-06-11 04:32:56 +08:00
|
|
|
templateUrl: './photo.grid.gallery.component.html',
|
|
|
|
styleUrls: ['./photo.grid.gallery.component.css'],
|
2017-07-16 02:23:02 +08:00
|
|
|
providers: [RouterLink]
|
2016-05-12 17:00:46 +08:00
|
|
|
})
|
2017-06-11 04:32:56 +08:00
|
|
|
export class GalleryPhotoComponent implements IRenderable, OnInit, OnDestroy {
|
2018-11-05 02:28:32 +08:00
|
|
|
@Input() gridPhoto: GridMedia;
|
2018-03-31 03:30:30 +08:00
|
|
|
@ViewChild('img') imageRef: ElementRef;
|
|
|
|
@ViewChild('info') infoDiv: ElementRef;
|
|
|
|
@ViewChild('photoContainer') container: ElementRef;
|
2017-06-11 04:32:56 +08:00
|
|
|
|
|
|
|
thumbnail: Thumbnail;
|
2017-07-16 02:23:02 +08:00
|
|
|
infoBar = {
|
|
|
|
marginTop: 0,
|
|
|
|
visible: false,
|
2018-03-31 03:30:30 +08:00
|
|
|
background: 'rgba(0,0,0,0.0)'
|
2017-06-11 04:32:56 +08:00
|
|
|
};
|
2018-11-29 06:49:33 +08:00
|
|
|
animationTimer: number = null;
|
2017-06-11 04:32:56 +08:00
|
|
|
|
2018-11-29 06:49:33 +08:00
|
|
|
readonly SearchTypes: typeof SearchTypes;
|
2018-05-04 07:17:08 +08:00
|
|
|
searchEnabled = true;
|
2017-06-11 04:32:56 +08:00
|
|
|
|
|
|
|
wasInView: boolean = null;
|
|
|
|
|
2017-07-16 02:23:02 +08:00
|
|
|
constructor(private thumbnailService: ThumbnailManagerService,
|
|
|
|
private _animationBuilder: AnimationBuilder) {
|
2017-06-11 04:32:56 +08:00
|
|
|
this.SearchTypes = SearchTypes;
|
2017-07-14 05:39:09 +08:00
|
|
|
this.searchEnabled = Config.Client.Search.enabled;
|
2017-06-11 04:32:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
this.thumbnail = this.thumbnailService.getThumbnail(this.gridPhoto);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ngOnDestroy() {
|
|
|
|
this.thumbnail.destroy();
|
2017-07-20 04:40:27 +08:00
|
|
|
|
|
|
|
if (this.animationTimer != null) {
|
|
|
|
clearTimeout(this.animationTimer);
|
|
|
|
}
|
2017-06-11 04:32:56 +08:00
|
|
|
}
|
2016-05-12 17:00:46 +08:00
|
|
|
|
2016-05-16 17:03:11 +08:00
|
|
|
|
2017-06-11 04:32:56 +08:00
|
|
|
isInView(): boolean {
|
2018-05-17 06:52:08 +08:00
|
|
|
return PageHelper.ScrollY < this.container.nativeElement.offsetTop + this.container.nativeElement.clientHeight
|
|
|
|
&& PageHelper.ScrollY + window.innerHeight > this.container.nativeElement.offsetTop;
|
2017-06-11 04:32:56 +08:00
|
|
|
}
|
2016-05-12 17:00:46 +08:00
|
|
|
|
2018-05-17 06:52:08 +08:00
|
|
|
get ScrollListener(): boolean {
|
|
|
|
return !this.thumbnail.Available && !this.thumbnail.Error;
|
|
|
|
}
|
2016-05-16 00:52:07 +08:00
|
|
|
|
2017-06-11 04:32:56 +08:00
|
|
|
onScroll() {
|
2018-05-17 06:52:08 +08:00
|
|
|
if (this.thumbnail.Available === true || this.thumbnail.Error === true) {
|
2017-06-22 03:16:04 +08:00
|
|
|
return;
|
|
|
|
}
|
2018-05-04 07:17:08 +08:00
|
|
|
const isInView = this.isInView();
|
|
|
|
if (this.wasInView !== isInView) {
|
2017-06-11 04:32:56 +08:00
|
|
|
this.wasInView = isInView;
|
|
|
|
this.thumbnail.Visible = isInView;
|
2016-05-16 00:52:07 +08:00
|
|
|
}
|
2017-06-11 04:32:56 +08:00
|
|
|
}
|
2016-05-16 17:03:11 +08:00
|
|
|
|
2018-05-14 04:59:57 +08:00
|
|
|
|
2017-06-11 04:32:56 +08:00
|
|
|
getPositionText(): string {
|
2018-11-18 02:32:31 +08:00
|
|
|
if (!this.gridPhoto || !this.gridPhoto.isPhoto()) {
|
2018-03-31 03:30:30 +08:00
|
|
|
return '';
|
2016-05-12 17:00:46 +08:00
|
|
|
}
|
2018-11-18 02:32:31 +08:00
|
|
|
return (<PhotoDTO>this.gridPhoto.media).metadata.positionData.city ||
|
|
|
|
(<PhotoDTO>this.gridPhoto.media).metadata.positionData.state ||
|
|
|
|
(<PhotoDTO>this.gridPhoto.media).metadata.positionData.country;
|
2017-06-11 04:32:56 +08:00
|
|
|
}
|
|
|
|
|
2017-07-16 02:23:02 +08:00
|
|
|
|
2017-07-16 23:15:42 +08:00
|
|
|
mouseOver() {
|
2017-07-16 02:23:02 +08:00
|
|
|
this.infoBar.visible = true;
|
|
|
|
if (this.animationTimer != null) {
|
|
|
|
clearTimeout(this.animationTimer);
|
|
|
|
}
|
2018-11-29 06:49:33 +08:00
|
|
|
this.animationTimer = window.setTimeout(() => {
|
2018-03-31 03:30:30 +08:00
|
|
|
this.infoBar.background = 'rgba(0,0,0,0.8)';
|
2017-07-16 23:15:42 +08:00
|
|
|
if (!this.infoDiv) {
|
2018-11-29 06:49:33 +08:00
|
|
|
this.animationTimer = window.setTimeout(() => {
|
2017-07-16 23:15:42 +08:00
|
|
|
if (!this.infoDiv) {
|
|
|
|
this.infoBar.marginTop = -50;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.infoBar.marginTop = -this.infoDiv.nativeElement.clientHeight;
|
|
|
|
}, 10);
|
|
|
|
return;
|
|
|
|
}
|
2017-07-20 04:40:27 +08:00
|
|
|
this.infoBar.marginTop = -this.infoDiv.nativeElement.clientHeight;
|
2017-07-16 02:23:02 +08:00
|
|
|
}, 1);
|
2017-06-11 04:32:56 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
mouseOut() {
|
2017-07-16 02:23:02 +08:00
|
|
|
if (this.animationTimer != null) {
|
|
|
|
clearTimeout(this.animationTimer);
|
|
|
|
}
|
2018-11-29 06:49:33 +08:00
|
|
|
this.animationTimer = window.setTimeout(() => {
|
2018-05-08 03:42:32 +08:00
|
|
|
this.infoBar.marginTop = 0;
|
|
|
|
this.infoBar.background = 'rgba(0,0,0,0.0)';
|
|
|
|
if (this.animationTimer != null) {
|
|
|
|
clearTimeout(this.animationTimer);
|
|
|
|
}
|
2018-11-29 06:49:33 +08:00
|
|
|
this.animationTimer = window.setTimeout(() => {
|
2018-05-08 03:42:32 +08:00
|
|
|
this.infoBar.visible = false;
|
|
|
|
}, 500);
|
|
|
|
}, 100);
|
2017-06-11 04:32:56 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-12-06 20:50:55 +08:00
|
|
|
get Title(): string {
|
|
|
|
if (Config.Client.Other.captionFirstNaming === false) {
|
|
|
|
return this.gridPhoto.media.name;
|
|
|
|
}
|
|
|
|
if ((<PhotoDTO>this.gridPhoto.media).metadata.caption) {
|
|
|
|
if ((<PhotoDTO>this.gridPhoto.media).metadata.caption.length > 20) {
|
|
|
|
return (<PhotoDTO>this.gridPhoto.media).metadata.caption.substring(0, 17) + '...';
|
|
|
|
}
|
|
|
|
return (<PhotoDTO>this.gridPhoto.media).metadata.caption;
|
|
|
|
}
|
|
|
|
return this.gridPhoto.media.name;
|
|
|
|
}
|
|
|
|
|
2017-06-11 04:32:56 +08:00
|
|
|
/*
|
|
|
|
onImageLoad() {
|
|
|
|
this.loading.show = false;
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
public getDimension(): Dimension {
|
2017-06-23 04:07:47 +08:00
|
|
|
if (!this.imageRef) {
|
|
|
|
return <Dimension>{
|
|
|
|
top: 0,
|
|
|
|
left: 0,
|
|
|
|
width: 0,
|
|
|
|
height: 0
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-06-11 04:32:56 +08:00
|
|
|
return <Dimension>{
|
|
|
|
top: this.imageRef.nativeElement.offsetTop,
|
|
|
|
left: this.imageRef.nativeElement.offsetLeft,
|
|
|
|
width: this.imageRef.nativeElement.width,
|
|
|
|
height: this.imageRef.nativeElement.height
|
|
|
|
};
|
|
|
|
}
|
2016-05-12 17:00:46 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|