Skip to content

Commit

Permalink
make profile history and multiple profiles optional
Browse files Browse the repository at this point in the history
  • Loading branch information
MilosKozak committed Nov 9, 2015
1 parent 86691d9 commit 447e4e0
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 8 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
2 changes: 2 additions & 0 deletions env.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
9 changes: 8 additions & 1 deletion lib/client/boluscalc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down Expand Up @@ -154,7 +161,7 @@ function init(client, $, plugins) {
profiles.forEach(function (p) {
$('#bc_profile').append('<option val="' + p + '">' + p + '</option>');
});
$('#bc_profileLabel').toggle(profiles.length > 1);
$('#bc_profileLabel').toggle(isProfileEnabled(profiles));

$('#bc_usebg').prop('checked','checked');
$('#bc_usecarbs').prop('checked','checked');
Expand Down
2 changes: 2 additions & 0 deletions lib/client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ( ) {
Expand Down
5 changes: 3 additions & 2 deletions lib/plugins/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
16 changes: 16 additions & 0 deletions lib/plugins/profile.js
Original file line number Diff line number Diff line change
@@ -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;
2 changes: 1 addition & 1 deletion lib/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];

Expand Down
2 changes: 1 addition & 1 deletion static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
<form id="settings-form">
<ul class="navigation">
<li><a href="/report/index.html" target="reports" class="translate">Reports</a></li>
<li><a id="editprofilelink" href="/profile/index.html" target="profileeditor" class="translate">Profile Editor</a></li>
<li class="profilecontrol"><a id="editprofilelink" href="/profile/index.html" target="profileeditor" class="translate">Profile Editor</a></li>
<li class="foodcontrol"><a id="editfoodlink" href="/food/index.html" target="foodeditor" class="translate">Food Editor</a></li>
<li><a id="admintoolslink" href="/admin/index.html" target="admintools" class="translate">Admin Tools</a></li>
</ul>
Expand Down
5 changes: 2 additions & 3 deletions static/profile/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ <h1 class="translate">Profile Editor</h1>
</fieldset>

<fieldset class="browserSettings">
<legend>
<legend id="pe_history" style="display:none">
<span class="translate">Database records</span>:
<select id="pe_databaserecords"></select>
&nbsp;
Expand All @@ -71,7 +71,6 @@ <h1 class="translate">Profile Editor</h1>
<img id="pe_records_clone" title="Clone this record to new" class="titletranslate" style="cursor:pointer" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAACSklEQVQ4T5VTYU9SYRR+zn0vXhDEFyRBXcpmbZnZsOXsI2xpVnNcv/ilufET8h/oL8h/gN/aWhs2yjKt26rPSvUh5yQodQlqgKQCd5fbLg2jxlycT+/OOc85z/OcvYSa8MoRLqimUEuzOSgwBl0nFFUtW1K1J/Ho6Hxtr/H2yQqnarJ3fFHucNnC57tdXIUJhydl6CAwIhwfFXCwf5hUC6XpjYXAQgUcUngRzkxlgHc0Kl+57I443S7s5VQwxqCVCYVSGfkTFSQQmsQmHGVzKJ78nJMs2izBohRg8ZFB293iSPQPdPOiqiOdyiGdysdKmp4t64LXxlu9otUKTVdhkSSUjgooHOez7R1uvr2bA10cfx66cb0n3GS14tPHrWz6R34i+fT2m6q0rruv7tvs9gdOtxNk0mA2SRB0gqVZwGb8AOSbXIkMDV+Qt7cy2IinJ+LRWxWNf5ur+Kx2vub0OABRg2QSIYqEr/EMaHjqrdJ/tce/upqIxR76B/8FVzySFc7MzWvtnW6vyjSAAFFgyBkSrt17n7jU1+ldjcVn1x+PzNTZzkWLTXF5zvmYmaEslCEIxnUE7H07AA1NvVPaO9r8X5Kpic+Pfp+oNvpCH/R6rKo5GphUIq1Oh7y++T2wv/LHvLNAtTXqHX8Zkqyt4XQ6M73/emzuf4GnDLg/wu0tbYliqTifWhqZbniAAfCMLs/oRMHU0s26VzjTA6PI/QqXJC1BxAZ3XwSSjbA4/UyesWU/Y2Jw51mgIRmnA4ytXXcU385iINYIg1+OJdcoyf/hkgAAAABJRU5ErkJggg==">
&nbsp;
</legend>

<br>
<dl>
<b title="Start of record validity" class="titletranslate"><span class="translate">Record valid from</span>: </b>
Expand All @@ -80,7 +79,7 @@ <h1 class="translate">Profile Editor</h1>
</dl>

<fieldset class="browserSettings pe_stored_profile">
<legend>
<legend id="pe_multiple" style="display:none">
<b><span class="translate">Stored profiles</span>: </b>
<select id="pe_profiles">
</select>
Expand Down
3 changes: 3 additions & 0 deletions static/profile/js/profileeditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@
}

function initeditor() {
$('#pe_history').toggle(client.settings.extendedSettings.profile && client.settings.extendedSettings.profile.history);
$('#pe_multiple').toggle(client.settings.extendedSettings.profile && client.settings.extendedSettings.profile.multiple);

// Load timezones
timezoneInput.empty();
moment.tz.names().forEach(function addTz(tz) {
Expand Down

0 comments on commit 447e4e0

Please sign in to comment.