1
0
mirror of https://github.com/xuthus83/pigallery2.git synced 2025-01-14 14:43:17 +08:00
pigallery2/frontend/app/gallery/directory/directory.gallery.component.ts

55 lines
1.8 KiB
TypeScript
Raw Normal View History

import {Component, ElementRef, Input, OnDestroy, OnInit, ViewChild} from "@angular/core";
2017-06-21 11:33:21 +02:00
import {DomSanitizer} from "@angular/platform-browser";
2016-12-27 20:55:51 +01:00
import {DirectoryDTO} from "../../../../common/entities/DirectoryDTO";
2016-12-26 23:36:38 +01:00
import {RouterLink} from "@angular/router";
2016-03-26 19:24:12 +01:00
import {Utils} from "../../../../common/Utils";
2017-03-18 00:11:53 +01:00
import {Photo} from "../Photo";
import {Thumbnail, ThumbnailManagerService} from "../thumnailManager.service";
2017-07-03 19:17:49 +02:00
import {ShareService} from "../share.service";
2016-03-20 20:05:51 +01:00
@Component({
selector: 'gallery-directory',
templateUrl: './directory.gallery.component.html',
styleUrls: ['./directory.gallery.component.css'],
providers: [RouterLink],
2016-03-20 20:05:51 +01:00
})
export class GalleryDirectoryComponent implements OnInit, OnDestroy {
@Input() directory: DirectoryDTO;
@ViewChild("dirContainer") container: ElementRef;
thumbnail: Thumbnail = null;
2016-05-09 17:04:56 +02:00
2017-07-03 19:17:49 +02:00
constructor(private thumbnailService: ThumbnailManagerService,
private _sanitizer: DomSanitizer,
public _shareService: ShareService) {
}
2016-03-20 20:05:51 +01:00
ngOnInit() {
if (this.directory.photos.length > 0) {
this.thumbnail = this.thumbnailService.getThumbnail(new Photo(this.directory.photos[0], 100, 100));
2017-03-20 00:01:41 +01:00
}
}
2017-03-20 00:01:41 +01:00
2017-06-21 11:33:21 +02:00
getSanitizedThUrl() {
return this._sanitizer.bypassSecurityTrustStyle('url(' + encodeURI(this.thumbnail.Src).replace(/\(/g, "%28").replace(/\)/g, "%29") + ')');
}
//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 00:11:53 +01:00
getDirectoryPath() {
return Utils.concatUrls(this.directory.path, this.directory.name);
}
2016-03-26 19:24:12 +01:00
ngOnDestroy() {
if (this.thumbnail != null) {
this.thumbnail.destroy();
2017-03-20 00:01:41 +01:00
}
}
2016-05-09 17:04:56 +02:00
2016-03-20 20:05:51 +01:00
}