Merge branch 'wip/onlinestatus' of https://github.com/sulkaharo/cgm-remote-monitor into wip/onlinestatus

This commit is contained in:
Jason Calabrese
2017-09-02 12:56:13 -07:00
25 changed files with 225 additions and 37 deletions
+1 -1
View File
@@ -1,7 +1,7 @@
language: node_js
sudo: required
node_js:
- 6
- 8.1.4
matrix:
fast_finish: true
services:
+1 -1
View File
@@ -45,7 +45,7 @@ test:
travis:
NODE_ENV=test ${MONGO_SETTINGS} \
${ISTANBUL} cover ${MOCHA} --report lcovonly -- --timeout 30000 -R tap ${TESTS}
${ISTANBUL} cover ${MOCHA} --report lcovonly -- --timeout 50000 -R tap ${TESTS}
docker_release:
# Get the version from the package.json file
+2
View File
@@ -113,6 +113,8 @@ Clone this repo then install dependencies into the root of the project:
$ npm install
```
If deploying the software to Microsoft Azure, you must set *WEBSITE_NODE_DEFAULT_VERSION* in the app settings to *8.1.4* or the site deployment will fail. Other hosting environments do not require this setting.
# Usage
The data being uploaded from the server to the client is from a
+19
View File
@@ -6,12 +6,22 @@ var compression = require('compression');
var bodyParser = require('body-parser');
var prettyjson = require('prettyjson');
var path = require('path');
var fs = require('fs');
function create(env, ctx) {
var app = express();
var appInfo = env.name + ' ' + env.version;
app.set('title', appInfo);
app.enable('trust proxy'); // Allows req.secure test on heroku https connections.
app.set('view engine', 'ejs');
// this allows you to render .html files as templates in addition to .ejs
app.engine('html', require('ejs').renderFile);
app.engine('appcache', require('ejs').renderFile);
app.set("views", path.join(__dirname, "views/"));
app.locals.cachebuster = fs.readFileSync(process.cwd() + '/tmp/cacheBusterToken').toString().trim();
if (ctx.bootErrors && ctx.bootErrors.length > 0) {
app.get('*', require('./lib/booterror')(ctx));
@@ -50,6 +60,15 @@ function create(env, ctx) {
}));
// app.use(bodyParser({limit: 1048576 * 50, extended: true }));
app.get("/", (req, res) => {
res.render("index.html", {locals: app.locals});
});
app.get("/nightscout.appcache", (req, res) => {
res.render("nightscout.appcache", {locals: app.locals});
});
//if (env.api_secret) {
// console.log("API_SECRET", env.api_secret);
//}
+17 -3
View File
@@ -18,6 +18,8 @@ var receiveDData = require('./receiveddata');
var client = { };
$('#loadingMessageText').html('Connecting to server');
client.hashauth = require('../hashauth').init(client, $);
client.headers = function headers ( ) {
@@ -55,16 +57,28 @@ client.init = function init(callback) {
, headers: client.headers()
}).done(function success (serverSettings) {
client.settingsFailed = false;
console.log('Application appears to be online');
$('#centerMessagePanel').hide();
client.load(serverSettings, callback);
}).fail(function fail( ) {
}).fail(function fail(jqXHR, textStatus, errorThrown) {
// check if we couldn't reach the server at all, show offline message
if (jqXHR.readyState == 0) {
console.log('Application appears to be OFFLINE');
$('#loadingMessageText').html('Connecting to Nightscout server failed, retrying every 2 seconds');
window.setTimeout(window.Nightscout.client.init(), 2000);
return;
}
//no server setting available, use defaults, auth, etc
if (client.settingsFailed) {
console.info('Already tried to get settings after auth, but failed');
console.log('Already tried to get settings after auth, but failed');
} else {
client.settingsFailed = true;
language.set('en');
client.translate = language.translate;
// auth failed, hide loader and request for key
$('#centerMessagePanel').hide();
client.hashauth.requestAuthentication(function afterRequest ( ) {
client.init(null, callback);
});
+49 -2
View File
@@ -635,11 +635,35 @@
}
}
},
"caller-callsite": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/caller-callsite/-/caller-callsite-2.0.0.tgz",
"integrity": "sha1-hH4PzgoiN1CpoCfFSzNzGtMVQTQ=",
"dev": true,
"requires": {
"callsites": "2.0.0"
}
},
"caller-path": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/caller-path/-/caller-path-2.0.0.tgz",
"integrity": "sha1-Ro+DBE42mrIBD6xfBs7uFbsssfQ=",
"dev": true,
"requires": {
"caller-callsite": "2.0.0"
}
},
"callsite": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/callsite/-/callsite-1.0.0.tgz",
"integrity": "sha1-KAOY5dZkvXQDi28JBRU+borxvCA="
},
"callsites": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/callsites/-/callsites-2.0.0.tgz",
"integrity": "sha1-BuuE8A7qQT2oav/vrL/7Ngk7PFA=",
"dev": true
},
"camelcase": {
"version": "1.2.1",
"resolved": "https://registry.npmjs.org/camelcase/-/camelcase-1.2.1.tgz",
@@ -735,6 +759,16 @@
"chalk": "1.1.3"
}
},
"clear-require": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/clear-require/-/clear-require-2.0.0.tgz",
"integrity": "sha1-qgH1w1WJMmvVXphp6r2kj4ZEfes=",
"dev": true,
"requires": {
"caller-path": "2.0.0",
"resolve-from": "2.0.0"
}
},
"cliff": {
"version": "0.1.10",
"resolved": "https://registry.npmjs.org/cliff/-/cliff-0.1.10.tgz",
@@ -1330,8 +1364,7 @@
"ejs": {
"version": "2.5.7",
"resolved": "https://registry.npmjs.org/ejs/-/ejs-2.5.7.tgz",
"integrity": "sha1-zIcsFoiArjxxiXYv1f/ACJbJUYo=",
"dev": true
"integrity": "sha1-zIcsFoiArjxxiXYv1f/ACJbJUYo="
},
"electron-to-chromium": {
"version": "1.3.18",
@@ -4523,6 +4556,15 @@
"resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.1.tgz",
"integrity": "sha1-yKuMkiO6NIiKpkopeyiFO+wY2lY="
},
"path": {
"version": "0.12.7",
"resolved": "https://registry.npmjs.org/path/-/path-0.12.7.tgz",
"integrity": "sha1-1NwqUGxM4hl+tIHr/NWzbAFAsQ8=",
"requires": {
"process": "0.11.10",
"util": "0.10.3"
}
},
"path-browserify": {
"version": "0.0.0",
"resolved": "https://registry.npmjs.org/path-browserify/-/path-browserify-0.0.0.tgz",
@@ -5263,6 +5305,11 @@
"resolved": "https://registry.npmjs.org/querystring-es3/-/querystring-es3-0.2.1.tgz",
"integrity": "sha1-nsYfeQSYdXB9aUFFlv2Qek1xHnM="
},
"random-token": {
"version": "0.0.8",
"resolved": "https://registry.npmjs.org/random-token/-/random-token-0.0.8.tgz",
"integrity": "sha1-HPhFrz+zHlf3yqS5oXNHjEZIO2E="
},
"randomatic": {
"version": "1.1.7",
"resolved": "https://registry.npmjs.org/randomatic/-/randomatic-1.1.7.tgz",
+7 -2
View File
@@ -27,9 +27,10 @@
"start": "node server.js",
"test": "make test",
"env": "env",
"postinstall": "webpack --config webpack.config.js",
"postinstall": "webpack --config webpack.config.js && npm run-script update-buster",
"bundle": "webpack --config webpack.config.js",
"bower": "node node_modules/bower/bin/bower --allow-root install && "
"bower": "node node_modules/bower/bin/bower --allow-root install && ",
"update-buster": "node scripts/generateCacheBuster.js >tmp/cacheBusterToken"
},
"config": {
"blanket": {
@@ -56,6 +57,7 @@
"css-loader": "^0.28.4",
"cssmin": "^0.4.3",
"d3": "^3.5.17",
"ejs": "^2.5.7",
"errorhandler": "^1.5.0",
"event-stream": "^3.3.4",
"expand-braces": "^0.1.2",
@@ -84,8 +86,10 @@
"mqtt": "^0.3.13",
"node-cache": "^4.1.1",
"parse-duration": "^0.1.1",
"path": "^0.12.7",
"prettyjson": "^1.2.1",
"pushover-notifications": "^0.2.4",
"random-token": "0.0.8",
"request": "^2.81.0",
"sgvdata": "git://github.com/ktind/sgvdata.git#wip/protobuf",
"share2nightscout-bridge": "git://github.com/bewest/share2nightscout-bridge.git#wip/generalize",
@@ -101,6 +105,7 @@
},
"devDependencies": {
"benv": "3.3.0",
"clear-require": "^2.0.0",
"istanbul": "~0.4.5",
"mocha": "~3.1.2",
"should": "~11.1.1",
+4
View File
@@ -0,0 +1,4 @@
var randomToken = require('random-token');
var token = randomToken(16);
console.log(token);
+2 -2
View File
@@ -45,8 +45,8 @@
<b><span class="translate">Authentication status</span>: </b>
<span id="authentication_placeholder"></span>
<script src="/js/bundle.js?v=0.10.0-dev-20170821"></script>
<script src="/js/bundle.js?v=8.1.4-dev-2017082601"></script>
<script src="/socket.io/socket.io.js"></script>
<script src="/admin/js/admin.js?v=0.10.0-dev-20170821"></script>
<script src="/admin/js/admin.js?v=8.1.4-dev-2017082601"></script>
</body>
</html>
+1 -1
View File
@@ -41,7 +41,7 @@
<h1 class="clock"></h1>
</div>
<script src="/api/v1/status.js"></script>
<script src="/js/bundle.js?v=0.10.0-dev-20170821"></script>
<script src="/js/bundle.js?v=8.1.4-dev-2017082601"></script>
<script type="text/javascript">
function query ( ) {
console.log('query');
+1 -1
View File
@@ -86,7 +86,7 @@
</main>
<script src="/api/v1/status.js"></script>
<script src="/js/bundle.js?v=0.10.0-dev-20170821"></script>
<script src="/js/bundle.js?v=8.1.4-dev-2017082601"></script>
<script type="text/javascript">
+1 -1
View File
@@ -45,7 +45,7 @@
</div>
</main>
<script src="/api/v1/status.js"></script>
<script src="/js/bundle.js?v=0.10.0-dev-20170821"></script>
<script src="/js/bundle.js?v=8.1.4-dev-2017082601"></script>
<script type="text/javascript">
function query ( ) {
console.log('query');
+2 -2
View File
@@ -110,8 +110,8 @@
<span id="authentication_placeholder"></span>
</div>
<script src="/js/bundle.js?v=0.10.0-dev-20170821"></script>
<script src="/js/bundle.js?v=8.1.4-dev-2017082601"></script>
<script src="/socket.io/socket.io.js"></script>
<script src="/food/js/food.js?v=0.10.0-dev-20170821"></script>
<script src="/food/js/food.js?v=8.1.4-dev-2017082601"></script>
</body>
</html>
Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.2 KiB

After

Width:  |  Height:  |  Size: 3.0 KiB

+9 -1
View File
@@ -1,3 +1,11 @@
'use strict';
window.Nightscout.client.init();
$(document).on('online', function() {
console.log('Application got online event, reloading');
window.location.reload();
});
$(document).ready(function() {
console.log('Application got ready event');
window.Nightscout.client.init();
});
+2 -2
View File
@@ -173,8 +173,8 @@
</form>
<script src="/api/v1/status.js"></script>
<script src="/js/bundle.js?v=0.10.0-dev-20170821"></script>
<script src="/js/bundle.js?v=8.1.4-dev-2017082601"></script>
<script src="/socket.io/socket.io.js"></script>
<script src="/profile/js/profileeditor.js?v=0.10.0-dev-20170821"></script>
<script src="/profile/js/profileeditor.js?v=8.1.4-dev-2017082601"></script>
</body>
</html>
+4 -4
View File
@@ -23,7 +23,7 @@
<meta name="msapplication-config" content="/browserconfig.xml">
<meta name="theme-color" content="#333333">
<link rel="stylesheet" type="text/css" href="/css/report.css?v=0.10.0-dev-20170821" />
<link rel="stylesheet" type="text/css" href="/css/report.css?v=8.1.4-dev-2017082601" />
<link rel="stylesheet" type="text/css" href="/css/ui-lightness/jquery-ui.min.css">
</head>
@@ -117,9 +117,9 @@
<hr>
<b><span class="translate">Authentication status</span>: </b><span id="authentication_placeholder"></span>
<script src="/js/bundle.js?v=0.10.0-dev-20170821"></script>
<script src="/js/bundle.js?v=8.1.4-dev-2017082601"></script>
<script src="/socket.io/socket.io.js"></script>
<script src="/report/js/report.js?v=0.10.0-dev-20170821"></script>
<script src="/report/js/flotcandle.js?v=0.10.0-dev-20170821"></script>
<script src="/report/js/report.js?v=8.1.4-dev-2017082601"></script>
<script src="/report/js/flotcandle.js?v=8.1.4-dev-2017082601"></script>
</body>
</html>
+1 -1
View File
@@ -33,7 +33,7 @@
<hr>
<b><span class="translate">Authentication status</span>: </b><span id="authentication_placeholder"></span>
<script src="/js/bundle.js?v=0.10.0-dev-20170821"></script>
<script src="/js/bundle.js?v=8.1.4-dev-2017082601"></script>
<script src="/api/v1/status.js"></script>
<script src="/socket.io/socket.io.js"></script>
+1 -1
View File
@@ -57,7 +57,7 @@ var someData = {
describe('admintools', function ( ) {
var self = this;
this.timeout(10000);
this.timeout(50000);
before(function (done) {
benv.setup(function() {
+3
View File
@@ -147,6 +147,9 @@ describe('ar2', function ( ) {
});
it('should handle alexa requests', function (done) {
var now = Date.now();
var before = now - FIVE_MINS;
ctx.ddata.sgvs = [{mgdl: 100, mills: before}, {mgdl: 105, mills: now}];
var sbx = prepareSandbox();
+1 -1
View File
@@ -10,7 +10,7 @@ function headless (benv, binding) {
function init (opts, callback) {
var localStorage = opts.localStorage || './localstorage';
var htmlFile = opts.htmlFile || __dirname + '/../../static/index.html';
var htmlFile = opts.htmlFile || __dirname + '/../../views/index.html';
var serverSettings = opts.serverSettings || require('./default-server-settings');
var someData = opts.mockAjax || { };
benv.setup(function() {
+5
View File
@@ -63,6 +63,7 @@ describe('hashauth', function ( ) {
*/
it ('should make module unauthorized', function () {
this.timeout(50000);
var client = require('../lib/client');
var hashauth = require('../lib/hashauth');
@@ -81,6 +82,7 @@ describe('hashauth', function ( ) {
});
it ('should make module authorized', function () {
this.timeout(50000);
var client = require('../lib/client');
var hashauth = require('../lib/hashauth');
@@ -97,6 +99,9 @@ describe('hashauth', function ( ) {
});
it ('should store hash and the remove authentication', function () {
this.timeout(50000);
var client = require('../lib/client');
var hashauth = require('../lib/hashauth');
var localStorage = require('./fixtures/localstorage');
+1 -1
View File
@@ -71,7 +71,7 @@ var someData = {
describe('Profile editor', function ( ) {
this.timeout(10000);
this.timeout(30000);
var headless = require('./fixtures/headless')(benv, this);
before(function (done) {
+86 -5
View File
@@ -27,11 +27,92 @@
<meta name="msapplication-TileImage" content="/images/mstile-144x144.png">
<meta name="msapplication-config" content="/browserconfig.xml">
<meta name="theme-color" content="#333333">
<link rel="stylesheet" type="text/css" href="/css/main.css?v=0.10.0-dev-20170821" />
<link rel="stylesheet" type="text/css" href="/css/ui-darkness/jquery-ui.min.css">
<link rel="stylesheet" type="text/css" href="/css/main.css?v=<%= locals.cachebuster %>" media="none" onload="if(media!='all')media='all'" />
<link rel="stylesheet" type="text/css" href="/css/ui-darkness/jquery-ui.min.css" media="none" onload="if(media!='all')media='all'">
<style media="screen" type="text/css">
#centerMessagePanel
{
position:fixed;
top:0;
left:0;
bottom:0;
right:0;
height: 100%;
width: 100%;
margin: 0;
padding: 0;
background: #000000;
z-index: 1000;
}
#loadingMessage {
text-align: center;
position: absolute;
width: 100%;
height: 90%;
top: 30%;
left: 0%;
font-size: 16px;
}
.spinner {
margin: 100px auto 0;
width: 70px;
text-align: center;
}
.spinner > div {
width: 18px;
height: 18px;
background-color: #333;
border-radius: 100%;
display: inline-block;
-webkit-animation: sk-bouncedelay 1.4s infinite ease-in-out both;
animation: sk-bouncedelay 1.4s infinite ease-in-out both;
}
.spinner .bounce1 {
-webkit-animation-delay: -0.32s;
animation-delay: -0.32s;
}
.spinner .bounce2 {
-webkit-animation-delay: -0.16s;
animation-delay: -0.16s;
}
@-webkit-keyframes sk-bouncedelay {
0%, 80%, 100% { -webkit-transform: scale(0) }
40% { -webkit-transform: scale(1.0) }
}
@keyframes sk-bouncedelay {
0%, 80%, 100% {
-webkit-transform: scale(0);
transform: scale(0);
} 40% {
-webkit-transform: scale(1.0);
transform: scale(1.0);
}
}
</style>
</head>
<body>
<div id="centerMessagePanel">
<div id="loadingMessage">
<p><img src="/images/launch.png"></p>
<p id="loadingMessageText">Loading the client</p>
<div class="spinner">
<div class="bounce1"></div>
<div class="bounce2"></div>
<div class="bounce3"></div>
</div>
</div>
</div>
<div class="container loading" id="container">
<div id="toolbar">
<div id="buttonbar" role="navigation" aria-label="Menu" >
@@ -589,8 +670,8 @@
<audio src="/audio/alarm2.mp3" preload="auto" loop="true" class="urgent alarm2 mp3" type="audio/mp3"></audio>
</div>
<script src="/js/bundle.js?v=0.10.0-dev-20170821"></script>
<script src="/socket.io/socket.io.js?v=0.10.0-dev-20170821"></script>
<script src="/js/client.js?v=0.10.0-dev-20170821"></script>
<script src="/js/bundle.js?v=<%= locals.cachebuster %>"></script>
<script src="/socket.io/socket.io.js?v=<%= locals.cachebuster %>"></script>
<script src="/js/client.js?v=<%= locals.cachebuster %>"></script>
</body>
</html>
@@ -24,11 +24,11 @@ CACHE MANIFEST
/css/ui-darkness/images/ui-icons_cccccc_256x240.png
/css/ui-darkness/images/ui-bg_inset-soft_25_000000_1x100.png
/css/ui-darkness/images/ui-bg_gloss-wave_25_333333_500x100.png
/css/main.css?v=0.10.0-dev-20170821
/js/bundle.js?v=0.10.0-dev-20170821
/socket.io/socket.io.js?v=0.10.0-dev-20170821
/js/client.js?v=0.10.0-dev-20170821
/css/main.css?v=<%= locals.cachebuster %>
/js/bundle.js?v=<%= locals.cachebuster %>
/socket.io/socket.io.js?v=<%= locals.cachebuster %>
/js/client.js?v=<%= locals.cachebuster %>
/images/logo2.png
NETWORK:
*
*