Skip to content

Commit

Permalink
Merge 5ecff6c into d9b7cdc
Browse files Browse the repository at this point in the history
  • Loading branch information
jasoncalabrese committed Feb 15, 2016
2 parents d9b7cdc + 5ecff6c commit a59f3b1
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 46 deletions.
24 changes: 22 additions & 2 deletions lib/client/browser-utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict';

var SMALL_SCREEN = 500;

function init ($) {
var lastOpenedDrawer = null;

Expand Down Expand Up @@ -82,7 +84,23 @@ function init ($) {
closeOpenDraw(function () {
lastOpenedDrawer = id;
if (prepare) { prepare(); }
$(id).css({display:'block', right: '0'});

var style = {display:'block', right: '0'};

var windowWidth = $(window).width();
if (windowWidth < SMALL_SCREEN || ($(window).height() < SMALL_SCREEN) && windowWidth < 800) {
style.width = windowWidth + 'px';
var top = $("#chartContainer").offset().top - 45;
style.top = top + 'px';
style.height = ($(window).height() - top - 45) + 'px';
} else {
style.top = '0px';
style.height = ($(window).height() - 45) + 'px';
style.width = '350px';
}


$(id).css(style);
});

}
Expand Down Expand Up @@ -111,7 +129,9 @@ function init ($) {
notify.addClass(type ? type : 'urgent');

notify.find('span').html(note);
notify.css('left', 'calc(50% - ' + (notify.width() / 2) + 'px)');
var windowWidth = $(window).width();
var left = (windowWidth - notify.width()) / 2;
notify.css('left', left + 'px');
notify.show();
}

Expand Down
3 changes: 2 additions & 1 deletion lib/client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,8 @@ client.init = function init(serverSettings, plugins) {
chart.scroll(nowDate);
}

$('#chartContainer').css('top', (client.bottomOfPills() + 5) + 'px');
var top = (client.bottomOfPills() + 5);
$('#chartContainer').css({top: top + 'px', height: $(window).height() - top - 10});
}

