fised index loader bug -- did not merge diffs correctly...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2015-11-16 11:31:15 +03:00
parent bca8b3c6e9
commit afb97ab46e
5 changed files with 57 additions and 45 deletions

View File

@ -159,6 +159,7 @@ function loadJSON(path){
// XXX need to do better error handling -- stop when an error is not recoverable... // XXX need to do better error handling -- stop when an error is not recoverable...
// XXX a bit overcomplicated (???), see if this can be split into more generic // XXX a bit overcomplicated (???), see if this can be split into more generic
// sections... // sections...
// XXX problem with diff merging...
var loadIndex = var loadIndex =
module.loadIndex = module.loadIndex =
function(path, logger){ function(path, logger){
@ -252,11 +253,12 @@ function(path, logger){
} }
}) })
// load... // load...
Promise Promise
.all(Object.keys(index).map(function(k){ .all(Object.keys(index).map(function(keyword){
// get relevant paths... // get relevant paths...
var diffs = index[k] var diffs = index[keyword]
var latest = diffs.splice(-1)[0][1] var latest = diffs.splice(-1)[0][1]
// NOTE: so far I really do not like how nested and // NOTE: so far I really do not like how nested and
@ -270,32 +272,45 @@ function(path, logger){
// load latest... // load latest...
return loadJSON(latest) return loadJSON(latest)
.then(function(data){ .then(function(data){
logger && logger.emit('loaded', latest)
var loading = {}
// handle diffs... // handle diffs...
return Promise return Promise
.all(diffs // load diffs...
.reverse() .all(diffs.map(function(p){
.map(function(p){ p = p[1]
p = p[1] return loadJSON(p)
// load diff... // XXX handle errors...
return loadJSON(p) // XXX we should abort loading this index...
// XXX handle errors... .catch(function(err){
// XXX we should abort loading this index... logger && logger.emit('error', err)
.catch(function(err){ })
logger && logger.emit('error', err) .then(function(json){
}) // NOTE: we can't merge here
.done(function(json){ // as the files can be
// merge... // read in arbitrary order...
for(var k in json){ loading[p] = json
data[k] = json[k] })
} }))
// merge diffs...
logger && logger.emit('loaded', p)
})
}))
.then(function(){ .then(function(){
res[k] = data diffs
.reverse()
.forEach(function(p){
p = p[1]
logger && logger.emit('loaded', latest) var json = loading[p]
for(var n in json){
data[n] = json[n]
}
logger && logger.emit('loaded', p)
})
res[keyword] = data
}) })
}) })
})) }))
@ -312,6 +327,7 @@ function(path, logger){
// no explicit index given -- find all in sub tree... // no explicit index given -- find all in sub tree...
} else { } else {
var res = {} var res = {}
var loaders = []
// XXX handle 'error' event... // XXX handle 'error' event...
listIndexes(path) listIndexes(path)
@ -321,8 +337,8 @@ function(path, logger){
}) })
// collect the found indexes... // collect the found indexes...
.on('match', function(path){ .on('match', function(path){
loadIndex(path, logger) loaders.push(loadIndex(path, logger)
.done(function(obj){ .then(function(obj){
// NOTE: considering that all the paths within // NOTE: considering that all the paths within
// the index are relative to the preview // the index are relative to the preview
// dir (the parent dir to the index root) // dir (the parent dir to the index root)
@ -330,11 +346,12 @@ function(path, logger){
// itself in the base path... // itself in the base path...
var p = path.split(INDEX_DIR)[0] var p = path.split(INDEX_DIR)[0]
res[p] = obj[path] res[p] = obj[path]
}) }))
}) })
// done... // done...
.on('end', function(paths){ .on('end', function(paths){
resolve(res) // wait for all the loaders to complete...
Promise.all(loaders).then(function(){ resolve(res) })
}) })
} }
}) })
@ -408,6 +425,7 @@ function(base, previews, absolute_path){
// XXX move this to a better spot... // XXX move this to a better spot...
// XXX make this merge if we locate more than one index...
var buildIndex = var buildIndex =
module.buildIndex = function(index, base){ module.buildIndex = function(index, base){
var d = data.Data.fromJSON(index.data) var d = data.Data.fromJSON(index.data)
@ -453,12 +471,6 @@ module.buildIndex = function(index, base){
} }
// XXX
var mergeIndex =
module.mergeIndex = function(index, base){
// XXX
}
/*********************************************************************/ /*********************************************************************/
// Writer... // Writer...

View File

@ -168,9 +168,9 @@ body {
</style> </style>
<!--script> <script>
require('nw.gui').Window.get().showDevTools() typeof(require) != 'undefined' && require('nw.gui').Window.get().showDevTools()
</script--> </script>
<script src="ext-lib/jquery.js"></script> <script src="ext-lib/jquery.js"></script>

View File

@ -108,7 +108,7 @@ var getElementOrigin = makeCSSVendorAttrGetter(
'transformOrigin', 'transformOrigin',
{top: 0, left: 0}, {top: 0, left: 0},
function(data){ function(data){
res = /(-?[0-9.]*(px|%)) (-?[0-9.]*(px|%))/.exec(data) var res = /(-?[0-9.]*(px|%)) (-?[0-9.]*(px|%))/.exec(data)
return { return {
left: res[1].slice(-2) == 'px' ? parseFloat(res[1]) : res[1], left: res[1].slice(-2) == 'px' ? parseFloat(res[1]) : res[1],
top: res[3].slice(-2) == 'px' ? parseFloat(res[3]) : res[3], top: res[3].slice(-2) == 'px' ? parseFloat(res[3]) : res[3],
@ -130,7 +130,7 @@ var getElementOffset = makeCSSVendorAttrGetter(
'transform', 'transform',
{left: 0, top: 0}, {left: 0, top: 0},
function(data){ function(data){
res = /(translate\(|matrix\([^,]*,[^,]*,[^,]*,[^,]*,)([^,]*),([^\)]*)\)/.exec(data) var res = /(translate\(|matrix\([^,]*,[^,]*,[^,]*,[^,]*,)([^,]*),([^\)]*)\)/.exec(data)
return { return {
left: parseFloat(res[2]), left: parseFloat(res[2]),
top: parseFloat(res[3]) top: parseFloat(res[3])

View File

@ -125,8 +125,8 @@ if(typeof(glob) != 'undefined'){
} }
window.loadMBFWR1 = function(){ window.loadMBFWR1 = function(logger){
a.loadPath('L:/mnt/hdd15 (photo)/NTFS2/media/img/my/work/20151022 - MBFWR (1),/*') a.loadPath('L:/mnt/hdd15 (photo)/NTFS2/media/img/my/work/20151022 - MBFWR (1),/*', logger)
} }

View File

@ -3022,15 +3022,15 @@ if(window.nodejs != null){
var FileSystemLoaderActions = actions.Actions({ var FileSystemLoaderActions = actions.Actions({
// XXX // XXX
loadPath: ['File/', loadPath: ['File/',
function(path){ function(path, logger){
var that = this var that = this
// XXX get a logger... // XXX get a logger...
// XXX this will not work for explicit path (path to a dir // XXX this will not work for explicit path (path to a dir
// that contains the index) // that contains the index)
file.loadIndex(path) file.loadIndex(path, logger)
.done(function(res){ .then(function(res){
// XXX if res is empty load raw... // XXX if res is empty load raw...
// XXX res may contain multiple indexes, need to // XXX res may contain multiple indexes, need to
@ -3040,7 +3040,7 @@ var FileSystemLoaderActions = actions.Actions({
var index = res[k] var index = res[k]
// XXX use the logger... // XXX use the logger...
console.log('LOADING:', k) console.log('LOADING:', k, res)
that.load(file.buildIndex(index, k)) that.load(file.buildIndex(index, k))
}) })