From e00fb6af4b7bb1e18b118922fae71ad3a6df435b Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Tue, 24 Dec 2013 22:03:54 +0400 Subject: [PATCH] refactored DATA save mechanics, now only saves a file when it's updated (backwards compatible)... Signed-off-by: Alex A. Naanou --- ui/data.js | 19 +++++++++++++++++++ ui/files.js | 41 ++++++++++++++++++++++++++++++++++++++++- ui/sort.js | 23 +++++++++++++++++++++++ 3 files changed, 82 insertions(+), 1 deletion(-) diff --git a/ui/data.js b/ui/data.js index 723d1841..451f4287 100755 --- a/ui/data.js +++ b/ui/data.js @@ -2210,6 +2210,8 @@ function alignRibbons(ribbon){ DATA = alignDataToRibbon(ribbon) + $('.viewer').trigger('ribbonsAligned', [ribbon]) + reloadViewer(false) } @@ -2258,6 +2260,8 @@ function loadRibbonsFromPath(path, cmp, reverse, dir_name){ reloadViewer(false) } + $('.viewer').trigger('ribbonsLoadedFromPath', [path]) + return DATA } @@ -2283,6 +2287,21 @@ function setupData(viewer){ console.log('Data: setup...') return viewer + // mark data updated... + // NOTE: manual data manipulation will dataUpdated() called + // manually... + .on([ + // ribbons.js API... + 'shiftedImage', + 'createdRibbon', + 'removedRibbon', + // data.js API... + 'ribbonsAligned', + 'ribbonsLoadedFromPath', + ].join(' '), function(){ + dataUpdated() + }) + // NOTE: we do not need to worry about explicit centering the ribbon // here, just ball-park-load the correct batch... // NOTE: if we decide to hide ribbons, uncomment the visibility diff --git a/ui/files.js b/ui/files.js index d824506e..b2801858 100755 --- a/ui/files.js +++ b/ui/files.js @@ -19,6 +19,8 @@ var IMAGES_DIFF_FILE_PATTERN = /^[0-9]*-images-diff.json$/ var DATA_FILE_DEFAULT = 'data.json' var DATA_FILE_PATTERN = /^[0-9]*-data.json$/ +var CURRENT_FILE = 'current.json' + var IMAGE_PATTERN = /.*\.(jpg|jpeg|png|gif)$/i @@ -289,6 +291,25 @@ function runFileSavers(name, all){ +/*********************************************************************/ +// XXX should this be here or in data.js??? + +var saveFileData = makeFileSaver( + 'Data', + DATA_FILE_DEFAULT, + function(){ + var data = getAllData() + data.current = DATA.current + return data + }) + + +function dataUpdated(){ + fileUpdated('Data') +} + + + /*********************************************************************/ // Construct a ribbons hierarchy from the fav dirs structure @@ -469,6 +490,17 @@ function loadFileState(path, prefix){ DATA = json $.when( // XXX load config... + + // load current position... + bubbleProgress(prefix, + loadLatestFile(path, + CURRENT_FILE, + null, + null, + DATA.current), res, true) + .done(function(cur){ + DATA.current = cur + }), // load images... bubbleProgress(prefix, loadFileImages(base), res, true), @@ -505,7 +537,8 @@ function saveFileState(name, no_normalize_path){ name = name == null ? Date.timeStamp() : name if(!no_normalize_path){ - name = normalizePath(CONFIG.cache_dir_var +'/'+ name) + var path = normalizePath(CONFIG.cache_dir_var) + name = normalizePath(path +'/'+ name) // write .image_file only if saving data to a non-cache dir... // XXX check if this is correct... @@ -515,10 +548,15 @@ function saveFileState(name, no_normalize_path){ } } + /* var data = getAllData() data.current = DATA.current dumpJSON(name + '-data.json', data) + */ + + // allways update the current position... + dumpJSON(path + '/current.json', DATA.current) // save the updated images... if(IMAGES_UPDATED.length > 0){ @@ -530,6 +568,7 @@ function saveFileState(name, no_normalize_path){ IMAGES_UPDATED = [] } + // save the rest of the data... runFileSavers(name) } diff --git a/ui/sort.js b/ui/sort.js index f56622c0..b785e446 100755 --- a/ui/sort.js +++ b/ui/sort.js @@ -181,6 +181,7 @@ function reverseImageOrder(){ r.reverse() }) reloadViewer(true) + $('.viewer').trigger('reversedImageOrder', [cmp]) } @@ -310,6 +311,7 @@ function sortImagesByFileNameSeqWithOverflow(reverse, proximity, overflow_gap, c } updateRibbonOrder() + $('.viewer').trigger('sortedImagesByFileNameSeqWithOverflow') } @@ -354,6 +356,7 @@ function horizontalShiftImage(image, direction){ // update stuff that changed, mainly order... updateImages() + $('.viewer').trigger('horizontalSiftedImage', [gid, direction]) return image } @@ -420,6 +423,26 @@ function sortImagesDialog(){ } +/*********************************************************************/ + +function setupSorting(viewer){ + console.log('Sorting: setup...') + + return viewer + // NOTE: manual data manipulation will dataUpdated() called + // manually... + .on([ + 'reversedImageOrder', + 'sortedImages', + 'sortedImagesByFileNameSeqWithOverflow', + 'horizontalSiftedImage' + ].join(' '), function(){ + dataUpdated() + }) +} +SETUP_BINDINGS.push(setupSorting) + + /********************************************************************** * vim:set ts=4 sw=4 : */