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 {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;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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<ThumbnailTask> = [];
|
||||
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);
|
||||
|
Loading…
Reference in New Issue
Block a user