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
2016-06-23 22:25:16 +02:00

105 lines
3.3 KiB
TypeScript

///<reference path="../../../../browser.d.ts"/>
import {Component, Input, ElementRef, ViewChild, AfterViewInit} from "@angular/core";
import {IRenderable, Dimension} from "../../../model/IRenderable";
import {GridPhoto} from "../GridPhoto";
import {SearchTypes} from "../../../../../common/entities/AutoCompleteItem";
import {RouterLink} from "@angular/router-deprecated";
import {Config} from "../../../config/Config";
import {ThumbnailLoaderService} from "../thumnailLoader.service";
import {GalleryPhotoLoadingComponent} from "./loading/loading.photo.grid.gallery.component";
@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'],
directives: [RouterLink, GalleryPhotoLoadingComponent],
})
export class GalleryPhotoComponent implements IRenderable, AfterViewInit {
@Input() gridPhoto:GridPhoto;
@ViewChild("img") imageRef:ElementRef;
@ViewChild("info") infoDiv:ElementRef;
image = {
src: "#",
show: false
};
loading = {
animate: false,
show: false
};
infoStyle = {
height: 0,
background: "rgba(0,0,0,0.0)"
};
SearchTypes:any = [];
searchEnabled:boolean = true;
constructor(private thumbnailService:ThumbnailLoaderService) {
this.SearchTypes = SearchTypes;
this.searchEnabled = Config.Client.Search.searchEnabled;
}
ngAfterViewInit() {
//schedule change after Angular checks the model
setImmediate(() => {
if (this.gridPhoto.isThumbnailAvailable()) {
this.image.src = this.gridPhoto.getThumbnailPath();
this.image.show = true;
this.loading.show = false;
} else {
this.loading.show = true;
this.thumbnailService.loadImage(this.gridPhoto,
()=> { //onLoadStarted
this.loading.animate = true;
},
()=> {//onLoaded
this.image.src = this.gridPhoto.getThumbnailPath();
this.image.show = true;
this.loading.show = false;
},
(error)=> {//onError
//TODO: handle error
console.error("something bad happened");
console.error(error);
});
}
});
}
getPositionText():string {
if (!this.gridPhoto) {
return ""
}
return this.gridPhoto.photo.metadata.positionData.city ||
this.gridPhoto.photo.metadata.positionData.state ||
this.gridPhoto.photo.metadata.positionData.country;
}
hover() {
this.infoStyle.height = this.infoDiv.nativeElement.clientHeight;
this.infoStyle.background = "rgba(0,0,0,0.8)";
}
mouseOut() {
this.infoStyle.height = 0;
this.infoStyle.background = "rgba(0,0,0,0.0)";
}
public getDimension():Dimension {
return new Dimension(this.imageRef.nativeElement.offsetTop,
this.imageRef.nativeElement.offsetLeft,
this.imageRef.nativeElement.width,
this.imageRef.nativeElement.height);
}
}