From 1616e0d292abea1c4512cd17cc6361cf419a377d Mon Sep 17 00:00:00 2001 From: Braun Patrik Date: Sun, 26 Jun 2016 15:54:10 +0200 Subject: [PATCH] saving photo state change back to cache --- frontend/app/gallery/cache.gallery.service.ts | 37 ++++++++++++++++++- .../gallery/grid/thumnailLoader.service.ts | 4 +- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/frontend/app/gallery/cache.gallery.service.ts b/frontend/app/gallery/cache.gallery.service.ts index a73f475e..defbc42f 100644 --- a/frontend/app/gallery/cache.gallery.service.ts +++ b/frontend/app/gallery/cache.gallery.service.ts @@ -4,12 +4,16 @@ import {Injectable} from "@angular/core"; import {Photo} from "../../../common/entities/Photo"; import {Directory} from "../../../common/entities/Directory"; import {Utils} from "../../../common/Utils"; +import {Config} from "../config/Config"; @Injectable() export class GalleryCacheService { public getDirectory(directoryName:string):Directory { + if (Config.Client.enableCache == false) { + return null; + } let value = localStorage.getItem(directoryName); if (value != null) { let directory:Directory = JSON.parse(value); @@ -24,7 +28,10 @@ export class GalleryCacheService { } public setDirectory(directory:Directory):void { - + if (Config.Client.enableCache == false) { + return; + } + localStorage.setItem(Utils.concatUrls(directory.path, directory.name), JSON.stringify(directory)); directory.directories.forEach((dir:Directory) => { @@ -36,5 +43,33 @@ export class GalleryCacheService { } + /** + * Update photo state at cache too (Eg.: thumbnail rendered) + * @param photo + */ + public photoUpdated(photo:Photo):void { + + if (Config.Client.enableCache == false) { + return; + } + + let directoryName = Utils.concatUrls(photo.directory.path, photo.directory.name); + let value = localStorage.getItem(directoryName); + if (value != null) { + let directory:Directory = JSON.parse(value); + directory.photos.forEach((p) => { + if (p.name === photo.name) { + //update data + p.metadata = photo.metadata; + p.readyThumbnails = photo.readyThumbnails; + + //save changes + localStorage.setItem(directoryName, JSON.stringify(directory)); + return; + } + }); + } + + } } diff --git a/frontend/app/gallery/grid/thumnailLoader.service.ts b/frontend/app/gallery/grid/thumnailLoader.service.ts index 343af54f..07c05285 100644 --- a/frontend/app/gallery/grid/thumnailLoader.service.ts +++ b/frontend/app/gallery/grid/thumnailLoader.service.ts @@ -3,6 +3,7 @@ import {Injectable} from "@angular/core"; import {GridPhoto} from "./GridPhoto"; import {Config} from "../../config/Config"; +import {GalleryCacheService} from "../cache.gallery.service"; export enum ThumbnailLoadingPriority{ high, medium, low @@ -14,7 +15,7 @@ export class ThumbnailLoaderService { que:Array = []; runningRequests:number = 0; - constructor() { + constructor(private galleryChacheService:GalleryCacheService) { } removeTasks() { @@ -126,6 +127,7 @@ export class ThumbnailLoaderService { curImg.onload = () => { task.gridPhoto.thumbnailLoaded(); + this.galleryChacheService.photoUpdated(task.gridPhoto.photo); task.taskEntities.forEach(te=>te.listener.onLoad()); this.taskReady(task);