Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Settings #51

Merged
merged 91 commits into from
Jul 29, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
91 commits
Select commit Hold shift + click to select a range
4b68711
Forcing codeship.io push to heroku
brianhanifin Jul 7, 2014
b34ae0d
merging local changes
brianhanifin Jul 18, 2014
fcef373
experiments
brianhanifin Jul 20, 2014
77d13c3
Update package.json
brianhanifin Jul 20, 2014
9f387a3
Toolbar added + example settings forms in drawer
brianhanifin Jul 22, 2014
dd89938
Toolbar added + example settings forms in drawer
brianhanifin Jul 22, 2014
f0e175b
Toolbar added + example settings forms in drawer
brianhanifin Jul 22, 2014
9f8b36b
More UI polish
brianhanifin Jul 22, 2014
eb7811c
Static toolbar exeriment
brianhanifin Jul 22, 2014
8284cec
Static toolbar
brianhanifin Jul 22, 2014
85f64b4
Browser Setting Storage
brianhanifin Jul 22, 2014
15e6d72
Settings UI to switch to mmol display!
brianhanifin Jul 22, 2014
ddd3e47
/pebble?units=mmol
brianhanifin Jul 23, 2014
37a008e
Fixed bgdelta mmol to 1 decimal place
brianhanifin Jul 23, 2014
9c99b40
bump package version
bewest Jul 23, 2014
c857a6a
add some basic metadata about the software to env
bewest Jul 23, 2014
7a1a83d
Add version info to rest API
bewest Jul 23, 2014
dac829a
Fix bug in paths handling
bewest Jul 23, 2014
cf5398a
Merge branch 'rebase/settings' of github.com:nightscout/cgm-remote-mo…
bewest Jul 23, 2014
a2d5927
put version of npm package on the screen
bewest Jul 23, 2014
91ec89d
Restored lost settings in client.js
brianhanifin Jul 23, 2014
2a57cab
Enable/Disable Night Mode
brianhanifin Jul 23, 2014
3e9df95
Tooltips (e.g. explains Night Mode)
brianhanifin Jul 23, 2014
ff55952
Favicon experiements
brianhanifin Jul 23, 2014
af7f36f
Favicon experiments
brianhanifin Jul 23, 2014
fb4f31c
Favicon Experiments (added drop2a.png)
brianhanifin Jul 23, 2014
1f7c7f0
Favicon Experiments (2 more artist's icons)
brianhanifin Jul 23, 2014
fbda0c5
Toolbar Logo experiments
brianhanifin Jul 23, 2014
5ef617f
Fix: restored mg/dL chart "tickValues"
brianhanifin Jul 23, 2014
34ddd82
Fix: time flicker
brianhanifin Jul 23, 2014
6c99055
Toolbar hide/show buttons + Custom glyph font
brianhanifin Jul 24, 2014
a11bbff
Fix: misc mobile sizing
brianhanifin Jul 24, 2014
9879009
Fix: touchscreen tooltip changes
brianhanifin Jul 24, 2014
a355c4e
Fix: firefox settings save issue + trimmed fonts
brianhanifin Jul 24, 2014
ab0657b
Moved version info inside drawer.
brianhanifin Jul 24, 2014
73b1339
Cleanup + added ?mute=true for testing
brianhanifin Jul 24, 2014
79f91b0
Restore alerts
brianhanifin Jul 24, 2014
fa9e0e5
Cleanup:
brianhanifin Jul 25, 2014
fd6b9e3
Change: Form Tooltip now = Github's Question Mark
brianhanifin Jul 25, 2014
4cf38cb
Hamburger Experiment
brianhanifin Jul 25, 2014
42114e8
Hamburger Experiment
brianhanifin Jul 25, 2014
a476b9f
Cleanup + ?drawer=true + `mv fonts/ glyphs/`
brianhanifin Jul 25, 2014
50d14d9
api/status: include default units and apiEnabled
bewest Jul 25, 2014
69d7b44
tweak comment
bewest Jul 25, 2014
868dad1
Merge branch 'rebase/settings' of github.com:nightscout/cgm-remote-mo…
bewest Jul 25, 2014
ce19663
?toolbar=false
brianhanifin Jul 25, 2014
1e2cb5d
add jsSHA via bower
bewest Jul 25, 2014
e85b707
Merge branch 'rebase/settings' of github.com:nightscout/cgm-remote-mo…
bewest Jul 25, 2014
b7ef943
Merge remote-tracking branch 'origin/master' into rebase/settings
bewest Jul 25, 2014
c839814
add type=text/css to link elements
bewest Jul 25, 2014
57c30b9
Rudimentary Notifications
brianhanifin Jul 25, 2014
c8c3781
Rudimentary Notifications
brianhanifin Jul 25, 2014
c619738
Notifications
brianhanifin Jul 25, 2014
b6cd9b5
tweak settings a bit to be more like profiles
bewest Jul 26, 2014
a5ad4a9
cleanup/comment settings api
bewest Jul 26, 2014
629e8cb
nix spurious console.log
bewest Jul 26, 2014
9b79e75
clock mode with @brandonarbiter
bewest Jul 26, 2014
55f7778
Cross browser fix + more responsive
brianhanifin Jul 26, 2014
fe5cc89
Fix: Snooze list now appears above all else
brianhanifin Jul 26, 2014
d147b68
Cross platform UI cleanup
brianhanifin Jul 26, 2014
e620027
Red alert button position adjustments.
brianhanifin Jul 26, 2014
812d35e
Cleanup: 2 tiny tweaks.
brianhanifin Jul 26, 2014
3f4075f
Interface tweaks
brianhanifin Jul 26, 2014
aac2dcf
strike out when data is old
bewest Jul 26, 2014
5127fda
azure: try fresh deploy.sh
bewest Jul 27, 2014
704b040
Merge branch 'feature/base-api' into rebase/settings
Jul 27, 2014
c7def83
Merge branch 'fix/deploy' into wip/clock/init
bewest Jul 27, 2014
ff84000
migrate to API-SECRET header
bewest Jul 27, 2014
f51b6c3
hack to allow DISPLAY_UNITS actually change default
bewest Jul 27, 2014
dd70399
Merge commit 'f51b6c3a8b98a0ecc350f307cda6746ba002e6db' into rebase/s…
brianhanifin Jul 28, 2014
da8d78d
Merged dropdown.js into ui-utils.js
brianhanifin Jul 28, 2014
4d97571
Committing important unsaved changes to ui-utils.js.
brianhanifin Jul 29, 2014
b8c908c
High contrast display for last entry time.
brianhanifin Jul 29, 2014
a1562fd
Fixed javascript error in ui-utils.js when no query string parameters…
brianhanifin Jul 29, 2014
92d56f8
Created high contrast treatment for the last entry time.
brianhanifin Jul 29, 2014
f558a5b
About: added link to Release Notes
brianhanifin Jul 29, 2014
913e5c5
About: further tweaking text
brianhanifin Jul 29, 2014
2dd8f53
Added Battery Glyphs in preparation for display of battery percentage.
brianhanifin Jul 29, 2014
b43767f
Prep work for battery status in button bar.
brianhanifin Jul 29, 2014
7ebe17a
Changed battery glyph to `visibility:hidden`
brianhanifin Jul 29, 2014
51ee7d8
lower case api-secret header just incase some server or user agent do…
Jul 29, 2014
e5a2696
Merge branch 'rebase/settings' of github.com:nightscout/cgm-remote-mo…
Jul 29, 2014
d10df6b
Last Entry: out of date colored backgrounds
brianhanifin Jul 29, 2014
7b5bff9
no message
brianhanifin Jul 29, 2014
9ce67b0
Stale data: strikethrough when 20 minutes out of date
brianhanifin Jul 29, 2014
9c4f5d1
Settings: Patient Name
brianhanifin Jul 29, 2014
9bd5ace
Settings: renamed Patient Name -> Custom Title
brianhanifin Jul 29, 2014
b5fdb3d
Adding custom title to page title
brianhanifin Jul 29, 2014
4fa27ab
Status layout: removed unnecessary font shrinkage step.
brianhanifin Jul 29, 2014
291abb5
Fix truncated arrow
brianhanifin Jul 29, 2014
439a8d7
arrow fix
brianhanifin Jul 29, 2014
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cgm-remote-monitor (a.k.a. NightScout)
======================================

[![Build Status](https://travis-ci.org/nightscout/cgm-remote-monitor.png)](https://travis-ci.org/nightscout/cgm-remote-monitor)
[![Dependency Status](https://david-dm.org/nightscout/cgm-remote-monitor.png)](https://david-dm.org/nightscout/cgm-remote-monitor)
[![Gitter chat](https://badges.gitter.im/nightscout.png)](https://gitter.im/nightscout/public)
Expand Down
6 changes: 6 additions & 0 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
"version": "0.0.1",
"dependencies": {
"d3": "3.4.3",
"jquery": "2.1.0",
"jQuery-Storage-API": "~1.7.2",
"tipsy-jmalonzo": "~1.0.1",
"jsSHA": "~1.5.0"
},
"resolutions": {
"jquery": "2.1.0"
}
}
34 changes: 12 additions & 22 deletions deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# ----------------------
# KUDU Deployment Script
# Version: 0.1.10
# Version: 0.1.11
# ----------------------

# Helpers
Expand Down Expand Up @@ -100,32 +100,22 @@ selectNodeVersion () {

echo Handling node.js deployment.

# 1. Select node version
# 1. KuduSync
if [[ "$IN_PLACE_DEPLOYMENT" -ne "1" ]]; then
"$KUDU_SYNC_CMD" -v 50 -f "$DEPLOYMENT_SOURCE" -t "$DEPLOYMENT_TARGET" -n "$NEXT_MANIFEST_PATH" -p "$PREVIOUS_MANIFEST_PATH" -i ".git;.hg;.deployment;deploy.sh"
exitWithMessageOnError "Kudu Sync failed"
fi

# 2. Select node version
selectNodeVersion

# 2. Install npm packages
if [ -e "$DEPLOYMENT_SOURCE/package.json" ]; then
# cd "$DEPLOYMENT_SOURCE"
eval $NPM_CMD set ca ""
# 3. Install npm packages
if [ -e "$DEPLOYMENT_TARGET/package.json" ]; then
cd "$DEPLOYMENT_TARGET"
eval $NPM_CMD install --production
exitWithMessageOnError "npm failed"
# cd - > /dev/null
cd - > /dev/null
fi
if [ -e "$DEPLOYMENT_SOURCE/bower.json" ]; then
# cd "$DEPLOYMENT_SOURCE"
./node_modules/.bin/bower install
exitWithMessageOnError "bower failed"
# cd - > /dev/null
fi

# 3. KuduSync
# if [[ "$IN_PLACE_DEPLOYMENT" -ne "1" ]]; then
# "$KUDU_SYNC_CMD" -v 50 -f "$DEPLOYMENT_SOURCE" -t "$DEPLOYMENT_TARGET" -n "$NEXT_MANIFEST_PATH" -p "$PREVIOUS_MANIFEST_PATH" -i ".git;.hg;.deployment;deploy.sh"
# exitWithMessageOnError "Kudu Sync failed"
# fi
# 3. KuduSync to Target
"$KUDU_SYNC_CMD" -v 500 -f "$DEPLOYMENT_SOURCE/" -t "$DEPLOYMENT_TARGET" -n "$NEXT_MANIFEST_PATH" -p "$PREVIOUS_MANIFEST_PATH" -i ".git;.hg;.deployment;deploy.sh"
exitWithMessageOnError "Kudu Sync to Target failed"

##################################################################################################################################

Expand Down
4 changes: 4 additions & 0 deletions env.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ function config ( ) {
* static files over http. Default value is the included `static`
* directory.
*/
var software = require('./package.json');

env.version = software.version;
env.name = software.name;
env.DISPLAY_UNITS = process.env.DISPLAY_UNITS || 'mg/dl';
env.PORT = process.env.PORT || 1337;
env.mongo = process.env.MONGO_CONNECTION || process.env.CUSTOMCONNSTR_mongo;
env.mongo_collection = process.env.CUSTOMCONNSTR_mongo_collection || 'entries';
Expand Down
11 changes: 6 additions & 5 deletions lib/api/entries/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,10 @@ function configure (app, wares, entries) {
es.pipeline(inputs( ), persist(done));
}

api.get('/', function(req, res, next) {
api.get('/entries', function(req, res, next) {
// If "?count=" is present, use that number to decided how many to return.
var query = req.query;
if (!query.count) { query.count = 10 };
entries.list(query, function(err, entries) {
res.entries = entries;
res.entries_err = err;
Expand All @@ -115,7 +116,7 @@ function configure (app, wares, entries) {
return;
}, format_entries);

api.get('/current', function(req, res, next) {
api.get('/entries/current', function(req, res, next) {
entries.list({count: 1}, function(err, records) {
res.entries = records;
res.entries_err = err;
Expand All @@ -127,23 +128,23 @@ function configure (app, wares, entries) {

// Allow previewing your post content, just echos everything you
// posted back out.
api.post('/preview', function (req, res, next) {
api.post('/entries/preview', function (req, res, next) {
req.persist_entries = false;
next( );
return;
}, insert_entries, format_entries);

if (app.enabled('api')) {
// Create and store new sgv entries
api.post('/', wares.verifyAuthorization, function (req, res, next) {
api.post('/entries/', wares.verifyAuthorization, function (req, res, next) {
req.persist_entries = true;
next( );
return;
}, insert_entries, format_entries);
}

// Fetch one entry by id
api.get('/find/:id', function(req, res) {
api.get('/entries/:id', function(req, res) {
entries.getEntry(function(err, entry) {
if (err)
res.sendJSONStatus(res, consts.HTTP_INTERNAL_ERROR, 'Mongo Error', err);
Expand Down
11 changes: 7 additions & 4 deletions lib/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@ function create (env, entries, settings) {
var wares = require('../middleware/')(env);

// set up express app with our options
app.set('name', env.name);
app.set('version', env.version);
app.set('units', env.DISPLAY_UNITS);
// Only allow access to the API if API_SECRET is set on the server.
app.disable('api');
if (env.api_secret) {
console.log("API_SECRET", env.api_secret);
app.enable('api');
}

app.set('title', 'Nightscout API v1');
app.set('title', [app.get('name'), 'API', app.get('version')].join(' '));

// Start setting up routes
if (app.enabled('api')) {
Expand All @@ -24,11 +27,11 @@ function create (env, entries, settings) {
}

// Entries and settings
app.use('/entries', require('./entries/')(app, wares, entries));
app.use('/settings', require('./settings/')(app, wares, settings));
app.use('/', require('./entries/')(app, wares, entries));
app.use('/', require('./settings/')(app, wares, settings));

// Status
app.use('/status', require('./status')(app, wares));
app.use('/', require('./status')(app, wares));
return app;
}

Expand Down
57 changes: 30 additions & 27 deletions lib/api/settings/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,44 +19,47 @@ function configure (app, wares, settings) {
/**********\
* Settings
\**********/
// Handler for grabbing alias/profile
api.param('alias', function (req, res, next, alias) {
settings.alias(alias, function (err, profile) {
req.alias = profile;
next(err);
});
});

// List settings available
api.get('/settings/', function(req, res) {
settings.list(function (err, profiles) {
return res.json(profiles);
});
});

// Fetch settings
api.get('/', function(req, res) {
settings.getSettings(function(err, settings) {
if (err)
res.sendJSONStatus(res, consts.HTTP_INTERNAL_ERROR, 'Mongo Error', err);
else
return res.json(settings);
});
api.get('/settings/:alias', function(req, res) {
res.json(req.alias);
});

function config_authed (app, api, wares, settings) {

// Delete settings
api.delete('/', wares.verifyAuthorization, function(req, res) {
settings.remove(function ( ) {
api.delete('/settings/:alias', wares.verifyAuthorization, function(req, res) {
settings.remove(req.alias.alias, function ( ) {
res.json({ });
});
});

// Replace settings
api.put('/', wares.verifyAuthorization, function(req, res) {
// Retrieve the JSON formatted record.
var json = req.body;
function save_settings (req, res) {
var b = req.body;
b.alias = req.params.alias
settings.update(b, function (err, profile) {
res.json(profile);
});
}

// Update settings
api.put('/settings/:alias', wares.verifyAuthorization, save_settings);
api.post('/settings/:alias', wares.verifyAuthorization, save_settings);

// Send the new settings to mongodb.
settings.updateSettings(json, function(err, config) {
if (err)
res.sendJSONStatus(res, consts.HTTP_INTERNAL_ERROR, 'Mongo Error', err);
else {
// Add a warning to the outgoing status when HTTPS is not being used.
var warning = '';
if (req.secure === false)
warning = 'WARNING: HTTPS is required to secure your data!';

res.json(config);
}
});
});
}

if (app.enabled('api')) {
Expand Down
18 changes: 14 additions & 4 deletions lib/api/status.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@ function configure (app, wares) {
;

api.use(wares.extensions([
'json', 'svg', 'csv', 'txt', 'png', 'html'
'json', 'svg', 'csv', 'txt', 'png', 'html', 'js'
]));
// Status badge/text/json
api.get('/', function (req, res, next) {
var status = {status: 'ok'};
api.get('/status', function (req, res, next) {
var info = { status: 'ok'
, apiEnabled: app.enabled('api')
, units: app.get('units')
, version: app.get('version')
, name: app.get('name')};
var badge = 'http://img.shields.io/badge/Nightscout-OK-green';
return res.format({
html: function ( ) {
Expand All @@ -22,11 +26,17 @@ function configure (app, wares) {
svg: function ( ) {
res.redirect(302, badge + '.svg');
},
js: function ( ) {
var head = "this.serverSettings =";
var body = JSON.stringify(info);
var tail = ';';
res.send([head, body, tail].join(' '));
},
text: function ( ) {
res.send("STATUS OK");
},
json: function ( ) {
res.json(status);
res.json(info);
}
});
});
Expand Down
4 changes: 2 additions & 2 deletions lib/middleware/verify-token.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ function configure (env) {
function verifyAuthorization(req, res, next) {
// Retrieve the secret values to be compared.
var api_secret = env.api_secret;
var secret = req.params.secret ? req.params.secret : req.header('API_SECRET');
var secret = req.params.secret ? req.params.secret : req.header('api-secret');

// Return an error message if the authorization fails.
var unauthorized = (typeof api_secret === 'undefined' || secret != api_secret);
if (unauthorized) {
res.sendJSONStatus(res, consts.HTTP_UNAUTHORIZED, 'Unauthorized', 'API_SECRET Request Header is incorect or missing.');
res.sendJSONStatus(res, consts.HTTP_UNAUTHORIZED, 'Unauthorized', 'api-secret Request Header is incorrect or missing.');
} else {
next();
}
Expand Down
68 changes: 43 additions & 25 deletions lib/pebble.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,35 +21,54 @@ function directionToTrend (direction) {

function pebble (req, res) {
var FORTY_MINUTES = 2400000;

var cgmData = [ ];

function requestMetric() {
var units = req.query.units;
if (units == "mmol") {
return true;
}
return false;
}
var useMetricBg = requestMetric();

function scaleBg(bg) {
if (useMetricBg) {
return (Math.round((bg / 18) * 10) / 10).toFixed(1);
} else
return bg;
}

function get_latest (err, results) {
var now = Date.now();
results.forEach(function(element, index, array) {
var next = null;
if (index + 1 < results.length) {
next = results[index + 1];
results.forEach(function(element, index, array) {
var next = null;
if (index + 1 < results.length) {
next = results[index + 1];
}
if (element) {
var obj = {};
obj.sgv = scaleBg(element.sgv);
obj.bgdelta = (next ? (scaleBg(element.sgv) - scaleBg(next.sgv) ) : 0);
if (useMetricBg) {
obj.bgdelta = obj.bgdelta.toFixed(1);
}
if (element) {
var obj = {};
obj.sgv = element.sgv;
obj.bgdelta = (next ? (element.sgv - next.sgv ) : 0);
if ('direction' in element) {
obj.trend = directionToTrend(element.direction);
obj.direction = element.direction;
}
// obj.y = element.sgv;
// obj.x = element.date;
obj.datetime = element.date;
// obj.date = element.date.toString( );
cgmData.push(obj);
if ('direction' in element) {
obj.trend = directionToTrend(element.direction);
obj.direction = element.direction;
}
});
var result = { status: [ {now:now}], bgs: cgmData.slice(0, 1) };
res.setHeader('content-type', 'application/json');
res.write(JSON.stringify(result));
res.end( );
// collection.db.close();
// obj.y = element.sgv;
// obj.x = element.date;
obj.datetime = element.date;
// obj.date = element.date.toString( );
cgmData.push(obj);
}
});
var result = { status: [ {now:now}], bgs: cgmData.slice(0, 1) };
res.setHeader('content-type', 'application/json');
res.write(JSON.stringify(result));
res.end( );
// collection.db.close();
}
req.entries.list({count: 2}, get_latest);
}
Expand All @@ -63,4 +82,3 @@ function configure (entries) {

configure.pebble = pebble;
module.exports = configure;

Loading