From a3a633096cacb809cdb01ee78b6daa403139f2d9 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Mon, 13 Feb 2017 05:47:14 +0300 Subject: [PATCH] chnages not generic... Signed-off-by: Alex A. Naanou --- ui (gen4)/features/base.js | 90 ++++++++++++- ui (gen4)/features/core.js | 127 ++++++++++++++++++ ui (gen4)/features/filesystem.js | 212 ------------------------------- ui (gen4)/features/metadata.js | 2 +- ui (gen4)/features/sharp.js | 4 +- ui (gen4)/features/sort.js | 29 ++++- ui (gen4)/features/ui-status.js | 4 - 7 files changed, 241 insertions(+), 227 deletions(-) diff --git a/ui (gen4)/features/base.js b/ui (gen4)/features/base.js index fc9cb1da..c955e8d3 100755 --- a/ui (gen4)/features/base.js +++ b/ui (gen4)/features/base.js @@ -840,13 +840,16 @@ module.Base = core.ImageGridFeatures.Feature({ title: 'ImageGrid base', tag: 'base', - /* XXX ??? + depends: [ + 'changes', + ], + /* suggested: [ 'tags', 'sort', 'tasks', ], - */ + //*/ actions: BaseActions, @@ -859,6 +862,45 @@ module.Base = core.ImageGridFeatures.Feature({ 'shiftImageRight', ], function(){ this.shiftImage.apply(this, [].slice(arguments, 1))}], + + // manage changes... + // everything changed... + [[ + 'claer', + 'loadURLs', + ], + function(){ this.markChanged('all') }], + + // data... + [[ + //'load', + + 'setBaseRibbon', + + 'shiftImageTo', + 'shiftImageUp', + 'shiftImageDown', + 'shiftImageLeft', + 'shiftImageRight', + 'shiftRibbonUp', + 'shiftRibbonDown', + + 'reverseImages', + 'reverseRibbons', + + 'alignToRibbon', + ], + function(_, target){ this.markChanged('data') }], + + // image specific... + [[ + 'rotateCW', + 'rotateCCW', + 'flipHorizontal', + 'flipVertical', + ], + function(_, target){ this.markChanged('images', [that.data.getImage(target)]) }], + ], }) @@ -1014,9 +1056,42 @@ module.Tags = core.ImageGridFeatures.Feature({ tag: 'tags', depends: [ 'base', + 'changes', ], actions: TagsActions, + + handlers: [ + // tags and images... + // NOTE: tags are also stored in images... + ['tag untag', + function(_, tags, gids){ + var that = this + var changes = [] + + gids = gids || [this.data.getImage()] + gids = gids.constructor !== Array ? + [this.data.getImage(gids)] + : gids + .map(function(e){ return that.data.getImage(e) }) + + tags = tags || [] + tags = tags.constructor !== Array ? [tags] : tags + + // tags... + if(tags.length > 0){ + this.markChanged('tags') + + tags.indexOf('selected') >= 0 + && this.markChanged('selected') + + tags.indexOf('bookmark') >= 0 + && this.markChanged('bookmarked') + } + + this.markChanged('images', gids) + }], + ], }) @@ -1366,9 +1441,20 @@ module.ImageGroup = core.ImageGridFeatures.Feature({ tag: 'image-group', depends: [ 'base', + 'changes', ], actions: ImageGroupActions, + + handlers: [ + [[ + 'group', + 'ungroup', + 'expandGroup', + 'collapseGroup', + ], + function(_, target){ this.markChanged('data') }], + ], }) diff --git a/ui (gen4)/features/core.js b/ui (gen4)/features/core.js index 7ffe1ab8..1415a410 100755 --- a/ui (gen4)/features/core.js +++ b/ui (gen4)/features/core.js @@ -21,6 +21,8 @@ * - journal * action journaling and undo/redo functionality * XXX needs revision... +* - changes +* change tracking * - workspace * XXX needs revision... * - tasks @@ -29,6 +31,8 @@ * basic framework for running test actions at startup... * * +* XXX some actions use the .clone(..) action/protocol, should this be +* defined here??? * **********************************************************************/ ((typeof define)[0]=='u'?function(f){module.exports=f(require)}:define) @@ -794,6 +798,129 @@ module.Journal = ImageGridFeatures.Feature({ +//--------------------------------------------------------------------- +// Changes API... + +var ChangesActions = actions.Actions({ + // This can be: + // - null/undefined - write all + // - true - write all + // - false - write nothing + // - { + // // write/skip data... + // data: , + // + // // write/skip images or write a diff including the given + // // s only... + // images: | [ , ... ], + // + // // write/skip tags... + // tags: , + // + // // write/skip bookmarks... + // bookmarked: , + // + // // write/skip selected... + // selected: , + // + // // feature specific custom flags... + // ... + // } + // + // NOTE: in the complex format all fields ar optional; if a field + // is not included it is not written (same as when set to false) + // NOTE: .current is written always. + chages: null, + + clone: [function(full){ + return function(res){ + res.changes = null + if(full && this.hasOwnProperty('changes') && this.changes){ + res.changes = JSON.parse(JSON.stringify(this.changes)) + } + } + }], + + markChanged: ['- System/', + doc`Mark data sections as changed... + + Mark everything changed... + .markChanged('all') + + Mark nothing changed... + .markChanged('none') + + Mark section(s) as changed... + .markChanged(
) + .markChanged(
, ..) + .markChanged([
, ..]) + + Mark item(s) of section as changed... + .markChanged(
, [, .. ]) + + 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. + `, + function(section, items){ + var that = this + var args = section instanceof Array ? + section + : util.args2array(arguments) + //var changes = this.changes = + var changes = + this.hasOwnProperty('changes') ? + this.changes || {} + : {} + + // all... + if(args.length == 1 && args[0] == 'all'){ + // NOTE: this is better than delete as it will shadow + // the parent's changes in case we got cloned from + // a live instance... + //delete this.changes + this.changes = null + + // none... + } else if(args.length == 1 && args[0] == 'none'){ + this.changes = false + + // everything is marked changed, everything will be saved + // anyway... + // NOTE: to reset this use .markChanged('none') and then + // manually add the desired changes... + } else if(this.changes == null){ + return + + // section items... + } else if(items instanceof Array) { + changes[section] = (changes[section] || []).concat(items) + this.changes = changes + + // section(s)... + } else { + args.forEach(function(arg){ + changes[arg] = true + }) + this.changes = changes + } + }], +}) + + +var Changes = +module.Changes = ImageGridFeatures.Feature({ + title: '', + doc: '', + + tag: 'changes', + depends: [ ], + + actions: ChangesActions, +}) + + + //--------------------------------------------------------------------- // Workspace... // diff --git a/ui (gen4)/features/filesystem.js b/ui (gen4)/features/filesystem.js index 6c5b18af..a355f376 100755 --- a/ui (gen4)/features/filesystem.js +++ b/ui (gen4)/features/filesystem.js @@ -115,218 +115,6 @@ module.FileSystemInfo = core.ImageGridFeatures.Feature({ -/*********************************************************************/ -// Changes API... - -var ChangesActions = actions.Actions({ - // This can be: - // - null/undefined - write all - // - true - write all - // - false - write nothing - // - { - // // write/skip data... - // data: , - // - // // write/skip images or write a diff including the given - // // s only... - // images: | [ , ... ], - // - // // write/skip tags... - // tags: , - // - // // write/skip bookmarks... - // bookmarked: , - // - // // write/skip selected... - // selected: , - // } - // - // NOTE: in the complex format all fields ar optional; if a field - // is not included it is not written (same as when set to false) - // NOTE: .current is written always. - chages: null, - - clone: [function(full){ - return function(res){ - res.changes = null - if(full && this.hasOwnProperty('changes') && this.changes){ - res.changes = JSON.parse(JSON.stringify(this.changes)) - } - } - }], - - // Mark data sections as changed... - // - // Mark everything changed... - // .markChanged('all') - // - // Mark nothing changed... - // .markChanged('none') - // - // Mark a section changed... - // .markChanged('data') - // .markChanged('tags') - // .markChanged('selected') - // .markChanged('bookmarked') - // - // Mark image changed... - // .markChanged(, ...) - // .markChanged([, ...]) - // - // - // 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: ['- System/', - function(section){ - var that = this - var args = section instanceof Array ? section : util.args2array(arguments) - //var changes = this.changes = - var changes = - this.hasOwnProperty('changes') ? - this.changes || {} - : {} - - //console.log('CHANGED:', args) - - // all... - if(args.length == 1 && args[0] == 'all'){ - // NOTE: this is better than delete as it will shadow - // the parent's changes in case we got cloned from - // a live instance... - //delete this.changes - this.changes = null - - // none... - } else if(args.length == 1 && args[0] == 'none'){ - this.changes = false - - // everything is marked changed, everything will be saved - // anyway... - // NOTE: to reset this use .markChanged('none') and then - // manually add the desired changes... - } else if(this.changes == null){ - return - - } else { - var images = (changes.images || []) - - args.forEach(function(arg){ - var gid = that.data.getImage(arg) - - // special case: image gid... - if(gid != -1 && gid != null){ - images.push(gid) - images = images.unique() - - changes.images = images - that.changes = changes - - // all other keywords... - } else { - changes[arg] = true - that.changes = changes - } - }) - } - }], -}) - - -var Changes = -module.Changes = core.ImageGridFeatures.Feature({ - title: '', - doc: '', - - tag: 'changes', - depends: [ ], - - actions: ChangesActions, - - handlers: [ - // everything changed... - [[ - 'loadURLs', - 'clear', - ], - function(){ - this.markChanged('all') - }], - - // data... - [[ - //'clear', - //'load', - - 'setBaseRibbon', - - 'shiftImageTo', - 'shiftImageUp', - 'shiftImageDown', - 'shiftImageLeft', - 'shiftImageRight', - 'shiftRibbonUp', - 'shiftRibbonDown', - - 'sortImages', - 'reverseImages', - 'reverseRibbons', - - 'alignToRibbon', - - 'group', - 'ungroup', - 'expandGroup', - 'collapseGroup', - ], - function(_, target){ this.markChanged('data') }], - - // image specific... - [[ - 'rotateCW', - 'rotateCCW', - 'flipHorizontal', - 'flipVertical', - ], - function(_, target){ this.markChanged(target) }], - - // tags and images... - // NOTE: tags are also stored in images... - ['tag untag', - function(_, tags, gids){ - var changes = [] - - gids = gids || [this.data.getImage()] - gids = gids.constructor !== Array ? [this.data.getImage(gids)] : gids - - tags = tags || [] - tags = tags.constructor !== Array ? [tags] : tags - - // images... - changes = changes.concat(gids) - - // tags... - if(tags.length > 0){ - changes.push('tags') - - // selected... - if(tags.indexOf('selected') >= 0){ - changes.push('selected') - } - - // bookmark... - if(tags.indexOf('bookmark') >= 0){ - changes.push('bookmarked') - } - } - - this.markChanged.apply(this, changes) - }], - ], -}) - - - /*********************************************************************/ // Loader... diff --git a/ui (gen4)/features/metadata.js b/ui (gen4)/features/metadata.js index 7b13d1ab..3ad78fb5 100755 --- a/ui (gen4)/features/metadata.js +++ b/ui (gen4)/features/metadata.js @@ -157,7 +157,7 @@ var MetadataReaderActions = actions.Actions({ that.images[gid].metadata = m // XXX - that.markChanged && that.markChanged(gid) + that.markChanged && that.markChanged('images', [gid]) } resolve(data) diff --git a/ui (gen4)/features/sharp.js b/ui (gen4)/features/sharp.js index 574bf4a7..ad1d2e0a 100755 --- a/ui (gen4)/features/sharp.js +++ b/ui (gen4)/features/sharp.js @@ -202,7 +202,7 @@ var SharpActions = actions.Actions({ img.orientation = o.orientation img.flipped = o.flipped - that.markChanged(data.gid) + that.markChanged('images', [data.gid]) } logger && logger.emit(data.status, data.path) @@ -287,7 +287,7 @@ module.Sharp = core.ImageGridFeatures.Feature({ img.orientation = o.orientation || 0 img.flipped = o.flipped - that.markChanged(gid) + that.markChanged('images', [gid]) // update image to use the orientation... // XXX this might be a source for recursion diff --git a/ui (gen4)/features/sort.js b/ui (gen4)/features/sort.js index b07cc3cf..7479097b 100755 --- a/ui (gen4)/features/sort.js +++ b/ui (gen4)/features/sort.js @@ -350,8 +350,8 @@ module.SortActions = actions.Actions({ this.data.sort_method = data.data.sort_method } - if(data.data && data.data.sort_cache){ - this.data.sort_cache = data.data.sort_cache + if(data.data && data.sort_cache){ + this.data.sort_cache = data.sort_cache } } }], @@ -363,11 +363,12 @@ module.SortActions = actions.Actions({ } if(this.data.sort_cache){ - res.data.sort_cache = this.data.sort_cache + res.sort_cache = this.data.sort_cache + } - } else if(this.toggleImageSort('?') == 'Manual'){ - res.data.sort_cache = res.data.sort_cache || {} - res.data.sort_cache['Manual'] = this.data.order + if(this.toggleImageSort('?') == 'Manual'){ + res.sort_cache = res.sort_cache || {} + res.sort_cache['Manual'] = this.data.order.slice() } } }], @@ -380,6 +381,7 @@ module.Sort = core.ImageGridFeatures.Feature({ tag: 'sort', depends: [ 'base', + 'changes', ], suggested: [ 'ui-sort', @@ -392,6 +394,21 @@ module.Sort = core.ImageGridFeatures.Feature({ function(){ this.data.sort_method = 'Manual' }], + + ['prepareIndexForWrite', + function(res){ + var changed = this.changes == null + || this.changes.sort_cache + + if(changed && res.raw.sort_cache){ + res.index['sort_cache'] = res.raw.sort_cache + } + }], + + // manage changes... + // XXX also need to mark 'sort_cache' + ['sortImages', + function(_, target){ this.markChanged('data') }], ], }) diff --git a/ui (gen4)/features/ui-status.js b/ui (gen4)/features/ui-status.js index 4edeebe1..43e94249 100755 --- a/ui (gen4)/features/ui-status.js +++ b/ui (gen4)/features/ui-status.js @@ -248,10 +248,6 @@ var StatusBarActions = actions.Actions({ return item }, changes: function(item, gid, img){ - if(this.changes === undefined){ - return $() - } - if(typeof(item) == typeof('str')){ item = $('') .addClass('changes')