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

Variability reporting, Webpack bundling #2736

Merged
merged 23 commits into from
Aug 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
e322005
Data cleaning pass 1
sulkaharo Aug 10, 2017
6c940a5
* Glucose data smoothing / patching before calculating variability to…
sulkaharo Aug 11, 2017
dbe2927
Run packaging in post install instead of runtime
sulkaharo Aug 15, 2017
7564420
CSS bundling
sulkaharo Aug 15, 2017
abb4db2
Fix templates that linked to old bundle.js location
sulkaharo Aug 15, 2017
7df05f0
Removing Bower part 1
sulkaharo Aug 15, 2017
297064d
Flot plugins
sulkaharo Aug 15, 2017
5c68964
jQuery packaging has changed, adding these to the repo
sulkaharo Aug 15, 2017
dda4277
Generate source map, use a small font subset instead of loading compl…
sulkaharo Aug 16, 2017
9e055ad
Added missing icons, changed how jQuery and jQuery-UI is packaged
sulkaharo Aug 16, 2017
76988d6
Bower is gone
sulkaharo Aug 16, 2017
76ef41e
Remove Crossfilter (needed by /reports/compare, which is not supporte…
sulkaharo Aug 16, 2017
0e9977f
Oops forgot package-lock.json
sulkaharo Aug 16, 2017
1dcd4fd
Revert back to using Open Sans, but embedded
sulkaharo Aug 16, 2017
936d631
Re-enabled Ubuntu to fix the layouts. Icon font embedded.
sulkaharo Aug 18, 2017
99b1c16
Update cache busters
sulkaharo Aug 18, 2017
49378c0
Added variability measure explanations to reporting
sulkaharo Aug 18, 2017
340e76b
Finnish localization
sulkaharo Aug 18, 2017
89cee93
Fix battery icon, some tests
sulkaharo Aug 21, 2017
89a6b81
Added app cache manifest to speed things further
sulkaharo Aug 22, 2017
f451503
Launch PNG was missing
sulkaharo Aug 22, 2017
918ecc2
Return 404 on app cache request when in development mode, added bold …
sulkaharo Aug 23, 2017
530df90
Formatting improvements to app.js
sulkaharo Aug 23, 2017
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: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@ coverage/

npm-debug.log
*.heapsnapshot

/tmp
228 changes: 148 additions & 80 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,95 +4,163 @@ var _ = require('lodash');
var express = require('express');
var compression = require('compression');
var bodyParser = require('body-parser');
var prettyjson = require('prettyjson');


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.

if (ctx.bootErrors && ctx.bootErrors.length > 0) {
app.get('*', require('./lib/booterror')(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
return compression.filter(req, res);
}
}));
// app.use(bodyParser({limit: 1048576 * 50, extended: true }));

//if (env.api_secret) {
// console.log("API_SECRET", env.api_secret);
//}
app.use('/api/v1', bodyParser({
limit: 1048576 * 50
}), api);

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);

// expose swagger.yaml
app.get('/swagger.yaml', function(req, res) {
res.sendFile(__dirname + '/swagger.yaml');
});

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.
if (env.settings.isEnabled('dumps')) {
var heapdump = require('heapdump');
app.get('/api/v2/dumps/start', function(req, res) {
var path = new Date().toISOString() + '.heapsnapshot';
path = path.replace(/:/g, '-');
console.info('writing dump to', path);
heapdump.writeSnapshot(path);
res.send('wrote dump to ' + path);
});
}

if (ctx.bootErrors && ctx.bootErrors.length > 0) {
app.get('*', require('./lib/booterror')(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();
}

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

// Allow static resources to be cached for week
var maxAge = 7 * 24 * 60 * 60 * 1000;

if (process.env.NODE_ENV === 'development') {
maxAge = 10;
console.log('Development environment detected, setting static file cache age to 10 seconds');

app.get('/nightscout.appcache', function(req, res) {
res.sendStatus(404);
});
}

//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: maxAge
});
}

///////////////////////////////////////////////////
// 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
return compression.filter(req, res);
}}));
// app.use(bodyParser({limit: 1048576 * 50, extended: true }));

//if (env.api_secret) {
// console.log("API_SECRET", env.api_secret);
//}
app.use('/api/v1', bodyParser({limit: 1048576 * 50 }), api);

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);

// expose swagger.yaml
app.get('/swagger.yaml', function (req, res) {
res.sendFile(__dirname + '/swagger.yaml');
});

