From db0e08c522dbfad3f55c649c17d0c9bf6dccb981 Mon Sep 17 00:00:00 2001 From: Ben West Date: Fri, 12 Jun 2020 07:17:38 -0700 Subject: [PATCH 01/80] do not redirect to profile editor by default (#5671) In a default configuration, there is no treatment data. The code to redirect the UI to the profile editor is buried deep within the chart rendering code for basals. This plugin is only supposed to go into action when enabled via ENABLE=basal. This commit fixes first-use experience for the default configuration intended to draw real-time CGM traces and no basal information is expected. Since no basal information is expected unless plugin is enabled via ENABLE=basal, this allows skipping instead of redirecting to the profile editor. --- lib/client/renderer.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/client/renderer.js b/lib/client/renderer.js index a0caed8083a..a3841695060 100644 --- a/lib/client/renderer.js +++ b/lib/client/renderer.js @@ -1034,6 +1034,9 @@ function init (client, d3) { renderer.addBasals = function addBasals (client) { + if (!client.settings.isEnabled('basal')) { + return; + } var mode = client.settings.extendedSettings.basal.render; var profile = client.sbx.data.profile; var linedata = []; From f3fab567c5e2d25da3d5a2f452c28b99cb016b0f Mon Sep 17 00:00:00 2001 From: Matthew Date: Fri, 12 Jun 2020 10:17:52 -0400 Subject: [PATCH 02/80] Fix Issue #5486 - Device Status Days Feature (#5651) * Device Status Days Feature * Edits per review from @sulkaharo --- README.md | 1 + env.js | 2 ++ lib/data/dataloader.js | 4 +++- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index bd55ebf8094..e8aeecdbcc5 100644 --- a/README.md +++ b/README.md @@ -557,6 +557,7 @@ For remote overrides, the following extended settings must be configured: Plugins only have access to their own extended settings, all the extended settings of client plugins will be sent to the browser. * `DEVICESTATUS_ADVANCED` (`true`) - Defaults to true. Users who only have a single device uploading data to Nightscout can set this to false to reduce the data use of the site. + * `DEVICESTATUS_DAYS` (`1`) - Defaults to 1, can optionally be set to 2. Users can use this to show 48 hours of device status data for in retro mode, rather than the default 24 hours. Setting this value to 2 will roughly double the bandwidth usage of nightscout, so users with a data cap may not want to update this setting. #### Pushover In addition to the normal web based alarms, there is also support for [Pushover](https://pushover.net/) based alarms and notifications. diff --git a/env.js b/env.js index 0d8d41409b0..9875435ff02 100644 --- a/env.js +++ b/env.js @@ -170,6 +170,8 @@ function findExtendedSettings (envs) { extended.devicestatus = {}; extended.devicestatus.advanced = true; + extended.devicestatus.days = 1; + if(process.env['DEVICESTATUS_DAYS'] && process.env['DEVICESTATUS_DAYS'] == '2') extended.devicestatus.days = 1; function normalizeEnv (key) { return key.toUpperCase().replace('CUSTOMCONNSTR_', ''); diff --git a/lib/data/dataloader.js b/lib/data/dataloader.js index b0eafdd4fe0..3c2d8c6502d 100644 --- a/lib/data/dataloader.js +++ b/lib/data/dataloader.js @@ -361,8 +361,10 @@ function loadFood(ddata, ctx, callback) { } function loadDeviceStatus(ddata, env, ctx, callback) { + var retroDays = ONE_DAY; + if(env.extendedSettings.devicestatus && env.extendedSettings.devicestatus.days && env.extendedSettings.devicestatus.days == 2) retroDays = TWO_DAYS; var dateRange = { - $gte: new Date(ddata.lastUpdated - ONE_DAY).toISOString() + $gte: new Date( ddata.lastUpdated - (retroDays) ).toISOString() }; if (ddata.page && ddata.page.frame) { dateRange['$lte'] = new Date(ddata.lastUpdated).toISOString(); From 3d6f488edab52eff2d8357997efcda1d6b5b28d8 Mon Sep 17 00:00:00 2001 From: ireneusz-ptak <31506973+ireneusz-ptak@users.noreply.github.com> Date: Fri, 12 Jun 2020 16:29:15 +0200 Subject: [PATCH 03/80] Configurable clock views (#5625) * Configurable clock views * Configurable clock views * Configurable clock views * Configurable clock views * Configurable clock views * Configurable clock views * Update README.md * Update README.md * Configurable clock views --- README.md | 22 ++- lib/client/clock-client.js | 180 +++++++++++-------- lib/server/clocks.js | 2 +- views/clockviews/bgclock.css | 28 --- views/clockviews/clock-color.css | 32 ---- views/clockviews/clock-config.css | 39 ++++ views/clockviews/clock-config.html | 65 +++++++ views/clockviews/clock-shared.css | 53 +++--- views/clockviews/clock.css | 5 - views/clockviews/{shared.html => clock.html} | 24 ++- views/index.html | 1 + 11 files changed, 263 insertions(+), 188 deletions(-) delete mode 100644 views/clockviews/bgclock.css delete mode 100644 views/clockviews/clock-color.css create mode 100644 views/clockviews/clock-config.css create mode 100644 views/clockviews/clock-config.html delete mode 100644 views/clockviews/clock.css rename views/clockviews/{shared.html => clock.html} (88%) diff --git a/README.md b/README.md index e8aeecdbcc5..d9e4a57262c 100644 --- a/README.md +++ b/README.md @@ -306,11 +306,29 @@ To learn more about the Nightscout API, visit https://YOUR-SITE.com/api-docs/ or ### Views - There are a few alternate web views available from the main menu that display a simplified BG stream. (If you launch one of these in a fullscreen view in iOS, you can use a left-to-right swipe gesture to exit the view.) + Nightscout allows to create custom, simplified views using a predefined set of elements. This option is available under `[+]` link in the main menu. + + List of available items: + * `SGV` - Sensor Glucose Value + * `SGV age` - time since the last SGV read + * `SGV delta` - change of SGV in the last 5 minutes + * `Trend arrow` - icon of the SG trend + * `Time` - current time + * `Line break` - invisible item that will move following items to the next line (by default all are showing on the same level) + + All visible items have `Size` property which allows to customize the view even more. Also, all items may appear multiple times on the view. + + Apart from adding items, it is possible to customize other aspects of the views, like selecting `Color` or `Black` background. The first one will indicate current BG threshold (green = in range; blue = below range; yellow = above range; red = urgent below/above). + `Show SGV age` option will make `SGV age` item appear `Always` or only if the predefined threshold is reached: `Only after threshold`. Breaching `SGV age threshold` will also make `Color` background turn grey and strike through `SGV`. + `Clock view configurator` will generate an URL (available under `Open my clock view!` link) that could be bookmarked. + + There are a few default views available from the main menu: * `Clock` - Shows current BG, trend arrow, and time of day. Grey text on a black background. - * `Color` - Shows current BG and trend arrow. White text on a background that changes color to indicate current BG threshold (green = in range; blue = below range; yellow = above range; red = urgent below/above). Set `SHOW_CLOCK_DELTA` to `true` to show BG change in the last 5 minutes, set `SHOW_CLOCK_LAST_TIME` to `true` to always show BG age. + * `Color` - Shows current BG and trend arrow. White text on a color background. * `Simple` - Shows current BG. Grey text on a black background. + If you launch one of these views in a fullscreen view in iOS, you can use a left-to-right swipe gesture to exit the view. + ### Split View Some users will need easy access to multiple Nightscout views at the same time. We have a special view for this case, accessed on /split path on your Nightscout URL. The view supports any number of sites between 1 to 8 way split, where the content for the screen can be loaded from multiple Nightscout instances. Note you still need to host separate instances for each Nightscout being monitored including the one that hosts the split view page - these variables only add the ability to load multiple views into one browser page. To set the URLs from which the content is loaded, set: diff --git a/lib/client/clock-client.js b/lib/client/clock-client.js index e6eec7190c6..891f10d57d5 100644 --- a/lib/client/clock-client.js +++ b/lib/client/clock-client.js @@ -6,7 +6,7 @@ var client = {}; client.settings = browserSettings(client, window.serverSettings, $); -// console.log('settings', client.settings); +//console.log('settings', client.settings); // client.settings now contains all settings client.query = function query () { @@ -20,7 +20,7 @@ client.query = function query () { }); var secret = localStorage.getItem('apisecrethash'); - var src = '/api/v1/entries.json?count=3&t=' + new Date().getTime(); + var src = '/api/v1/entries.json?find[type]=sgv&count=3&t=' + new Date().getTime(); if (secret) { src += '&secret=' + secret; @@ -39,6 +39,7 @@ client.render = function render (xhr) { let rec; let delta; + // Get SGV, calculate DELTA xhr.forEach(element => { if (element.sgv && !rec) { rec = element; @@ -49,28 +50,65 @@ client.render = function render (xhr) { }); let $errorMessage = $('#errorMessage'); + let $inner = $('#inner'); // If no one measured value found => show "-?-" if (!rec) { if (!$errorMessage.length) { - $('#arrowDiv').append('
-?-
'); - $('#arrow').hide(); + $inner.after('
-?-
') } else { $errorMessage.show(); } + $inner.hide(); return; } else { $errorMessage.length && $errorMessage.hide(); - $('#arrow').show(); + $inner.show(); + } + + //Parse face parameters + let face = $inner.data('face').toLowerCase(); + + // Backward compatible + if (face === 'clock-color') { + face = 'c' + (window.serverSettings.settings.showClockLastTime ? 'y' : 'n') + '13-sg40-' + (window.serverSettings.settings.showClockDelta ? 'dt14-' : '') + 'nl-ar30-nl-ag6'; + } + else if (face === 'clock') { + face = 'bn0-sg40'; + } + else if (face === 'bgclock') { + face = 'bn0-sg30-ar18-nl-nl-tm26'; + } + else if (face === 'config') { + face = $inner.attr('data-face-config'); + $inner.empty(); + } + + let faceParams = face.split('-'); + let bgColor = false; + let staleMinutes = 13; + let alwaysShowTime = false; + + let clockCreated = ($inner.children().length > 0); + + for (let param in faceParams) { + if (param === '0') { + bgColor = (faceParams[param].substr(0, 1) === 'c'); // do we want colorful background? + alwaysShowTime = (faceParams[param].substr(1, 1) === 'y'); // always show "stale time" text? + staleMinutes = (faceParams[param].substr(2,2) - 0 >= 0) ? faceParams[param].substr(2,2) : 13; // threshold value (0=never) + } else if (!clockCreated){ + let div = '
0) ? ' style="' + ((faceParams[param].substr(0,2) === 'ar') ? 'height' : 'font-size') + ':' + faceParams[param].substr(2,2) + 'vmin"' : '') + '>
'; + $inner.append(div); + } } - - let last = new Date(rec.date); - let now = new Date(); // Convert BG to mmol/L if necessary. + let displayValue; + let deltaDisplayValue; + if (window.serverSettings.settings.units === 'mmol') { - var displayValue = window.Nightscout.units.mgdlToMMOL(rec.sgv); - var deltaDisplayValue = window.Nightscout.units.mgdlToMMOL(delta); + displayValue = window.Nightscout.units.mgdlToMMOL(rec.sgv); + deltaDisplayValue = window.Nightscout.units.mgdlToMMOL(delta); } else { displayValue = rec.sgv; deltaDisplayValue = Math.round(delta); @@ -80,18 +118,8 @@ client.render = function render (xhr) { deltaDisplayValue = '+' + deltaDisplayValue; } - // Insert the BG value text. - $('#bgnow').html(displayValue); - - // Insert the trend arrow. - $('#arrow').attr('src', '/images/' + (!rec.direction || rec.direction === 'NOT COMPUTABLE' ? 'NONE' : rec.direction) + '.svg'); - - // Time before data considered stale. - let staleMinutes = 13; - let threshold = 1000 * 60 * staleMinutes; - - // Toggle stale if necessary. - $('#bgnow').toggleClass('stale', (now - last > threshold)); + // Insert the delta value text. + $('.dt').html(deltaDisplayValue); // Generate and insert the clock. let timeDivisor = parseInt(client.settings.timeFormat ? client.settings.timeFormat : 12, 10); @@ -105,51 +133,24 @@ client.render = function render (xhr) { } let m = today.getMinutes(); if (m < 10) m = "0" + m; - $('#clock').text(h + ":" + m); - - /* global clockFace */ - if (clockFace === 'clock-color') { - - var bgHigh = window.serverSettings.settings.thresholds.bgHigh; - var bgLow = window.serverSettings.settings.thresholds.bgLow; - var bgTargetBottom = window.serverSettings.settings.thresholds.bgTargetBottom; - var bgTargetTop = window.serverSettings.settings.thresholds.bgTargetTop; + $('.tm').html(h + ":" + m); - var bgNum = parseFloat(rec.sgv); + // Color background + if (bgColor) { // These are the particular shades of red, yellow, green, and blue. - var red = 'rgba(213,9,21,1)'; - var yellow = 'rgba(234,168,0,1)'; - var green = 'rgba(134,207,70,1)'; - var blue = 'rgba(78,143,207,1)'; - - var elapsedMins = Math.round(((now - last) / 1000) / 60); - - // Insert the BG stale time text. - let staleTimeText; - if (elapsedMins == 0) { - staleTimeText = 'Just now'; - } - else if (elapsedMins == 1) { - staleTimeText = '1 minute ago'; - } - else { - staleTimeText = elapsedMins + ' minutes ago'; - } - $('#staleTime').text(staleTimeText); - - // Force NS to always show 'x minutes ago' - if (window.serverSettings.settings.showClockLastTime) { - $('#staleTime').css('display', 'block'); - } + let red = 'rgba(213,9,21,1)'; + let yellow = 'rgba(234,168,0,1)'; + let green = 'rgba(134,207,70,1)'; + let blue = 'rgba(78,143,207,1)'; - // Insert the delta value text. - $('#delta').html(deltaDisplayValue); + // Threshold values + let bgHigh = client.settings.thresholds.bgHigh; + let bgLow = client.settings.thresholds.bgLow; + let bgTargetBottom = client.settings.thresholds.bgTargetBottom; + let bgTargetTop = client.settings.thresholds.bgTargetTop; - // Show delta - if (window.serverSettings.settings.showClockDelta) { - $('#delta').css('display', 'inline-block'); - } + let bgNum = parseFloat(rec.sgv); // Threshold background coloring. if (bgNum < bgLow) { @@ -168,25 +169,52 @@ client.render = function render (xhr) { $('body').css('background-color', red); } - // Restyle body bg, and make the "x minutes ago" visible too. - if (now - last > threshold) { - $('body').css('background-color', 'grey'); - $('body').css('color', 'black'); - $('#arrow').css('filter', 'brightness(0%)'); + } + else { + $('body').css('background-color', 'black'); + } - if (!window.serverSettings.settings.showClockLastTime) { - $('#staleTime').css('display', 'block'); - } + // Time before data considered stale. + let threshold = 1000 * 60 * staleMinutes; - } else { - $('body').css('color', 'white'); - $('#arrow').css('filter', 'brightness(100%)'); + let last = new Date(rec.date); + let now = new Date(); + + let elapsedMins = Math.round(((now - last) / 1000) / 60); + + let thresholdReached = (now - last > threshold) && threshold > 0; - if (!window.serverSettings.settings.showClockLastTime) { - $('#staleTime').css('display', 'none'); - } + // Insert the BG value text, toggle stale if necessary. + $('.sg').toggleClass('stale', thresholdReached).html(displayValue); + if (thresholdReached || alwaysShowTime) { + let staleTimeText; + if (elapsedMins === 0) { + staleTimeText = 'Just now'; + } + else if (elapsedMins === 1) { + staleTimeText = '1 minute ago'; + } + else { + staleTimeText = elapsedMins + ' minutes ago'; } + + $('.ag').html(staleTimeText); + } + else { + $('.ag').html(''); + } + + // Insert the trend arrow. + let arrow = $('arrow').attr('src', '/images/' + (!rec.direction || rec.direction === 'NOT COMPUTABLE' ? 'NONE' : rec.direction) + '.svg'); + + // Restyle body bg + if (thresholdReached) { + $('body').css('background-color', 'grey').css('color', 'black'); + $('.ar').css('filter', 'brightness(0%)').html(arrow); + } else { + $('body').css('color', bgColor ? 'white' : 'grey'); + $('.ar').css('filter', bgColor ? 'brightness(100%)' : 'brightness(50%)').html(arrow); } }; diff --git a/lib/server/clocks.js b/lib/server/clocks.js index 56bce7b6f13..9926eefcf82 100644 --- a/lib/server/clocks.js +++ b/lib/server/clocks.js @@ -17,7 +17,7 @@ function clockviews() { const face = req.params.face; console.log('Clockface requested:', face); - res.render('shared.html', { + res.render('clock.html', { face, locals }); diff --git a/views/clockviews/bgclock.css b/views/clockviews/bgclock.css deleted file mode 100644 index 3e2cbef246f..00000000000 --- a/views/clockviews/bgclock.css +++ /dev/null @@ -1,28 +0,0 @@ -.inner { - -webkit-transform: translateY(-2%); -} - -#bgnow, #arrowDiv { - display: flex; - flex-grow: 0; - font-weight: 700; - font-size: 30vmin; - padding: 0 20px; - margin: 0; -} - -img#arrow { - height: 18vmin; - filter: brightness(50%); - -webkit-transform: translateY(5%); -} - -#clock { - font-weight: 700; - font-size: 25vmin; - display: inline; -} - -.stale { - text-decoration: line-through; -} \ No newline at end of file diff --git a/views/clockviews/clock-color.css b/views/clockviews/clock-color.css deleted file mode 100644 index 6a6796ef823..00000000000 --- a/views/clockviews/clock-color.css +++ /dev/null @@ -1,32 +0,0 @@ -body { - color: white; -} - -#trend { - -webkit-transform: translateX(1%); - -webkit-flex-direction: column; - flex-direction: column; -} - -#bgnow { - display: inline-block; - vertical-align: middle; -} - -#delta { - font-size: 16vmin; - vertical-align: middle; -} - -#innerTrend { - word-spacing: 2em; -} - -#arrowDiv { - flex-grow: 1; - text-align: center; -} - -img#arrow { - height: 30vmin; -} \ No newline at end of file diff --git a/views/clockviews/clock-config.css b/views/clockviews/clock-config.css new file mode 100644 index 00000000000..0d5f2b8b912 --- /dev/null +++ b/views/clockviews/clock-config.css @@ -0,0 +1,39 @@ +#config-form { + position: fixed; + top: 10px; + left: 10px; + width: 250px; + min-width: 220px; + background: white; + color: black; + opacity: 0.8; + padding: 1%; + font-size: 10px; +} +#config-form p { + margin: 15px; + text-align: left; +} +input.elmt { + width: 120px; +} +select { + width: 100%; +} +#facename { + font-size: 7px; +} +#clocklink { + font-size: 18px; +} +#clocklink:link, #clocklink:visited { + background-color: #f44336; + color: white; + padding: 14px 25px; + text-align: center; + text-decoration: none; + display: inline-block; +} +#clocklink:hover, #clocklink:active { + background-color: red; +} \ No newline at end of file diff --git a/views/clockviews/clock-config.html b/views/clockviews/clock-config.html new file mode 100644 index 00000000000..fff92bb65cb --- /dev/null +++ b/views/clockviews/clock-config.html @@ -0,0 +1,65 @@ +
+