function sgvToColor(sgv) {
Expand Down
2 changes: 1 addition & 1 deletion lib/client/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,7 @@ function init (client, d3) {

client.ddata.tempbasalTreatments.forEach(function (t) {
// only if basal and focus interval overlap and there is a chance to fit
if (t.mills < to && t.mills + times.mins(t.duration).msecs > from) {
if (t.duration && t.mills < to && t.mills + times.mins(t.duration).msecs > from) {
var text = g.append('text')
.attr('class', 'tempbasaltext')
.style('font-size', 15)
Expand Down
11 changes: 10 additions & 1 deletion lib/data/dataloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

var _ = require('lodash');
var async = require('async');
var times = require('../times');
var fitTreatmentsToBGCurve = require('./treatmenttocurve');

var ONE_DAY = 86400000
Expand Down Expand Up @@ -96,10 +97,18 @@ function mergeToTreatments (ddata, results) {
var filtered = _.filter(results, function hasId (treatment) {
return _.isObject(treatment._id);
});

var treatments = _.map(filtered, function update (treatment) {
treatment.mills = new Date(treatment.created_at).getTime();
return treatment;
});

//filter out temps older than a day and an hour ago since we don't display them
var oneDayAgo = ddata.lastUpdated - ONE_DAY - times.hour().msecs;
treatments = _.filter(treatments, function noOldTemps (treatment) {
return !treatment.eventType || treatment.eventType.indexOf('Temp Basal') === -1 || treatment.mills > oneDayAgo;
});

ddata.treatments = _.union(ddata.treatments, treatments);
}

Expand Down Expand Up @@ -185,7 +194,7 @@ function loadDeviceStatus (ddata, env, ctx, callback) {
var opts = {
find: {
created_at: {
$gte: new Date(ddata.lastUpdated - TWO_DAYS).toISOString()
$gte: new Date(ddata.lastUpdated - ONE_DAY).toISOString()
}
}
, sort: {created_at: -1}
Expand Down
16 changes: 10 additions & 6 deletions lib/data/ddata.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,20 @@ function init( ) {

// cut by end events
tempbasalTreatments.forEach(function allTreatments(t) {
endevents.forEach(function allEndevents(e) {
cutIfInInterval(t, e);
});
if (t.duration) {
endevents.forEach(function allEndevents(e) {
cutIfInInterval(t, e);
});
}
});

// cut by overlaping events
tempbasalTreatments.forEach(function allTreatments(t) {
tempbasalTreatments.forEach(function allEndevents(e) {
cutIfInInterval(t, e);
});
if (t.duration) {
tempbasalTreatments.forEach(function allEndevents(e) {
cutIfInInterval(t, e);
});
}
});

// store prepared temp basal treatments
Expand Down
2 changes: 1 addition & 1 deletion lib/plugins/treatmentnotify.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var levels = require('../levels');
var times = require('../times');
var simplealarms = require('./simplealarms')();

var OPENAPS_WHITELIST = ['Meal Bolus', 'Carb Correction', 'Correction Bolus'];
var OPENAPS_WHITELIST = ['BG Check', 'Meal Bolus', 'Carb Correction', 'Correction Bolus'];

function init() {

Expand Down
38 changes: 15 additions & 23 deletions lib/times.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
'use strict';

var cache = { };

var factories = {
weeks: function weeks(value) {
return {
Expand Down Expand Up @@ -35,31 +33,25 @@ var factories = {
}
};

function getOrCreate (types) {
function create (types) {
return function withValue (value) {
var key = types + value;
var obj = cache[key];
if (!obj) {
obj = factories[types](value);
cache[key] = obj;
}
return obj;
};
return factories[types](value);
}
}

var times = {
week: function ( ) { return getOrCreate('weeks')(1); }
, weeks: function (value) { return getOrCreate('weeks')(value); }
, day: function ( ) { return getOrCreate('days')(1); }
, days: function (value) { return getOrCreate('days')(value); }
, hour: function ( ) { return getOrCreate('hours')(1); }
, hours: function (value) { return getOrCreate('hours')(value); }
, min: function ( ) { return getOrCreate('mins')(1); }
, mins: function (value) { return getOrCreate('mins')(value); }
, sec: function ( ) { return getOrCreate('secs')(1); }
, secs: function (value) { return getOrCreate('secs')(value); }
, msec: function ( ) { return getOrCreate('msecs')(1); }
, msecs: function (value) { return getOrCreate('msecs')(value); }
week: function ( ) { return create('weeks')(1); }
, weeks: function (value) { return create('weeks')(value); }
, day: function ( ) { return create('days')(1); }
, days: function (value) { return create('days')(value); }
, hour: function ( ) { return create('hours')(1); }
, hours: function (value) { return create('hours')(value); }
, min: function ( ) { return create('mins')(1); }
, mins: function (value) { return create('mins')(value); }
, sec: function ( ) { return create('secs')(1); }
, secs: function (value) { return create('secs')(value); }
, msec: function ( ) { return create('msecs')(1); }
, msecs: function (value) { return create('msecs')(value); }
};

module.exports = times;
17 changes: 9 additions & 8 deletions static/css/drawer.css
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
color: #eee;
display: none;
font-size: 16px;
height: 100%;
overflow-y: auto;
overflow-y: scroll;
overflow-x: hidden;
-webkit-overflow-scrolling: touch;
position: absolute;
margin-top: 45px;
right: -200px;
width: 300px;
top: 0;
z-index: 1;
}
Expand Down Expand Up @@ -55,12 +55,12 @@ input[type=number]:invalid {
color: #eee;
display: none;
font-size: 16px;
height: 100%;
overflow-y: auto;
overflow-y: scroll;
overflow-x: hidden;
-webkit-overflow-scrolling: touch;
position: absolute;
margin-top: 45px;
right: -200px;
width: 300px;
top: 0;
z-index: 1;
}
Expand Down Expand Up @@ -332,8 +332,9 @@ ul.navigation {
color: #eee;
display: none;
font-size: 16px;
height: 100%;
overflow-y: auto;
overflow-y: scroll;
overflow-x: hidden;
-webkit-overflow-scrolling: touch;
position: absolute;
margin-top: 45px;
right: -200px;
Expand Down
3 changes: 0 additions & 3 deletions static/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


html, body {
height: 100%;
margin: 0;
padding: 0;
}
Expand All @@ -17,12 +16,10 @@ body {
.container {
bottom: 0;
display: block;
height: 100%;
left: 0;
margin: 0;
padding: 0;
top: 45px;
width: 100%;
z-index: 2;
}

Expand Down

0 comments on commit a59f3b1

Please sign in to comment.