if (env.settings.isEnabled('dumps')) {
var heapdump = require('heapdump');
app.get('/api/v2/dumps/start', function (req, res) {
var path = new Date().toISOString() + '.heapsnapshot';
path = path.replace(/:/g, '-');
console.info('writing dump to', path);
heapdump.writeSnapshot(path);
res.send('wrote dump to ' + path);

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

var tmpFiles = express.static('tmp', {
maxAge: maxAge
});
}

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

if (process.env.NODE_ENV !== 'development') {

//app.get('/package.json', software);
console.log('Production environment detected, enabling Minify');

// 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});
var minify = require('express-minify');
var myUglifyJS = require('uglify-js');
var myCssmin = require('cssmin');

// serve the static content
app.use(staticFiles);
app.use(minify({
js_match: /\.js/,
css_match: /\.css/,
sass_match: /scss/,
less_match: /less/,
stylus_match: /stylus/,
coffee_match: /coffeescript/,
json_match: /json/,
uglifyJS: myUglifyJS,
cssmin: myCssmin,
cache: __dirname + '/cache',
onerror: undefined,
}));

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

// Handle errors with express's errorhandler, to display more readable error messages.
var errorhandler = require('errorhandler');
//if (process.env.NODE_ENV === 'development') {
// if this is dev environment, package scripts on the fly
// if production, rely on postinstall script to run packaging for us

if (process.env.NODE_ENV === 'development') {

var webpack = require("webpack");
var webpack_conf = require('./webpack.config');

webpack(webpack_conf, function(err, stats) {

var json = stats.toJson() // => webpack --json

var options = {
noColor: true
};

console.log(prettyjson.render(json.errors, options));
console.log(prettyjson.render(json.assets, options));

});
}

// 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;
//}
return app;
}
module.exports = create;

module.exports = create;
45 changes: 29 additions & 16 deletions bundle/bundle.source.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,34 @@
(function () {
import '../static/css/drawer.css';
import '../static/css/dropdown.css';
import '../static/css/sgv.css';
import '../node_modules/jquery.tipsy/src/jquery.tipsy.css';

window._ = require('lodash');
window.d3 = require('d3');
window.$ = window.jQuery = require('jquery');
window.moment = require('moment-timezone');
window.sugar = require('sugar');
window.crossfilter = require('crossfilter');
window.Nightscout = window.Nightscout || {};

window.Nightscout = {
client: require('../lib/client')
, units: require('../lib/units')()
, report_plugins: require('../lib/report_plugins/')()
, admin_plugins: require('../lib/admin_plugins/')()
};
$ = require("jquery");

console.info('Nightscout bundle ready');
require('jquery-ui-bundle');

})();
window._ = require('lodash');
window.d3 = require('d3');

require('jquery.tipsy');

window.Storage = require('js-storage');

require('flot');
require('../node_modules/flot/jquery.flot.time');
require('../node_modules/flot/jquery.flot.pie');
require('../node_modules/flot/jquery.flot.fillbetween');

window.moment = require('moment-timezone');

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

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

console.info('Nightscout bundle ready');
5 changes: 3 additions & 2 deletions lib/client/boluscalc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
var _ = require('lodash');
var moment = require('moment-timezone');
var times = require('../times');
var Storages = require('js-storage');

function init(client, $) {
var boluscalc = { };

var translate = client.translate;
var storage = $.localStorage;
var storage = Storages.localStorage;
var iob = client.plugins('iob');
var cob = client.plugins('cob');

Expand Down Expand Up @@ -176,7 +177,7 @@ function init(client, $) {
$('#bc_quickpick').val(-1);
$('#bc_preBolus').val(0);
$('#bc_notes').val('');
$('#bc_enteredBy').val($.localStorage.get('enteredBy') || '');
$('#bc_enteredBy').val(Storages.localStorage.get('enteredBy') || '');
$('#bc_nowtime').prop('checked', true);
$('#bc_othercorrection').val(0);
$('#bc_profile').val(client.profilefunctions.activeProfileToTime());
Expand Down
3 changes: 2 additions & 1 deletion lib/client/browser-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ var _ = require('lodash');

// VERSION 1 - 0.9.0 - 2015-Nov-07 - initial version
var STORAGE_VERSION = 1;
var Storages = require('js-storage');

function init (client, serverSettings, $) {

serverSettings = serverSettings || {settings: {}};

var storage = $.localStorage;
var storage = Storages.localStorage;
var settings = require('../settings')();

function loadForm ( ) {
Expand Down
3 changes: 2 additions & 1 deletion lib/client/careportal.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ var moment = require('moment-timezone');
var _ = require('lodash');
var parse_duration = require('parse-duration'); // https://www.npmjs.com/package/parse-duration
var times = require('../times');
var Storages = require('js-storage');

function init (client, $) {
var careportal = { };

var translate = client.translate;
var storage = $.localStorage;
var storage = Storages.localStorage;

careportal.allEventTypes = client.plugins.getAllEventTypes(client.sbx);

Expand Down
Loading