mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-10-30 10:50:08 +00:00
refactored DATA save mechanics, now only saves a file when it's updated (backwards compatible)...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
f85925db5a
commit
e00fb6af4b
19
ui/data.js
19
ui/data.js
@ -2210,6 +2210,8 @@ function alignRibbons(ribbon){
|
|||||||
|
|
||||||
DATA = alignDataToRibbon(ribbon)
|
DATA = alignDataToRibbon(ribbon)
|
||||||
|
|
||||||
|
$('.viewer').trigger('ribbonsAligned', [ribbon])
|
||||||
|
|
||||||
reloadViewer(false)
|
reloadViewer(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2258,6 +2260,8 @@ function loadRibbonsFromPath(path, cmp, reverse, dir_name){
|
|||||||
reloadViewer(false)
|
reloadViewer(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$('.viewer').trigger('ribbonsLoadedFromPath', [path])
|
||||||
|
|
||||||
return DATA
|
return DATA
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2283,6 +2287,21 @@ function setupData(viewer){
|
|||||||
console.log('Data: setup...')
|
console.log('Data: setup...')
|
||||||
|
|
||||||
return viewer
|
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
|
// NOTE: we do not need to worry about explicit centering the ribbon
|
||||||
// here, just ball-park-load the correct batch...
|
// here, just ball-park-load the correct batch...
|
||||||
// NOTE: if we decide to hide ribbons, uncomment the visibility
|
// NOTE: if we decide to hide ribbons, uncomment the visibility
|
||||||
|
|||||||
41
ui/files.js
41
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_DEFAULT = 'data.json'
|
||||||
var DATA_FILE_PATTERN = /^[0-9]*-data.json$/
|
var DATA_FILE_PATTERN = /^[0-9]*-data.json$/
|
||||||
|
|
||||||
|
var CURRENT_FILE = 'current.json'
|
||||||
|
|
||||||
var IMAGE_PATTERN = /.*\.(jpg|jpeg|png|gif)$/i
|
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
|
// Construct a ribbons hierarchy from the fav dirs structure
|
||||||
@ -469,6 +490,17 @@ function loadFileState(path, prefix){
|
|||||||
DATA = json
|
DATA = json
|
||||||
$.when(
|
$.when(
|
||||||
// XXX load config...
|
// 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...
|
// load images...
|
||||||
bubbleProgress(prefix,
|
bubbleProgress(prefix,
|
||||||
loadFileImages(base), res, true),
|
loadFileImages(base), res, true),
|
||||||
@ -505,7 +537,8 @@ function saveFileState(name, no_normalize_path){
|
|||||||
name = name == null ? Date.timeStamp() : name
|
name = name == null ? Date.timeStamp() : name
|
||||||
|
|
||||||
if(!no_normalize_path){
|
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...
|
// write .image_file only if saving data to a non-cache dir...
|
||||||
// XXX check if this is correct...
|
// XXX check if this is correct...
|
||||||
@ -515,10 +548,15 @@ function saveFileState(name, no_normalize_path){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
var data = getAllData()
|
var data = getAllData()
|
||||||
data.current = DATA.current
|
data.current = DATA.current
|
||||||
|
|
||||||
dumpJSON(name + '-data.json', data)
|
dumpJSON(name + '-data.json', data)
|
||||||
|
*/
|
||||||
|
|
||||||
|
// allways update the current position...
|
||||||
|
dumpJSON(path + '/current.json', DATA.current)
|
||||||
|
|
||||||
// save the updated images...
|
// save the updated images...
|
||||||
if(IMAGES_UPDATED.length > 0){
|
if(IMAGES_UPDATED.length > 0){
|
||||||
@ -530,6 +568,7 @@ function saveFileState(name, no_normalize_path){
|
|||||||
IMAGES_UPDATED = []
|
IMAGES_UPDATED = []
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// save the rest of the data...
|
||||||
runFileSavers(name)
|
runFileSavers(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
23
ui/sort.js
23
ui/sort.js
@ -181,6 +181,7 @@ function reverseImageOrder(){
|
|||||||
r.reverse()
|
r.reverse()
|
||||||
})
|
})
|
||||||
reloadViewer(true)
|
reloadViewer(true)
|
||||||
|
$('.viewer').trigger('reversedImageOrder', [cmp])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -310,6 +311,7 @@ function sortImagesByFileNameSeqWithOverflow(reverse, proximity, overflow_gap, c
|
|||||||
}
|
}
|
||||||
|
|
||||||
updateRibbonOrder()
|
updateRibbonOrder()
|
||||||
|
$('.viewer').trigger('sortedImagesByFileNameSeqWithOverflow')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -354,6 +356,7 @@ function horizontalShiftImage(image, direction){
|
|||||||
|
|
||||||
// update stuff that changed, mainly order...
|
// update stuff that changed, mainly order...
|
||||||
updateImages()
|
updateImages()
|
||||||
|
$('.viewer').trigger('horizontalSiftedImage', [gid, direction])
|
||||||
|
|
||||||
return image
|
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 : */
|
* vim:set ts=4 sw=4 : */
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user