diff --git a/frontend/app/gallery/grid/photo/loading/loading.photo.grid.gallery.component.html b/frontend/app/gallery/grid/photo/loading/loading.photo.grid.gallery.component.html index ccea2023..3308d366 100644 --- a/frontend/app/gallery/grid/photo/loading/loading.photo.grid.gallery.component.html +++ b/frontend/app/gallery/grid/photo/loading/loading.photo.grid.gallery.component.html @@ -1,5 +1,5 @@ -
-
+
+
diff --git a/frontend/app/gallery/grid/photo/loading/loading.photo.grid.gallery.component.ts b/frontend/app/gallery/grid/photo/loading/loading.photo.grid.gallery.component.ts index 6d8ad04a..47f5246a 100644 --- a/frontend/app/gallery/grid/photo/loading/loading.photo.grid.gallery.component.ts +++ b/frontend/app/gallery/grid/photo/loading/loading.photo.grid.gallery.component.ts @@ -1,6 +1,6 @@ /// -import {Component} from "@angular/core"; +import {Component, Input} from "@angular/core"; @Component({ selector: 'gallery-grid-photo-loading', @@ -9,10 +9,8 @@ import {Component} from "@angular/core"; }) export class GalleryPhotoLoadingComponent { - animate = false; + @Input() animate:boolean; + - startAnimation() { - this.animate = true; - } } diff --git a/frontend/app/gallery/grid/photo/photo.grid.gallery.component.html b/frontend/app/gallery/grid/photo/photo.grid.gallery.component.html index 980c904f..cdfc2a41 100644 --- a/frontend/app/gallery/grid/photo/photo.grid.gallery.component.html +++ b/frontend/app/gallery/grid/photo/photo.grid.gallery.component.html @@ -1,11 +1,11 @@
- + - + -
{{gridPhoto.photo.name}}
diff --git a/frontend/app/gallery/grid/photo/photo.grid.gallery.component.ts b/frontend/app/gallery/grid/photo/photo.grid.gallery.component.ts index d78d533f..faa70d8b 100644 --- a/frontend/app/gallery/grid/photo/photo.grid.gallery.component.ts +++ b/frontend/app/gallery/grid/photo/photo.grid.gallery.component.ts @@ -17,13 +17,20 @@ import {GalleryPhotoLoadingComponent} from "./loading/loading.photo.grid.gallery }) export class GalleryPhotoComponent implements IRenderable, AfterViewInit { @Input() gridPhoto:GridPhoto; - @ViewChild("image") imageRef:ElementRef; + @ViewChild("img") imageRef:ElementRef; @ViewChild("info") infoDiv:ElementRef; - @ViewChild(GalleryPhotoLoadingComponent) loading:GalleryPhotoLoadingComponent; - imageSrc = "#"; - showImage = false; - showLoading = false; + + image = { + src: "#", + show: false + }; + + loading = { + animate: false, + show: false + }; + infoStyle = { height: 0, background: "rgba(0,0,0,0.0)" @@ -41,22 +48,24 @@ export class GalleryPhotoComponent implements IRenderable, AfterViewInit { //schedule change after Angular checks the model setImmediate(() => { if (this.gridPhoto.isThumbnailAvailable()) { - this.imageSrc = this.gridPhoto.getThumbnailPath(); - this.showImage = true; - this.showLoading = false; + this.image.src = this.gridPhoto.getThumbnailPath(); + this.image.show = true; + this.loading.show = false; } else { - this.showLoading = true; + this.loading.show = true; this.thumbnailService.loadImage(this.gridPhoto, ()=> { //onLoadStarted - this.loading.startAnimation(); + this.loading.animate = true; }, ()=> {//onLoaded - this.imageSrc = this.gridPhoto.getThumbnailPath(); - this.showImage = true; - this.showLoading = false; + this.image.src = this.gridPhoto.getThumbnailPath(); + this.image.show = true; + this.loading.show = false; }, - ()=> {//onError + (error)=> {//onError + //TODO: handle error console.error("something bad happened"); + console.error(error); }); } }); diff --git a/frontend/app/gallery/grid/thumnailLoader.service.ts b/frontend/app/gallery/grid/thumnailLoader.service.ts index 9e239e2e..b6b5d3ce 100644 --- a/frontend/app/gallery/grid/thumnailLoader.service.ts +++ b/frontend/app/gallery/grid/thumnailLoader.service.ts @@ -13,21 +13,33 @@ export class ThumbnailLoaderService { constructor() { } - loadImage(gridPhoto:GridPhoto, onStartedLoading, onLoad, onError):void { + removeTasks() { + this.que = []; + } + + loadImage(gridPhoto:GridPhoto, onStartedLoading:()=>void, onLoad:()=>void, onError:(error)=>void):void { let tmp:ThumbnailTask = null; + //is image already qued? for (let i = 0; i < this.que.length; i++) { if (this.que[i].gridPhoto.getThumbnailPath() == gridPhoto.getThumbnailPath()) { tmp = this.que[i]; break; } } + //add to previous if (tmp != null) { tmp.onStartedLoading.push(onStartedLoading); tmp.onLoad.push(onLoad); tmp.onError.push(onError); - } else { + if (tmp.inProgress == true) { + onStartedLoading(); + } + + + } else {//create new task this.que.push({ gridPhoto: gridPhoto, + inProgress: false, onStartedLoading: [onStartedLoading], onLoad: [onLoad], onError: [onError] @@ -43,20 +55,28 @@ export class ThumbnailLoaderService { return; } this.runningRequests++; - let task = this.que.shift(); - task.onStartedLoading.forEach(cb=>cb()); - + let task = this.que[0]; + task.onStartedLoading.forEach(cb=>cb()); + task.inProgress = true; + let curImg = new Image(); curImg.src = task.gridPhoto.getThumbnailPath(); - curImg.onload = () => { + + curImg.onload = () => { + task.gridPhoto.thumbnailLoaded(); task.onLoad.forEach(cb=>cb()); + + this.que.shift(); this.runningRequests--; this.run(); }; - curImg.onerror = (error) => { + curImg.onerror = (error) => { + task.onLoad.forEach(cb=>cb(error)); + + this.que.shift(); this.runningRequests--; this.run(); }; @@ -66,6 +86,7 @@ export class ThumbnailLoaderService { interface ThumbnailTask { gridPhoto:GridPhoto; + inProgress:boolean; onStartedLoading:Array; onLoad:Array; onError:Array;