From fb9798769644b27bb7528aa47ff0b9afdd902a39 Mon Sep 17 00:00:00 2001 From: MilosKozak Date: Fri, 18 Sep 2015 20:15:15 +0200 Subject: [PATCH 001/140] codacy report.css --- static/css/report.css | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/static/css/report.css b/static/css/report.css index 991bf73be17..3ead166fec9 100644 --- a/static/css/report.css +++ b/static/css/report.css @@ -14,11 +14,11 @@ body { color: black; } -#.centeraligned { +.centeraligned { text-align:center; } -ul#tabnav { +#tabnav { text-align: left; margin: 1em 0 1em 0; font: bold 11px verdana, arial, sans-serif; @@ -27,11 +27,8 @@ ul#tabnav { padding: 3px 10px 3px 10px; } -ul#tabnav li { +#tabnav li{ display: inline; -} - -ul#tabnav li{ padding: 3px 4px; border: 1px solid #6c6; background-color: #cfc; @@ -41,11 +38,11 @@ ul#tabnav li{ border-bottom: none; } -ul#tabnav li.selected { +#tabnav li.selected { background: #fff; } -ul#tabnav li:hover { +#tabnav li:hover { background: #9f9; cursor:pointer; } From 343ced6f9808e46db01ceceb9206b6dbe395aebb Mon Sep 17 00:00:00 2001 From: MilosKozak Date: Fri, 18 Sep 2015 20:32:30 +0200 Subject: [PATCH 002/140] codacy percentil.js --- lib/report_plugins/percentile.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/report_plugins/percentile.js b/lib/report_plugins/percentile.js index 680e7f66d86..bc8d67ad8fa 100644 --- a/lib/report_plugins/percentile.js +++ b/lib/report_plugins/percentile.js @@ -41,16 +41,17 @@ percentile.report = function report_percentile(datastorage, sorteddaystoshow, op var data = datastorage.allstatsrecords; var bins = []; + var filterFunc = function withinWindow(record) { + var recdate = new Date(record.displayTime); + return recdate.getHours() === hour && recdate.getMinutes() >= minute && recdate.getMinutes() < minute + minutewindow; + }; + for (var hour = 0; hour < 24; hour++) { for (var minute = 0; minute < 60; minute = minute + minutewindow) { var date = new Date(); date.setHours(hour); date.setMinutes(minute); - var readings = data.filter(function(record) { - var recdate = new Date(record.displayTime); - return recdate.getHours() === hour && recdate.getMinutes() >= minute && - recdate.getMinutes() < minute + minutewindow; - }); + var readings = data.filter(filterFunc); readings = readings.map(function(record) { return record.sgv; }); From 3fadc961d4c4ead001f8bcf0af324d86526ca4b0 Mon Sep 17 00:00:00 2001 From: MilosKozak Date: Fri, 18 Sep 2015 20:43:51 +0200 Subject: [PATCH 003/140] codacy report.js --- static/report/js/report.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/static/report/js/report.js b/static/report/js/report.js index 83a19c3a10e..315dc73cb73 100644 --- a/static/report/js/report.js +++ b/static/report/js/report.js @@ -58,10 +58,10 @@ }; function fillFoodForm(event) { - $('#rp_category').empty().append(''); - for (var s in food_categories) { + $('#rp_category').empty().append(''); + Object.keys(food_categories).forEach(function eachCategory(s) { $('#rp_category').append(''); - } + }); filter.category = ''; fillFoodSubcategories(); @@ -75,11 +75,11 @@ function fillFoodSubcategories(event) { filter.category = $('#rp_category').val(); filter.subcategory = ''; - $('#rp_subcategory').empty().append(''); + $('#rp_subcategory').empty().append(''); if (filter.category !== '') { - for (var s in food_categories[filter.category]) { + Object.keys(food_categories[filter.category]).forEach(function eachSubCategory(s) { $('#rp_subcategory').append(''); - } + }); } doFoodFilter(); return maybePrevent(event); From d61972ed5500695b7dee0376c8d27e695b5f4173 Mon Sep 17 00:00:00 2001 From: MilosKozak Date: Fri, 18 Sep 2015 21:27:07 +0200 Subject: [PATCH 004/140] reuse rawbg.calc --- static/report/js/report.js | 24 +++--------------------- 1 file changed, 3 insertions(+), 21 deletions(-) diff --git a/static/report/js/report.js b/static/report/js/report.js index 315dc73cb73..b581a3790fc 100644 --- a/static/report/js/report.js +++ b/static/report/js/report.js @@ -186,26 +186,6 @@ setDataRange(null,7); } - function rawIsigToRawBg(entry, cal) { - var raw = 0 - , unfiltered = parseInt(entry.unfiltered) || 0 - , filtered = parseInt(entry.filtered) || 0 - , sgv = entry.y - , scale = parseFloat(cal.scale) || 0 - , intercept = parseFloat(cal.intercept) || 0 - , slope = parseFloat(cal.slope) || 0; - - if (slope === 0 || unfiltered === 0 || scale === 0) { - raw = 0; - } else if (filtered === 0 || sgv < 40) { - raw = scale * (unfiltered - intercept) / slope; - } else { - var ratio = scale * (filtered - intercept) / slope / sgv; - raw = scale * ( unfiltered - intercept) / slope / ratio; - } - return Math.round(raw); - } - function sgvToColor(sgv,options) { var color = 'darkgreen'; @@ -610,9 +590,11 @@ var cal = data.cal[data.cal.length-1]; var temp1 = [ ]; + var rawbg = Nightscout.plugins('rawbg'); if (cal) { temp1 = data.sgv.map(function (entry) { - var rawBg = rawIsigToRawBg(entry, cal); + entry.mgdl = entry.y; // value names changed from enchilada + var rawBg = rawbg.calc(entry, cal); return { mills: entry.mills, date: new Date(entry.mills - 2 * 1000), y: rawBg, sgv: client.utils.scaleMgdl(rawBg), color: 'gray', type: 'rawbg', filtered: entry.filtered, unfiltered: entry.unfiltered }; }).filter(function(entry) { return entry.y > 0}); } From 29792b1d14f3f850c976ee9a85a7902b6af942e5 Mon Sep 17 00:00:00 2001 From: MilosKozak Date: Fri, 18 Sep 2015 21:41:22 +0200 Subject: [PATCH 005/140] daysfilter() change --- static/report/js/report.js | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/static/report/js/report.js b/static/report/js/report.js index b581a3790fc..5ee9019a2e6 100644 --- a/static/report/js/report.js +++ b/static/report/js/report.js @@ -368,18 +368,16 @@ function daysfilter() { matchesneeded++; - for (var d in daystoshow) { - if (daystoshow.hasOwnProperty(d)) { - var day = new Date(d).getDay(); - if (day===0 && $('#rp_su').is(':checked')) { daystoshow[d]++; } - if (day===1 && $('#rp_mo').is(':checked')) { daystoshow[d]++; } - if (day===2 && $('#rp_tu').is(':checked')) { daystoshow[d]++; } - if (day===3 && $('#rp_we').is(':checked')) { daystoshow[d]++; } - if (day===4 && $('#rp_th').is(':checked')) { daystoshow[d]++; } - if (day===5 && $('#rp_fr').is(':checked')) { daystoshow[d]++; } - if (day===6 && $('#rp_sa').is(':checked')) { daystoshow[d]++; } - } - } + Object.keys(daystoshow).forEach( function eachDay(d) { + var day = new Date(d).getDay(); + if (day===0 && $('#rp_su').is(':checked')) { daystoshow[d]++; } + if (day===1 && $('#rp_mo').is(':checked')) { daystoshow[d]++; } + if (day===2 && $('#rp_tu').is(':checked')) { daystoshow[d]++; } + if (day===3 && $('#rp_we').is(':checked')) { daystoshow[d]++; } + if (day===4 && $('#rp_th').is(':checked')) { daystoshow[d]++; } + if (day===5 && $('#rp_fr').is(':checked')) { daystoshow[d]++; } + if (day===6 && $('#rp_sa').is(':checked')) { daystoshow[d]++; } + }); countDays(); display(); } From 070d19ea5a0705980d0d4b51053a2f80f2474525 Mon Sep 17 00:00:00 2001 From: Scott Leibrand Date: Sat, 19 Sep 2015 10:43:29 -0700 Subject: [PATCH 006/140] comment units, fix incorrect units in delayedCarbs calculation, and adjust liverSensRatio to partially compensate --- lib/plugins/cob.js | 11 +++++++++-- lib/plugins/iob.js | 4 +++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/plugins/cob.js b/lib/plugins/cob.js index 385ac6659bf..8892b8aa7f3 100644 --- a/lib/plugins/cob.js +++ b/lib/plugins/cob.js @@ -30,7 +30,8 @@ function init() { return {}; } - var liverSensRatio = 1; + // Adjusted from 1 to 8 to compensate for half of the effect (in adults; much less in kids) of fixing units on the delayedCarbs term + var liverSensRatio = 8; var totalCOB = 0; var lastCarbs = null; @@ -51,10 +52,16 @@ function init() { var cCalc = cob.cobCalc(treatment, profile, lastDecayedBy, time); var decaysin_hr = (cCalc.decayedBy - time) / 1000 / 60 / 60; if (decaysin_hr > -10) { + // units: BG var actStart = iob.calcTotal(treatments, profile, lastDecayedBy).activity; var actEnd = iob.calcTotal(treatments, profile, cCalc.decayedBy).activity; var avgActivity = (actStart + actEnd) / 2; - var delayedCarbs = avgActivity * liverSensRatio * profile.getSensitivity(treatment.mills) / profile.getCarbRatio(treatment.mills); + // These units were wrong: + // units: BG^2/g (?) = BG * scalar * BG / U / g / U + //var delayedCarbs = avgActivity * liverSensRatio * profile.getSensitivity(treatment.mills) / profile.getCarbRatio(treatment.mills); + // This is correct: + // units: g = BG * scalar / BG / U * g / U + var delayedCarbs = avgActivity * liverSensRatio / profile.getSensitivity(treatment.mills) * profile.getCarbRatio(treatment.mills); var delayMinutes = Math.round(delayedCarbs / profile.getCarbAbsorptionRate(treatment.mills) * 60); if (delayMinutes > 0) { cCalc.decayedBy.setMinutes(cCalc.decayedBy.getMinutes() + delayMinutes); diff --git a/lib/plugins/iob.js b/lib/plugins/iob.js index b4c4bbc518a..4d8f4e7a85a 100644 --- a/lib/plugins/iob.js +++ b/lib/plugins/iob.js @@ -38,6 +38,7 @@ function init() { lastBolus = treatment; } if (tIOB && tIOB.iobContrib) { totalIOB += tIOB.iobContrib; } + // units: BG (mg/dL or mmol/L) if (tIOB && tIOB.activityContrib) { totalActivity += tIOB.activityContrib; } } }); @@ -76,6 +77,7 @@ function init() { if (minAgo < peak) { var x1 = minAgo / 5 + 1; result.iobContrib = treatment.insulin * (1 - 0.001852 * x1 * x1 + 0.001852 * x1); + // units: BG (mg/dL) = (BG/U) * U insulin * scalar result.activityContrib = sens * treatment.insulin * (2 / dia / 60 / peak) * minAgo; } else if (minAgo < 180) { @@ -113,4 +115,4 @@ function init() { } -module.exports = init; \ No newline at end of file +module.exports = init; From df0d8803025085d56c763b1195e3ac5d94b25b39 Mon Sep 17 00:00:00 2001 From: Scott Leibrand Date: Sat, 19 Sep 2015 10:52:09 -0700 Subject: [PATCH 007/140] parentheses for clarity --- lib/plugins/cob.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/plugins/cob.js b/lib/plugins/cob.js index 8892b8aa7f3..fc3072e07f2 100644 --- a/lib/plugins/cob.js +++ b/lib/plugins/cob.js @@ -60,8 +60,8 @@ function init() { // units: BG^2/g (?) = BG * scalar * BG / U / g / U //var delayedCarbs = avgActivity * liverSensRatio * profile.getSensitivity(treatment.mills) / profile.getCarbRatio(treatment.mills); // This is correct: - // units: g = BG * scalar / BG / U * g / U - var delayedCarbs = avgActivity * liverSensRatio / profile.getSensitivity(treatment.mills) * profile.getCarbRatio(treatment.mills); + // units: g = BG * scalar / BG / U * g / U + var delayedCarbs = ( avgActivity * liverSensRatio / profile.getSensitivity(treatment.mills) ) * profile.getCarbRatio(treatment.mills); var delayMinutes = Math.round(delayedCarbs / profile.getCarbAbsorptionRate(treatment.mills) * 60); if (delayMinutes > 0) { cCalc.decayedBy.setMinutes(cCalc.decayedBy.getMinutes() + delayMinutes); From 26ebe88401658440400f7ef3b4d2c148902b7100 Mon Sep 17 00:00:00 2001 From: Scott Leibrand Date: Sat, 19 Sep 2015 11:04:41 -0700 Subject: [PATCH 008/140] remove commented old incorrect-units code --- lib/plugins/cob.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/plugins/cob.js b/lib/plugins/cob.js index fc3072e07f2..aa831f6c8b7 100644 --- a/lib/plugins/cob.js +++ b/lib/plugins/cob.js @@ -30,7 +30,7 @@ function init() { return {}; } - // Adjusted from 1 to 8 to compensate for half of the effect (in adults; much less in kids) of fixing units on the delayedCarbs term + // TODO: figure out the liverSensRatio that gives the most accurate purple line predictions var liverSensRatio = 8; var totalCOB = 0; var lastCarbs = null; @@ -56,10 +56,6 @@ function init() { var actStart = iob.calcTotal(treatments, profile, lastDecayedBy).activity; var actEnd = iob.calcTotal(treatments, profile, cCalc.decayedBy).activity; var avgActivity = (actStart + actEnd) / 2; - // These units were wrong: - // units: BG^2/g (?) = BG * scalar * BG / U / g / U - //var delayedCarbs = avgActivity * liverSensRatio * profile.getSensitivity(treatment.mills) / profile.getCarbRatio(treatment.mills); - // This is correct: // units: g = BG * scalar / BG / U * g / U var delayedCarbs = ( avgActivity * liverSensRatio / profile.getSensitivity(treatment.mills) ) * profile.getCarbRatio(treatment.mills); var delayMinutes = Math.round(delayedCarbs / profile.getCarbAbsorptionRate(treatment.mills) * 60); From 135b35d8875fa151af8f911465fd93748f75f593 Mon Sep 17 00:00:00 2001 From: xpucuto Date: Sun, 20 Sep 2015 14:38:59 +0300 Subject: [PATCH 009/140] Bulgarian language - 20 Sept. --- lib/language.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/language.js b/lib/language.js index d03a5544670..f1a241b9769 100644 --- a/lib/language.js +++ b/lib/language.js @@ -561,7 +561,7 @@ function init() { ,fr: 'Supérieur' ,pt: 'Superior' ,ro: 'Sus' - ,bg: 'горе' + ,bg: 'горна' ,hr: 'Gornja' ,sv: 'Toppen' ,it: 'Superiore' From 40d7946fd6f21d1b4b3d7f252ae1fee9da3d5162 Mon Sep 17 00:00:00 2001 From: sebastianlorant Date: Sun, 20 Sep 2015 16:28:55 +0200 Subject: [PATCH 010/140] svedisk language update --- lib/language.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/language.js b/lib/language.js index d03a5544670..a39d4fa3544 100644 --- a/lib/language.js +++ b/lib/language.js @@ -4062,25 +4062,30 @@ function init() { } ,'Language' : { cs: 'Jazyk' + ,sv: 'Språk' ,fi: 'Kieli' ,pt: 'Língua' ,bg: 'Език' } ,'Update' : { // Update button cs: 'Aktualizovat' + ,sv: 'Uppdatera' ,pt: 'Atualizar' ,bg: 'Актуализирай' } ,'Order' : { cs: 'Pořadí' + ,sv: 'Sortering' ,bg: 'Ред' } ,'oldest on top' : { cs: 'nejstarší nahoře' + ,sv: 'Äldst först' ,bg: 'Старите най-отгоре' } ,'newest on top' : { cs: 'nejnovější nahoře' + ,sv: 'Nyast först' ,bg: 'Новите най-отгоре' } From d36d05b14d46d045c43ee520c94551343cd43f22 Mon Sep 17 00:00:00 2001 From: MilosKozak Date: Tue, 22 Sep 2015 12:10:46 +0200 Subject: [PATCH 011/140] filter in report fix, 1 missing translation --- lib/language.js | 3 +++ static/report/js/report.js | 15 ++++++--------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/language.js b/lib/language.js index c799d512e7a..0fd95c26da5 100644 --- a/lib/language.js +++ b/lib/language.js @@ -4088,6 +4088,9 @@ function init() { ,sv: 'Nyast först' ,bg: 'Новите най-отгоре' } + ,'All sensor events' : { + cs: 'Všechny události sensoru' + } }; diff --git a/static/report/js/report.js b/static/report/js/report.js index 5ee9019a2e6..1e7cee3379b 100644 --- a/static/report/js/report.js +++ b/static/report/js/report.js @@ -384,6 +384,7 @@ function display() { var count = 0; + sorteddaystoshow = []; $('#info').html(''+translate('Loading')+' ...'); for (var d in daystoshow) { if (daystoshow[d]===matchesneeded) { @@ -421,14 +422,10 @@ console.log('Total: ', daystoshow, 'Matches needed: ', matchesneeded, 'Will be loaded: ', dayscount); } - function dataLoadedCallback () { + function dataLoadedCallback (day) { loadeddays++; + sorteddaystoshow.push(day); if (loadeddays === dayscount) { - // sort array - sorteddaystoshow = []; - Object.keys(daystoshow).forEach(function (day) { - sorteddaystoshow.push(day); - }); sorteddaystoshow.sort(); if (options.order === report_plugins.consts.ORDER_NEWESTONTOP) { sorteddaystoshow.reverse(); @@ -448,7 +445,7 @@ // prepare some data used in more reports datastorage.allstatsrecords = []; datastorage.alldays = 0; - Object.keys(daystoshow).forEach(function (day) { + sorteddaystoshow.forEach(function eachDay(day) { datastorage.allstatsrecords = datastorage.allstatsrecords.concat(datastorage[day].statsrecords); datastorage.alldays++; }); @@ -490,7 +487,7 @@ function loadData(day, options, callback) { // check for loaded data if (datastorage[day] && day !== moment().format('YYYY-MM-DD')) { - callback(); + callback(day); return; } // patientData = [actual, predicted, mbg, treatment, cal, devicestatusData]; @@ -635,7 +632,7 @@ datastorage[day] = data; - callback(); + callback(day); } function maybePrevent(event) { From 887c02eaa55cd46ea0d89f02254c7df75e154dd2 Mon Sep 17 00:00:00 2001 From: MilosKozak Date: Wed, 23 Sep 2015 14:28:43 +0200 Subject: [PATCH 012/140] unify timeFormat to number --- lib/client/browser-settings.js | 2 +- lib/report_plugins/daytoday.js | 2 +- lib/settings.js | 15 ++++++++++++++- static/profile/js/profileeditor.js | 2 +- tests/fixtures/default-server-settings.js | 2 +- tests/settings.test.js | 2 +- 6 files changed, 19 insertions(+), 6 deletions(-) diff --git a/lib/client/browser-settings.js b/lib/client/browser-settings.js index e49b05cb04f..fbd82e42731 100644 --- a/lib/client/browser-settings.js +++ b/lib/client/browser-settings.js @@ -123,7 +123,7 @@ function init (client, plugins, serverSettings, $) { showRawbg: $('input:radio[name=show-rawbg]:checked').val(), customTitle: $('input#customTitle').prop('value'), theme: $('input:radio[name=theme-browser]:checked').val(), - timeFormat: $('input:radio[name=timeformat-browser]:checked').val(), + timeFormat: parseInt($('input:radio[name=timeformat-browser]:checked').val()), language: $('#language').val(), showPlugins: checkedPluginNames() }); diff --git a/lib/report_plugins/daytoday.js b/lib/report_plugins/daytoday.js index 18ba0f23531..2918f2199c8 100644 --- a/lib/report_plugins/daytoday.js +++ b/lib/report_plugins/daytoday.js @@ -73,7 +73,7 @@ daytoday.report = function report_daytoday(datastorage,sorteddaystoshow,options) '12am', '', '2am', '', '4am', '', '6am', '', '8am', '', '10am', '', '12pm', '', '2pm', '', '4pm', '', '6pm', '', '8pm', '', '10pm', '', '12am' ]; - if (Nightscout.client.settings.timeFormat === '24') { + if (Nightscout.client.settings.timeFormat === 24) { return ('00' + i).slice(-2); } else { return t12[i]; diff --git a/lib/settings.js b/lib/settings.js index 9cc486929cc..7939790a851 100644 --- a/lib/settings.js +++ b/lib/settings.js @@ -7,7 +7,7 @@ function init ( ) { var settings = { units: 'mg/dL' - , timeFormat: '12' + , timeFormat: 12 , nightMode: false , showRawbg: 'never' , customTitle: 'Nightscout' @@ -45,6 +45,7 @@ function init ( ) { , alarmUrgentLowMins: mapNumberArray , alarmUrgentMins: mapNumberArray , alarmWarnMins: mapNumberArray + , timeFormat: mapNumber }; function mapNumberArray (value) { @@ -62,6 +63,18 @@ function init ( ) { } } + function mapNumber (value) { + if (!value) { + return value; + } + + if (isNaN(value)) { + return value; + } else { + return Number(value); + } + } + //TODO: getting sent in status.json, shouldn't be settings.DEFAULT_FEATURES = ['delta', 'direction', 'upbat', 'errorcodes']; diff --git a/static/profile/js/profileeditor.js b/static/profile/js/profileeditor.js index 92309e89523..f1415d769eb 100644 --- a/static/profile/js/profileeditor.js +++ b/static/profile/js/profileeditor.js @@ -429,7 +429,7 @@ function toDisplayTime (minfrommidnight) { var time = moment().startOf('day').add(minfrommidnight,'minutes'); - return client.settings.timeFormat === '24' ? time.format('HH:mm') : time.format('h:mm A'); + return client.settings.timeFormat === 24 ? time.format('HH:mm') : time.format('h:mm A'); } function profileSubmit(event) { diff --git a/tests/fixtures/default-server-settings.js b/tests/fixtures/default-server-settings.js index 20bbaa1b854..113a5fa4aeb 100644 --- a/tests/fixtures/default-server-settings.js +++ b/tests/fixtures/default-server-settings.js @@ -8,7 +8,7 @@ module.exports = { , head: 'ae71dca' , settings: { units: 'mg/dl' - , timeFormat: '12' + , timeFormat: 12 , nightMode: false , showRawbg: 'noise' , customTitle: 'Test Title' diff --git a/tests/settings.test.js b/tests/settings.test.js index 712928a2a29..7183fae1bc1 100644 --- a/tests/settings.test.js +++ b/tests/settings.test.js @@ -8,7 +8,7 @@ describe('settings', function ( ) { var settings = require('../lib/settings')(); it('have defaults ready', function () { - settings.timeFormat.should.equal('12'); + settings.timeFormat.should.equal(12); settings.nightMode.should.equal(false); settings.showRawbg.should.equal('never'); settings.customTitle.should.equal('Nightscout'); From da9cceb548ec326d89cd286ad9886833ce7e11f0 Mon Sep 17 00:00:00 2001 From: MilosKozak Date: Wed, 16 Sep 2015 22:28:36 +0200 Subject: [PATCH 013/140] admin tools initial release --- bundle/bundle.source.js | 1 + lib/admin_plugins/cleanstatusdb.js | 69 +++++++++++++++++++++++++++++ lib/admin_plugins/index.js | 71 ++++++++++++++++++++++++++++++ lib/api/devicestatus/index.js | 10 +++++ lib/devicestatus.js | 12 +++++ lib/language.js | 13 ++++-- static/admin/index.html | 56 +++++++++++++++++++++++ static/admin/js/admin.js | 21 +++++++++ static/css/admin.css | 27 ++++++++++++ 9 files changed, 277 insertions(+), 3 deletions(-) create mode 100644 lib/admin_plugins/cleanstatusdb.js create mode 100644 lib/admin_plugins/index.js create mode 100644 static/admin/index.html create mode 100644 static/admin/js/admin.js create mode 100644 static/css/admin.css diff --git a/bundle/bundle.source.js b/bundle/bundle.source.js index 0ca7d7235eb..d78ecb3c868 100644 --- a/bundle/bundle.source.js +++ b/bundle/bundle.source.js @@ -10,6 +10,7 @@ , units: require('../lib/units')() , plugins: require('../lib/plugins/')().registerClientDefaults() , report_plugins: require('../lib/report_plugins/')() + , admin_plugins: require('../lib/admin_plugins/')() }; console.info('Nightscout bundle ready'); diff --git a/lib/admin_plugins/cleanstatusdb.js b/lib/admin_plugins/cleanstatusdb.js new file mode 100644 index 00000000000..d1ac566a5fe --- /dev/null +++ b/lib/admin_plugins/cleanstatusdb.js @@ -0,0 +1,69 @@ +'use strict'; + +var cleanstatusdb = { + name: 'cleanstatusdb' + , label: 'Clean mongo status database' + , pluginType: 'admin' +}; + +function init() { + return cleanstatusdb; +} + +module.exports = init; + +cleanstatusdb.actions = [ + { + name: 'Delete all documents from devicestatus collection' + , description: 'This task removes all documents from devicestatus collection. Usefull when uploader battery status is not properly updated' + , buttonLabel: 'Delete all documents' + , confirmText: 'Delete all documents from devicestatus collection?' + } + ]; + +cleanstatusdb.actions[0].init = function init(client, callback) { + var translate = client.translate; + var $status = $('#admin_' + cleanstatusdb.name + '_0_status'); + + $status.hide().text(translate('Loading database ...')).fadeIn('slow'); + $.ajax('/api/v1/devicestatus.json?count=500000', { + success: function (records) { + $status.hide().text(translate('Database contains %1 records',{ params: [records.length] })).fadeIn('slow'); + }, + error: function () { + $status.hide().text(translate('Error loading database')).fadeIn('slow'); + } + }).done(function () { if (callback) { callback(); } }); +}; + +cleanstatusdb.actions[0].code = function deleteRecords(client, callback) { + var translate = client.translate; + var $status = $('#admin_' + cleanstatusdb.name + '_0_status'); + + if (!client.hashauth.isAuthenticated()) { + alert(translate('Your device is not authenticated yet')); + if (callback) { + callback(); + } + return; + } + + $status.hide().text(translate('Deleting records ...')).fadeIn('slow'); + $.ajax({ + method: 'DELETE' + , url: '/api/v1/devicestatus/ALL' + , headers: { + 'api-secret': client.hashauth.hash() + } + }).done(function success () { + $status.hide().text(translate('All records removed ...')).fadeIn('slow'); + if (callback) { + callback(); + } + }).fail(function fail() { + $status.hide().text(translate('Error')).fadeIn('slow'); + if (callback) { + callback(); + } + }); +} diff --git a/lib/admin_plugins/index.js b/lib/admin_plugins/index.js new file mode 100644 index 00000000000..db2c50d1e11 --- /dev/null +++ b/lib/admin_plugins/index.js @@ -0,0 +1,71 @@ +'use strict'; + +var _ = require('lodash'); + +function init() { + var allPlugins = [ + require('./cleanstatusdb')() + ]; + + function plugins(name) { + if (name) { + return _.find(allPlugins, {name: name}); + } else { + return plugins; + } + } + + plugins.eachPlugin = function eachPlugin(f) { + _.each(allPlugins, f); + }; + + plugins.createHTML = function createHTML(client) { + var translate = client.translate; + plugins.eachPlugin(function addHtml(p) { + var fs = $('
'); + $('#admin_placeholder').append(fs); + fs.append($('').append(translate(p.label))); + for (var i = 0; i < p.actions.length; i++) { + if (i !== 0) { + fs.append('
'); + } + var a = p.actions[i]; + // add main plugin html + fs.append($('').append(translate(a.description))); + fs.append($('
').attr('id','admin_' + p.name + '_' + i + '_html')); + fs.append($('