From 447e4e0d4d357bc22f7848d5cc8651997aba8213 Mon Sep 17 00:00:00 2001 From: MilosKozak Date: Mon, 9 Nov 2015 21:21:36 +0100 Subject: [PATCH] make profile history and multiple profiles optional --- README.md | 3 +++ env.js | 2 ++ lib/client/boluscalc.js | 9 ++++++++- lib/client/index.js | 2 ++ lib/plugins/index.js | 5 +++-- lib/plugins/profile.js | 16 ++++++++++++++++ lib/settings.js | 2 +- static/index.html | 2 +- static/profile/index.html | 5 ++--- static/profile/js/profileeditor.js | 3 +++ 10 files changed, 41 insertions(+), 8 deletions(-) create mode 100644 lib/plugins/profile.js diff --git a/README.md b/README.md index d47a35df..2c339349 100644 --- a/README.md +++ b/README.md @@ -230,6 +230,9 @@ To learn more about the Nightscout API, visit https://YOUR-SITE.com/api-docs.htm * `AR2_CONE_FACTOR` (`2`) - to adjust size of cone, use `0` for a single line. * `simplealarms` (Simple BG Alarms) - Uses `BG_HIGH`, `BG_TARGET_TOP`, `BG_TARGET_BOTTOM`, `BG_LOW` thresholds to generate alarms. * Enabled by default if 1 of these thresholds is set **OR** `ALARM_TYPES` includes `simple`. + * `profile` (Treatment Profile) - Add link to Profile Editor and allow to enter treatment profile settings. Also uses the extended setting: + * `PROFILE_HISTORY` (`off`) - possible values `on` or `off`. Enable/disable NS ability to keep history of your profiles (still experimental) + * `PROFILE_MULTIPLE` (`off`) - possible values `on` or `off`. Enable/disable NS ability to handle and switch between multiple treatment profiles #### Built-in/Example Plugins: diff --git a/env.js b/env.js index 03b53f84..cc7995f8 100644 --- a/env.js +++ b/env.js @@ -158,6 +158,8 @@ function findExtendedSettings (envs) { extended[enable] = exts; var ext = _.camelCase(env.substring(split + 1).toLowerCase()); if (!isNaN(value)) { value = Number(value); } + if (typeof value === 'string' && value.toLowerCase() === 'on') { value = true; } + if (typeof value === 'string' && value.toLowerCase() === 'off') { value = false; } exts[ext] = value; } } diff --git a/lib/client/boluscalc.js b/lib/client/boluscalc.js index 165ab0c5..0da8f5fb 100644 --- a/lib/client/boluscalc.js +++ b/lib/client/boluscalc.js @@ -33,6 +33,13 @@ function init(client, $, plugins) { } } + function isProfileEnabled(profiles) { + return client.settings.enable.indexOf('profile') > -1 + && client.settings.extendedSettings.profile + && client.settings.extendedSettings.profile.multiple + && profiles.length > 1; + } + function isTouch() { try { document.createEvent('TouchEvent'); return true; } catch (e) { return false; } @@ -154,7 +161,7 @@ function init(client, $, plugins) { profiles.forEach(function (p) { $('#bc_profile').append(''); }); - $('#bc_profileLabel').toggle(profiles.length > 1); + $('#bc_profileLabel').toggle(isProfileEnabled(profiles)); $('#bc_usebg').prop('checked','checked'); $('#bc_usecarbs').prop('checked','checked'); diff --git a/lib/client/index.js b/lib/client/index.js index 3a088ce2..409dc4a4 100644 --- a/lib/client/index.js +++ b/lib/client/index.js @@ -781,6 +781,8 @@ client.init = function init(serverSettings, plugins) { $('.foodcontrol').toggle(client.settings.enable.indexOf('food') > -1); // hide cob control if not enabled $('.cobcontrol').toggle(client.settings.enable.indexOf('cob') > -1); + // hide profile controls if not enabled + $('.profilecontrol').toggle(client.settings.enable.indexOf('profile') > -1); container.toggleClass('has-minor-pills', plugins.hasShownType('pill-minor', client.settings)); function prepareData ( ) { diff --git a/lib/plugins/index.js b/lib/plugins/index.js index a27aec89..0df25263 100644 --- a/lib/plugins/index.js +++ b/lib/plugins/index.js @@ -30,8 +30,9 @@ function init() { , require('./sensorage')() , require('./basalprofile')() , require('./upbat')() - , require('./careportal')() - , require('./boluscalc')() + , require('./careportal')() // fake plugin to show/hide + , require('./boluscalc')() // fake plugin to show/hide + , require('./profile')() // fake plugin to hold extended settings ]; var serverDefaultPlugins = [ diff --git a/lib/plugins/profile.js b/lib/plugins/profile.js new file mode 100644 index 00000000..e35caec0 --- /dev/null +++ b/lib/plugins/profile.js @@ -0,0 +1,16 @@ +'use strict'; + +// this is just a fake plugin to hold extended settings + +function init() { + + var profile = { + name: 'profile' + , label: 'Profile' + , pluginType: 'fake' + }; + + return profile; +} + +module.exports = init; \ No newline at end of file diff --git a/lib/settings.js b/lib/settings.js index c489fa48..1836fde6 100644 --- a/lib/settings.js +++ b/lib/settings.js @@ -77,7 +77,7 @@ function init ( ) { } //TODO: getting sent in status.json, shouldn't be - settings.DEFAULT_FEATURES = ['delta', 'direction', 'upbat', 'errorcodes']; + settings.DEFAULT_FEATURES = ['delta', 'direction', 'upbat', 'errorcodes', 'profile']; var wasSet = []; diff --git a/static/index.html b/static/index.html index 9437bf3a..7b61002d 100644 --- a/static/index.html +++ b/static/index.html @@ -82,7 +82,7 @@
diff --git a/static/profile/index.html b/static/profile/index.html index bc20ca4e..7fee3f10 100644 --- a/static/profile/index.html +++ b/static/profile/index.html @@ -60,7 +60,7 @@
- + -
Record valid from: @@ -80,7 +79,7 @@
- +