From 8e14c613ea846a18be7d85fc50fb79a5b7bbe7e4 Mon Sep 17 00:00:00 2001 From: Braun Patrik Date: Mon, 4 Jul 2016 16:58:10 +0200 Subject: [PATCH] removing animation from lightbox + improving thumbnail rendering at lightbox --- frontend/app/gallery/gallery.component.html | 4 +- frontend/app/gallery/gallery.component.ts | 5 + frontend/app/gallery/gallery.service.spec.ts | 26 ++-- .../gallery/grid/grid.gallery.component.ts | 52 ++++--- .../lightbox/lightbox.gallery.component.css | 6 +- .../lightbox/lightbox.gallery.component.html | 10 +- .../lightbox/lightbox.gallery.component.ts | 141 ++---------------- .../photo.lightbox.gallery.component.html | 8 +- .../photo/photo.lightbox.gallery.component.ts | 27 ++++ 9 files changed, 109 insertions(+), 170 deletions(-) diff --git a/frontend/app/gallery/gallery.component.html b/frontend/app/gallery/gallery.component.html index 20b47469..4f4e5ff8 100644 --- a/frontend/app/gallery/gallery.component.html +++ b/frontend/app/gallery/gallery.component.html @@ -1,8 +1,10 @@ - + +
+
{ + beforeEach(() => { + addProviders([ + MockBackend, + BaseRequestOptions, + provide(Http, { + useFactory: (backend, options) => { + return new Http(backend, options); + }, deps: [MockBackend, BaseRequestOptions] + }), + NetworkService, + GalleryService + ]); + }); - beforeEachProviders(() => [ - MockBackend, - BaseRequestOptions, - provide(Http, { - useFactory: (backend, options) => { - return new Http(backend, options); - }, deps: [MockBackend, BaseRequestOptions] - }), - NetworkService, - GalleryService - ]); it('placeholder test', inject([], () => { diff --git a/frontend/app/gallery/grid/grid.gallery.component.ts b/frontend/app/gallery/grid/grid.gallery.component.ts index 57f7dba0..dcf62e75 100644 --- a/frontend/app/gallery/grid/grid.gallery.component.ts +++ b/frontend/app/gallery/grid/grid.gallery.component.ts @@ -33,6 +33,7 @@ export class GalleryGridComponent implements OnChanges,AfterViewInit { @Input() lightbox:GalleryLightboxComponent; photosToRender:Array = []; + containerWidth:number = 0; private IMAGE_MARGIN = 2; private TARGET_COL_COUNT = 5; @@ -58,6 +59,7 @@ export class GalleryGridComponent implements OnChanges,AfterViewInit { if (this.isAfterViewInit === false) { return; } + this.updateContainerWidth(); this.sortPhotos(); this.clearRenderedPhotos(); setImmediate(() => { @@ -73,7 +75,7 @@ export class GalleryGridComponent implements OnChanges,AfterViewInit { //TODO: implement scroll detection - this.sortPhotos(); + this.updateContainerWidth(); this.clearRenderedPhotos(); setImmediate(() => { this.renderPhotos(); @@ -130,31 +132,15 @@ export class GalleryGridComponent implements OnChanges,AfterViewInit { private renderedPhotoIndex:number = 0; private renderPhotos() { - if (this.getContainerWidth() == 0 || this.renderedPhotoIndex >= this.photos.length || !this.shouldRenderMore()) { + if (this.containerWidth == 0 || this.renderedPhotoIndex >= this.photos.length || !this.shouldRenderMore()) { return; } - let maxRowHeight = window.innerHeight / this.MIN_ROW_COUNT; - let minRowHeight = window.innerHeight / this.MAX_ROW_COUNT; let renderedContentHeight = 0; while (this.renderedPhotoIndex < this.photos.length && this.shouldRenderMore(renderedContentHeight) === true) { - - let photoRowBuilder = new GridRowBuilder(this.photos, this.renderedPhotoIndex, this.IMAGE_MARGIN, this.getContainerWidth()); - photoRowBuilder.addPhotos(this.TARGET_COL_COUNT); - photoRowBuilder.adjustRowHeightBetween(minRowHeight, maxRowHeight); - - let rowHeight = photoRowBuilder.calcRowHeight(); - let imageHeight = rowHeight - (this.IMAGE_MARGIN * 2); - - photoRowBuilder.getPhotoRow().forEach((photo) => { - let imageWidth = imageHeight * (photo.metadata.size.width / photo.metadata.size.height); - this.photosToRender.push(new GridPhoto(photo, imageWidth, imageHeight, this.renderedPhotoIndex)); - }); - - renderedContentHeight += rowHeight; - this.renderedPhotoIndex += photoRowBuilder.getPhotoRow().length; + renderedContentHeight += this.renderARow(); } } @@ -184,11 +170,33 @@ export class GalleryGridComponent implements OnChanges,AfterViewInit { } } - private getContainerWidth():number { + public renderARow():number { + + let maxRowHeight = window.innerHeight / this.MIN_ROW_COUNT; + let minRowHeight = window.innerHeight / this.MAX_ROW_COUNT; + + let photoRowBuilder = new GridRowBuilder(this.photos, this.renderedPhotoIndex, this.IMAGE_MARGIN, this.containerWidth); + photoRowBuilder.addPhotos(this.TARGET_COL_COUNT); + photoRowBuilder.adjustRowHeightBetween(minRowHeight, maxRowHeight); + + let rowHeight = photoRowBuilder.calcRowHeight(); + let imageHeight = rowHeight - (this.IMAGE_MARGIN * 2); + + photoRowBuilder.getPhotoRow().forEach((photo) => { + let imageWidth = imageHeight * (photo.metadata.size.width / photo.metadata.size.height); + this.photosToRender.push(new GridPhoto(photo, imageWidth, imageHeight, this.renderedPhotoIndex)); + }); + + this.renderedPhotoIndex += photoRowBuilder.getPhotoRow().length; + console.log(this.photosToRender.length); + return rowHeight; + } + + private updateContainerWidth():number { if (!this.gridContainer) { - return 0; + return; } - return this.gridContainer.nativeElement.clientWidth; + this.containerWidth = this.gridContainer.nativeElement.clientWidth; } diff --git a/frontend/app/gallery/lightbox/lightbox.gallery.component.css b/frontend/app/gallery/lightbox/lightbox.gallery.component.css index 3dea54d9..5effa5de 100644 --- a/frontend/app/gallery/lightbox/lightbox.gallery.component.css +++ b/frontend/app/gallery/lightbox/lightbox.gallery.component.css @@ -3,16 +3,16 @@ z-index: 1100; /* Sit on top */ left: 0; top: 0; - width: 0; /* Full width */ - height: 0; /* Full height */ + width: 100%; /* Full width */ + height: 100%; /* Full height */ overflow: hidden; display: flex; /* add */ justify-content: center; /* add to align horizontal */ align-items: center; /* add to align vertical */ cursor: pointer; } + .blackCanvas{ - display: none; position: fixed; /* Stay in place */ z-index: 1099; /* Sit on top */ left: 0; diff --git a/frontend/app/gallery/lightbox/lightbox.gallery.component.html b/frontend/app/gallery/lightbox/lightbox.gallery.component.html index 1cd9d660..d4fef322 100644 --- a/frontend/app/gallery/lightbox/lightbox.gallery.component.html +++ b/frontend/app/gallery/lightbox/lightbox.gallery.component.html @@ -1,10 +1,14 @@
-
+
-