Skip to content

Commit

Permalink
Merge branch 'release/0.7.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
jasoncalabrese committed Apr 19, 2015
2 parents 48bdd80 + da7b24b commit c11d4c7
Show file tree
Hide file tree
Showing 84 changed files with 2,955 additions and 1,029 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
bower_components/
node_modules/


bundle/bundle.out.js

.idea/
*.iml
my.env
Expand All @@ -15,3 +18,5 @@ static/bower_components/

# istanbul output
coverage/

npm-debug.log
18 changes: 6 additions & 12 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
language: node_js
sudo: false
node_js:
- "0.10"
- "0.11"
matrix:
allow_failures:
- node_js: "0.11"
services:
- mongodb
before_script:
- sleep 10
- echo mongo mongo_travis
script:
- make travis
- "0.10"
- "0.12"
services: mongodb
script: make travis
after_script: make report
5 changes: 2 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@
[build-url]: https://travis-ci.org/nightscout/cgm-remote-monitor
[dependency-img]: https://img.shields.io/david/nightscout/cgm-remote-monitor.svg
[dependency-url]: https://david-dm.org/nightscout/cgm-remote-monitor
[coverage-img]: https://img.shields.io/coveralls/nightscout/cgm-remote-monitor/coverage.svg
[coverage-url]: https://coveralls.io/r/nightscout/cgm-remote-monitor?branch=dev
[coverage-img]: https://img.shields.io/coveralls/nightscout/cgm-remote-monitor/master.svg
[coverage-url]: https://coveralls.io/r/nightscout/cgm-remote-monitor?branch=master
[gitter-img]: https://img.shields.io/badge/Gitter-Join%20Chat%20%E2%86%92-1dce73.svg
[gitter-url]: https://gitter.im/nightscout/public
[ready-img]: https://badge.waffle.io/nightscout/cgm-remote-monitor.svg?label=ready&title=Ready
[waffle]: https://waffle.io/nightscout/cgm-remote-monitor
[progress-img]: https://badge.waffle.io/nightscout/cgm-remote-monitor.svg?label=in+progress&title=In+Progress


## Design

Participate in the design process by creating an issue to discuss your
Expand Down
40 changes: 30 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

