Add the option to only show items with particular capabilities

This commit is contained in:
Keegan
2016-05-30 20:30:17 -07:00
parent 7e2b75dd58
commit 5fe87a04de
6 changed files with 398 additions and 25 deletions
+28 -25
View File
@@ -11,6 +11,7 @@
* @property {Object} [attributes]
* @property {Array} [options]
* @property {Array} [items]
* @property {Array} [capabilities]
*/
var HTML = require('../vendor/minified').HTML;
@@ -61,34 +62,36 @@ function ClayConfig(settings, config, $rootContainer, meta) {
item.forEach(function(item) {
_addItems(item, $container);
});
} else if (item.type === 'section') {
var $wrapper = HTML('<div class="section">');
$container.add($wrapper);
_addItems(item.items, $wrapper);
} else {
var _item = _.copyObj(item);
_item.clayId = _items.length;
} else if (utils.includesCapability(meta.activeWatchInfo, item.capabilities)) {
if (item.type === 'section') {
var $wrapper = HTML('<div class="section">');
$container.add($wrapper);
_addItems(item.items, $wrapper);
} else {
var _item = _.copyObj(item);
_item.clayId = _items.length;
var clayItem = new ClayItem(_item).initialize(self);
var clayItem = new ClayItem(_item).initialize(self);
if (_item.id) {
_itemsById[_item.id] = clayItem;
if (_item.id) {
_itemsById[_item.id] = clayItem;
}
if (_item.appKey) {
_itemsByAppKey[_item.appKey] = clayItem;
}
_items.push(clayItem);
// set the value of the item via the manipulator to ensure consistency
var value = typeof _settings[_item.appKey] !== 'undefined' ?
_settings[_item.appKey] :
(_item.defaultValue || '');
clayItem.set(value);
$container.add(clayItem.$element);
}
if (_item.appKey) {
_itemsByAppKey[_item.appKey] = clayItem;
}
_items.push(clayItem);
// set the value of the item via the manipulator to ensure consistency
var value = typeof _settings[_item.appKey] !== 'undefined' ?
_settings[_item.appKey] :
(_item.defaultValue || '');
clayItem.set(value);
$container.add(clayItem.$element);
}
}
+109
View File
@@ -17,3 +17,112 @@ module.exports.updateProperties = function(obj, descriptor) {
Object.defineProperty(obj, prop, descriptor);
});
};
module.exports.capabilityMap = {
APLITE: {
platforms: ['aplite'],
minFwMajor: 0,
minFwMinor: 0
},
BASALT: {
platforms: ['basalt'],
minFwMajor: 0,
minFwMinor: 0
},
CHALK: {
platforms: ['chalk'],
minFwMajor: 0,
minFwMinor: 0
},
DIORITE: {
platforms: ['diorite'],
minFwMajor: 0,
minFwMinor: 0
},
EMERY: {
platforms: ['emery'],
minFwMajor: 0,
minFwMinor: 0
},
BW: {
platforms: ['aplite', 'diorite'],
minFwMajor: 0,
minFwMinor: 0
},
COLOR: {
platforms: ['basalt', 'chalk', 'emery'],
minFwMajor: 0,
minFwMinor: 0
},
MICROPHONE: {
platforms: ['basalt', 'chalk', 'diorite', 'emery'],
minFwMajor: 0,
minFwMinor: 0
},
SMARTSTRAP: {
platforms: ['basalt', 'chalk', 'diorite', 'emery'],
minFwMajor: 3,
minFwMinor: 4
},
SMARTSTRAP_POWER: {
platforms: ['basalt', 'chalk', 'emery'],
minFwMajor: 3,
minFwMinor: 4
},
HEALTH: {
platforms: ['basalt', 'chalk', 'diorite', 'emery'],
minFwMajor: 3,
minFwMinor: 10
},
RECT: {
platforms: ['aplite', 'basalt', 'diorite', 'emery'],
minFwMajor: 0,
minFwMinor: 0
},
ROUND: {
platforms: ['chalk'],
minFwMajor: 3,
minFwMinor: 4
},
DISPLAY_144x168: {
platforms: ['aplite', 'basalt', 'diorite'],
minFwMajor: 0,
minFwMinor: 0
},
DISPLAY_180x180_ROUND: {
platforms: ['chalk'],
minFwMajor: 0,
minFwMinor: 0
},
DISPLAY_200x228: {
platforms: ['emery'],
minFwMajor: 0,
minFwMinor: 0
}
};
/**
* Checks if all of the provided capabilities are compatible with the watch
* @param {Object} activeWatchInfo
* @param {Array} [capabilities]
* @return {boolean}
*/
module.exports.includesCapability = function(activeWatchInfo, capabilities) {
if (!capabilities || !capabilities.length) {
return true;
}
for (var i = capabilities.length - 1; i >= 0; i--) {
var capability = capabilities[i];
var mapping = module.exports.capabilityMap[capability];
if (!mapping ||
mapping.platforms.indexOf(activeWatchInfo.platform) === -1 ||
mapping.minFwMajor > activeWatchInfo.firmware.major ||
mapping.minFwMajor === activeWatchInfo.firmware.major &&
mapping.minFwMinor > activeWatchInfo.firmware.minor
) {
return false;
}
}
return true;
};