-
Notifications
You must be signed in to change notification settings - Fork 72.8k
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
Conversation
Add .npmignore file
Make authentication dialog bigger to suit for other languages.
|
Not sure this needs a .npmignore? Also, see https://medium.com/@jdxcode/for-the-love-of-god-dont-use-npmignore-f93c08909d8d |
|
There are tons of changes in here — can you elaborate please on exactly what functionality has been added and/or altered? |
lib/client/index.js
Outdated
| language.set('en'); | ||
|
|
||
| // detect browser language | ||
| var lang = (navigator.language || navigator.userLanguage).toLowerCase(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For language, you should check the client preferences on the language picked in the UI in the main view. Nightscout explicitly does not use the browser language detection
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
@unsoluble I read through the changes and everything except for the language auto-detection and the .npmignore look like they're good to go. This fixes the clock views not working on instances that don't allow API reads without authentication. |
And get suitable language for the very first auth dialog (before the settings were read from server or user can select language in the configuration)
| language.set('en'); | ||
|
|
||
| // detect browser language | ||
| var lang = Storages.localStorage.get('language') || (navigator.language || navigator.userLanguage).toLowerCase(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I changed it. Please don't forget that for the VERY FIRST authentication dialog it is better to show it in the browser language, than in english.
E.g. my browser language is german and I would like to see the auth dialog in german.
|
Will it be merged or I should split it? (what will costs me time :) ) |
The author forgot to write ".npmrc" into .npmignore and wrote the whole article about it on medium. Don't believe in everything what is written in internet. The authors there are just like you and me. :) |
|
|
||
| // 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'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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.
|
|
||
| // 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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just number validation.
lib/client/clock-client.js
Outdated
| if (timeDivisor == 12) { | ||
| h = (h == 0) ? 12 : h; // In the case of 00:xx, change to 12:xx for 12h time | ||
| if (timeDivisor === 12) { | ||
| h = h || 12; // In the case of 00:xx, change to 12:xx for 12h time |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Formatting
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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 ==
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed on my branch
| // defined in the template this is loaded into | ||
| // eslint-disable-next-line no-undef | ||
| if (clockFace == 'clock-color') { | ||
| if (clockFace === 'clock-color') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Formatting
| , height: 240 | ||
| width: 400 | ||
| , height: 270 | ||
| , closeText: '' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make an auth dialog a little bit bigger, because in other languages the text is longer and scroll bars appear.
| , buttons: [ | ||
| { | ||
| text: translate('Update') | ||
| id: 'requestauthenticationdialog-btn' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Search is better by ID than $(this).parent().find('button.ui-button-text-only')
| ] | ||
| , open: function open ( ) { | ||
| $('#requestauthenticationdialog').keypress(function pressed (e) { | ||
| $('#apisecret').off('keyup').on('keyup' ,function pressed (e) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Install handler only on INPUT element and not on the whole dialog.
| '<div id="requestauthenticationdialog" style="display:none" title="'+translate('Device authentication')+'">'+ | ||
| '<label for="apisecret">'+translate('Your API secret')+': </label>'+ | ||
| '<input type="password" id="apisecret" size="20" />'+ | ||
| '<input type="password" id="apisecret" size="20" style="width: 100%;"/>'+ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make a secret input element to be a full width, because the secret could be longer than 20 chars.
|
|
||
| language.languages.forEach(function (l) { | ||
| if (l.code == language.lang && l.speechCode) language.speechCode = l.speechCode; | ||
| if (l.code === language.lang && l.speechCode) language.speechCode = l.speechCode; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Formatting
| <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> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a HTML w3c requirement. Alt should be in every "img"
| }; | ||
| script.src = src; | ||
|
|
||
| document.head.appendChild(script); //or something of the likes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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.
|
Thanks for all the notes. Was really just wanting to know if any other functionality was affected, but appreciate the details. :) |
views/clockviews/shared.html
Outdated
| <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> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please cherry pick PieterGit@e143142
|
@GermanBluefox Thanks for your contributions. I tested this and did a code review of the changes. I don't understand how you have managed to test this ok, without removing the extra I'm sure you and @sulkaharo can find a solution on whether to keep or remove the |
|
Weird, I thought I posted a long piece here about the .npmignore. The main reason I'd prefer not having it is, given it's a file blacklist, the package maintainers will have to remember to consider the blacklist for every commit to the repository, while a whitelist approach would mean we detect something breaks if a mistake is made. As someone who's been looking after this repo for some years, I really want to reduce the maintenance effort as much as possible, so any new code that comes in should do everything possible to the least additional effort on maintenance. (Related - we should talk about how / where / when / why to release nightscout as a npm package. If it's done, it should be done from the original repo using the Nightscout org. |
|
merged with #4914 (without npmignore) |
|
@sulkaharo Your reaction on npmignore is #4860 (comment) here. Based on the article I wrote #4860 (comment) @GermanBluefox @sulkaharo agree to close this issue? |
It is Ok. |

Add .npmignore file