mirror of
https://github.com/pebble-dev/clay.git
synced 2026-08-29 05:16:32 -04:00
Add the option to only show items with particular capabilities
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user