2017-03-20 07:01:41 +08:00
|
|
|
import {Component, Input, OnInit, OnDestroy, ViewChild, ElementRef} from "@angular/core";
|
2016-12-28 03:55:51 +08:00
|
|
|
import {DirectoryDTO} from "../../../../common/entities/DirectoryDTO";
|
2016-12-27 06:36:38 +08:00
|
|
|
import {RouterLink} from "@angular/router";
|
2016-03-27 02:24:12 +08:00
|
|
|
import {Utils} from "../../../../common/Utils";
|
2017-03-18 07:11:53 +08:00
|
|
|
import {Photo} from "../Photo";
|
2017-03-20 07:01:41 +08:00
|
|
|
import {Thumbnail, ThumbnailManagerService} from "../grid/thumnailManager.service";
|
2016-03-21 03:05:51 +08:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'gallery-directory',
|
2016-03-26 23:25:48 +08:00
|
|
|
templateUrl: 'app/gallery/directory/directory.gallery.component.html',
|
2017-03-18 07:11:53 +08:00
|
|
|
styleUrls: ['app/gallery/directory/directory.gallery.component.css'],
|
2016-12-27 06:36:38 +08:00
|
|
|
providers: [RouterLink],
|
2016-03-21 03:05:51 +08:00
|
|
|
})
|
2017-03-20 07:01:41 +08:00
|
|
|
export class GalleryDirectoryComponent implements OnInit,OnDestroy {
|
2016-12-28 03:55:51 +08:00
|
|
|
@Input() directory: DirectoryDTO;
|
2017-03-20 07:01:41 +08:00
|
|
|
@ViewChild("dirContainer") container: ElementRef;
|
|
|
|
thumbnail: Thumbnail = null;
|
2016-05-09 23:04:56 +08:00
|
|
|
|
2017-03-20 07:01:41 +08:00
|
|
|
constructor(private thumbnailService: ThumbnailManagerService) {
|
2016-03-21 03:05:51 +08:00
|
|
|
}
|
|
|
|
|
2017-03-20 07:01:41 +08:00
|
|
|
ngOnInit() {
|
|
|
|
if (this.directory.photos.length > 0) {
|
|
|
|
this.thumbnail = this.thumbnailService.getThumbnail(new Photo(this.directory.photos[0], 100, 100));
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//TODO: implement scroll
|
|
|
|
isInView(): boolean {
|
|
|
|
return document.body.scrollTop < this.container.nativeElement.offsetTop + this.container.nativeElement.clientHeight
|
|
|
|
&& document.body.scrollTop + window.innerHeight > this.container.nativeElement.offsetTop;
|
2017-03-18 07:11:53 +08:00
|
|
|
}
|
|
|
|
|
2016-05-09 23:04:56 +08:00
|
|
|
getDirectoryPath() {
|
|
|
|
return Utils.concatUrls(this.directory.path, this.directory.name);
|
2016-03-27 02:24:12 +08:00
|
|
|
}
|
|
|
|
|
2017-03-20 07:01:41 +08:00
|
|
|
ngOnDestroy() {
|
|
|
|
if (this.thumbnail != null) {
|
|
|
|
this.thumbnail.destroy();
|
|
|
|
}
|
|
|
|
}
|
2016-05-09 23:04:56 +08:00
|
|
|
|
2016-03-21 03:05:51 +08:00
|
|
|
}
|
|
|
|
|