mirror of
https://github.com/xuthus83/pigallery2.git
synced 2024-11-03 21:04:03 +08:00
saving photo state change back to cache
This commit is contained in:
parent
f5383c51c0
commit
1616e0d292
@ -4,12 +4,16 @@ import {Injectable} from "@angular/core";
|
|||||||
import {Photo} from "../../../common/entities/Photo";
|
import {Photo} from "../../../common/entities/Photo";
|
||||||
import {Directory} from "../../../common/entities/Directory";
|
import {Directory} from "../../../common/entities/Directory";
|
||||||
import {Utils} from "../../../common/Utils";
|
import {Utils} from "../../../common/Utils";
|
||||||
|
import {Config} from "../config/Config";
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class GalleryCacheService {
|
export class GalleryCacheService {
|
||||||
|
|
||||||
|
|
||||||
public getDirectory(directoryName:string):Directory {
|
public getDirectory(directoryName:string):Directory {
|
||||||
|
if (Config.Client.enableCache == false) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
let value = localStorage.getItem(directoryName);
|
let value = localStorage.getItem(directoryName);
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
let directory:Directory = JSON.parse(value);
|
let directory:Directory = JSON.parse(value);
|
||||||
@ -24,6 +28,9 @@ export class GalleryCacheService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public setDirectory(directory:Directory):void {
|
public setDirectory(directory:Directory):void {
|
||||||
|
if (Config.Client.enableCache == false) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
localStorage.setItem(Utils.concatUrls(directory.path, directory.name), JSON.stringify(directory));
|
localStorage.setItem(Utils.concatUrls(directory.path, directory.name), JSON.stringify(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;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
import {Injectable} from "@angular/core";
|
import {Injectable} from "@angular/core";
|
||||||
import {GridPhoto} from "./GridPhoto";
|
import {GridPhoto} from "./GridPhoto";
|
||||||
import {Config} from "../../config/Config";
|
import {Config} from "../../config/Config";
|
||||||
|
import {GalleryCacheService} from "../cache.gallery.service";
|
||||||
|
|
||||||
export enum ThumbnailLoadingPriority{
|
export enum ThumbnailLoadingPriority{
|
||||||
high, medium, low
|
high, medium, low
|
||||||
@ -14,7 +15,7 @@ export class ThumbnailLoaderService {
|
|||||||
que:Array<ThumbnailTask> = [];
|
que:Array<ThumbnailTask> = [];
|
||||||
runningRequests:number = 0;
|
runningRequests:number = 0;
|
||||||
|
|
||||||
constructor() {
|
constructor(private galleryChacheService:GalleryCacheService) {
|
||||||
}
|
}
|
||||||
|
|
||||||
removeTasks() {
|
removeTasks() {
|
||||||
@ -126,6 +127,7 @@ export class ThumbnailLoaderService {
|
|||||||
curImg.onload = () => {
|
curImg.onload = () => {
|
||||||
|
|
||||||
task.gridPhoto.thumbnailLoaded();
|
task.gridPhoto.thumbnailLoaded();
|
||||||
|
this.galleryChacheService.photoUpdated(task.gridPhoto.photo);
|
||||||
task.taskEntities.forEach(te=>te.listener.onLoad());
|
task.taskEntities.forEach(te=>te.listener.onLoad());
|
||||||
|
|
||||||
this.taskReady(task);
|
this.taskReady(task);
|
||||||
|
Loading…
Reference in New Issue
Block a user