Clock view configurator

+
+

+ + +

+

+ + +

+

SGV age threshold: minutes

+

+

Size:

+

Size:

+

Size:

+

Size:

+

Size:

+

+ Open my clock view! +
cy10
+
+
+ \ No newline at end of file diff --git a/views/clockviews/clock-shared.css b/views/clockviews/clock-shared.css index 83328fe4114..fc624a52c00 100644 --- a/views/clockviews/clock-shared.css +++ b/views/clockviews/clock-shared.css @@ -3,57 +3,50 @@ body { margin: 0 0; padding: 0; overflow: hidden; - font-family: 'Open Sans'; + font-family: 'Open Sans', Arial, Helvetica, sans-serif; color: grey; background-color: black; } main { + height: 100vh; +} + +#inner { display: -webkit-box; display: -ms-flexbox; display: -webkit-flex; display: flex; - -webkit-box-align: center; - -ms-flex-align: center; - -webkit-align-items: center; align-items: center; - height: 100vh; -} - -.inner { + justify-content: center; + align-content: center; + flex-flow: wrap; + height: 100%; width: 100%; - -webkit-transform: translateY(-5%); } -#bgnow { - font-weight: 700; - font-size: 40vmin; +#inner div { + margin-right: 2vmin; + margin-left: 2vmin; + line-height: 1em; } -#trend { - display: -ms-flexbox; - display: -webkit-flex; - display: flex; - -ms-flex-align: center; - -webkit-align-items: center; - align-items: center; - justify-content: center; - -webkit-flex-direction: row; - flex-direction: row; +#inner div img { + height: 100%; } -#staleTime { - flex-grow: 1; - font-size: 6vmin; - display: none; +#inner div.nl { + width: 100%; + margin: 0; + height: 3vmin; } -#clock { - display: none; +#errorMessage { + font-size: 25em; } -#delta { - display: none; +.stale { + text-decoration: line-through; } .close { diff --git a/views/clockviews/clock.css b/views/clockviews/clock.css deleted file mode 100644 index 96ffe68b84a..00000000000 --- a/views/clockviews/clock.css +++ /dev/null @@ -1,5 +0,0 @@ -#trend { - -webkit-transform: translateX(1%); - -webkit-flex-direction: column; - flex-direction: column; -} \ No newline at end of file diff --git a/views/clockviews/shared.html b/views/clockviews/clock.html similarity index 88% rename from views/clockviews/shared.html rename to views/clockviews/clock.html index beac7dc0f2e..2893aec3612 100644 --- a/views/clockviews/shared.html +++ b/views/clockviews/clock.html @@ -1,5 +1,5 @@ - + @@ -21,23 +21,16 @@
-
-
-
- - -
-
arrow
-
-
-
+
>
@@ -69,7 +62,7 @@ script.src = src; document.head.appendChild(script); //or something of the likes - + <%if (face !== 'config') { %> var buttonVisible = true; function hideClose () { @@ -99,8 +92,11 @@ window.addEventListener('click', function() { showClose(); }); - + <% } %> + <%if (face == 'config') { %> + <%- include('clock-config.html', {}); %> + <% } %> diff --git a/views/index.html b/views/index.html index 6ef0dc2cce6..617d7dd8e67 100644 --- a/views/index.html +++ b/views/index.html @@ -174,6 +174,7 @@ Clock Color Simple + [+]
From 5698ae28c131c1562c62f194f084dfa7b41b643b Mon Sep 17 00:00:00 2001 From: josep1972 Date: Fri, 12 Jun 2020 09:33:17 -0500 Subject: [PATCH 04/80] Add remote bolus/carbs + otp entry for loop (#5598) Add a remote bolus entry field for users on Loop, along with support for an OTP field --- lib/client/careportal.js | 31 +++++++++++++++++++++++++++++- lib/plugins/loop.js | 21 ++++++++++++++++++++ lib/server/loop.js | 41 +++++++++++++++++++++++++++++++++++----- test | 0 views/index.html | 20 +++++++++++++++++++- 5 files changed, 106 insertions(+), 7 deletions(-) create mode 100644 test diff --git a/lib/client/careportal.js b/lib/client/careportal.js index 632ab24986f..bff59a821c0 100644 --- a/lib/client/careportal.js +++ b/lib/client/careportal.js @@ -52,7 +52,7 @@ function init (client, $) { submitHooks = {}; _.forEach(careportal.allEventTypes, function each (event) { - inputMatrix[event.val] = _.pick(event, ['bg', 'insulin', 'carbs', 'protein', 'fat', 'prebolus', 'duration', 'percent', 'absolute', 'profile', 'split', 'reasons', 'targets']); + inputMatrix[event.val] = _.pick(event, ['otp','remoteCarbs', 'remoteAbsorption', 'remoteBolus', 'bg', 'insulin', 'carbs', 'protein', 'fat', 'prebolus', 'duration', 'percent', 'absolute', 'profile', 'split', 'reasons', 'targets']); submitHooks[event.val] = event.submitHook; }); } @@ -80,11 +80,18 @@ function init (client, $) { $('#reasonLabel').css('display', displayType(reasons && reasons.length > 0)); $('#targets').css('display', displayType(inputMatrix[eventType]['targets'])); + $('#otpLabel').css('display', displayType(inputMatrix[eventType]['otp'])); + $('#remoteCarbsLabel').css('display', displayType(inputMatrix[eventType]['remoteCarbs'])); + $('#remoteAbsorptionLabel').css('display', displayType(inputMatrix[eventType]['remoteAbsorption'])); + $('#remoteBolusLabel').css('display', displayType(inputMatrix[eventType]['remoteBolus'])); + $('#bg').css('display', displayType(inputMatrix[eventType]['bg'])); $('#insulinGivenLabel').css('display', displayType(inputMatrix[eventType]['insulin'])); + $('#carbsGivenLabel').css('display', displayType(inputMatrix[eventType]['carbs'])); $('#proteinGivenLabel').css('display', displayType(inputMatrix[eventType]['protein'])); $('#fatGivenLabel').css('display', displayType(inputMatrix[eventType]['fat'])); + $('#durationLabel').css('display', displayType(inputMatrix[eventType]['duration'])); $('#percentLabel').css('display', displayType(inputMatrix[eventType]['percent'] && $('#absolute').val() === '')); $('#absoluteLabel').css('display', displayType(inputMatrix[eventType]['absolute'] && $('#percent').val() === '')); @@ -99,6 +106,11 @@ function init (client, $) { careportal.reasonable(); + resetIfHidden(inputMatrix[eventType]['otp'], '#otp'); + resetIfHidden(inputMatrix[eventType]['remoteCarbs'], '#remoteCarbs'); + resetIfHidden(inputMatrix[eventType]['remoteAbsorption'], '#remoteAbsorption'); + resetIfHidden(inputMatrix[eventType]['remoteBolus'], '#remoteBolus'); + resetIfHidden(inputMatrix[eventType]['insulin'], '#insulinGiven'); resetIfHidden(inputMatrix[eventType]['carbs'], '#carbsGiven'); resetIfHidden(inputMatrix[eventType]['protein'], '#proteinGiven'); @@ -192,6 +204,12 @@ function init (client, $) { $('#eventType').val(''); $('#glucoseValue').val('').attr('placeholder', translate('Value in') + ' ' + client.settings.units); $('#meter').prop('checked', true); + + $('#otp').val(''); + $('#remoteCarbs').val(''); + $('#remoteAbsorption').val(''); + $('#remoteBolus').val(''); + $('#carbsGiven').val(''); $('#proteinGiven').val(''); $('#fatGiven').val(''); @@ -214,6 +232,10 @@ function init (client, $) { var data = { enteredBy: $('#enteredBy').val() , eventType: eventType + , otp: $('#otp').val() + , remoteCarbs: $('#remoteCarbs').val() + , remoteAbsorption: $('#remoteAbsorption').val() + , remoteBolus: $('#remoteBolus').val() , glucose: $('#glucoseValue').val().replace(',', '.') , reason: selectedReason , targetTop: $('#targetTop').val().replace(',', '.') @@ -337,6 +359,8 @@ function init (client, $) { } } + // TODO: add check for remote (Bolus, Carbs, Absorption) + return { allOk , messages @@ -360,6 +384,11 @@ function init (client, $) { text[text.length - 1] += ' ' + translate('Cancel'); } + pushIf(data.remoteCarbs, translate('Remote Carbs') + ': ' + data.remoteCarbs); + pushIf(data.remoteAbsorption, translate('Remote Absorption') + ': ' + data.remoteAbsorption); + pushIf(data.remoteBolus, translate('Remote Bolus') + ': ' + data.remoteBolus); + pushIf(data.otp, translate('One Time Pascode') + ': ' + data.otp); + pushIf(data.glucose, translate('Blood Glucose') + ': ' + data.glucose); pushIf(data.glucose, translate('Measurement Method') + ': ' + translate(data.glucoseType)); diff --git a/lib/plugins/loop.js b/lib/plugins/loop.js index 9b099dd188c..46d16738787 100644 --- a/lib/plugins/loop.js +++ b/lib/plugins/loop.js @@ -214,6 +214,8 @@ function init (ctx) { }); } + // TODO: add OTP entry + return [ { val: 'Temporary Override' @@ -229,6 +231,7 @@ function init (ctx) { , split: false , targets: false , reasons: reasonconf + , otp: true , submitHook: postLoopNotification }, { @@ -245,10 +248,28 @@ function init (ctx) { , split: false , targets: false , submitHook: postLoopNotification + }, + { + val: 'Remote Carbs Entry' + , name: 'Remote Carbs Entry' + , remoteCarbs: true + , remoteAbsorption: true + , otp: true + , submitHook: postLoopNotification + }, + { + val: 'Remote Bolus Entry' + , name: 'Remote Bolus Entry' + , remoteBolus: true + , otp: true + , submitHook: postLoopNotification } ]; }; + // TODO: Add event listener to customize labels + + loop.updateVisualisation = function updateVisualisation (sbx) { var prop = sbx.properties.loop; diff --git a/lib/server/loop.js b/lib/server/loop.js index a5e3aec5d8e..ca87892bba6 100644 --- a/lib/server/loop.js +++ b/lib/server/loop.js @@ -1,4 +1,4 @@ -'use strict'; +//'use strict'; const apn = require('apn'); @@ -9,6 +9,10 @@ function init (env, ctx) { } loop.sendNotification = function sendNotification (data, remoteAddress, completion) { + + // console.info("JAP"); + // console.info(data); + if (env.extendedSettings.loop.apnsKey === undefined || env.extendedSettings.loop.apnsKey.length == 0) { completion("Loop notification failed: LOOP_APNS_KEY not set."); return; @@ -63,7 +67,38 @@ function init (env, ctx) { alert = "Cancel Temporary Override"; } else if (data.eventType === 'Temporary Override') { payload["override-name"] = data.reason; + if (data.duration !== undefined && parseInt(data.duration) > 0) { + payload["override-duration-minutes"] = parseInt(data.duration); + } alert = data.reasonDisplay + " Temporary Override"; + } else if (data.eventType === 'Remote Carbs Entry') { + payload["carbs-entry"] = parseFloat(data.remoteCarbs); + if(payload["carbs-entry"] > 0.0 ) { + payload["absorption-time"] = 3.0; + if (data.remoteAbsorption !== undefined && parseFloat(data.remoteAbsorption) > 0.0) { + payload["absorption-time"] = parseFloat(data.remoteAbsorption); + } + if (data.otp !== undefined && data.otp.length > 0) { + payload["otp"] = ""+data.otp + } + alert = "Remote Carbs Entry: "+payload["carbs-entry"]+" grams\n"; + alert += "Absorption Time: "+payload["absorption-time"]+" hours"; + } else { + completion("Loop remote carbs failed. Incorrect carbs entry: ", data.remoteCarbs); + return; + } + + } else if (data.eventType === 'Remote Bolus Entry') { + payload["bolus-entry"] = parseFloat(data.remoteBolus); + if(payload["bolus-entry"] > 0.0 ) { + alert = "Remote Bolus Entry: "+payload["bolus-entry"]+" U\n"; + if (data.otp !== undefined && data.otp.length > 0) { + payload["otp"] = ""+data.otp + } + } else { + completion("Loop remote bolus failed. Incorrect bolus entry: ", data.remoteBolus); + return; + } } else { completion("Loop notification failed: Unhandled event type:", data.eventType); return; @@ -84,10 +119,6 @@ function init (env, ctx) { notification.expiry = Math.round((Date.now() / 1000)) + 60 * 5; // Allow this to enact within 5 minutes. notification.payload = payload; - if (data.duration && parseInt(data.duration) > 0) { - notification.payload["override-duration-minutes"] = parseInt(data.duration); - } - provider.send(notification, [loopSettings.deviceToken]).then( (response) => { if (response.sent && response.sent.length > 0) { completion(); diff --git a/test b/test new file mode 100644 index 00000000000..e69de29bb2d diff --git a/views/index.html b/views/index.html index 617d7dd8e67..c0f6b31613e 100644 --- a/views/index.html +++ b/views/index.html @@ -340,7 +340,24 @@ Sensor
-
+ + + + + +
+