expose meta containing watch and account info in ClayConfig

This commit is contained in:
Keegan
2016-02-19 19:31:17 -08:00
parent 94428b1826
commit 2169d5334f
6 changed files with 48 additions and 9 deletions
+5 -1
View File
@@ -607,7 +607,11 @@ This is the main way of talking to your generated config page.
|----------|------|-------------| |----------|------|-------------|
| `.EVENTS.BEFORE_BUILD` | String | Dispatched prior to building the page. | | `.EVENTS.BEFORE_BUILD` | String | Dispatched prior to building the page. |
| `.EVENTS.AFTER_BUILD` | String | Dispatched after building the page. | | `.EVENTS.AFTER_BUILD` | String | Dispatched after building the page. |
| `.config` | Array | Reference to the config passed to the constructer and used for generating the page. | | `.config` | Array | Reference to the config passed to the constructor and used for generating the page. |
| `.meta` | Object | Contains information about the current user and watch |
| `.meta.activeWatchInfo` | watchinfo|null | An object containing information on the currently connected Pebble smartwatch or null if unavailable. Read more [here](https://developer.pebble.com/docs/js/Pebble/#getActiveWatchInfo). |
| `.meta.accountToken` | String | A unique account token that is associated with the Pebble account of the current user. Read more [here](https://developer.pebble.com/docs/js/Pebble/#getAccountToken). |
| `.meta.watchToken` | String | A unique token that can be used to identify a Pebble device. Read more [here](https://developer.pebble.com/docs/js/Pebble/#getWatchToken). |
#### Methods #### Methods
+3 -3
View File
File diff suppressed because one or more lines are too long
+2 -1
View File
@@ -11,6 +11,7 @@ var settings = _.extend({}, window.claySettings || {});
var returnTo = window.returnTo || 'pebblejs://close#'; var returnTo = window.returnTo || 'pebblejs://close#';
var customFn = window.customFn || function() {}; var customFn = window.customFn || function() {};
var clayComponents = window.clayComponents || {}; var clayComponents = window.clayComponents || {};
var clayMeta = window.clayMeta || {};
var platform = window.navigator.userAgent.match(/android/i) ? 'android' : 'ios'; var platform = window.navigator.userAgent.match(/android/i) ? 'android' : 'ios';
document.documentElement.classList.add('platform-' + platform); document.documentElement.classList.add('platform-' + platform);
@@ -21,7 +22,7 @@ _.eachObj(clayComponents, function(key, component) {
}); });
var $mainForm = $('#main-form'); var $mainForm = $('#main-form');
var clayConfig = new ClayConfig(settings, config, $mainForm); var clayConfig = new ClayConfig(settings, config, $mainForm, clayMeta);
// add listeners here // add listeners here
$mainForm.on('submit', function() { $mainForm.on('submit', function() {
+4 -2
View File
@@ -26,9 +26,10 @@ var manipulators = require('./manipulators');
* @param {Object} settings - setting that were set from a previous session * @param {Object} settings - setting that were set from a previous session
* @param {Array|Object} config * @param {Array|Object} config
* @param {M} $rootContainer * @param {M} $rootContainer
* @param {Object} meta
* @constructor * @constructor
*/ */
function ClayConfig(settings, config, $rootContainer) { function ClayConfig(settings, config, $rootContainer, meta) {
var self = this; var self = this;
var _settings = _.copyObj(settings); var _settings = _.copyObj(settings);
@@ -95,6 +96,8 @@ function ClayConfig(settings, config, $rootContainer) {
return true; return true;
} }
self.meta = meta;
self.EVENTS = { self.EVENTS = {
/** /**
* Called before framework has initialized. This is when you would attach your * Called before framework has initialized. This is when you would attach your
@@ -183,7 +186,6 @@ function ClayConfig(settings, config, $rootContainer) {
// expose the config to allow developers to update it before the build is run // expose the config to allow developers to update it before the build is run
self.config = config; self.config = config;
} }
/** /**
+25 -1
View File
@@ -10,6 +10,29 @@ var components = require('../src/scripts/components');
var componentRegistry = require('../src/scripts/lib/component-registry'); var componentRegistry = require('../src/scripts/lib/component-registry');
var idCounter = 0; var idCounter = 0;
/**
* @returns {{accountToken: string, watchToken: string, activeWatchInfo: {platform:
* string, model: string, language: string, firmware: {major: number, minor:
* number, patch: number, suffix: string}}}}
*/
module.exports.meta = function() {
return {
accountToken: '0123456789abcdef0123456789abcdef',
watchToken: '0123456789abcdef0123456789abcdef',
activeWatchInfo: {
platform: 'chalk',
model: 'qemu_platform_chalk',
language: 'en_US',
firmware: {
major: 3,
minor: 3,
patch: 2,
suffix: ''
}
}
};
};
/** /**
* @param {string|Object} config * @param {string|Object} config
* @param {boolean} [autoRegister=true] * @param {boolean} [autoRegister=true]
@@ -70,7 +93,8 @@ module.exports.clayConfig = function(types, build, autoRegister, settings) {
var clayConfig = new ClayConfig( var clayConfig = new ClayConfig(
settings || {}, settings || {},
module.exports.config(types, autoRegister), module.exports.config(types, autoRegister),
$(HTML('<div>')) $(HTML('<div>')),
module.exports.meta()
); );
return build === false ? clayConfig : clayConfig.build(); return build === false ? clayConfig : clayConfig.build();
}; };
+9 -1
View File
@@ -20,12 +20,20 @@ describe('ClayConfig', function() {
'build', 'build',
'on', 'on',
'off', 'off',
'trigger' 'trigger',
'meta'
]; ];
var clayConfig = fixtures.clayConfig(['input']); var clayConfig = fixtures.clayConfig(['input']);
checkReadOnly(clayConfig, properties); checkReadOnly(clayConfig, properties);
}); });
describe('.meta', function() {
it('populates meta', function() {
var clayConfig = fixtures.clayConfig(['input']);
assert.deepEqual(clayConfig.meta, fixtures.meta());
});
});
describe('throws when trying to run methods before being built', function() { describe('throws when trying to run methods before being built', function() {
[ [
'getItemByAppKey', 'getItemByAppKey',