Skip to content

Commit

Permalink
Merge pull request #2247 from nightscout/dev
Browse files Browse the repository at this point in the history
0.9.1 (Grilled Cheese)
  • Loading branch information
jasoncalabrese authored Nov 25, 2016
2 parents a00c5dc + beacd91 commit d407bab
Show file tree
Hide file tree
Showing 109 changed files with 5,758 additions and 1,277 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ Community maintained fork of the
- [`pump` (Pump Monitoring)](#pump-pump-monitoring)
- [`openaps` (OpenAPS)](#openaps-openaps)
- [`loop` (Loop)](#loop-loop)
- [`alexa` (Amazon Alexa)](#alexa-amazon-alexa)
- [`cors` (CORS)](#cors-cors)
- [Extended Settings](#extended-settings)
- [Pushover](#pushover)
- [IFTTT Maker](#ifttt-maker)
Expand Down Expand Up @@ -151,6 +153,7 @@ You can get many more results, by using the `count`, `date`, `dateString`, and `
(replace `http://localhost:1337` with your base url, YOUR-SITE)

* 100's: `http://localhost:1337/api/v1/entries.json?find[sgv]=100`
* Count of 100's in a month: `http://localhost:1337/api/v1/count/entries/where?find[dateString][$gte]=2016-09&find[dateString][$lte]=2016-10&find[sgv]=100`
* BGs between 2 days: `http://localhost:1337/api/v1/entries/sgv.json?find[dateString][$gte]=2015-08-28&find[dateString][$lte]=2015-08-30`
* Juice Box corrections in a year: `http://localhost:1337/api/v1/treatments.json?count=1000&find[carbs]=15&find[eventType]=Carb+Correction&find[created_at][$gte]=2015`
* Boluses over 2U: `http://localhost:1337/api/v1/treatments.json?find[insulin][$gte]=2`
Expand All @@ -177,6 +180,7 @@ To learn more about the Nightscout API, visit https://YOUR-SITE.com/api-docs.htm
* `AUTH_DEFAULT_ROLES` (`readable`) - possible values `readable`, `denied`, or any valid role
name. When `readable`, anyone can view Nightscout without a token.
Setting it to `denied` will require a token from every visit, using `status-only` will enable api-secret based login.
* `IMPORT_CONFIG` - Used to import settings and extended settings from a url such as a gist. Structure of file should be something like: `{"settings": {"theme": "colors"}, "extendedSettings": {"upbat": {"enableAlerts": true}}}`
* `TREATMENTS_AUTH` (`on`) - possible values `on` or `off`. Deprecated, if set to `off` the `careportal` role will be added to `AUTH_DEFAULT_ROLES`


Expand Down
30 changes: 25 additions & 5 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
'use strict';

var _ = require('lodash');
var express = require('express');
var compression = require('compression');
var bodyParser = require('body-parser');

function create (env, ctx) {
///////////////////////////////////////////////////
// api and json object variables
///////////////////////////////////////////////////
var api = require('./lib/api/')(env, ctx);

var app = express();
var appInfo = env.name + ' ' + env.version;
app.set('title', appInfo);
Expand All @@ -20,6 +16,29 @@ function create (env, ctx) {
return app;
}

if (env.settings.isEnabled('cors')) {
var allowOrigin = _.get(env, 'extendedSettings.cors.allowOrigin') || '*';
console.info('Enabled CORS, allow-origin:', allowOrigin);
app.use(function allowCrossDomain (req, res, next) {
res.header('Access-Control-Allow-Origin', allowOrigin);
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS');
res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization, Content-Length, X-Requested-With');

// intercept OPTIONS method
if ('OPTIONS' === req.method) {
res.send(200);
} else {
next();
}
});
}

///////////////////////////////////////////////////
// api and json object variables
///////////////////////////////////////////////////
var api = require('./lib/api/')(env, ctx);
var ddata = require('./lib/data/endpoints')(env, ctx);

app.use(compression({filter: 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
Expand All @@ -34,6 +53,7 @@ function create (env, ctx) {

app.use('/api/v2/properties', ctx.properties);
app.use('/api/v2/authorization', ctx.authorization.endpoints);
app.use('/api/v2/ddata', ddata);

// pebble data
app.get('/pebble', ctx.pebble);
Expand Down
13 changes: 11 additions & 2 deletions azuredeploy.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@
"mongoConnection": {
"type": "string"
},
"mongoCollection": {
"type": "string",
"defaultValue": "entries"
},
"displayUnits": {
"type": "string",
"allowedValues": [
Expand Down Expand Up @@ -77,6 +81,7 @@
"cs",
"dk",
"de",
"el",
"en",
"es",
"fr",
Expand Down Expand Up @@ -235,7 +240,11 @@
"appSettings": [{
"name": "MONGO_CONNECTION",
"value": "[parameters('mongoConnection')]"
}, {
},
{
"name": "MONGO_COLLECTION",
"value": "[parameters('mongoCollection')]"
}, {
"name": "DISPLAY_UNITS",
"value": "[parameters('displayUnits')]"
}, {
Expand Down Expand Up @@ -313,4 +322,4 @@
}
}]
}]
}
}
5 changes: 3 additions & 2 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
{
"name": "nightscout",
"version": "0.9.0",
"version": "0.9.1",
"dependencies": {
"colorbrewer": "~1.0.0",
"jQuery-Storage-API": "~1.7.2",
"jquery": "2.1.0",
"jquery-flot": "0.8.3",
"jquery-ui": "~1.11.3",
"swagger-ui": "~2.1.2",
"tipsy-jmalonzo": "~1.0.1"
"tipsy-jmalonzo": "~1.0.1",
"tone": "*"
},
"resolutions": {
"jquery": "2.1.0"
Expand Down
1 change: 0 additions & 1 deletion bundle/bundle.source.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
window.Nightscout = {
client: require('../lib/client')
, units: require('../lib/units')()
, plugins: require('../lib/plugins/')().registerClientDefaults()
, report_plugins: require('../lib/report_plugins/')()
, admin_plugins: require('../lib/admin_plugins/')()
};
Expand Down
4 changes: 2 additions & 2 deletions bundle/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ function bundle() {
watch: __dirname + '/../lib/',
mount: '/public/js/bundle.js',
verbose: true,
//minify: true,
minify: true,
bundle_opts: { debug: true }, // enable inline sourcemap on js files
write_file: __dirname + '/bundle.out.js'
});
}

module.exports = bundle;
module.exports = bundle;
19 changes: 10 additions & 9 deletions env.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ function config ( ) {
env.DISPLAY_UNITS = readENV('DISPLAY_UNITS', 'mg/dl');
env.PORT = readENV('PORT', 1337);
env.HOSTNAME = readENV('HOSTNAME', null);
env.IMPORT_CONFIG = readENV('IMPORT_CONFIG', null);
env.static_files = readENV('NIGHTSCOUT_STATIC_FILES', __dirname + '/static/');

if (env.err) {
Expand All @@ -27,7 +28,7 @@ function config ( ) {
setSSL();
setAPISecret();
setVersion();
setMongo();
setStorage();
updateSettings();

return env;
Expand Down Expand Up @@ -90,12 +91,12 @@ function setVersion() {
env.name = software.name;
}

function setMongo() {
env.mongo = readENV('MONGO_CONNECTION') || readENV('MONGO') || readENV('MONGOLAB_URI') || readENV('MONGODB_URI');
env.mongo_collection = readENV('MONGO_COLLECTION', 'entries');
function setStorage() {
env.storageURI = readENV('STORAGE_URI') || readENV('MONGO_CONNECTION') || readENV('MONGO') || readENV('MONGOLAB_URI') || readENV('MONGODB_URI');
env.entries_collection = readENV('ENTRIES_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 hostDbCollection = [env.storageURI.split('mongodb://').pop().split('@').pop(), env.entries_collection].join('/');
var mongoHash = crypto.createHash('sha1');
mongoHash.update(hostDbCollection);
//some MQTT servers only allow the client id to be 23 chars
Expand All @@ -117,10 +118,10 @@ function setMongo() {
// Some people prefer to use a json configuration file instead.
// This allows a provided json config to override environment variables
var DB = require('./database_configuration.json'),
DB_URL = DB.url ? DB.url : env.mongo,
DB_COLLECTION = DB.collection ? DB.collection : env.mongo_collection;
env.mongo = DB_URL;
env.mongo_collection = DB_COLLECTION;
DB_URL = DB.url ? DB.url : env.storageURI,
DB_COLLECTION = DB.collection ? DB.collection : env.entries_collection;
env.storageURI = DB_URL;
env.entries_collection = DB_COLLECTION;
}

function updateSettings() {
Expand Down
10 changes: 5 additions & 5 deletions lib/admin_plugins/roles.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ function createOrSaveRole (role, client, callback) {
}).done(function success() {
reload(client, callback);
}).fail(function fail(err) {
console.error('Unable to ' + method + ' Subject', err.responseText);
window.alert(client.translate('Unable to ' + method + ' Subject'));
console.error('Unable to ' + method + ' Role', err.responseText);
window.alert(client.translate('Unable to %1 Role', { params: [method] }));
if (callback) {
callback(err);
}
Expand All @@ -59,8 +59,8 @@ function deleteRole (role, client, callback) {
}).done(function success() {
reload(client, callback);
}).fail(function fail(err) {
console.error('Unable to delete Subject', err.responseText);
window.alert(client.translate('Unable to delete Subject'));
console.error('Unable to delete Role', err.responseText);
window.alert(client.translate('Unable to delete Role'));
if (callback) {
callback(err);
}
Expand Down Expand Up @@ -150,7 +150,7 @@ function openDialog (role, client) {
}

function showRole (role, table, client) {
var editIcon = $('<img title="Edit this role" class="titletranslate" style="cursor:pointer" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAABEUlEQVQ4jZ3MMUsCYQDG8ee8IySQbNCLyyEKG/RLNAXicqvQcAeNLrcFLlE0+xHuNpt8wy04rrYm8Q4HQRE56BSC3lSqU1BwCoxM39dnffj9BWyxXvVeEzvtctBwHyRebNu2Nk2lzMlrgJB+qBEeTByiKYpihl+fIO8jTI9PDJEVF1+K2iw+M6PhDuyag4NkQi/c3FkCK5Z3ZbM76qLltpCbn+vXxq0FABsDy9hzPdBvqvtXvvXzrw1swmsDLPjfACteGeDBfwK8+FdgGwwAIgC0ncsjxGRSH/eiPBgAJADY2z8sJ4JBfNBsDqlADVYMANIzKalv/bHaefKsTH9iPFb8ISsGAJym0+Qinz3jQktbAHcxvx3559eSAAAAAElFTkSuQmCC">');
var editIcon = $('<img title="' + client.translate('Edit this role') + '" style="cursor:pointer" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAABEUlEQVQ4jZ3MMUsCYQDG8ee8IySQbNCLyyEKG/RLNAXicqvQcAeNLrcFLlE0+xHuNpt8wy04rrYm8Q4HQRE56BSC3lSqU1BwCoxM39dnffj9BWyxXvVeEzvtctBwHyRebNu2Nk2lzMlrgJB+qBEeTByiKYpihl+fIO8jTI9PDJEVF1+K2iw+M6PhDuyag4NkQi/c3FkCK5Z3ZbM76qLltpCbn+vXxq0FABsDy9hzPdBvqvtXvvXzrw1swmsDLPjfACteGeDBfwK8+FdgGwwAIgC0ncsjxGRSH/eiPBgAJADY2z8sJ4JBfNBsDqlADVYMANIzKalv/bHaefKsTH9iPFb8ISsGAJym0+Qinz3jQktbAHcxvx3559eSAAAAAElFTkSuQmCC">');
editIcon.click(function clicked ( ) {
openDialog(role, client);
});
Expand Down
4 changes: 2 additions & 2 deletions lib/admin_plugins/subjects.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,11 @@ function openDialog (subject, client) {
}

function showSubject (subject, table, client) {
var editIcon = $('<img title="Edit this subject" class="titletranslate" style="cursor:pointer" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAABEUlEQVQ4jZ3MMUsCYQDG8ee8IySQbNCLyyEKG/RLNAXicqvQcAeNLrcFLlE0+xHuNpt8wy04rrYm8Q4HQRE56BSC3lSqU1BwCoxM39dnffj9BWyxXvVeEzvtctBwHyRebNu2Nk2lzMlrgJB+qBEeTByiKYpihl+fIO8jTI9PDJEVF1+K2iw+M6PhDuyag4NkQi/c3FkCK5Z3ZbM76qLltpCbn+vXxq0FABsDy9hzPdBvqvtXvvXzrw1swmsDLPjfACteGeDBfwK8+FdgGwwAIgC0ncsjxGRSH/eiPBgAJADY2z8sJ4JBfNBsDqlADVYMANIzKalv/bHaefKsTH9iPFb8ISsGAJym0+Qinz3jQktbAHcxvx3559eSAAAAAElFTkSuQmCC">');
var editIcon = $('<img title="' + client.translate('Edit this subject') + '" style="cursor:pointer" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAABEUlEQVQ4jZ3MMUsCYQDG8ee8IySQbNCLyyEKG/RLNAXicqvQcAeNLrcFLlE0+xHuNpt8wy04rrYm8Q4HQRE56BSC3lSqU1BwCoxM39dnffj9BWyxXvVeEzvtctBwHyRebNu2Nk2lzMlrgJB+qBEeTByiKYpihl+fIO8jTI9PDJEVF1+K2iw+M6PhDuyag4NkQi/c3FkCK5Z3ZbM76qLltpCbn+vXxq0FABsDy9hzPdBvqvtXvvXzrw1swmsDLPjfACteGeDBfwK8+FdgGwwAIgC0ncsjxGRSH/eiPBgAJADY2z8sJ4JBfNBsDqlADVYMANIzKalv/bHaefKsTH9iPFb8ISsGAJym0+Qinz3jQktbAHcxvx3559eSAAAAAElFTkSuQmCC">');
editIcon.click(function clicked ( ) {
openDialog(subject, client);
});
var deleteIcon = $('<img title="Delete this subject" class="titletranslate" style="cursor:pointer" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAACrElEQVQ4T42Ty2sTQRzHv5tmk2yyjRNtpfZhL8V6s2KoUNC2XqwgaCsVQcGiFqpHi0c9iRdR/ANE9KR40FIQX4cueKoPaKFoLdSYNtE0abKT1+5s9iW7aUMiHtzTzO7v85md+c6PA4DrHbsPCKIgOWO1pA7dT6YXnXH949SE/F63pqwZtRrO+SCKgjQ5NUV+azpmHj2krMwaJC4c8Erj+/eRyloMMwWFKgbn1nC3ervlK1evkXBLGBZT8SOewotnTylTNLdgeg/pDgZDC2cPHSR8bB22DVC9hFe0SG/H0xFXcHlykjRHRDBWgJcZSCY38Xx2lhqMnRYE34Px/sN9vlQWeoHBAx2yXsRruVAVuFsIBaSJ8+eJGPaBqQV4NROJjTzez89jLBoFn6FgybQL54wS3uTyVDFQ3cL2IYpBv3RhdJSIIQ80tQyv7gEqJvS8AmUlBs7UXPhtjtZgh3UFNYngk86NHCfNAg9dMwHVBPu+CpsVkTXKeJeVG+AGgTOZ3tt6MSKKjy+NjEBjFrR4ElZmA4pdxstMFsyyJu6tZZ7Ux9vwB6EAL50ZGiRECEPPUOixVTRxHlicgSVWxEdZpuZWfNuS2hk48NjwMIkIYZglBnV5Cbqtws/5IaAJmsfCglrEl2y2QeKmEBJ80tixKmxrFpSVr0gV0viQoxho2YUuPohmeFD22PiklLC4ma5JuBvdrfLJI0dJd0s7bM0ES8aR/BXDXGaTskqlL+D3Lwy0tZEePoAd4EA5YF4tYymdonfjmQh3s6dTPjU4SHYGwjAKecSXFyGlM1TdytntE56T+ts7SC/vhw3gm6njc2Kd3vm5Ub1IwQAvnYhGiZpYw1wiWYPrIw7wnBTt7CLOOwdmut14kQQvqt24tfK/utGR6LaF+iRqMf4N/O/8D28HiiCRYqzAAAAAAElFTkSuQmCC">');
var deleteIcon = $('<img title="' + client.translate('Delete this subject') + '" style="cursor:pointer" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAACrElEQVQ4T42Ty2sTQRzHv5tmk2yyjRNtpfZhL8V6s2KoUNC2XqwgaCsVQcGiFqpHi0c9iRdR/ANE9KR40FIQX4cueKoPaKFoLdSYNtE0abKT1+5s9iW7aUMiHtzTzO7v85md+c6PA4DrHbsPCKIgOWO1pA7dT6YXnXH949SE/F63pqwZtRrO+SCKgjQ5NUV+azpmHj2krMwaJC4c8Erj+/eRyloMMwWFKgbn1nC3ervlK1evkXBLGBZT8SOewotnTylTNLdgeg/pDgZDC2cPHSR8bB22DVC9hFe0SG/H0xFXcHlykjRHRDBWgJcZSCY38Xx2lhqMnRYE34Px/sN9vlQWeoHBAx2yXsRruVAVuFsIBaSJ8+eJGPaBqQV4NROJjTzez89jLBoFn6FgybQL54wS3uTyVDFQ3cL2IYpBv3RhdJSIIQ80tQyv7gEqJvS8AmUlBs7UXPhtjtZgh3UFNYngk86NHCfNAg9dMwHVBPu+CpsVkTXKeJeVG+AGgTOZ3tt6MSKKjy+NjEBjFrR4ElZmA4pdxstMFsyyJu6tZZ7Ux9vwB6EAL50ZGiRECEPPUOixVTRxHlicgSVWxEdZpuZWfNuS2hk48NjwMIkIYZglBnV5Cbqtws/5IaAJmsfCglrEl2y2QeKmEBJ80tixKmxrFpSVr0gV0viQoxho2YUuPohmeFD22PiklLC4ma5JuBvdrfLJI0dJd0s7bM0ES8aR/BXDXGaTskqlL+D3Lwy0tZEePoAd4EA5YF4tYymdonfjmQh3s6dTPjU4SHYGwjAKecSXFyGlM1TdytntE56T+ts7SC/vhw3gm6njc2Kd3vm5Ub1IwQAvnYhGiZpYw1wiWYPrIw7wnBTt7CLOOwdmut14kQQvqt24tfK/utGR6LaF+iRqMf4N/O/8D28HiiCRYqzAAAAAAElFTkSuQmCC">');
deleteIcon.click(function clicked ( ) {
var ok = window.confirm(client.translate('Are you sure you want to delete: ') + subject.name);
if (ok) {
Expand Down
32 changes: 32 additions & 0 deletions lib/aggregate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
var find_options = require('./query');

function create (conf, api) {

var template = function ( ) {
return [
{
$group: {
_id: null
, count: { $sum: 1 }
}
}
];
};

// var collection = api( );
function aggregate (opts, done) {
var query = find_options(opts);

var pipeline = (conf.pipeline || [ ]).concat(opts.pipeline || [ ]);
var groupBy = [ {$match: query } ].concat(pipeline).concat(template( ));
console.log('$match query', query);
console.log('AGGREGATE', groupBy);
api( ).aggregate(groupBy, done);
}

return aggregate;

}

module.exports = create;

Loading

0 comments on commit d407bab

Please sign in to comment.