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

159 lines
4.6 KiB
TypeScript
Raw Normal View History

2017-03-20 07:01:41 +08:00
import {Component, Input, ElementRef, ViewChild, OnInit, OnDestroy} from "@angular/core";
2016-05-12 17:00:46 +08:00
import {IRenderable, Dimension} from "../../../model/IRenderable";
import {GridPhoto} from "../GridPhoto";
2016-05-16 17:03:11 +08:00
import {SearchTypes} from "../../../../../common/entities/AutoCompleteItem";
2016-12-27 06:36:38 +08:00
import {RouterLink} from "@angular/router";
2016-05-17 01:36:04 +08:00
import {Config} from "../../../config/Config";
import {Thumbnail, ThumbnailManagerService} from "../../thumnailManager.service";
2016-05-12 17:00:46 +08:00
@Component({
selector: 'gallery-grid-photo',
templateUrl: 'app/gallery/grid/photo/photo.grid.gallery.component.html',
styleUrls: ['app/gallery/grid/photo/photo.grid.gallery.component.css'],
2016-12-27 06:36:38 +08:00
providers: [RouterLink],
2016-05-12 17:00:46 +08:00
})
2017-03-20 07:01:41 +08:00
export class GalleryPhotoComponent implements IRenderable, OnInit, OnDestroy {
2016-12-27 06:36:38 +08:00
@Input() gridPhoto: GridPhoto;
@ViewChild("img") imageRef: ElementRef;
@ViewChild("info") infoDiv: ElementRef;
@ViewChild("photoContainer") container: ElementRef;
2016-05-12 17:00:46 +08:00
2017-03-20 07:01:41 +08:00
thumbnail: Thumbnail;
/*
image = {
src: '',
show: false
};
2016-06-24 04:25:16 +08:00
2017-03-20 07:01:41 +08:00
loading = {
animate: false,
show: true
};
*/
infoStyle = {
height: 0,
background: "rgba(0,0,0,0.0)"
};
2016-06-17 06:05:31 +08:00
2016-12-27 06:36:38 +08:00
SearchTypes: any = [];
searchEnabled: boolean = true;
2016-05-16 00:52:07 +08:00
2016-12-27 06:36:38 +08:00
wasInView: boolean = null;
2017-03-20 07:01:41 +08:00
constructor(private thumbnailService: ThumbnailManagerService) {
2016-05-16 17:03:11 +08:00
this.SearchTypes = SearchTypes;
2016-05-17 01:36:04 +08:00
this.searchEnabled = Config.Client.Search.searchEnabled;
2016-05-12 17:00:46 +08:00
}
ngOnInit() {
2017-03-20 07:01:41 +08:00
this.thumbnail = this.thumbnailService.getThumbnail(this.gridPhoto);
/* this.loading.show = true;
//set up before adding task to thumbnail generator
if (this.gridPhoto.isThumbnailAvailable()) {
this.image.src = this.gridPhoto.getThumbnailPath();
this.image.show = true;
} else if (this.gridPhoto.isReplacementThumbnailAvailable()) {
this.image.src = this.gridPhoto.getReplacementThumbnailPath();
this.image.show = true;
}*/
}
2017-03-20 07:01:41 +08:00
/*
ngAfterViewInit() {
//schedule change after Angular checks the model
if (!this.gridPhoto.isThumbnailAvailable()) {
setImmediate(() => {
let listener: ThumbnailLoadingListener = {
onStartedLoading: () => { //onLoadStarted
this.loading.animate = true;
},
onLoad: () => {//onLoaded
this.image.src = this.gridPhoto.getThumbnailPath();
this.image.show = true;
this.loading.show = false;
this.thumbnailTask = null;
},
onError: (error) => {//onError
this.thumbnailTask = null;
//TODO: handle error
//TODO: not an error if its from cache
console.error("something bad happened");
console.error(error);
}
};
if (this.gridPhoto.isReplacementThumbnailAvailable()) {
this.thumbnailTask = this.thumbnailService.loadImage(this.gridPhoto, ThumbnailLoadingPriority.medium, listener);
} else {
this.thumbnailTask = this.thumbnailService.loadImage(this.gridPhoto, ThumbnailLoadingPriority.high, listener);
}
});
}
}*/
2016-06-17 17:25:15 +08:00
ngOnDestroy() {
2017-03-20 07:01:41 +08:00
this.thumbnail.destroy();
/*
if (this.thumbnailTask != null) {
this.thumbnailService.removeTask(this.thumbnailTask);
this.thumbnailTask = null;
}*/
}
2016-12-27 06:36:38 +08:00
isInView(): boolean {
return document.body.scrollTop < this.container.nativeElement.offsetTop + this.container.nativeElement.clientHeight
&& document.body.scrollTop + window.innerHeight > this.container.nativeElement.offsetTop;
}
2016-06-25 20:13:06 +08:00
onScroll() {
2017-03-20 07:01:41 +08:00
let isInView = this.isInView();
if (this.wasInView != isInView) {
this.wasInView = isInView;
this.thumbnail.Visible = isInView;
}
}
2016-06-17 06:05:31 +08:00
2016-12-27 06:36:38 +08:00
getPositionText(): string {
2016-05-16 17:03:11 +08:00
if (!this.gridPhoto) {
return ""
}
return this.gridPhoto.photo.metadata.positionData.city ||
this.gridPhoto.photo.metadata.positionData.state ||
this.gridPhoto.photo.metadata.positionData.country;
}
2016-05-12 17:00:46 +08:00
2016-05-16 00:52:07 +08:00
hover() {
this.infoStyle.height = this.infoDiv.nativeElement.clientHeight;
this.infoStyle.background = "rgba(0,0,0,0.8)";
2016-05-16 17:03:11 +08:00
2016-05-12 17:00:46 +08:00
}
2016-05-16 00:52:07 +08:00
mouseOut() {
this.infoStyle.height = 0;
this.infoStyle.background = "rgba(0,0,0,0.0)";
2016-05-16 00:52:07 +08:00
}
2016-05-16 17:03:11 +08:00
2017-03-20 07:01:41 +08:00
/*
onImageLoad() {
this.loading.show = false;
}
*/
2016-12-27 06:36:38 +08:00
public getDimension(): Dimension {
2016-12-30 18:58:04 +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
}
}