Skip to content

Commit

Permalink
Fix #5188 - move predictions to bundle and don't render chart on pred…
Browse files Browse the repository at this point in the history
…ictions offset change (#5395)

* Fix #5188 - move predictions to bundle and don't render chart on predictions offset change

* Fix predictions show for day to day
  • Loading branch information
Bartlomiejsz authored and sulkaharo committed Jan 6, 2020
1 parent bb34500 commit 5e47c4d
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 48 deletions.
1 change: 1 addition & 0 deletions bundle/bundle.reports.source.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import './bundle.source';

window.Nightscout.report_plugins = require('../lib/report_plugins/')();
window.Nightscout.predictions = require('../lib/report/predictions');

console.info('Nightscout report bundle ready');

Expand Down
33 changes: 33 additions & 0 deletions lib/report/predictions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
var predictions = {
offset: 0,
backward: function () {
this.offset -= 5;
this.updateOffsetHtml();
},
forward: function () {
this.offset += 5;
this.updateOffsetHtml();
},
moreBackward: function () {
this.offset -= 30;
this.updateOffsetHtml();
},
moreForward: function () {
this.offset += 30;
this.updateOffsetHtml();
},
reset: function () {
this.offset = 0;
this.updateOffsetHtml();
},
updateOffsetHtml: function () {
$('#rp_predictedOffset').html(this.offset);
}
};

$(document).on('change', '#rp_optionspredicted', function() {
$('#rp_predictedSettings').toggle(this.checked);
predictions.reset();
});

module.exports = predictions;
14 changes: 7 additions & 7 deletions lib/report_plugins/daytoday.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ daytoday.html = function html (client) {
translate('Predictions offset') + ': ' +
'<b><label id="rp_predictedOffset"></label> minutes</b>' +
'&nbsp;&nbsp;&nbsp;&nbsp;' +
'<input type="button" onclick="predictMoreBackward();" value="' + translate('-30 min') + '">' +
'<input type="button" onclick="predictBackward();" value="' + translate('-5 min') + '">' +
'<input type="button" onclick="predictResetToZero();" value="' + translate('Zero') + '">' +
'<input type="button" onclick="predictForward();" value="' + translate('+5 min') + '">' +
'<input type="button" onclick="predictMoreForward();" value="' + translate('+30 min') + '">' +
'<input type="button" onclick="Nightscout.predictions.moreBackward();" value="' + translate('-30 min') + '">' +
'<input type="button" onclick="Nightscout.predictions.backward();" value="' + translate('-5 min') + '">' +
'<input type="button" onclick="Nightscout.predictions.reset();" value="' + translate('Zero') + '">' +
'<input type="button" onclick="Nightscout.predictions.forward();" value="' + translate('+5 min') + '">' +
'<input type="button" onclick="Nightscout.predictions.moreForward();" value="' + translate('+30 min') + '">' +
'</div>' +
'<br>' +
'<div id="daytodaycharts">' +
Expand Down Expand Up @@ -363,15 +363,15 @@ daytoday.report = function report_daytoday (datastorage, sorteddaystoshow, optio
var timestamp = treatmentsTimestamps[treatmentsIndex];
// TODO refactor code so this is set here - now set as global in file loaded by the browser
// eslint-disable-next-line no-undef
var predictedIndex = findPredicted(predictions, timestamp, predictedOffset); // Find predictions offset before or after timestamp
var predictedIndex = findPredicted(predictions, timestamp, Nightscout.predictions.offset); // Find predictions offset before or after timestamp

if (predictedIndex != null) {
entry = predictions[predictedIndex]; // Start entry
var d = moment(entry.startDate);
var end = moment().endOf('day');
if (options.predictedTruncate) {
// eslint-disable-next-line no-undef
if (predictedOffset >= 0) {
if (Nightscout.predictions.offset >= 0) {
// If we are looking forward we want to stop at the next treatment
if (treatmentsIndex < treatmentsTimestamps.length - 1) {
end = moment(treatmentsTimestamps[treatmentsIndex + 1]);
Expand Down
40 changes: 0 additions & 40 deletions static/report/js/predictions.js

This file was deleted.

1 change: 0 additions & 1 deletion views/reportindex.html
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@
<script src="/socket.io/socket.io.js?v=<%= locals.cachebuster %>"></script>
<script src="/report/js/report.js?v=<%= locals.cachebuster %>"></script>
<script src="/report/js/flotcandle.js?v=<%= locals.cachebuster %>"></script>
<script src="/report/js/predictions.js?v=<%= locals.cachebuster %>"></script>
<script src="/report/js/loopalyzer.js?v=<%= locals.cachebuster %>"></script>
</main>
</body>
Expand Down

0 comments on commit 5e47c4d

Please sign in to comment.