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

92 lines
3.0 KiB
TypeScript
Raw Normal View History

2016-05-12 17:00:46 +08:00
///<reference path="../../../../browser.d.ts"/>
2016-06-17 17:25:15 +08:00
import {Component, Input, ElementRef, ViewChild, AfterViewInit} 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";
import {RouterLink} from "@angular/router-deprecated";
2016-05-17 01:36:04 +08:00
import {Config} from "../../../config/Config";
2016-06-17 06:05:31 +08:00
import {ThumbnailLoaderService} from "../thumnailLoader.service";
2016-06-17 17:25:15 +08:00
import {GalleryPhotoLoadingComponent} from "./loading/loading.photo.grid.gallery.component";
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-06-17 17:25:15 +08:00
directives: [RouterLink, GalleryPhotoLoadingComponent],
2016-05-12 17:00:46 +08:00
})
2016-06-17 17:25:15 +08:00
export class GalleryPhotoComponent implements IRenderable, AfterViewInit {
2016-05-12 17:00:46 +08:00
@Input() gridPhoto:GridPhoto;
@ViewChild("image") imageRef:ElementRef;
2016-05-16 00:52:07 +08:00
@ViewChild("info") infoDiv:ElementRef;
2016-06-17 17:25:15 +08:00
@ViewChild(GalleryPhotoLoadingComponent) loading:GalleryPhotoLoadingComponent;
2016-05-12 17:00:46 +08:00
2016-06-17 06:05:31 +08:00
imageSrc = "#";
showImage = false;
infoStyle = {
height: 0,
background: ""
};
2016-06-17 06:05:31 +08:00
2016-05-16 17:03:11 +08:00
SearchTypes:any = [];
2016-05-17 01:36:04 +08:00
searchEnabled:boolean = true;
2016-05-16 00:52:07 +08:00
2016-06-17 06:05:31 +08:00
constructor(private thumbnailService:ThumbnailLoaderService) {
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
}
2016-06-17 17:25:15 +08:00
ngAfterViewInit() {
//schedule change after Angular checks the model
setImmediate(() => {
if (this.gridPhoto.isThumbnailAvailable()) {
2016-06-17 06:05:31 +08:00
this.imageSrc = this.gridPhoto.getThumbnailPath();
2016-06-17 17:25:15 +08:00
this.showImage = true;
} else {
this.thumbnailService.loadImage(this.gridPhoto,
()=> { //onLoadStarted
this.loading.startAnimation();
},
()=> {//onLoaded
this.imageSrc = this.gridPhoto.getThumbnailPath();
this.showImage = true;
},
()=> {//onError
console.error("something bad happened");
});
}
});
2016-06-17 06:05:31 +08:00
}
2016-06-17 17:25:15 +08:00
2016-06-17 06:05:31 +08:00
2016-05-16 17:03:11 +08:00
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;
}
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
2016-05-12 17:00:46 +08:00
public getDimension():Dimension {
return new Dimension(this.imageRef.nativeElement.offsetTop,
this.imageRef.nativeElement.offsetLeft,
this.imageRef.nativeElement.width,
this.imageRef.nativeElement.height);
}
}