From 88a2460d48135a973b1c8ee6b86124afa08cc61f Mon Sep 17 00:00:00 2001 From: "Patrik J. Braun" Date: Sat, 20 Jul 2019 00:29:16 +0200 Subject: [PATCH] performance improvements --- .../gallery/grid/grid.gallery.component.html | 2 +- .../photo/photo.grid.gallery.component.css | 42 +++++++++-- .../photo/photo.grid.gallery.component.html | 16 ++--- .../photo/photo.grid.gallery.component.ts | 69 +++++-------------- .../controls.lightbox.gallery.component.html | 22 +++--- .../controls.lightbox.gallery.component.ts | 24 +++---- .../lightbox/lightbox.gallery.component.html | 6 +- .../lightbox/lightbox.gallery.component.ts | 30 ++++---- 8 files changed, 105 insertions(+), 106 deletions(-) diff --git a/frontend/app/ui/gallery/grid/grid.gallery.component.html b/frontend/app/ui/gallery/grid/grid.gallery.component.html index e096580..da8e4c6 100644 --- a/frontend/app/ui/gallery/grid/grid.gallery.component.html +++ b/frontend/app/ui/gallery/grid/grid.gallery.component.html @@ -2,7 +2,7 @@ - {{gridPhoto.media.name}} -
- {{gridPhoto.Video.metadata.duration | duration}}
+ {{gridMedia.Video.metadata.duration | duration}} -
{{Title}}
-
+ diff --git a/frontend/app/ui/gallery/grid/photo/photo.grid.gallery.component.ts b/frontend/app/ui/gallery/grid/photo/photo.grid.gallery.component.ts index caec2a0..ffb9a25 100644 --- a/frontend/app/ui/gallery/grid/photo/photo.grid.gallery.component.ts +++ b/frontend/app/ui/gallery/grid/photo/photo.grid.gallery.component.ts @@ -15,18 +15,13 @@ import {PhotoDTO, PhotoMetadata} from '../../../../../../common/entities/PhotoDT providers: [RouterLink] }) export class GalleryPhotoComponent implements IRenderable, OnInit, OnDestroy { - @Input() gridPhoto: GridMedia; + @Input() gridMedia: GridMedia; @ViewChild('img', {static: false}) imageRef: ElementRef; - @ViewChild('info', {static: false}) infoDiv: ElementRef; @ViewChild('photoContainer', {static: true}) container: ElementRef; thumbnail: Thumbnail; keywords: { value: string, type: SearchTypes }[] = null; - infoBar = { - marginTop: 0, - visible: false, - background: 'rgba(0,0,0,0.0)' - }; + infoBarVisible = false; animationTimer: number = null; readonly SearchTypes: typeof SearchTypes; @@ -46,20 +41,20 @@ export class GalleryPhotoComponent implements IRenderable, OnInit, OnDestroy { get Title(): string { if (Config.Client.Other.captionFirstNaming === false) { - return this.gridPhoto.media.name; + return this.gridMedia.media.name; } - if ((this.gridPhoto.media).metadata.caption) { - if ((this.gridPhoto.media).metadata.caption.length > 20) { - return (this.gridPhoto.media).metadata.caption.substring(0, 17) + '...'; + if ((this.gridMedia.media).metadata.caption) { + if ((this.gridMedia.media).metadata.caption.length > 20) { + return (this.gridMedia.media).metadata.caption.substring(0, 17) + '...'; } - return (this.gridPhoto.media).metadata.caption; + return (this.gridMedia.media).metadata.caption; } - return this.gridPhoto.media.name; + return this.gridMedia.media.name; } ngOnInit() { - this.thumbnail = this.thumbnailService.getThumbnail(this.gridPhoto); - const metadata = this.gridPhoto.media.metadata as PhotoMetadata; + this.thumbnail = this.thumbnailService.getThumbnail(this.gridMedia); + const metadata = this.gridMedia.media.metadata as PhotoMetadata; if ((metadata.keywords && metadata.keywords.length > 0) || (metadata.faces && metadata.faces.length > 0)) { const names: string[] = (metadata.faces || []).map(f => f.name); @@ -95,34 +90,20 @@ export class GalleryPhotoComponent implements IRenderable, OnInit, OnDestroy { } getPositionText(): string { - if (!this.gridPhoto || !this.gridPhoto.isPhoto()) { + if (!this.gridMedia || !this.gridMedia.isPhoto()) { return ''; } - return (this.gridPhoto.media).metadata.positionData.city || - (this.gridPhoto.media).metadata.positionData.state || - (this.gridPhoto.media).metadata.positionData.country; + return (this.gridMedia.media).metadata.positionData.city || + (this.gridMedia.media).metadata.positionData.state || + (this.gridMedia.media).metadata.positionData.country; } mouseOver() { - this.infoBar.visible = true; + this.infoBarVisible = true; if (this.animationTimer != null) { clearTimeout(this.animationTimer); + this.animationTimer = null; } - this.animationTimer = window.setTimeout(() => { - this.infoBar.background = 'rgba(0,0,0,0.8)'; - if (!this.infoDiv) { - this.animationTimer = window.setTimeout(() => { - if (!this.infoDiv) { - this.infoBar.marginTop = -50; - return; - } - this.infoBar.marginTop = -this.infoDiv.nativeElement.clientHeight; - }, 10); - return; - } - this.infoBar.marginTop = -this.infoDiv.nativeElement.clientHeight; - }, 1); - } mouseOut() { @@ -130,23 +111,11 @@ export class GalleryPhotoComponent implements IRenderable, OnInit, OnDestroy { clearTimeout(this.animationTimer); } this.animationTimer = window.setTimeout(() => { - this.infoBar.marginTop = 0; - this.infoBar.background = 'rgba(0,0,0,0.0)'; - if (this.animationTimer != null) { - clearTimeout(this.animationTimer); - } - this.animationTimer = window.setTimeout(() => { - this.infoBar.visible = false; - }, 500); - }, 100); - + this.animationTimer = null; + this.infoBarVisible = false; + }, 500); } - /* - onImageLoad() { - this.loading.show = false; - } - */ public getDimension(): Dimension { if (!this.imageRef) { return { diff --git a/frontend/app/ui/gallery/lightbox/controls/controls.lightbox.gallery.component.html b/frontend/app/ui/gallery/lightbox/controls/controls.lightbox.gallery.component.html index 71e6972..1c21bd8 100644 --- a/frontend/app/ui/gallery/lightbox/controls/controls.lightbox.gallery.component.html +++ b/frontend/app/ui/gallery/lightbox/controls/controls.lightbox.gallery.component.html @@ -1,12 +1,12 @@
{{Title}}
+ [href]="activePhoto.gridMedia.getPhotoPath()" + [download]="activePhoto.gridMedia.media.name"> @@ -59,11 +59,11 @@ + [style.top.%]="face.box.top / activePhoto.gridMedia.Photo.metadata.size.height*100" + [style.left.%]="face.box.left / activePhoto.gridMedia.Photo.metadata.size.width*100" + [style.height.%]="face.box.height / activePhoto.gridMedia.Photo.metadata.size.height*100" + [style.width.%]="face.box.width / activePhoto.gridMedia.Photo.metadata.size.width*100" + *ngFor="let face of activePhoto.gridMedia.Photo.metadata.faces">
{{face.name}}
@@ -97,7 +97,7 @@
+ *ngIf="zoom == 1 && activePhoto && activePhoto.gridMedia.isPhoto()">
+ *ngIf="activePhoto && activePhoto.gridMedia.isVideo() && mediaElement.Paused">
-
+
diff --git a/frontend/app/ui/gallery/lightbox/controls/controls.lightbox.gallery.component.ts b/frontend/app/ui/gallery/lightbox/controls/controls.lightbox.gallery.component.ts index f68a6e4..feeddf3 100644 --- a/frontend/app/ui/gallery/lightbox/controls/controls.lightbox.gallery.component.ts +++ b/frontend/app/ui/gallery/lightbox/controls/controls.lightbox.gallery.component.ts @@ -61,7 +61,7 @@ export class ControlsLightboxComponent implements OnDestroy, OnInit, OnChanges { } public set Zoom(zoom: number) { - if (!this.activePhoto || this.activePhoto.gridPhoto.isVideo()) { + if (!this.activePhoto || this.activePhoto.gridMedia.isVideo()) { return; } if (zoom < 1) { @@ -86,7 +86,7 @@ export class ControlsLightboxComponent implements OnDestroy, OnInit, OnChanges { if (!this.activePhoto) { return null; } - return (this.activePhoto.gridPhoto.media).metadata.caption; + return (this.activePhoto.gridMedia.media).metadata.caption; } public containerWidth() { @@ -117,7 +117,7 @@ export class ControlsLightboxComponent implements OnDestroy, OnInit, OnChanges { pan($event: { deltaY: number, deltaX: number, isFinal: boolean }) { - if (!this.activePhoto || this.activePhoto.gridPhoto.isVideo()) { + if (!this.activePhoto || this.activePhoto.gridMedia.isVideo()) { return; } if (this.zoom === 1) { @@ -135,7 +135,7 @@ export class ControlsLightboxComponent implements OnDestroy, OnInit, OnChanges { } wheel($event: { deltaY: number }) { - if (!this.activePhoto || this.activePhoto.gridPhoto.isVideo()) { + if (!this.activePhoto || this.activePhoto.gridMedia.isVideo()) { return; } if ($event.deltaY < 0) { @@ -147,7 +147,7 @@ export class ControlsLightboxComponent implements OnDestroy, OnInit, OnChanges { @HostListener('pinch', ['$event']) pinch($event: { scale: number }) { - if (!this.activePhoto || this.activePhoto.gridPhoto.isVideo()) { + if (!this.activePhoto || this.activePhoto.gridMedia.isVideo()) { return; } this.showControls(); @@ -156,7 +156,7 @@ export class ControlsLightboxComponent implements OnDestroy, OnInit, OnChanges { @HostListener('pinchend', ['$event']) pinchend($event: { scale: number }) { - if (!this.activePhoto || this.activePhoto.gridPhoto.isVideo()) { + if (!this.activePhoto || this.activePhoto.gridMedia.isVideo()) { return; } this.showControls(); @@ -165,7 +165,7 @@ export class ControlsLightboxComponent implements OnDestroy, OnInit, OnChanges { } tap($event: any) { - if (!this.activePhoto || this.activePhoto.gridPhoto.isVideo()) { + if (!this.activePhoto || this.activePhoto.gridMedia.isVideo()) { return; } if ($event.tapCount < 2) { @@ -231,7 +231,7 @@ export class ControlsLightboxComponent implements OnDestroy, OnInit, OnChanges { this.closed.emit(); break; case ' ': // space - if (this.activePhoto && this.activePhoto.gridPhoto.isVideo()) { + if (this.activePhoto && this.activePhoto.gridMedia.isVideo()) { this.mediaElement.playPause(); } break; @@ -246,7 +246,7 @@ export class ControlsLightboxComponent implements OnDestroy, OnInit, OnChanges { return; } // do not skip video if its playing - if (this.activePhoto && this.activePhoto.gridPhoto.isVideo() && + if (this.activePhoto && this.activePhoto.gridMedia.isVideo() && !this.mediaElement.Paused) { return; } @@ -262,7 +262,7 @@ export class ControlsLightboxComponent implements OnDestroy, OnInit, OnChanges { if (this.mediaElement.imageLoadFinished === false) { return; } - if (this.activePhoto && this.activePhoto.gridPhoto.isVideo() && + if (this.activePhoto && this.activePhoto.gridMedia.isVideo() && !this.mediaElement.Paused) { return; } @@ -308,7 +308,7 @@ export class ControlsLightboxComponent implements OnDestroy, OnInit, OnChanges { return; } - const photoAspect = MediaDTO.calcRotatedAspectRatio(this.activePhoto.gridPhoto.media); + const photoAspect = MediaDTO.calcRotatedAspectRatio(this.activePhoto.gridMedia.media); const widthFilled = photoAspect > this.photoFrameDim.aspect; const divWidth = this.photoFrameDim.width; const divHeight = this.photoFrameDim.height; @@ -369,7 +369,7 @@ export class ControlsLightboxComponent implements OnDestroy, OnInit, OnChanges { } - const photoAspect = MediaDTO.calcRotatedAspectRatio(this.activePhoto.gridPhoto.media); + const photoAspect = MediaDTO.calcRotatedAspectRatio(this.activePhoto.gridMedia.media); if (photoAspect < this.photoFrameDim.aspect) { this.faceContainerDim.height = this.photoFrameDim.height; diff --git a/frontend/app/ui/gallery/lightbox/lightbox.gallery.component.html b/frontend/app/ui/gallery/lightbox/lightbox.gallery.component.html index 5f32c63..0caf7c9 100644 --- a/frontend/app/ui/gallery/lightbox/lightbox.gallery.component.html +++ b/frontend/app/ui/gallery/lightbox/lightbox.gallery.component.html @@ -5,7 +5,7 @@
diff --git a/frontend/app/ui/gallery/lightbox/lightbox.gallery.component.ts b/frontend/app/ui/gallery/lightbox/lightbox.gallery.component.ts index 6e939e4..e4cf5fc 100644 --- a/frontend/app/ui/gallery/lightbox/lightbox.gallery.component.ts +++ b/frontend/app/ui/gallery/lightbox/lightbox.gallery.component.ts @@ -71,7 +71,7 @@ export class GalleryLightboxComponent implements OnDestroy, OnInit { if (!this.activePhoto) { return null; } - return (this.activePhoto.gridPhoto.media).metadata.caption; + return (this.activePhoto.gridMedia.media).metadata.caption; } public toggleFullscreen(): void { @@ -117,19 +117,19 @@ export class GalleryLightboxComponent implements OnDestroy, OnInit { } onNavigateTo(photoStringId: string) { - if (this.activePhoto && this.queryService.getMediaStringId(this.activePhoto.gridPhoto.media) === photoStringId) { + if (this.activePhoto && this.queryService.getMediaStringId(this.activePhoto.gridMedia.media) === photoStringId) { return; } if (this.controls) { this.controls.resetZoom(); } - const photo = this.gridPhotoQL.find(i => this.queryService.getMediaStringId(i.gridPhoto.media) === photoStringId); + const photo = this.gridPhotoQL.find(i => this.queryService.getMediaStringId(i.gridMedia.media) === photoStringId); if (!photo) { return this.delayedMediaShow = photoStringId; } if (this.status === LightboxStates.Closed) { - this.showLigthbox(photo.gridPhoto.media); + this.showLigthbox(photo.gridMedia.media); } else { this.showPhoto(this.gridPhotoQL.toArray().indexOf(photo)); } @@ -195,7 +195,7 @@ export class GalleryLightboxComponent implements OnDestroy, OnInit { const lightboxDimension = selectedPhoto.getDimension(); lightboxDimension.top -= PageHelper.ScrollY; this.animating = true; - this.animatePhoto(selectedPhoto.getDimension(), this.calcLightBoxPhotoDimension(selectedPhoto.gridPhoto.media)).onDone(() => { + this.animatePhoto(selectedPhoto.getDimension(), this.calcLightBoxPhotoDimension(selectedPhoto.gridMedia.media)).onDone(() => { this.animating = false; }); this.animateLightbox( @@ -263,13 +263,12 @@ export class GalleryLightboxComponent implements OnDestroy, OnInit { this.iPvisibilityTimer = window.setTimeout(() => { this.iPvisibilityTimer = null; this.infoPanelVisible = false; - // this.controls.onResize(); }, 1000); - const starPhotoPos = this.calcLightBoxPhotoDimension(this.activePhoto.gridPhoto.media); + const starPhotoPos = this.calcLightBoxPhotoDimension(this.activePhoto.gridMedia.media); this.infoPanelWidth = 0; this.updatePhotoFrameDim(); - const endPhotoPos = this.calcLightBoxPhotoDimension(this.activePhoto.gridPhoto.media); + const endPhotoPos = this.calcLightBoxPhotoDimension(this.activePhoto.gridMedia.media); if (_animate) { this.animatePhoto(starPhotoPos, endPhotoPos); } @@ -297,10 +296,10 @@ export class GalleryLightboxComponent implements OnDestroy, OnInit { showInfoPanel() { this.infoPanelVisible = true; - const starPhotoPos = this.calcLightBoxPhotoDimension(this.activePhoto.gridPhoto.media); + const starPhotoPos = this.calcLightBoxPhotoDimension(this.activePhoto.gridMedia.media); this.infoPanelWidth = 400; this.updatePhotoFrameDim(); - const endPhotoPos = this.calcLightBoxPhotoDimension(this.activePhoto.gridPhoto.media); + const endPhotoPos = this.calcLightBoxPhotoDimension(this.activePhoto.gridMedia.media); this.animatePhoto(starPhotoPos, endPhotoPos); this.animateLightbox({ top: 0, @@ -326,6 +325,9 @@ export class GalleryLightboxComponent implements OnDestroy, OnInit { public isVisible(): boolean { return this.status !== LightboxStates.Closed; } + public isOpen(): boolean { + return this.status === LightboxStates.Open; + } private updatePhotoFrameDim = () => { @@ -336,7 +338,7 @@ export class GalleryLightboxComponent implements OnDestroy, OnInit { private navigateToPhoto(photoIndex: number) { this.router.navigate([], - {queryParams: this.queryService.getParams(this.gridPhotoQL.toArray()[photoIndex].gridPhoto.media)}).catch(console.error); + {queryParams: this.queryService.getParams(this.gridPhotoQL.toArray()[photoIndex].gridMedia.media)}).catch(console.error); } private showPhoto(photoIndex: number, resize: boolean = true) { @@ -362,7 +364,7 @@ export class GalleryLightboxComponent implements OnDestroy, OnInit { lightboxDimension.top -= PageHelper.ScrollY; this.blackCanvasOpacity = 0; - this.animatePhoto(this.calcLightBoxPhotoDimension(this.activePhoto.gridPhoto.media), this.activePhoto.getDimension()); + this.animatePhoto(this.calcLightBoxPhotoDimension(this.activePhoto.gridMedia.media), this.activePhoto.getDimension()); this.animateLightbox({ top: 0, left: 0, @@ -391,7 +393,7 @@ export class GalleryLightboxComponent implements OnDestroy, OnInit { this.activePhoto = pcList[photoIndex]; if (resize) { - this.animatePhoto(this.calcLightBoxPhotoDimension(this.activePhoto.gridPhoto.media)); + this.animatePhoto(this.calcLightBoxPhotoDimension(this.activePhoto.gridMedia.media)); } this.navigation.hasPrev = photoIndex > 0; this.navigation.hasNext = photoIndex + 1 < pcList.length; @@ -409,7 +411,7 @@ export class GalleryLightboxComponent implements OnDestroy, OnInit { private findPhotoComponent(media: MediaDTO): GalleryPhotoComponent { const galleryPhotoComponents = this.gridPhotoQL.toArray(); for (let i = 0; i < galleryPhotoComponents.length; i++) { - if (galleryPhotoComponents[i].gridPhoto.media === media) { + if (galleryPhotoComponents[i].gridMedia.media === media) { return galleryPhotoComponents[i]; } }