From ec748636f255389f2e6d328804d35a2abf180e29 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Mon, 2 Oct 2017 01:35:09 +0300 Subject: [PATCH] storing collections in index done, still needs testing... Signed-off-by: Alex A. Naanou --- ui (gen4)/features/base.js | 8 ++++ ui (gen4)/features/collections.js | 74 +++++++++++++++++++++++++++---- ui (gen4)/features/core.js | 16 +++++++ ui (gen4)/features/filesystem.js | 5 ++- ui (gen4)/features/sort.js | 4 ++ 5 files changed, 96 insertions(+), 11 deletions(-) diff --git a/ui (gen4)/features/base.js b/ui (gen4)/features/base.js index 60747fd8..8db51cc1 100755 --- a/ui (gen4)/features/base.js +++ b/ui (gen4)/features/base.js @@ -657,6 +657,10 @@ core.ImageGridFeatures.Feature({ var changes = res.changes + if(!changes){ + return + } + // data... if(changes === true || changes.data){ res.index.data = res.raw.data @@ -1289,6 +1293,10 @@ module.TagsEdit = core.ImageGridFeatures.Feature({ function(res){ var changes = res.changes + if(!changes){ + return + } + if((changes === true || changes.tags) && res.raw.data.tags){ res.index.tags = res.raw.data.tags } diff --git a/ui (gen4)/features/collections.js b/ui (gen4)/features/collections.js index 09a089b3..2fb7d1f1 100755 --- a/ui (gen4)/features/collections.js +++ b/ui (gen4)/features/collections.js @@ -1100,23 +1100,73 @@ module.Collection = core.ImageGridFeatures.Feature({ } }], + // update current collection changes... + // + // This will: + // 1) update .changes['collection: '] with the current + // loaded .changes state... + // 2) in 'base' mode, update the res.changes with base data + // changes... + // + // NOTE: we do not need to do anything on the .load(..) side... + ['json.pre', + function(mode){ + var cur = this.collection || MAIN_COLLECTION_TITLE + if(cur == null || cur == MAIN_COLLECTION_TITLE){ + return + } + + var changes = this.changes + + // everything/nothing changed -- nothing to do... + if(!changes || changes === true || changes[cur] === true){ + return + } + + var gid = this.collectionGID + var id = 'collection: '+ JSON.stringify(gid) + var change_tags = this.config['collection-transfer-changes'] || ['data'] + + var changed = change_tags + .filter(function(tag){ + return changes[tag] === true }) + + if(changed.length){ + this.changes[id] = (this.changes[id] || []) + .concat(changed) + .unique() } + + // reset the base change tags to the base data (from collection data)... + if(mode == 'base'){ + return function(res){ + var base_id = 'collection: '+ JSON.stringify(MAIN_COLLECTION_GID) + var base = this.changes[base_id] || [] + + // no need to save the base collection changes... + delete res.changes[base_id] + + // clear... + change_tags.forEach(function(tag){ + delete res.changes[tag] }) + // set... + base.forEach(function(tag){ + res.changes[tag] = true }) + } + } + }], - // XXX account for 'base' mode changes... (???) - // use : .config['collection-transfer-changes'] - // 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){ + if(!res.changes){ + return + } var that = this var changed = res.changes === true || res.changes.collections var collections = this.collections // collections partially changed... - var partial = Object.keys(this.collections) + var partial = Object.keys(collections || {}) .filter(function(t){ return res.changes['collection: ' + JSON.stringify(collections[t].gid)] }) @@ -1143,6 +1193,8 @@ module.Collection = core.ImageGridFeatures.Feature({ .forEach(function(title){ index[collections[title].gid || title] = title }) + var change_tags = this.config['collection-transfer-changes'] || ['data'] + changed // skip the raw field... .filter(function(k){ @@ -1176,12 +1228,16 @@ module.Collection = core.ImageGridFeatures.Feature({ 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] delete metadata[key] }) + // cleanup metadata... + // XXX do we need this??? + change_tags.forEach(function(key){ + delete metadata[key] + }) }) } }], diff --git a/ui (gen4)/features/core.js b/ui (gen4)/features/core.js index 769b060d..ffd2d0d9 100755 --- a/ui (gen4)/features/core.js +++ b/ui (gen4)/features/core.js @@ -968,6 +968,22 @@ module.Changes = ImageGridFeatures.Feature({ ], actions: ChangesActions, + + handlers: [ + // handle changes... + ['json', + function(res, mode){ + if(this.changes != null){ + res.changes = JSON.parse(JSON.stringify(this.changes)) + } + }], + ['load', + function(_, data){ + if(data.changes){ + this.changes = JSON.parse(JSON.stringify(data.changes)) + } + }], + ], }) diff --git a/ui (gen4)/features/filesystem.js b/ui (gen4)/features/filesystem.js index a7d5b92b..72b23e5a 100755 --- a/ui (gen4)/features/filesystem.js +++ b/ui (gen4)/features/filesystem.js @@ -152,8 +152,9 @@ var IndexFormatActions = actions.Actions({ function(json, changes){ json = json || this.json('base') changes = changes !== undefined ? changes - : this.hasOwnProperty('changes') ? this.changes - : null + : json.changes + //: this.hasOwnProperty('changes') ? this.changes + //: null changes = changes === null ? true : changes return { date: json.date || Date.timeStamp(), diff --git a/ui (gen4)/features/sort.js b/ui (gen4)/features/sort.js index 01a0f9af..3d80aba3 100755 --- a/ui (gen4)/features/sort.js +++ b/ui (gen4)/features/sort.js @@ -539,6 +539,10 @@ module.Sort = core.ImageGridFeatures.Feature({ function(res){ var c = res.changes + if(!c){ + return + } + ;['sort_order', 'sort_cache'] .forEach(function(attr){ if((c === true || c[attr]) && res.raw.data[attr]){