-
Notifications
You must be signed in to change notification settings - Fork 73.1k
Fix clock if authentication is enabled #4860
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
Changes from 1 commit
3c25914
366d10c
3a52cac
d61e8f9
050808d
ccad081
293ac55
afbe6a3
d361a72
bd42ad8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
Add .npmignore file
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| .github | ||
| bin | ||
| docs | ||
| node_modules | ||
| testing | ||
| tests | ||
| .deployment | ||
| .dockerignore | ||
| .eslintrc.js | ||
| .gitattributes | ||
| .gitignore | ||
| .jsbeautifyrc | ||
| .nvmrc | ||
| .travis.yml | ||
| .npmignore | ||
| azuredeploy.json | ||
| CONTRIBUTING.md | ||
| deploy.sh | ||
| Dockerfile.example | ||
| example-profiles.md | ||
| Makefile | ||
| my.env.template | ||
| prep_repo_release.sh | ||
| Procfile | ||
| setup.sh | ||
| Vagrantfile |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,10 +11,27 @@ client.settings = browserSettings(client, window.serverSettings, $); | |
|
|
||
| client.query = function query () { | ||
| console.log('query'); | ||
| $.ajax('/api/v1/entries.json?count=3', { | ||
| var parts = (location.search || '?').substring(1).split('&'); | ||
| var token = ''; | ||
| parts.forEach(function (val) { | ||
| if (val.startsWith('token=')) { | ||
| token = val.substring('token='.length); | ||
| } | ||
| }); | ||
|
|
||
| var secret = localStorage.getItem('apisecrethash'); | ||
| var src = '/api/v1/entries.json?count=3&t=' + new Date().getTime(); | ||
|
|
||
| if (secret) { | ||
| src += '&secret=' + secret; | ||
| } else if (token) { | ||
| src += '&token=' + token; | ||
| } | ||
|
|
||
| $.ajax(src, { | ||
|
PieterGit marked this conversation as resolved.
|
||
| success: client.render | ||
| }); | ||
| } | ||
| }; | ||
|
PieterGit marked this conversation as resolved.
|
||
|
|
||
| client.render = function render (xhr) { | ||
| console.log('got data', xhr); | ||
|
|
@@ -32,7 +49,7 @@ client.render = function render (xhr) { | |
| let now = new Date(); | ||
|
|
||
| // Convert BG to mmol/L if necessary. | ||
| if (window.serverSettings.settings.units == 'mmol') { | ||
| if (window.serverSettings.settings.units === 'mmol') { | ||
| var displayValue = window.Nightscout.units.mgdlToMMOL(rec.sgv); | ||
|
PieterGit marked this conversation as resolved.
|
||
| } else { | ||
| displayValue = rec.sgv; | ||
|
|
@@ -42,7 +59,7 @@ client.render = function render (xhr) { | |
| $('#bgnow').html(displayValue); | ||
|
|
||
| // Insert the trend arrow. | ||
| $('#arrow').attr('src', '/images/' + rec.direction + '.svg'); | ||
| $('#arrow').attr('src', '/images/' + (!rec.direction || rec.direction === 'NOT COMPUTABLE' ? 'NONE' : rec.direction) + '.svg'); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If calculation cannot be done, so invalid icon was shown. This will fix the icon. |
||
|
|
||
| // Time before data considered stale. | ||
| let staleMinutes = 13; | ||
|
|
@@ -52,13 +69,13 @@ client.render = function render (xhr) { | |
| $('#bgnow').toggleClass('stale', (now - last > threshold)); | ||
|
|
||
| // Generate and insert the clock. | ||
| let timeDivisor = (client.settings.timeFormat) ? client.settings.timeFormat : 12; | ||
| let timeDivisor = parseInt(client.settings.timeFormat ? client.settings.timeFormat : 12, 10); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just number validation. |
||
| let today = new Date() | ||
| , h = today.getHours() % timeDivisor; | ||
| if (timeDivisor == 12) { | ||
| h = (h == 0) ? 12 : h; // In the case of 00:xx, change to 12:xx for 12h time | ||
| , h = today.getHours() % timeDivisor; | ||
| if (timeDivisor === 12) { | ||
| h = h || 12; // In the case of 00:xx, change to 12:xx for 12h time | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Formatting
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not only formatting. For h == 4 this will be changed to h==12. Please restore old behaviour, perhaps with === instead of ==
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed on my branch |
||
| } | ||
| if (timeDivisor == 24) { | ||
| if (timeDivisor === 24) { | ||
| h = (h < 10) ? ("0" + h) : h; // Pad the hours with a 0 in 24h time | ||
| } | ||
| let m = today.getMinutes(); | ||
|
|
@@ -67,14 +84,14 @@ client.render = function render (xhr) { | |
|
|
||
| var queryDict = {}; | ||
| location.search.substr(1).split("&").forEach(function(item) { queryDict[item.split("=")[0]] = item.split("=")[1] }); | ||
|
|
||
| if (!window.serverSettings.settings.showClockClosebutton || !queryDict['showClockClosebutton']) { | ||
| $('#close').css('display', 'none'); | ||
| } | ||
|
|
||
| // defined in the template this is loaded into | ||
| // eslint-disable-next-line no-undef | ||
| if (clockFace == 'clock-color') { | ||
| if (clockFace === 'clock-color') { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Formatting |
||
|
|
||
| var bgHigh = window.serverSettings.settings.thresholds.bgHigh; | ||
| var bgLow = window.serverSettings.settings.thresholds.bgLow; | ||
|
|
@@ -138,12 +155,12 @@ client.render = function render (xhr) { | |
| $('#arrow').css('filter', 'brightness(100%)'); | ||
| } | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| client.init = function init () { | ||
| console.log('init'); | ||
| client.query(); | ||
| setInterval(client.query, 1 * 60 * 1000); | ||
| } | ||
| }; | ||
|
|
||
| module.exports = client; | ||
| module.exports = client; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,9 +3,9 @@ | |
| <head> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
| <meta name="apple-mobile-web-app-capable" content="yes"> | ||
|
|
||
| <title>Nightscout</title> | ||
|
|
||
| <link href="/images/round1.png" rel="icon" id="favicon" type="image/png" /> | ||
| <link rel="apple-touch-icon" sizes="57x57" href="/images/apple-touch-icon-57x57.png"> | ||
| <link rel="apple-touch-icon" sizes="60x60" href="/images/apple-touch-icon-60x60.png"> | ||
|
|
@@ -16,11 +16,11 @@ | |
| <link rel="apple-touch-icon" sizes="144x144" href="/images/apple-touch-icon-144x144.png"> | ||
| <link rel="apple-touch-icon" sizes="152x152" href="/images/apple-touch-icon-152x152.png"> | ||
| <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-180x180.png"> | ||
|
|
||
| <style type="text/css"> | ||
| @import url("//fonts.googleapis.com/css?family=Open+Sans:700"); | ||
| @import url("//fonts.googleapis.com/css?family=Open+Sans:700"); | ||
| <%- include(face + '.css', {}); %> | ||
|
|
||
| </style> | ||
| </head> | ||
|
|
||
|
|
@@ -30,19 +30,40 @@ | |
| <div class="inner"> | ||
| <div id="trend"> | ||
| <div id="bgnow"></div> | ||
| <div id="arrowDiv"><img id="arrow" src=""/></div> | ||
| <div id="arrowDiv"><img id="arrow" src="" alt="arrow"/></div> | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just a HTML w3c requirement. Alt should be in every "img" |
||
| </div> | ||
| <div id="clock"></div> | ||
| <div id="staleTime"></div> | ||
| </div> | ||
| </main> | ||
|
|
||
| <script src="/api/v1/status.js"></script> | ||
| <script src="<%= locals.bundle %>/js/bundle.clock.js?v=<%= locals.cachebuster %>"></script> | ||
|
|
||
| <script src="/<%= locals.bundle %>/js/bundle.clock.js?v=<%= locals.cachebuster %>"></script> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please cherry pick PieterGit@e143142 |
||
|
|
||
| <script type="text/javascript"> | ||
| let clockFace = "<%= face %>"; // can now be used in scripts | ||
| window.Nightscout.client.init( ); | ||
| var clockFace = "<%= face %>"; // can now be used in scripts | ||
|
|
||
| var parts = (location.search || '?').substring(1).split('&'); | ||
| var token = ''; | ||
| parts.forEach(function (val) { | ||
| if (val.startsWith('token=')) { | ||
| token = val.substring('token='.length); | ||
| } | ||
| }); | ||
|
|
||
| var secret = typeof localStorage !== 'undefined' ? localStorage.getItem('apisecrethash') : ''; | ||
| var src = '/api/v1/status.js?t=' + Date.now(); | ||
|
|
||
| if (secret) { | ||
| src += '&secret=' + secret; | ||
| } else if (token) { | ||
| src += '&token=' + token; | ||
| } | ||
|
|
||
| var script = document.createElement('script'); | ||
| script.onload = function () { | ||
| window.Nightscout.client.init( ); | ||
| }; | ||
| script.src = src; | ||
|
|
||
| document.head.appendChild(script); //or something of the likes | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Load JSON with token or secret for the case that authentication is enabled. There is still an open case if the user starts directly to work with clock view without calling the index.html. In this case no authentication dialog will be shown. But I don't know such a use case. In this case the user can use token. |
||
| </script> | ||
| </body> | ||
| </html> | ||
| </html> | ||

Uh oh!
There was an error while loading. Please reload this page.