From f204503464f9cd6f97f961be2b30952a257defcd Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Wed, 15 Feb 2017 03:28:18 +0300 Subject: [PATCH] started tuning the order saving and caching... Signed-off-by: Alex A. Naanou --- ui (gen4)/features/base.js | 2 +- ui (gen4)/features/core.js | 8 +++++--- ui (gen4)/features/sort.js | 29 +++++++++++++++++++++-------- 3 files changed, 27 insertions(+), 12 deletions(-) diff --git a/ui (gen4)/features/base.js b/ui (gen4)/features/base.js index c955e8d3..84940707 100755 --- a/ui (gen4)/features/base.js +++ b/ui (gen4)/features/base.js @@ -899,7 +899,7 @@ module.Base = core.ImageGridFeatures.Feature({ 'flipHorizontal', 'flipVertical', ], - function(_, target){ this.markChanged('images', [that.data.getImage(target)]) }], + function(_, target){ this.markChanged('images', [this.data.getImage(target)]) }], ], }) diff --git a/ui (gen4)/features/core.js b/ui (gen4)/features/core.js index 1415a410..5d57198f 100755 --- a/ui (gen4)/features/core.js +++ b/ui (gen4)/features/core.js @@ -858,9 +858,11 @@ var ChangesActions = actions.Actions({ Mark item(s) of section as changed... .markChanged(
, [, .. ]) + NOTE: when marking section items, the new items will be added to + the set of already marked items. NOTE: when .changes is null (i.e. everything changed, marked via - .markChanged('all')) then calling this with anything other - than 'none' will have no effect. + .markChanged('all')) then calling this with anything other + than 'none' will have no effect. `, function(section, items){ var that = this @@ -894,7 +896,7 @@ var ChangesActions = actions.Actions({ // section items... } else if(items instanceof Array) { - changes[section] = (changes[section] || []).concat(items) + changes[section] = (changes[section] || []).concat(items).unique() this.changes = changes // section(s)... diff --git a/ui (gen4)/features/sort.js b/ui (gen4)/features/sort.js index 037b106c..5b4850dd 100755 --- a/ui (gen4)/features/sort.js +++ b/ui (gen4)/features/sort.js @@ -469,21 +469,34 @@ module.Sort = core.ImageGridFeatures.Feature({ ['prepareIndexForWrite', function(res){ - var changed = this.changes == null - || this.changes.sort_cache + var c = this.changes - if(changed && res.raw.sort_order){ - res.index['sort_order'] = res.raw.sort_order - } - if(changed && res.raw.sort_cache){ - res.index['sort_cache'] = res.raw.sort_cache + var save = function(attr){ + if((c == null || c[attr]) && res.raw[attr]){ + // full save... + if(c == null){ + res.index[attr] = res.raw[attr] + + // build diff... + } else { + var diff = {} + c[attr].forEach(function(k){ diff[k] = res.raw[attr][k] }) + res.index[attr +'-diff'] = diff + } + } } + + save('sort_order') + save('sort_cache') }], // manage changes... - // XXX also need to mark 'sort_cache' ['sortImages', function(_, target){ this.markChanged('data') }], + ['saveOrder', + function(_, title){ this.markChanged('sort_order', [title]) }], + ['cacheOrder', + function(){ this.markChanged('sort_cache', [this.data.sort_method]) }], ], })