# Nightscout tests/builds/analysis
TESTS=tests/*.js
MONGO_CONNECTION?=mongodb://localhost/test_db
CUSTOMCONNSTR_mongo_settings_collection?=test_settings
Expand All @@ -7,19 +8,38 @@ MONGO_SETTINGS=MONGO_CONNECTION=${MONGO_CONNECTION} \
CUSTOMCONNSTR_mongo_collection=${CUSTOMCONNSTR_mongo_collection} \
CUSTOMCONNSTR_mongo_settings_collection=${CUSTOMCONNSTR_mongo_settings_collection}

# XXX.bewest: Mocha is an odd process, and since things are being
# wrapped and transformed, this odd path needs to be used, not the
# normal wrapper. When ./node_modules/.bin/mocha is used, no coverage
# information is generated. This happens because typical shell
# wrapper performs process management that mucks with the test
# coverage reporter's ability to instrument the tests correctly.
# Hard coding it to the local with our pinned version is bigger for
# initial installs, but ensures a consistent environment everywhere.
# On Travis, ./node_modules/.bin and other `nvm` and `npm` bundles are
# inserted into the default `$PATH` enviroinment, making pointing to
# the unwrapped mocha executable necessary.
MOCHA=./node_modules/mocha/bin/_mocha
# Pinned from dependency list.
ISTANBUL=./node_modules/.bin/istanbul
ANALYZED=./coverage/lcov.info

all: test

travis-cov:
NODE_ENV=test \
${MONGO_SETTINGS} \
istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -vvv -R tap ${TESTS} && \
cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && \
rm -rf ./coverage
coverage:
NODE_ENV=test ${MONGO_SETTINGS} \
${ISTANBUL} cover ${MOCHA} -- -R tap ${TESTS}

report:
test -f ${ANALYZED} && \
(npm install coveralls && cat ${ANALYZED} | \
./node_modules/.bin/coveralls) || echo "NO COVERAGE"

test:
${MONGO_SETTINGS} \
mocha --verbose -vvv -R tap ${TESTS}
${MONGO_SETTINGS} ${MOCHA} -R tap ${TESTS}

travis: test travis-cov
travis:
NODE_ENV=test ${MONGO_SETTINGS} \
${ISTANBUL} cover ${MOCHA} --report lcovonly -- -R tap ${TESTS}

.PHONY: test
.PHONY: all coverage report test travis
2 changes: 1 addition & 1 deletion Procfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
web: node server.js
web: ./node_modules/.bin/forever --minUptime 100 -c node server.js
22 changes: 20 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ Use the [autoconfigure tool][autoconfigure] to sync an uploader to your config.

#### Features/Labs

* `ENABLE` - Used to enable optional features, expects a space delimited list such as: `careportal rawbg` (also `rawbg-on` to show raw data by default)
* `ENABLE` - Used to enable optional features, expects a space delimited list such as: `careportal rawbg iob`
* `API_SECRET` - A secret passphrase that must be at least 12 characters long, required to enable `POST` and `PUT`; also required for the Care Portal
* `BG_HIGH` (`260`) - must be set using mg/dl units; the high BG outside the target range that is considered urgent
* `BG_TARGET_TOP` (`180`) - must be set using mg/dl units; the top of the target range, also used to draw the line on the chart
Expand All @@ -114,11 +114,29 @@ Use the [autoconfigure tool][autoconfigure] to sync an uploader to your config.
* `SSL_CERT` - Path to your ssl cert file, so that ssl(https) can be enabled directly in node.js
* `SSL_CA` - Path to your ssl ca file, so that ssl(https) can be enabled directly in node.js


#### Predefined values for your browser settings (optional)
* `TIME_FORMAT` (`12`)- possible values `12` or `24`
* `NIGHT_MODE` (`off`) - possible values `on` or `off`
* `SHOW_RAWBG` (`never`) - possible values `always`, `never` or `noise`
* `CUSTOM_TITLE` (`Nightscout`) - Usually name of T1
* `THEME` (`default`) - possible values `default` or `colors`
* `ALARM_URGENT_HIGH` (`on`) - possible values `on` or `off`
* `ALARM_HIGH` (`on`) - possible values `on` or `off`
* `ALARM_LOW` (`on`) - possible values `on` or `off`
* `ALARM_URGENT_LOW` (`on`) - possible values `on` or `off`
* `ALARM_TIMEAGO_WARN` (`on`) - possible values `on` or `off`
* `ALARM_TIMEAGO_WARN_MINS` (`15`) - minutes since the last reading to trigger a warning
* `ALARM_TIMEAGO_URGENT` (`on`) - possible values `on` or `off`
* `ALARM_TIMEAGO_URGENT_MINS` (`30`) - minutes since the last reading to trigger a urgent alarm


## Setting environment variables
Easy to emulate on the commandline:

```bash
echo 'MONGO_CONNECTION="mongodb://sally:[email protected]:99999/nightscout"' >> my.env
echo 'MONGO_CONNECTION=mongodb://sally:[email protected]:99999/nightscout' >> my.env
echo 'MONGO_COLLECTION=entries' >> my.env
```

From now on you can run using
Expand Down
59 changes: 59 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@

var express = require('express');
var compression = require('compression');
function create (env, ctx) {
///////////////////////////////////////////////////
// api and json object variables
///////////////////////////////////////////////////
var api = require('./lib/api/')(env, ctx.entries, ctx.settings, ctx.treatments, ctx.profiles, ctx.devicestatus);
var pebble = ctx.pebble;

var app = express();
app.entries = ctx.entries;
app.treatments = ctx.treatments;
app.profiles = ctx.profiles;
app.devicestatus = ctx.devicestatus;
var appInfo = env.name + ' ' + env.version;
app.set('title', appInfo);
app.enable('trust proxy'); // Allows req.secure test on heroku https connections.

app.use(compression({filter: shouldCompress}));

function shouldCompress(req, res) {
//TODO: return false here if we find a condition where we don't want to compress
// fallback to standard filter function
return compression.filter(req, res);
}

//if (env.api_secret) {
// console.log("API_SECRET", env.api_secret);
//}
app.use('/api/v1', api);


// pebble data
app.get('/pebble', pebble(ctx.entries, ctx.treatments, ctx.profiles, ctx.devicestatus, env));

//app.get('/package.json', software);

// define static server
//TODO: JC - changed cache to 1 hour from 30d ays to bypass cache hell until we have a real solution
var staticFiles = express.static(env.static_files, {maxAge: 60 * 60 * 1000});

// serve the static content
app.use(staticFiles);

var bundle = require('./bundle')();
app.use(bundle);

// Handle errors with express's errorhandler, to display more readable error messages.

// Handle errors with express's errorhandler, to display more readable error messages.
var errorhandler = require('errorhandler');
//if (process.env.NODE_ENV === 'development') {
app.use(errorhandler());
//}
return app;
}
module.exports = create;

8 changes: 7 additions & 1 deletion app.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
"value": "",
"required": true
},
"DISPLAY_UNITS": {
"description": "Server display units for BG values. Default null value implies 'mg/dl'. Set to 'mmol' to change the server to mmol mode.",
"value": "",
"required": false
},
"ENABLE": {
"description": "Space delimited list of optional features to enable, such as 'careportal'.",
"value": "",
Expand Down Expand Up @@ -54,6 +59,7 @@
}
},
"addons": [
"mongolab:sandbox"
"mongolab:sandbox",
"papertrail"
]
}
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nightscout",
"version": "0.6.4",
"version": "0.7.0",
"dependencies": {
"angularjs": "1.3.0-beta.19",
"bootstrap": "~3.2.0",
Expand Down
13 changes: 13 additions & 0 deletions bundle/bundle.source.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
(function () {

window.Nightscout = window.Nightscout || {};

window.Nightscout = {
iob: require('../lib/iob')()
, units: require('../lib/units')()
};

console.info("Nightscout bundle ready", window.Nightscout);

})();

17 changes: 17 additions & 0 deletions bundle/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
'use strict';

var browserify_express = require('browserify-express');

function bundle() {
return browserify_express({
entry: __dirname + '/bundle.source.js',
watch: __dirname + '/../lib/',
mount: '/public/js/bundle.js',
verbose: true,
//minify: true,
bundle_opts: { debug: true }, // enable inline sourcemap on js files
write_file: __dirname + '/bundle.out.js'
});
}

module.exports = bundle;
1 change: 1 addition & 0 deletions deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ selectNodeVersion () {
# ----------

echo Handling node.js deployment.
echo "\"$SCM_COMMIT_ID\"" > $DEPLOYMENT_SOURCE/scm-commit-id.json

# 1. KuduSync
if [[ "$IN_PLACE_DEPLOYMENT" -ne "1" ]]; then
Expand Down
72 changes: 63 additions & 9 deletions env.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,80 @@ function config ( ) {
var software = require('./package.json');
var git = require('git-rev');

if (readENV('SCM_GIT_EMAIL') == 'windowsazure' && readENV('ScmType') == 'GitHub') {
git.cwd('/home/site/repository');
}
if (readENV('SCM_COMMIT_ID')) {
env.head = readENV('SCM_COMMIT_ID');
if (readENV('APPSETTING_ScmType') == readENV('ScmType') && readENV('ScmType') == 'GitHub') {
env.head = require('./scm-commit-id.json');
console.log("SCM COMMIT ID", env.head);
} else {
git.short(function record_git_head (head) {
console.log("GIT HEAD", head);
env.head = head;
env.head = head || readENV('SCM_COMMIT_ID') || readENV('COMMIT_HASH', '');
});
}
env.version = software.version;
env.name = software.name;

env.DISPLAY_UNITS = readENV('DISPLAY_UNITS', 'mg/dl');
env.PORT = readENV('PORT', 1337);
env.mongo = readENV('MONGO_CONNECTION') || readENV('MONGO') || readENV('MONGOLAB_URI');
env.mongo_collection = readENV('MONGO_COLLECTION', 'entries');
env.MQTT_MONITOR = readENV('MQTT_MONITOR', null);
if (env.MQTT_MONITOR) {
var hostDbCollection = [env.mongo.split('mongodb://').pop().split('@').pop( ), env.mongo_collection].join('/');
var mongoHash = crypto.createHash('sha1');
mongoHash.update(hostDbCollection);
//some MQTT servers only allow the client id to be 23 chars
env.mqtt_client_id = mongoHash.digest('base64').substring(0, 23);
console.info('Using Mongo host/db/collection to create the default MQTT client_id', hostDbCollection);
if (env.MQTT_MONITOR.indexOf('?clientId=') == -1) {
console.info('Set MQTT client_id to: ', env.mqtt_client_id);
} else {
console.info('MQTT configured to use a custom client id, it will override the default: ', env.mqtt_client_id);
}
}
env.settings_collection = readENV('MONGO_SETTINGS_COLLECTION', 'settings');
env.treatments_collection = readENV('MONGO_TREATMENTS_COLLECTION', 'treatments');
env.profile_collection = readENV('MONGO_PROFILE_COLLECTION', 'profile');
env.devicestatus_collection = readENV('MONGO_DEVICESTATUS_COLLECTION', 'devicestatus');

env.enable = readENV('ENABLE');
env.enable = readENV('ENABLE', "");

env.defaults = { // currently supported keys must defined be here
'units': 'mg/dL'
, 'timeFormat': '12'
, 'nightMode': false
, 'showRawbg': 'never'
, 'customTitle': 'Nightscout'
, 'theme': 'default'
, 'alarmUrgentHigh': true
, 'alarmHigh': true
, 'alarmLow': true
, 'alarmUrgentLow': true
, 'alarmTimeAgoWarn': true
, 'alarmTimeAgoWarnMins': 15
, 'alarmTimeAgoUrgent': true
, 'alarmTimeAgoUrgentMins': 30
, 'language': 'en' // not used yet
} ;

// add units from separate variable
env.defaults.units = env.DISPLAY_UNITS;

// Highest priority per line defaults
env.defaults.timeFormat = readENV('TIME_FORMAT', env.defaults.timeFormat);
env.defaults.nightMode = readENV('NIGHT_MODE', env.defaults.nightMode);
env.defaults.showRawbg = readENV('SHOW_RAWBG', env.defaults.showRawbg);
env.defaults.customTitle = readENV('CUSTOM_TITLE', env.defaults.customTitle);
env.defaults.theme = readENV('THEME', env.defaults.theme);
env.defaults.alarmUrgentHigh = readENV('ALARM_URGENT_HIGH', env.defaults.alarmUrgentHigh);
env.defaults.alarmHigh = readENV('ALARM_HIGH', env.defaults.alarmHigh);
env.defaults.alarmLow = readENV('ALARM_LOW', env.defaults.alarmLow);
env.defaults.alarmUrgentLow = readENV('ALARM_URGENT_LOW', env.defaults.alarmUrgentLow);
env.defaults.alarmTimeAgoWarn = readENV('ALARM_TIMEAGO_WARN', env.defaults.alarmTimeAgoWarn);
env.defaults.alarmTimeAgoWarnMins = readENV('ALARM_TIMEAGO_WARN_MINS', env.defaults.alarmTimeAgoWarnMins);
env.defaults.alarmTimeAgoUrgent = readENV('ALARM_TIMEAGO_URGENT', env.defaults.alarmTimeAgoUrgent);
env.defaults.alarmTimeAgoUrgentMins = readENV('ALARM_TIMEAGO_URGENT_MINS', env.defaults.alarmTimeAgoUrgentMins);

//console.log(JSON.stringify(env.defaults));

env.SSL_KEY = readENV('SSL_KEY');
env.SSL_CERT = readENV('SSL_CERT');
env.SSL_CA = readENV('SSL_CA');
Expand Down Expand Up @@ -145,7 +196,10 @@ function readENV(varName, defaultValue) {
|| process.env[varName]
|| process.env[varName.toLowerCase()];

return value || defaultValue;
if (typeof value === 'string' && value.toLowerCase() == 'on') value = true;
if (typeof value === 'string' && value.toLowerCase() == 'off') value = false;

return value != null ? value : defaultValue;
}

module.exports = config;
Loading

0 comments on commit c11d4c7

Please sign in to comment.