forked from nightscout/cgm-remote-monitor
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
nightscout#6701 Save report preferences
Proof of concept to demonstrate saving report preferences
- Loading branch information
Showing
3 changed files
with
51 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters