added feature applicability test...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2014-12-04 20:21:45 +03:00
parent 96a2eab041
commit 67b7d2f6a6
2 changed files with 44 additions and 5 deletions

View File

@ -215,6 +215,7 @@ $(function(){
'ui-partial-ribbons', 'ui-partial-ribbons',
'ui-ribbon-align-to-order', 'ui-ribbon-align-to-order',
'ui-single-image-view', 'ui-single-image-view',
'fs-loader',
// ui elements... // ui elements...
'image-marks', 'image-marks',

View File

@ -1185,6 +1185,10 @@ var FeatureProto =
module.FeatureProto = { module.FeatureProto = {
tag: null, tag: null,
isApplicable: function(actions){
return true
},
getPriority: function(){ getPriority: function(){
var res = this.priority || 0 var res = this.priority || 0
return res == 'high' ? 99 return res == 'high' ? 99
@ -1282,10 +1286,9 @@ Feature.prototype.constructor = Feature
// XXX if this works out might be a good idea to organize everything as // XXX if this works out might be a good idea to organize everything as
// a feature... including the Client and Viewer // a feature... including the Client and Viewer
// ...needs more thought... // ...needs more thought...
// XXX add a standard doc set...
var FeatureSet = var FeatureSet =
module.FeatureSet = { module.FeatureSet = {
buildFeatureList: function(lst){ buildFeatureList: function(obj, lst){
lst = lst.constructor !== Array ? [lst] : lst lst = lst.constructor !== Array ? [lst] : lst
var that = this var that = this
@ -1298,12 +1301,25 @@ module.FeatureSet = {
}) })
// sort features via dependencies... // sort features via dependencies...
var unapplicable = []
var conflicts = {} var conflicts = {}
lst = lst.filter(function(n, i){ lst = lst.filter(function(n, i){
var e = that[n] var e = that[n]
if(e == null || e.depends == null ){ if(e == null){
return true return true
} }
// check applicability...
if(!e.isApplicable(obj)){
unapplicable.push(n)
return false
}
// no dependencies...
if(e.depends == null ){
return true
}
// keep only conflicting... // keep only conflicting...
var deps = e.depends.filter(function(dep){ var deps = e.depends.filter(function(dep){
dep = lst.indexOf(dep) dep = lst.indexOf(dep)
@ -1350,13 +1366,14 @@ module.FeatureSet = {
return { return {
features: lst, features: lst,
excluded: excluded, excluded: excluded,
conflicts: conflicts conflicts: conflicts,
unapplicable: unapplicable,
} }
}, },
setup: function(obj, lst){ setup: function(obj, lst){
lst = lst.constructor !== Array ? [lst] : lst lst = lst.constructor !== Array ? [lst] : lst
var features = this.buildFeatureList(lst) var features = this.buildFeatureList(obj, lst)
lst = features.features lst = features.features
// check for conflicts... // check for conflicts...
@ -1377,6 +1394,12 @@ module.FeatureSet = {
features.excluded.join(', ')) features.excluded.join(', '))
} }
// report unapplicable features...
if(features.unapplicable.length > 0){
console.log('Features not applicable in current context:',
features.unapplicable.join(', '))
}
// do the setup... // do the setup...
var that = this var that = this
var setup = FeatureProto.setup var setup = FeatureProto.setup
@ -2434,6 +2457,21 @@ module.ImageBookmarks = Feature({
//---------------------------------------------------------------------
var FileSystemLoader =
module.FileSystemLoader = Feature({
title: '',
doc: '',
tag: 'fs-loader',
isApplicable: function(){
return window.nodejs != null
},
})
/********************************************************************** /**********************************************************************
* vim:set ts=4 sw=4 : */ * vim:set ts=4 sw=4 : */