diff --git a/lib/report/reportclient.js b/lib/report/reportclient.js index a074a793cb3..aed324d84a7 100644 --- a/lib/report/reportclient.js +++ b/lib/report/reportclient.js @@ -247,6 +247,8 @@ var init = function init () { options.openAps = true; } + const reportStorage = require('./reportstorage'); + reportStorage.saveProps(options); var matchesneeded = 0; // date range diff --git a/lib/report/reportstorage.js b/lib/report/reportstorage.js new file mode 100644 index 00000000000..e0a8d8b9d17 --- /dev/null +++ b/lib/report/reportstorage.js @@ -0,0 +1,35 @@ +const storage = require('js-storage').localStorage; +const COOKIE_KEY = 'reportProperties'; +const defaultValues = { + insulin: true, + carbs: true, + basal: true, + notes: false, + food: true, + raw: false, + iob: false, + cob: false, + predicted: false, + openAps: false, + insulindistribution: true, + predictedTruncate: true +}; +let cachedProps; + +const saveProps = function (props) { + let propsToSave = {}; + for (const prop in props) { + if (!Object.prototype.hasOwnProperty.call(defaultValues, prop)) + continue; + propsToSave[prop] = props[prop]; + } + storage.set(COOKIE_KEY, propsToSave); +}; + +const getValue = function (p) { + if (!cachedProps) + cachedProps = storage.get(COOKIE_KEY) || defaultValues; + return cachedProps[p]; +}; + +module.exports = {saveProps: saveProps, getValue: getValue}; diff --git a/lib/report_plugins/daytoday.js b/lib/report_plugins/daytoday.js index 47c16cf71a8..6e41efc5543 100644 --- a/lib/report_plugins/daytoday.js +++ b/lib/report_plugins/daytoday.js @@ -18,22 +18,23 @@ function init () { module.exports = init; daytoday.html = function html (client) { + const reportStorage = require('../report/reportstorage'); var translate = client.translate; var ret = '