From df378430c1b384b33ea465fb8b382e4d9f156bd0 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Wed, 11 May 2016 05:00:40 +0300 Subject: [PATCH] added ability to disable features... Signed-off-by: Alex A. Naanou --- ui (gen4)/features/meta.js | 2 ++ ui (gen4)/features/sort.js | 1 + ui (gen4)/features/ui.js | 2 ++ ui (gen4)/lib/actions.js | 2 +- ui (gen4)/lib/features.js | 30 +++++++++++++++++++++++++++++- ui (gen4)/lib/tasks.js | 3 ++- ui (gen4)/ui.js | 4 ++++ 7 files changed, 41 insertions(+), 3 deletions(-) diff --git a/ui (gen4)/features/meta.js b/ui (gen4)/features/meta.js index 4905ee7e..fe041c84 100755 --- a/ui (gen4)/features/meta.js +++ b/ui (gen4)/features/meta.js @@ -123,6 +123,8 @@ core.ImageGridFeatures.Feature('viewer-testing', [ 'fail-safe-devtools', + + '-experiments', ]) /* diff --git a/ui (gen4)/features/sort.js b/ui (gen4)/features/sort.js index f31bbe5c..34045edc 100755 --- a/ui (gen4)/features/sort.js +++ b/ui (gen4)/features/sort.js @@ -474,6 +474,7 @@ module.SortUI = core.ImageGridFeatures.Feature({ tag: 'ui-sort', depends: [ 'ui', + 'sort', ], actions: SortUIActions, diff --git a/ui (gen4)/features/ui.js b/ui (gen4)/features/ui.js index adcbcd41..edfb37e8 100755 --- a/ui (gen4)/features/ui.js +++ b/ui (gen4)/features/ui.js @@ -1922,7 +1922,9 @@ var ControlActions = actions.Actions({ // on... if(state == 'on'){ + this.off('updateRibbon', handler) this.on('updateRibbon', handler) + this.data.ribbon_order.forEach(function(gid){ handler.call(that, null, gid) }) diff --git a/ui (gen4)/lib/actions.js b/ui (gen4)/lib/actions.js index 8143dfde..d70b31f9 100755 --- a/ui (gen4)/lib/actions.js +++ b/ui (gen4)/lib/actions.js @@ -710,7 +710,7 @@ module.MetaActions = { mode = mode[1] // get the handlers... - var h = that._action_handlers[action] + var h = that._action_handlers[action] || [] // remove explicit handler... if(typeof(handler) == 'function'){ diff --git a/ui (gen4)/lib/features.js b/ui (gen4)/lib/features.js index 0db42761..5692f2bb 100755 --- a/ui (gen4)/lib/features.js +++ b/ui (gen4)/lib/features.js @@ -47,6 +47,9 @@ var actions = require('lib/actions') // and mixed out on .remove() // .config - feature configuration, will be merged with base // object's .config +// NOTE: the final .config is an empty object with +// .__proto__ set to the merged configuration +// data... // .handlers - feature event handlers (list | null) // // @@ -273,6 +276,14 @@ module.FeatureSet = { // breaking either the dependency or priority ordering. // // + // Forcing a feature disabled: + // + // If a feature is indicated with a leading '-' then it is forced + // disabled and will not load. + // Disabled features are treated in the same way as inaplicable + // features. + // + // // Dependency sorting: // // These are order dependencies, i.e. for a dependency to be @@ -451,6 +462,15 @@ module.FeatureSet = { // NOTE: this will not resolve all the conflicts... lst = _sortDep(lst, missing, depth).unique() + // get disabled features... + var disabled = [] + Object.keys(missing).forEach(function(n){ + if(n[0] == '-'){ + delete missing[n] + disabled.push(n.slice(1)) + } + }) + // clasify features... var unapplicable = [] var conflicts = {} @@ -461,6 +481,11 @@ module.FeatureSet = { return true } + // disabled... + if(disabled.indexOf(n) >= 0){ + return false + } + // check applicability... if(!e.isApplicable.call(that, obj)){ unapplicable.push(n) @@ -472,11 +497,13 @@ module.FeatureSet = { return true } - // mark feature unapplicable if it depends on an unapplicable... + // mark feature unapplicable if it depends on an unapplicable + // or a disabled... // NOTE: we need to do this once as features at this point // are sorted by dependencies... if(e.depends.filter(function(dep){ return unapplicable.indexOf(dep) > -1 + || disabled.indexOf(dep) > -1 }).length > 0){ unapplicable.push(n) return false @@ -533,6 +560,7 @@ module.FeatureSet = { return { features: lst, + disabled: disabled, excluded: excluded, missing: missing, conflicts: conflicts, diff --git a/ui (gen4)/lib/tasks.js b/ui (gen4)/lib/tasks.js index 9ce543c5..1b5ab68d 100755 --- a/ui (gen4)/lib/tasks.js +++ b/ui (gen4)/lib/tasks.js @@ -89,7 +89,8 @@ module.QueueActions = actions.Actions({ taskFailed: ['', function(){}], taskDone: ['', function(){}], - done: ['', function(){}], + done: ['', function(func){ + func && this.on('done', func) }], // Task manipulation actions... diff --git a/ui (gen4)/ui.js b/ui (gen4)/ui.js index 36e7bc65..35801951 100755 --- a/ui (gen4)/ui.js +++ b/ui (gen4)/ui.js @@ -75,6 +75,10 @@ $(function(){ && console.warn('Features excluded (%d):', a.features.excluded.length, a.features.excluded) + a.features.disabled.length > 0 + && console.log('Features disabled (%d):', + a.features.disabled.length, + a.features.disabled) console.log('Features not applicable (%d):', a.features.unapplicable.length, a.features.unapplicable)