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

77 lines
2.5 KiB
TypeScript
Raw Normal View History

2018-03-30 15:30:30 -04:00
import {Component, ElementRef, Input, OnDestroy, OnInit, ViewChild} from '@angular/core';
import {DomSanitizer} from '@angular/platform-browser';
import {DirectoryDTO} from '../../../../common/entities/DirectoryDTO';
import {RouterLink} from '@angular/router';
import {Utils} from '../../../../common/Utils';
2018-11-04 19:28:32 +01:00
import {Media} from '../Media';
2018-03-30 15:30:30 -04:00
import {Thumbnail, ThumbnailManagerService} from '../thumnailManager.service';
2018-05-09 13:56:02 -04:00
import {PageHelper} from '../../model/page.helper';
import {QueryService} from '../../model/query.service';
2018-11-02 10:40:09 +01:00
import {PhotoDTO} from '../../../../common/entities/PhotoDTO';
2018-11-04 19:28:32 +01:00
import {MediaDTO} from '../../../../common/entities/MediaDTO';
2016-03-20 20:05:51 +01:00
@Component({
2018-05-03 19:17:08 -04:00
selector: 'app-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;
2018-03-30 15:30:30 -04:00
@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 queryService: QueryService) {
2017-07-03 19:17:49 +02:00
}
2016-03-20 20:05:51 +01:00
size: number = null;
2017-03-20 00:01:41 +01:00
2018-11-04 19:28:32 +01:00
public get SamplePhoto(): MediaDTO {
if (this.directory.media.length > 0) {
return this.directory.media[0];
2018-11-02 10:40:09 +01:00
}
return null;
}
2017-06-21 11:33:21 +02:00
getSanitizedThUrl() {
return this._sanitizer.bypassSecurityTrustStyle('url(' + encodeURI(this.thumbnail.Src).replace(/\(/g, '%28')
.replace(/\)/g, '%29') + ')');
2017-06-21 11:33:21 +02:00
}
// 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
ngOnInit() {
2018-11-04 19:28:32 +01:00
if (this.directory.media.length > 0) {
this.thumbnail = this.thumbnailService.getThumbnail(new Media(this.SamplePhoto, this.calcSize(), this.calcSize()));
}
}
2017-07-20 21:06:59 +02:00
calcSize() {
2018-05-09 13:56:02 -04:00
if (this.size == null || PageHelper.isScrollYVisible()) {
const size = 220 + 5;
const containerWidth = this.container.nativeElement.parentElement.parentElement.clientWidth;
this.size = containerWidth / Math.round((containerWidth / size));
}
return Math.floor(this.size - 5);
2017-07-20 21:06:59 +02:00
}
2016-03-20 20:05:51 +01:00
}