-
Notifications
You must be signed in to change notification settings - Fork 71.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from nightscout/master
NS8.5 for Mongodb compatability updates around 20160930
- Loading branch information
Showing
60 changed files
with
2,827 additions
and
351 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
'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. Useful 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=500', { | ||
success: function (records) { | ||
var recs = (records.length === 500 ? '500+' : records.length); | ||
$status.hide().text(translate('Database contains %1 records',{ params: [recs] })).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/*' | ||
, 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(); | ||
} | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
'use strict'; | ||
|
||
var futureitems = { | ||
name: 'futureitems' | ||
, label: 'Remove future items from mongo database' | ||
, pluginType: 'admin' | ||
}; | ||
|
||
function init() { | ||
return futureitems; | ||
} | ||
|
||
module.exports = init; | ||
|
||
futureitems.actions = [ | ||
{ | ||
name: 'Find and remove treatments in the future' | ||
, description: 'This task find and remove treatments in the future.' | ||
, buttonLabel: 'Remove treatments in the future' | ||
} | ||
, { | ||
name: 'Find and remove entries in the future' | ||
, description: 'This task find and remove CGM data in the future created by uploader with wrong date/time.' | ||
, buttonLabel: 'Remove entries in the future' | ||
} | ||
]; | ||
|
||
futureitems.actions[0].init = function init(client, callback) { | ||
var translate = client.translate; | ||
var $status = $('#admin_' + futureitems.name + '_0_status'); | ||
|
||
function valueOrEmpty (value) { | ||
return value ? value : ''; | ||
} | ||
|
||
function showOneTreatment (tr, table) { | ||
table.append($('<tr>').css('background-color','#0f0f0f') | ||
.append($('<td>').attr('width','20%').append(new Date(tr.created_at).toLocaleString().replace(/([\d]+:[\d]{2})(:[\d]{2})(.*)/, '$1$3'))) | ||
.append($('<td>').attr('width','20%').append(tr.eventType ? translate(client.careportal.resolveEventName(tr.eventType)) : '')) | ||
.append($('<td>').attr('width','10%').attr('align','center').append(tr.glucose ? tr.glucose + ' ('+translate(tr.glucoseType)+')' : '')) | ||
.append($('<td>').attr('width','10%').attr('align','center').append(valueOrEmpty(tr.insulin))) | ||
.append($('<td>').attr('width','10%').attr('align','center').append(valueOrEmpty(tr.carbs))) | ||
.append($('<td>').attr('width','10%').append(valueOrEmpty(tr.enteredBy))) | ||
.append($('<td>').attr('width','20%').append(valueOrEmpty(tr.notes))) | ||
); | ||
} | ||
|
||
function showTreatments(treatments, table) { | ||
table.append($('<tr>').css('background','#040404') | ||
.append($('<th>').css('width','80px').attr('align','left').append(translate('Time'))) | ||
.append($('<th>').css('width','150px').attr('align','left').append(translate('Event Type'))) | ||
.append($('<th>').css('width','150px').attr('align','left').append(translate('Blood Glucose'))) | ||
.append($('<th>').css('width','50px').attr('align','left').append(translate('Insulin'))) | ||
.append($('<th>').css('width','50px').attr('align','left').append(translate('Carbs'))) | ||
.append($('<th>').css('width','150px').attr('align','left').append(translate('Entered By'))) | ||
.append($('<th>').css('width','300px').attr('align','left').append(translate('Notes'))) | ||
); | ||
for (var t=0; t<treatments.length; t++) { | ||
showOneTreatment (treatments[t], table); | ||
} | ||
}; | ||
|
||
$status.hide().text(translate('Loading database ...')).fadeIn('slow'); | ||
var nowiso = new Date().toISOString(); | ||
$.ajax('/api/v1/treatments.json?&find[created_at][$gte]=' + nowiso, { | ||
success: function (records) { | ||
futureitems.treatmentrecords = records; | ||
$status.hide().text(translate('Database contains %1 future records',{ params: [records.length] })).fadeIn('slow'); | ||
var table = $('<table>').css('margin-top','10px'); | ||
$('#admin_' + futureitems.name + '_0_html').append(table); | ||
showTreatments(records, table); | ||
futureitems.actions[0].confirmText = translate('Remove %1 selected records?', { params: [records.length] }); | ||
}, | ||
error: function () { | ||
$status.hide().text(translate('Error loading database')).fadeIn('slow'); | ||
futureitems.treatmentrecords = []; | ||
} | ||
}).done(function () { if (callback) { callback(); } }); | ||
}; | ||
|
||
futureitems.actions[0].code = function deleteRecords(client, callback) { | ||
var translate = client.translate; | ||
var $status = $('#admin_' + futureitems.name + '_0_status'); | ||
|
||
if (!client.hashauth.isAuthenticated()) { | ||
alert(translate('Your device is not authenticated yet')); | ||
if (callback) { | ||
callback(); | ||
} | ||
return; | ||
}; | ||
|
||
function deleteRecordById (_id) { | ||
$.ajax({ | ||
method: 'DELETE' | ||
, url: '/api/v1/treatments/' + _id | ||
, headers: { | ||
'api-secret': client.hashauth.hash() | ||
} | ||
}).done(function success () { | ||
$status.text(translate('Record %1 removed ...', { params: [_id] })); | ||
}).fail(function fail() { | ||
$status.text(translate('Error removing record %1', { params: [_id] })); | ||
}); | ||
} | ||
|
||
$status.hide().text(translate('Deleting records ...')).fadeIn('slow'); | ||
for (var i = 0; i < futureitems.treatmentrecords.length; i++) { | ||
deleteRecordById(futureitems.treatmentrecords[i]._id); | ||
} | ||
$('#admin_' + futureitems.name + '_0_html').html(''); | ||
|
||
if (callback) { | ||
callback(); | ||
} | ||
}; | ||
|
||
futureitems.actions[1].init = function init(client, callback) { | ||
var translate = client.translate; | ||
var $status = $('#admin_' + futureitems.name + '_1_status'); | ||
|
||
$status.hide().text(translate('Loading database ...')).fadeIn('slow'); | ||
var now = new Date().getTime(); | ||
$.ajax('/api/v1/entries.json?&find[date][$gte]=' + now, { | ||
success: function (records) { | ||
futureitems.entriesrecords = records; | ||
$status.hide().text(translate('Database contains %1 future records',{ params: [records.length] })).fadeIn('slow'); | ||
futureitems.actions[1].confirmText = translate('Remove %1 selected records?', { params: [records.length] }); | ||
}, | ||
error: function () { | ||
$status.hide().text(translate('Error loading database')).fadeIn('slow'); | ||
futureitems.entriesrecords = []; | ||
} | ||
}).done(function () { if (callback) { callback(); } }); | ||
}; | ||
|
||
futureitems.actions[1].code = function deleteRecords(client, callback) { | ||
var translate = client.translate; | ||
var $status = $('#admin_' + futureitems.name + '_1_status'); | ||
|
||
if (!client.hashauth.isAuthenticated()) { | ||
alert(translate('Your device is not authenticated yet')); | ||
if (callback) { | ||
callback(); | ||
} | ||
return; | ||
}; | ||
|
||
function deteleteRecordById (_id) { | ||
$.ajax({ | ||
method: 'DELETE' | ||
, url: '/api/v1/entries/' + _id | ||
, headers: { | ||
'api-secret': client.hashauth.hash() | ||
} | ||
}).done(function success () { | ||
$status.text(translate('Record %1 removed ...', { params: [_id] })); | ||
}).fail(function fail() { | ||
$status.text(translate('Error removing record %1', { params: [_id] })); | ||
}); | ||
} | ||
|
||
|
||
$status.hide().text(translate('Deleting records ...')).fadeIn('slow'); | ||
for (var i = 0; i < futureitems.entriesrecords.length; i++) { | ||
deteleteRecordById(futureitems.entriesrecords[i]._id); | ||
} | ||
|
||
if (callback) { | ||
callback(); | ||
} | ||
}; |
Oops, something went wrong.