From 9125e1760bbbea0797df8565e63166b0ec63c99f Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Sun, 5 Jun 2016 04:11:20 +0300 Subject: [PATCH] split out recover from location... Signed-off-by: Alex A. Naanou --- ui (gen4)/features/all.js | 1 + ui (gen4)/features/filesystem.js | 1 + ui (gen4)/features/location.js | 97 ---------------------- ui (gen4)/features/recover.js | 135 +++++++++++++++++++++++++++++++ 4 files changed, 137 insertions(+), 97 deletions(-) create mode 100755 ui (gen4)/features/recover.js diff --git a/ui (gen4)/features/all.js b/ui (gen4)/features/all.js index 0674195f..4f0edbae 100755 --- a/ui (gen4)/features/all.js +++ b/ui (gen4)/features/all.js @@ -15,6 +15,7 @@ require('features/base') require('features/sort') require('features/tags') require('features/location') +require('features/recover') require('features/history') require('features/app') require('features/ui') diff --git a/ui (gen4)/features/filesystem.js b/ui (gen4)/features/filesystem.js index 8e3a9916..fea6540d 100755 --- a/ui (gen4)/features/filesystem.js +++ b/ui (gen4)/features/filesystem.js @@ -547,6 +547,7 @@ module.FileSystemLoader = core.ImageGridFeatures.Feature({ tag: 'fs-loader', depends: [ 'location', + 'recover', 'fs-info', 'tasks', ], diff --git a/ui (gen4)/features/location.js b/ui (gen4)/features/location.js index 126be51d..3acfeb21 100755 --- a/ui (gen4)/features/location.js +++ b/ui (gen4)/features/location.js @@ -18,7 +18,6 @@ var core = require('features/core') /*********************************************************************/ - // XXX add url scheme support... // ://#? // XXX add .hash support for in-location .current setting when no index @@ -30,8 +29,6 @@ var core = require('features/core') var LocationActions = actions.Actions({ config: { - 'recover-load-errors-to-previous-location': true, - 'default-load-method': null, }, @@ -144,100 +141,6 @@ var LocationActions = actions.Actions({ return res }], - - // Load index with recovery... - // - // This will: - // - save recovery data (.__recover) - // - load - // - clear recovery data (if load successful) - // - // NOTE: for more info on the load protocol see: base.BaseActions.load - load: [ - function(data){ - var location = data.location - - // prepare to recover, just in case... - this.__recover = (this.__recover !== false - && this.config['recover-load-errors-to-previous-location']) ? - this.location - : false - - return function(){ - // NOTE: we are setting this after the load because the - // loader may .clear() the viewer, thus clearing the - // .location too... - this.__location = location - - // all went well clear the recovery data... - delete this.__recover - } - }], - - // Load data and recover on error... - // - // This is the same as .load(..) but will monitor for load errors - // and attempt to recover if it fails... - // - // NOTE: this avoids load loops by attempting to recover only once... - // NOTE: this is done as a wrapper because we can't catch errors in - // parent actions at this point... - loadOrRecover: ['- Location/', - function(data){ - // this is the critical section, after this point we - // are doing the actual loading.... - try { - - this.load(data) - - // something bad happened, clear and handle it... - } catch(err){ - this.clear() - - console.error(err) - - // recover to last location... - if(this.__recover){ - this.recover() - - // fail... - } else { - // clear the recovery data... - delete this.__recover - - // fail... - throw err - } - } - }], - - // Recover from load error... - // - // This will: - // - get recovery data if present - // - load recovery data - // - clear recovery data - // - // NOTE: if no recovery data present (.__recover) this will do nothing. - recover: ['- File/Recover from load error', - function(){ - var l = this.__recover - - // nothing to recover... - if(!l){ - delete this.__recover - return - } - - // NOTE: this will prevent us from entering - // a recover attempt loop... - // ...if the recovery fails we will just - // clear and stop. - this.__recover = false - - // do the loading... - this.location = l - }], }) module.Location = core.ImageGridFeatures.Feature({ diff --git a/ui (gen4)/features/recover.js b/ui (gen4)/features/recover.js new file mode 100755 index 00000000..c2c4a811 --- /dev/null +++ b/ui (gen4)/features/recover.js @@ -0,0 +1,135 @@ +/********************************************************************** +* +* +* +**********************************************************************/ + +define(function(require){ var module = {} + +var actions = require('lib/actions') +var features = require('lib/features') + +var core = require('features/core') + + + +/*********************************************************************/ + +var RecoverActions = actions.Actions({ + config: { + 'recover-load-errors-to-previous-location': true, + }, + + // Load index with recovery... + // + // This will: + // - save recovery data (.__recover) + // - load + // - clear recovery data (if load successful) + // + // NOTE: for more info on the load protocol see: base.BaseActions.load + load: [ + function(data){ + var location = data.location + + // prepare to recover, just in case... + this.__recover = (this.__recover !== false + && this.config['recover-load-errors-to-previous-location']) ? + this.location + : false + + return function(){ + // NOTE: we are setting this after the load because the + // loader may .clear() the viewer, thus clearing the + // .location too... + this.__location = location + + // all went well clear the recovery data... + delete this.__recover + } + }], + + // Load data and recover on error... + // + // This is the same as .load(..) but will monitor for load errors + // and attempt to recover if it fails... + // + // NOTE: this avoids load loops by attempting to recover only once... + // NOTE: this is done as a wrapper because we can't catch errors in + // parent actions at this point... + loadOrRecover: ['- Location/', + function(data){ + // this is the critical section, after this point we + // are doing the actual loading.... + try { + + this.load(data) + + // something bad happened, clear and handle it... + } catch(err){ + this.clear() + + console.error(err) + + // recover to last location... + if(this.__recover){ + this.recover() + + // fail... + } else { + // clear the recovery data... + delete this.__recover + + // fail... + throw err + } + } + }], + + // Recover from load error... + // + // This will: + // - get recovery data if present + // - load recovery data + // - clear recovery data + // + // NOTE: if no recovery data present (.__recover) this will do nothing. + recover: ['- File/Recover from load error', + function(){ + var l = this.__recover + + // nothing to recover... + if(!l){ + delete this.__recover + return + } + + // NOTE: this will prevent us from entering + // a recover attempt loop... + // ...if the recovery fails we will just + // clear and stop. + this.__recover = false + + // do the loading... + this.location = l + }], +}) + +module.Recovery = core.ImageGridFeatures.Feature({ + title: '', + doc: '', + + tag: 'recover', + + depends: [ + 'location', + ], + + actions: RecoverActions, +}) + + + +/********************************************************************** +* vim:set ts=4 sw=4 : */ +return module })