From 590171ed9144d627cc47cb83c642ea23bc601a9e Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Thu, 21 May 2015 04:00:28 +0300 Subject: [PATCH] some work on loading indexes... Signed-off-by: Alex A. Naanou --- ui (gen4)/data.js | 15 +++++++ ui (gen4)/file.js | 106 ++++++++++++++++++++++++++++++++++++++++++-- ui (gen4)/viewer.js | 17 +++++++ 3 files changed, 135 insertions(+), 3 deletions(-) diff --git a/ui (gen4)/data.js b/ui (gen4)/data.js index 25703aff..5465a4bf 100755 --- a/ui (gen4)/data.js +++ b/ui (gen4)/data.js @@ -2655,6 +2655,21 @@ DataWithTagsPrototype.__proto__ = DataPrototype +/*********************************************************************/ + +// Proxy Data API to one of the target data objects... +var DataProxyPrototype = { + datasets: null, + + get order(){ + // XXX + }, + +} +//DataProxyPrototype.__proto__ = DataPrototype +DataProxyPrototype.__proto__ = DataWithTagsPrototype + + /*********************************************************************/ // Main Data object... diff --git a/ui (gen4)/file.js b/ui (gen4)/file.js index cf0e7699..aeb859b1 100755 --- a/ui (gen4)/file.js +++ b/ui (gen4)/file.js @@ -68,11 +68,20 @@ function(glob){ return guaranteeEvents('match end', glob) } // XXX glob has a problem: if a match happens fast enough and we are slow // enough to register a 'match' handler, then that match(s) will get // missed... -function listIndexes(base){ +var listIndexes = +module.listIndexes = +function(base){ return guaranteeGlobEvents(glob(base +'/**/'+ INDEX_DIR)) } +var listPreviews = +module.listPreviews = +function(base){ + return guaranteeGlobEvents(glob(base +'/*px/*jpg')) +} + + // XXX return a promise rather than an event emitter (???) function listJSON(path, pattern){ pattern = pattern || '*' @@ -105,6 +114,9 @@ function loadJSON(path){ // - get and load latest base file per keyword // - merge all later than loaded base diff files per keyword // +// Merging is done by copying the key-value pairs from diff to the +// resulting object. +// // // Index format (input): // .ImageGrid/ @@ -133,8 +145,9 @@ function loadJSON(path){ // NOTE: this is fairly generic and does not care about the type of data // or it's format as long as it's JSON and the file names comply // with the scheme above... +// NOTE: this only loads the JSON data and does not import or process +// anything... // -// XXX add support for sharding... // XXX test with: // requirejs(['file'], // function(m){ @@ -163,6 +176,27 @@ function(path, logger){ var root = {} // group by keyword... + // + // this will build a structure in the following format: + // { + // : [ + // // diff files... + // // NOTE: the first argument indicates + // // if this is a diff or not, used to + // // skip past the last base... + // [true, ], + // ... + // + // // base file (non-diff) + // [false, ] + // ], + // ... + // } + // + // This is used to sequence, load and correctly merge + // the found JSON files. + // + // NOTE: all files past the first non-diff are skipped. files .sort() .reverse() @@ -172,7 +206,7 @@ function(path, logger){ // .json / non-diff // NOTE: this is a special case, we add this to - // a seporate index and then concat it to + // a separate index and then concat it to // the final list if needed... if(s.length == 1){ var k = s[0] @@ -296,6 +330,72 @@ function(path, logger){ } +// get/populate the previews... +// +// format: +// { +// : { +// : { +// : , +// ... +// }, +// ... +// }, +// ... +// } +// +// XXX should this be compatible with loadIndex(..) data??? +// XXX handle errors.... +var loadPreviews = +module.loadPreviews = +function(base, previews, absolute_path){ + previews = previews || {} + + return new Promise(function(resolve, reject){ + listIndexes(base) + // XXX handle errors.... + //.on('error', function(err){ + //}) + .on('match', function(base){ + if(!(base in previews)){ + previews[base] = {} + } + + var images = previews[base] + + listPreviews(base) + // XXX handle errors.... + //.on('error', function(err){ + //}) + // preview name syntax: + // px/ - .jpg + .on('match', function(path){ + // get the data we need... + var gid = pathlib.basename(path).split(' - ')[0] + var res = pathlib.basename(pathlib.dirname(path)) + + // build the structure if it does not exist... + if(!(gid in images)){ + images[gid] = {} + } + if(images[gid].preview == null){ + images[gid].preview = {} + } + + // add a preview... + // NOTE: this will overwrite a previews if they are found in + // several locations... + images[gid].preview[res] = INDEX_DIR +'/'+ path.split(INDEX_DIR)[1] + }) + }) + .on('end', function(){ + resolve(previews) + }) + }) +} + + + /*********************************************************************/ // Writer... diff --git a/ui (gen4)/viewer.js b/ui (gen4)/viewer.js index 2fc45498..0d87aef4 100755 --- a/ui (gen4)/viewer.js +++ b/ui (gen4)/viewer.js @@ -1,6 +1,23 @@ /********************************************************************** * * +* Base architecture: +* +* Two trees are maintained: +* - no-gui +* - gui +* +* no-gui: +* aggregates: +* data +* images +* defines universal set of actions to manage and control state +* +* gui: +* extends no-gui and adds: +* ribbons +* extends and defines a set of gui control and state actions +* * **********************************************************************/