{{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 ea3c77d2..e4c1e092 100644
--- a/frontend/app/gallery/grid/photo/photo.grid.gallery.component.ts
+++ b/frontend/app/gallery/grid/photo/photo.grid.gallery.component.ts
@@ -1,11 +1,12 @@
///
-import {Component, Input, ElementRef, ViewChild} from "@angular/core";
+import {Component, Input, ElementRef, ViewChild, OnChanges} from "@angular/core";
import {IRenderable, Dimension} from "../../../model/IRenderable";
import {GridPhoto} from "../GridPhoto";
import {SearchTypes} from "../../../../../common/entities/AutoCompleteItem";
import {RouterLink} from "@angular/router-deprecated";
import {Config} from "../../../config/Config";
+import {ThumbnailLoaderService} from "../thumnailLoader.service";
@Component({
selector: 'gallery-grid-photo',
@@ -13,23 +14,42 @@ import {Config} from "../../../config/Config";
styleUrls: ['app/gallery/grid/photo/photo.grid.gallery.component.css'],
directives: [RouterLink],
})
-export class GalleryPhotoComponent implements IRenderable {
+export class GalleryPhotoComponent implements IRenderable, OnChanges {
@Input() gridPhoto:GridPhoto;
@ViewChild("image") imageRef:ElementRef;
@ViewChild("info") infoDiv:ElementRef;
+ imageSrc = "#";
+ showImage = false;
infoStyle = {
height: 0,
background: ""
};
+
SearchTypes:any = [];
searchEnabled:boolean = true;
- constructor() {
+ constructor(private thumbnailService:ThumbnailLoaderService) {
this.SearchTypes = SearchTypes;
this.searchEnabled = Config.Client.Search.searchEnabled;
}
+ ngOnChanges() {
+ if (this.gridPhoto.isThumbnailAvailable()) {
+ this.imageSrc = this.gridPhoto.getThumbnailPath();
+ // this.showImage = true;
+ } else {
+ this.thumbnailService.loadImage(this.gridPhoto).then(()=> {
+ this.imageSrc = this.gridPhoto.getThumbnailPath();
+ // this.showImage = true;
+ this.gridPhoto.thumbnailLoaded();
+ }).catch((error)=> {
+ console.error("something bad happened");
+ });
+ }
+ }
+
+
getPositionText():string {
if (!this.gridPhoto) {
return ""
diff --git a/frontend/app/gallery/grid/thumnailLoader.service.ts b/frontend/app/gallery/grid/thumnailLoader.service.ts
new file mode 100644
index 00000000..915fdcbd
--- /dev/null
+++ b/frontend/app/gallery/grid/thumnailLoader.service.ts
@@ -0,0 +1,73 @@
+///
+
+import {Injectable} from "@angular/core";
+import {GridPhoto} from "./GridPhoto";
+
+@Injectable()
+export class ThumbnailLoaderService {
+
+ que:Array = [];
+
+ constructor() {
+ }
+
+ loadImage(gridPhoto:GridPhoto):Promise {
+ console.log("[LOAD IMG]" + gridPhoto.photo.name);
+ return new Promise((resolve:Function, reject:Function)=> {
+ let tmp:ThumbnailTask = null;
+ for (let i = 0; i < this.que.length; i++) {
+ if (this.que[i].src == gridPhoto.getThumbnailPath()) {
+ tmp = this.que[i];
+ break;
+ }
+ }
+ if (tmp != null) {
+ tmp.resolve.push(resolve);
+ tmp.reject.push(reject);
+ } else {
+ this.que.push({src: gridPhoto.getThumbnailPath(), resolve: [resolve], reject: [reject]});
+ }
+ this.run();
+ });
+
+ }
+
+ isRunning:boolean = false;
+
+ run() {
+ if (this.que.length === 0 || this.isRunning === true) {
+ return;
+ }
+ this.isRunning = true;
+ let task = this.que.shift();
+ console.log("loadingstarted: " + task.src);
+
+ let curImg = new Image();
+ curImg.src = task.src;
+ curImg.onload = () => {
+ console.log(task.src + "done");
+ task.resolve.forEach((resolve:()=>{}) => {
+ resolve();
+
+ });
+ this.isRunning = false;
+ this.run();
+ };
+
+ curImg.onerror = (error) => {
+ console.error(task.src + "error");
+ task.reject.forEach((reject:(error)=>{}) => {
+ reject(error);
+ });
+ this.isRunning = false;
+ this.run();
+ };
+ }
+
+}
+
+interface ThumbnailTask {
+ src:string;
+ resolve:Array;
+ reject:Array;
+}
diff --git a/frontend/webpack.config.js b/frontend/webpack.config.js
index 43f2a9be..13a02dab 100644
--- a/frontend/webpack.config.js
+++ b/frontend/webpack.config.js
@@ -11,7 +11,7 @@ module.exports = {
library: ['peer']
},
// Turn on sourcemaps
- //devtool: 'source-map',
+ devtool: 'source-map',
resolve: {
extensions: ['', '.webpack.js', '.web.js', '.ts', '.js'],