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

Make reports available to all #970

Merged
merged 66 commits into from
Sep 7, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
257cb4a
extracted needed files
MilosKozak Aug 26, 2015
5951797
added report files
MilosKozak Aug 27, 2015
e94aa85
make it at least load without errors
MilosKozak Aug 27, 2015
f3115f2
some renames
MilosKozak Aug 28, 2015
df0b8dc
make reports plugins
MilosKozak Aug 28, 2015
a837f22
removed tabulators, fixed idents
MilosKozak Aug 28, 2015
f61a772
doublequotes to quotes
MilosKozak Aug 28, 2015
e3cb1da
=== and !==
MilosKozak Aug 28, 2015
1e16946
maybePreventDefault
MilosKozak Aug 28, 2015
643cf00
if brackets
MilosKozak Aug 28, 2015
fd224a2
codacy pass 1
MilosKozak Aug 28, 2015
9146949
codacy pass 2
MilosKozak Aug 28, 2015
2fdb03b
codacy pass 3
MilosKozak Aug 28, 2015
03e1652
make html plugin's code dymnamicaly injected on load
MilosKozak Aug 29, 2015
4129a29
codacy pass 4
MilosKozak Aug 29, 2015
bd4b72e
restore replaced new code in treatments.js
MilosKozak Aug 29, 2015
56ae37c
rebase changes
MilosKozak Aug 30, 2015
2a24bc4
allow regex in query
MilosKozak Aug 30, 2015
11283be
.x -> .mills everywhere to make calibration.js work
MilosKozak Aug 30, 2015
b1cc6b1
units passed with options
MilosKozak Aug 30, 2015
c78e9b0
plugin.html must be a function(client) to be correctly translated wit…
MilosKozak Aug 30, 2015
f8079d4
require not needed anymore
MilosKozak Aug 30, 2015
549933a
codacy pass 5
MilosKozak Aug 30, 2015
89f184a
gui improvements
MilosKozak Aug 30, 2015
e1c5977
make careportal events dynamic
MilosKozak Aug 30, 2015
db784e5
careportal test fix
MilosKozak Aug 30, 2015
69c0121
careportal codacy fix
MilosKozak Aug 30, 2015
3ac1c71
reuse careportal's event list in reports
MilosKozak Aug 30, 2015
907f22d
fixed bug in processing request response
MilosKozak Aug 30, 2015
555fdca
resolved translation issue between eventType value and text in dropdo…
MilosKozak Aug 30, 2015
d995465
... and removed from todo
MilosKozak Aug 30, 2015
a765c04
updated fontello icons
MilosKozak Aug 30, 2015
8a0e7de
make treatments report working
MilosKozak Aug 30, 2015
5e34975
Merge pull request #870 from MilosKozak/wip/reports
MilosKozak Aug 30, 2015
3702e55
food html code not hidden properly fix
MilosKozak Aug 31, 2015
72d66e5
Fixed bug drawing was called multiple times
MilosKozak Aug 31, 2015
10ddbe1
Merge pull request #879 from MilosKozak/wip/reports
MilosKozak Aug 31, 2015
55e8d92
translation fix in dailystats
MilosKozak Aug 31, 2015
f2e047f
optimized merging data in reports
MilosKozak Aug 31, 2015
0cbdf57
added missing translation
MilosKozak Aug 31, 2015
57fe7dc
TREATMENT_AUTH handling, added authentication status to careportal
MilosKozak Aug 31, 2015
2d5e8f3
fixed mock func in test
MilosKozak Aug 31, 2015
8728f0b
treatments edit/save needed changes, XMLHttp -> $.ajax
MilosKozak Aug 31, 2015
81179a6
Merge pull request #880 from MilosKozak/wip/reports
MilosKozak Sep 1, 2015
344b069
codacy pass 6
MilosKozak Sep 4, 2015
c0bca7a
Merge pull request #917 from MilosKozak/wip/reports
MilosKozak Sep 4, 2015
f42df17
treatments.js refactoring
MilosKozak Sep 4, 2015
8df2a73
more treatments.js refactoring
MilosKozak Sep 4, 2015
84259d9
even more treatments.js refactoring
MilosKozak Sep 4, 2015
32e99c9
Merge pull request #918 from MilosKozak/wip/reports
MilosKozak Sep 4, 2015
816caa2
fix mg/dl vs mg/dL issue
MilosKozak Sep 4, 2015
2f64c15
Merge pull request #926 from MilosKozak/wip/reports
MilosKozak Sep 4, 2015
68cf970
use profile timezone
MilosKozak Sep 4, 2015
c5b4b3d
Merge pull request #928 from MilosKozak/wip/reports
MilosKozak Sep 4, 2015
bbe760a
1 day shift fix
MilosKozak Sep 4, 2015
7dc6af6
Merge pull request #929 from MilosKozak/wip/reports
MilosKozak Sep 4, 2015
2164ea2
fixed day name too
MilosKozak Sep 5, 2015
b9f69a8
Merge pull request #931 from MilosKozak/wip/reports
MilosKozak Sep 5, 2015
1ab11de
another date issue
MilosKozak Sep 5, 2015
29a6541
Merge pull request #939 from MilosKozak/wip/reports
MilosKozak Sep 5, 2015
6f10f4d
solved axis timezone issues
MilosKozak Sep 6, 2015
47d3ab5
removed unneeded code
MilosKozak Sep 6, 2015
8a1fbe9
improved 12h axis format
MilosKozak Sep 6, 2015
03529c5
Merge pull request #953 from MilosKozak/wip/reports
MilosKozak Sep 6, 2015
cd3f273
merge in dev, update icon for report page
jasoncalabrese Sep 7, 2015
de1f000
get thresholds from settings
jasoncalabrese Sep 7, 2015
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ To learn more about the Nightscout API, visit https://YOUR-SITE.com/api-docs.htm
* `ENABLE` - Used to enable optional features, expects a space delimited list, such as: `careportal rawbg iob`, see [plugins](#plugins) below
* `DISABLE` - Used to disable default features, expects a space delimited list, such as: `direction upbat`, see [plugins](#plugins) below
* `API_SECRET` - A secret passphrase that must be at least 12 characters long, required to enable `POST` and `PUT`; also required for the Care Portal
* `TREATMENTS_AUTH` (`off`) - possible values `on` or `off`. When on device must be authenticated by entering `API_SECRET` to create treatments


### Alarms
Expand Down
2 changes: 2 additions & 0 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
"jQuery-Storage-API": "~1.7.2",
"tipsy-jmalonzo": "~1.0.1",
"jquery-ui": "~1.11.3",
"jquery-flot": "0.8.3",
"simple-statistics": "0.7.0",
"swagger-ui": "~2.1.2"
},
"resolutions": {
Expand Down
1 change: 1 addition & 0 deletions bundle/bundle.source.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
client: require('../lib/client')
, units: require('../lib/units')()
, plugins: require('../lib/plugins/')().registerClientDefaults()
, report_plugins: require('../lib/report_plugins/')()
};

console.info('Nightscout bundle ready');
Expand Down
3 changes: 3 additions & 0 deletions env.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ function config ( ) {
setMongo();
updateSettings();

// require authorization for entering treatments
env.treatments_auth = readENV('TREATMENTS_AUTH',false);

return env;
}

Expand Down
2 changes: 2 additions & 0 deletions lib/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ function create (env, ctx) {

app.set('title', [app.get('name'), 'API', app.get('version')].join(' '));

app.set('treatments_auth', env.treatments_auth);

// Start setting up routes
if (app.enabled('api')) {
// experiments
Expand Down
28 changes: 27 additions & 1 deletion lib/api/treatments/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,43 @@ function configure (app, wares, ctx) {

function config_authed (app, api, wares, ctx) {

api.post('/treatments/', /*TODO: auth disabled for now, need to get login figured out... wares.verifyAuthorization, */ function(req, res) {
function post_response(req, res) {
var treatment = req.body;
ctx.treatments.create(treatment, function (err, created) {
if (err) {
console.log('Error adding treatment');
res.sendJSONStatus(res, consts.HTTP_INTERNAL_ERROR, 'Mongo Error', err);
} else {
console.log('Treatment created');
res.json(created);
}
});
}
if (app.settings.treatments_auth) {
api.post('/treatments/', wares.verifyAuthorization, post_response);
} else {
api.post('/treatments/', post_response);
}
api.delete('/treatments/:_id', wares.verifyAuthorization, function(req, res) {
ctx.treatments.remove(req.params._id, function ( ) {
res.json({ });
});
});

// update record
api.put('/treatments/', wares.verifyAuthorization, function(req, res) {
var data = req.body;
ctx.treatments.save(data, function (err, created) {
if (err) {
res.sendJSONStatus(res, consts.HTTP_INTERNAL_ERROR, 'Mongo Error', err);
console.log('Error saving treatment');
console.log(err);
} else {
res.json(created);
console.log('Treatment saved', data);
}
});
});
}

if (app.enabled('api') && app.enabled('careportal')) {
Expand Down
36 changes: 34 additions & 2 deletions lib/client/careportal.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,31 @@
'use strict';

var moment = require('moment-timezone');
var _ = require('lodash');

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

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

careportal.events = [
{ val: 'BG Check', name: 'BG Check' }
, { val: 'Snack Bolus', name: 'Snack Bolus' }
, { val: 'Meal Bolus', name: 'Meal Bolus' }
, { val: 'Correction Bolus', name: 'Correction Bolus' }
, { val: 'Carb Correction', name: 'Carb Correction' }
, { val: 'Announcement', name: 'Announcement' }
, { val: 'Note', name: 'Note' }
, { val: 'Question', name: 'Question' }
, { val: 'Exercise', name: 'Exercise' }
, { val: 'Site Change', name: 'Pump Site Change' }
, { val: 'Sensor Start', name: 'Dexcom Sensor Start' }
, { val: 'Sensor Change', name: 'Dexcom Sensor Change' }
, { val: 'Insulin Change', name: 'Insulin Cartridge Change' }
, { val: 'D.A.D. Alert', name: 'D.A.D. Alert' }
];

var eventTime = $('#eventTimeValue');
var eventDate = $('#eventDateValue');

Expand All @@ -32,7 +50,15 @@ function init (client, $) {
}
}

careportal.prepareEvents = function prepareEvents ( ) {
$('#eventType').empty();
_.each(careportal.events, function eachEvent(event) {
$('#eventType').append('<option value="' + event.val+ '">' + translate(event.name) + '</option>');
});
};

careportal.prepare = function prepare ( ) {
careportal.prepareEvents();
$('#eventType').val('BG Check');
$('#glucoseValue').val('').attr('placeholder', translate('Value in') + ' ' + client.settings.units);
$('#meter').prop('checked', true);
Expand Down Expand Up @@ -100,10 +126,16 @@ function init (client, $) {
if (window.confirm(buildConfirmText(data))) {
$.ajax({
method: 'POST',
url: '/api/v1/treatments/',
data: data
url: '/api/v1/treatments/'
, headers: {
'api-secret': client.hashauth.hash()
}
, data: data
}).done(function treatmentSaved (response) {
console.info('treatment saved', response);
}).fail(function treatmentSaveFail (response) {
console.info('treatment saved', response);
alert(translate('Entering record failed') + '. ' + translate('Status') + ': ' + response.status);
});

storage.set('enteredBy', data.enteredBy);
Expand Down
16 changes: 0 additions & 16 deletions lib/language.js
Original file line number Diff line number Diff line change
Expand Up @@ -506,21 +506,6 @@ function init() {
,fi: 'Merkinnät sisältävät'
,nb: 'Notater inneholder'
}
,'Event type contains' : {
cs: 'Typ události obsahuje'
,de: 'Ereignis-Typ beinhaltet'
,es: 'Contenido del tipo de evento'
,fr: 'Type d\'événement contient'
,pt: 'Tipo de evento contém'
,ro: 'Conținut tip de eveniment'
,bg: 'Типа събитие включва'
,hr: 'Sadržaj vrste događaja'
,sv: 'Händelsen innehåller'
,it: 'Contiene evento'
,dk: 'Hændelsen indeholder'
,fi: 'Tapahtuman tyyppi sisältää'
,nb: 'Hendelsen inneholder'
}
,'Target bg range bottom' : {
cs: 'Cílová glykémie spodní'
,de: 'Untergrenze des Blutzuckerzielbereiches'
Expand Down Expand Up @@ -3920,7 +3905,6 @@ function init() {
}
,'Update' : { // Update button
cs: 'Aktualizovat'
,fi: 'Päivitys'
}

};
Expand Down
6 changes: 5 additions & 1 deletion lib/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,11 @@ function walk_prop (prop, typer) {
}

function parseRegEx (str) {
return new RegExp(str);
var regtest = /\/(.*)\/(.*)/.exec(str);
if (regtest) {
return new RegExp(regtest[1],regtest[2]);
}
return str;
}

// attach helpers and utilities to main function for testing
Expand Down
Loading