From dd0b7f08425dd8ec6cbdcf0ccdf479d36f2e904f Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Sun, 1 Oct 2017 15:44:18 +0300 Subject: [PATCH] cleanup and refactoring... Signed-off-by: Alex A. Naanou --- ui (gen4)/features/collections.js | 40 +++++++++++++++++++++++++------ ui (gen4)/features/filesystem.js | 12 +++++----- ui (gen4)/features/meta.js | 6 +++++ 3 files changed, 45 insertions(+), 13 deletions(-) diff --git a/ui (gen4)/features/collections.js b/ui (gen4)/features/collections.js index a4b57a37..09a089b3 100755 --- a/ui (gen4)/features/collections.js +++ b/ui (gen4)/features/collections.js @@ -1106,25 +1106,36 @@ module.Collection = core.ImageGridFeatures.Feature({ // XXX might be a good idea to replace 'full' with changes to // override .changes... // XXX need to account for collection local .changes... + // XXX might be a good idea to build local changes in 'prepareIndexForWrite.pre'... + // ...or build and include .changes in .json(..) ['prepareIndexForWrite', - function(res, _, full){ + function(res){ var that = this - var changed = full == true - || res.changes === true + var changed = res.changes === true || res.changes.collections var collections = this.collections - if(changed && res.raw.collections){ + // collections partially changed... + var partial = Object.keys(this.collections) + .filter(function(t){ + return res.changes['collection: ' + + JSON.stringify(collections[t].gid)] }) + + if((partial.length > 0 || changed) + && res.raw.collections){ // select the actual changed collection list... changed = changed === true ? Object.keys(res.raw.collections) : changed + changed = (changed || []).concat(partial) // collection index... // // NOTE: we are placing this in the index root to // simplify lazy-loading of the collection // index... + // XXX save this only if index has changed... + // ...need 'collection-index' in changes... // XXX need lazy-load handler in fs-loader for this... // XXX don't like the name... var index = res.index['collection-index'] = {} @@ -1134,12 +1145,24 @@ module.Collection = core.ImageGridFeatures.Feature({ changed // skip the raw field... - .filter(function(k){ return changed.indexOf(k) >= 0 }) + .filter(function(k){ + return res.raw.collections[k] + && changed.indexOf(k) >= 0 }) .forEach(function(k){ var gid = res.raw.collections[k].gid || k var path = 'collections/'+ gid var raw = res.raw.collections[k] + // local collection changes... + // XXX local changes are not processed correctly + // when the target collection is loaded... + // XXX revise the local changes format... + var local_changes = partial.indexOf(k) < 0 || {} + if(local_changes !== true){ + (res.changes['collection: '+ JSON.stringify(gid)] || []) + .forEach(function(c){ local_changes[c] = true }) + } + // collections//metadata var metadata = res.index[path +'/metadata'] = {} Object.keys(raw) @@ -1149,8 +1172,11 @@ module.Collection = core.ImageGridFeatures.Feature({ // XXX use collection changes!!! // ...this will need .prepareIndexForWrite(..) // refactoring to replace 'full' with 'changed'... - var prepared = that.prepareIndexForWrite(raw, true).index + //var prepared = that.prepareIndexForWrite(raw, true).index + var prepared = that.prepareIndexForWrite(raw, local_changes).index + // move the collection data to collection path... + // XXX do we need to cleanup metadata??? Object.keys(prepared) .forEach(function(key){ res.index[path +'/'+ key] = prepared[key] @@ -1418,7 +1444,7 @@ module.CollectionTags = core.ImageGridFeatures.Feature({ // XXX would be nice to be able to reuse the base functionality // here... ['prepareIndexForWrite', - function(res, _, full){ + function(res){ var raw = res.raw.collections || {} // NOTE: we are cheating here, we do not need to check diff --git a/ui (gen4)/features/filesystem.js b/ui (gen4)/features/filesystem.js index 05de5907..a7d5b92b 100755 --- a/ui (gen4)/features/filesystem.js +++ b/ui (gen4)/features/filesystem.js @@ -88,9 +88,9 @@ var IndexFormatActions = actions.Actions({ .prepareIndexForWrite(json) -> data - Prepare a full state (current/specific)... - .prepareIndexForWrite(null, true) - .prepareIndexForWrite(json, true) + Prepare a state overwriting changes... + .prepareIndexForWrite(null, changes) + .prepareIndexForWrite(json, changes) -> data NOTE: this will disregard .changes @@ -149,9 +149,9 @@ var IndexFormatActions = actions.Actions({ - as returned by Date.timeStamp() (see: jli) `, - function(json, full){ + function(json, changes){ json = json || this.json('base') - var changes = full ? null + changes = changes !== undefined ? changes : this.hasOwnProperty('changes') ? this.changes : null changes = changes === null ? true : changes @@ -1060,7 +1060,7 @@ module.Comments = core.ImageGridFeatures.Feature({ // need to do anything special to restore, i.e. no need for // doing anything on .prepareJSONForLoad(..) ['prepareIndexForWrite', - function(res, _, full){ + function(res){ var changed = res.changes === true || res.changes.comments diff --git a/ui (gen4)/features/meta.js b/ui (gen4)/features/meta.js index cbb4199d..ead2b6d2 100755 --- a/ui (gen4)/features/meta.js +++ b/ui (gen4)/features/meta.js @@ -50,6 +50,12 @@ core.ImageGridFeatures.Feature('viewer-testing', [ 'viewer-commandline', 'viewer-minimal', + // NOTE: this is not strictly needed unless we need to save stuff, + // added here mostly for testing purposes... + // ...this is best included by direct feature dependency. + 'index-format', + + 'collections', // XXX remove when done testing...