From 3aa03faea6946302f62bdda05e4e3c6cf77a60fa Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Wed, 15 Feb 2017 05:21:28 +0300 Subject: [PATCH] moving to new read/write format... Signed-off-by: Alex A. Naanou --- ui (gen4)/features/base.js | 9 ++++++ ui (gen4)/features/filesystem.js | 17 ++++++++--- ui (gen4)/features/sort.js | 51 ++++++++++++++++---------------- 3 files changed, 48 insertions(+), 29 deletions(-) diff --git a/ui (gen4)/features/base.js b/ui (gen4)/features/base.js index ccb38bc1..32c2857f 100755 --- a/ui (gen4)/features/base.js +++ b/ui (gen4)/features/base.js @@ -1111,6 +1111,15 @@ module.Tags = core.ImageGridFeatures.Feature({ this.markChanged('images', gids) }], + // XXX + ['prepareIndexForWrite', + function(res, _, full){ + // XXX move code here from file.buildIndex(..) + // - res.raw.tags -> res.index.tags + // - ..tags.selected -> .selected + // - ..tags.bookmark -> .bookmarked + // XXX will need a symmetrical action to reverse all of this... + }], ], }) diff --git a/ui (gen4)/features/filesystem.js b/ui (gen4)/features/filesystem.js index c54d5b67..6ac03634 100755 --- a/ui (gen4)/features/filesystem.js +++ b/ui (gen4)/features/filesystem.js @@ -130,6 +130,16 @@ var FileSystemLoaderActions = actions.Actions({ 'default-load-method': 'loadIndex', }, + // NOTE: this is the reverse of .prepareIndexForWrite(..) + // + // XXX do we need both this and file.buildIndex(..), we essentially create + // a Data object and then create it again in .load()... + prepareJSONForLoad: ['- File/Prepare JSON for loading', + function(json, base_path){ + // XXX move the code up here from file.js... + return file.buildIndex(json, base_path) }], + + // XXX is this a hack??? // XXX need a more generic form... checkPath: ['- File/', @@ -147,8 +157,6 @@ var FileSystemLoaderActions = actions.Actions({ // NOTE: this will add a .from field to .location, this will indicate // the date starting from which saves are loaded. // - // XXX do we need both this and file.buildIndex(..), we essentially create - // a Data object and then create it again in .load()... // XXX look inside... loadIndex: ['- File/Load index', function(path, from_date, logger){ @@ -220,7 +228,7 @@ var FileSystemLoaderActions = actions.Actions({ continue } - var part = file.buildIndex(res[k], k) + var part = that.prepareJSONForLoad(res[k], k) // load the first index... if(index == null){ @@ -1588,6 +1596,7 @@ var FileSystemWriterActions = actions.Actions({ // // For more info see file.writeIndex(..) and file.loadIndex(..). // + // NOTE: this is the reverse of .prepareJSONForLoad(..) prepareIndexForWrite: ['- File/Prepare index for writing', function(json, full){ json = json || this.json('base') @@ -1600,7 +1609,7 @@ var FileSystemWriterActions = actions.Actions({ index: file.prepareIndex(json, changes), } }], - + // Save index... // // Returns: diff --git a/ui (gen4)/features/sort.js b/ui (gen4)/features/sort.js index bb628881..f496ca4d 100755 --- a/ui (gen4)/features/sort.js +++ b/ui (gen4)/features/sort.js @@ -380,10 +380,9 @@ module.SortActions = actions.Actions({ // XXX add drop/load actions... saveOrder: ['- Sort/', function(title){ - if(title){ - var cache = this.data.sort_order = this.data.sort_order || {} - cache[title] = this.data.order.slice() - } + title = title || 'Manual' + var cache = this.data.sort_order = this.data.sort_order || {} + cache[title] = this.data.order.slice() }], loadOrder: ['- Srot/', function(title, reverse){ @@ -413,35 +412,32 @@ module.SortActions = actions.Actions({ // .data.sort_cache - cached sort order (optional) load: [function(data){ return function(){ - if(data.data && data.data.sort_method){ - this.data.sort_method = data.data.sort_method - } + var that = this - if(data.data && data.sort_order){ - this.data.sort_order = data.sort_order - } - if(data.data && data.sort_cache){ - this.data.sort_cache = data.sort_cache - } + data.data + && ['sort_method', 'sort_order', 'sort_cache'] + .forEach(function(attr){ + if(data.data[attr]){ + that.data[attr] = data.data[attr] + } + }) } }], - // XXX should .sort_cache be stored separately??? json: [function(){ return function(res){ - if(this.data.sort_method){ - res.data.sort_method = this.data.sort_method - } + var that = this - if(this.data.sort_order){ - res.sort_order = this.data.sort_order - } - if(this.data.sort_cache){ - res.sort_cache = this.data.sort_cache - } + ;['sort_method', 'sort_order', 'sort_cache'] + .forEach(function(attr){ + if(that.data[attr]){ + res.data[attr] = that.data[attr] + } + }) + // special case: unsaved manual order... if(this.toggleImageSort('?') == 'Manual'){ - res.sort_order = res.sort_order || {} - res.sort_order['Manual'] = this.data.order.slice() + res.data.sort_order = res.sort_order || {} + res.data.sort_order['Manual'] = this.data.order.slice() } } }], @@ -490,6 +486,11 @@ module.Sort = core.ImageGridFeatures.Feature({ save('sort_order') save('sort_cache') }], + ['prepareJSONForLoad', + function(res){ + // XXX + //res.data.sort_cache = res.sort_cache + }], // manage changes... ['sortImages',