Skip to content

Home Information - Your home, your data, organized.

Python

Added console settings pane and audio state control.

Anthony Cassandraf4adc8602c35
diff --git a/src/hi/apps/config/templates/config/panes/base_page_settings.html b/src/hi/apps/config/templates/config/panes/base_page_settings.html
new file mode 100644
index 00000000..98e5497c
--- /dev/null
+++ b/src/hi/apps/config/templates/config/panes/base_page_settings.html
@@ -0,0 +1,6 @@
+<div id="hi-console-audio" style="display: none;">
+ {% for signal_name, signal_sound_url in CONSOLE_AUDIO_MAP.items %}
+ <audio id="hi-audio-signal-{{ signal_name }}" src="{{ signal_sound_url }}"
+ preload="auto" loop="true" hidden="hidden" ></audio>
+ {% endfor %}
+</div>
diff --git a/src/hi/apps/config/templates/config/panes/console_settings.html b/src/hi/apps/config/templates/config/panes/console_settings.html
index 98e5497c..0dc1050a 100644
--- a/src/hi/apps/config/templates/config/panes/console_settings.html
+++ b/src/hi/apps/config/templates/config/panes/console_settings.html
@@ -1,6 +1,27 @@
-<div id="hi-console-audio" style="display: none;">
- {% for signal_name, signal_sound_url in CONSOLE_AUDIO_MAP.items %}
- <audio id="hi-audio-signal-{{ signal_name }}" src="{{ signal_sound_url }}"
- preload="auto" loop="true" hidden="hidden" ></audio>
- {% endfor %}
+<div class="h3">Console</div>
+<div id="hi-audio-state-toggle">
+ <button id="hi-audio-state-enabled"
+ role="button"
+ style="display: none;"
+ class="btn btn-success"
+ onclick="Hi.settings.disableAudio() && $(this).hide() && $('#hi-audio-state-disabled').show();"
+ title="Sounds enabled. Click to Disable">
+ Sounds: On
+ </button>
+ <button id="hi-audio-state-disabled"
+ role="button"
+ class="btn btn-warning"
+ onclick="Hi.settings.enableAudio() && $(this).hide() && $('#hi-audio-state-enabled').show();"
+ title="Sounds disabled. Click to enable">
+ Sounds: Off
+ </button>
</div>
+<script type="text/javascript" charset="utf-8">
+ if ( Hi.settings.isAudioEnabled() ) {
+ $('#hi-audio-state-enabled').show();
+ $('#hi-audio-state-disabled').hide();
+ } else {
+ $('#hi-audio-state-enabled').hide();
+ $('#hi-audio-state-disabled').show();
+ }
+</script>
diff --git a/src/hi/apps/config/templates/config/panes/settings.html b/src/hi/apps/config/templates/config/panes/settings.html
index 5ee4c957..54bc2662 100644
--- a/src/hi/apps/config/templates/config/panes/settings.html
+++ b/src/hi/apps/config/templates/config/panes/settings.html
@@ -1,6 +1,12 @@
{% extends "config/pages/config_base.html" %}
{% block config_content %}
-<div class="h3">System Settings</div>
-{% include "config/panes/settings_form.html" %}
+<div class="row">
+ <div class="col-6">
+ {% include "config/panes/console_settings.html" %}
+ </div>
+ <div class="col-6">
+ {% include "config/panes/system_settings.html" %}
+ </div>
+</div>
{% endblock %}
diff --git a/src/hi/apps/config/templates/config/panes/system_settings.html b/src/hi/apps/config/templates/config/panes/system_settings.html
new file mode 100644
index 00000000..b94b0110
--- /dev/null
+++ b/src/hi/apps/config/templates/config/panes/system_settings.html
@@ -0,0 +1,2 @@
+<div class="h3">System</div>
+{% include "config/panes/settings_form.html" %}
diff --git a/src/hi/settings/base.py b/src/hi/settings/base.py
index 582446f9..bd9bb454 100644
--- a/src/hi/settings/base.py
+++ b/src/hi/settings/base.py
@@ -272,12 +272,13 @@ PIPELINE = {
'js/jquery-3.7.0.min.js',
'js/antinode.js',
'js/autosize.min.js',
+ 'js/main.js',
+ 'js/settings.js',
),
'output_filename': 'js/js_before_content.js',
},
'js_after_content': {
'source_filenames': (
- 'js/cookie.js',
'js/popper.min.js',
'bootstrap/js/bootstrap.js',
),
@@ -285,8 +286,6 @@ PIPELINE = {
},
'js_after_content_custom': {
'source_filenames': (
- 'js/main.js',
- 'js/settings.js',
'js/audio.js',
'js/svg-utils.js',
'js/watchdog.js',
diff --git a/src/hi/static/js/cookie.js b/src/hi/static/js/cookie.js
deleted file mode 100644
index 7f3dffde..00000000
--- a/src/hi/static/js/cookie.js
+++ /dev/null
@@ -1,151 +0,0 @@
-/*!
- * JavaScript Cookie v2.1.2
- * https://github.com/js-cookie/js-cookie
- *
- * Copyright 2006, 2015 Klaus Hartl & Fagner Brack
- * Released under the MIT license
- */
-;(function (factory) {
- if (typeof define === 'function' && define.amd) {
- define(factory);
- } else if (typeof exports === 'object') {
- module.exports = factory();
- } else {
- var OldCookies = window.Cookies;
- var api = window.Cookies = factory();
- api.noConflict = function () {
- window.Cookies = OldCookies;
- return api;
- };
- }
-}(function () {
- function extend () {
- var i = 0;
- var result = {};
- for (; i < arguments.length; i++) {
- var attributes = arguments[ i ];
- for (var key in attributes) {
- result[key] = attributes[key];
- }
- }
- return result;
- }
-
- function init (converter) {
- function api (key, value, attributes) {
- var result;
- if (typeof document === 'undefined') {
- return;
- }
-
- // Write
-
- if (arguments.length > 1) {
- attributes = extend({
- path: '/'
- }, api.defaults, attributes);
-
- if (typeof attributes.expires === 'number') {
- var expires = new Date();
- expires.setMilliseconds(expires.getMilliseconds() + attributes.expires * 864e+5);
- attributes.expires = expires;
- }
-
- try {
- result = JSON.stringify(value);
- if (/^[\{\[]/.test(result)) {
- value = result;
- }
- } catch (e) {}
-
- if (!converter.write) {
- value = encodeURIComponent(String(value))
- .replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g, decodeURIComponent);
- } else {
- value = converter.write(value, key);
- }
-
- key = encodeURIComponent(String(key));
- key = key.replace(/%(23|24|26|2B|5E|60|7C)/g, decodeURIComponent);
- key = key.replace(/[\(\)]/g, escape);
-
- return (document.cookie = [
- key, '=', value,
- attributes.expires && '; expires=' + attributes.expires.toUTCString(), // use expires attribute, max-age is not supported by IE
- attributes.path && '; path=' + attributes.path,
- attributes.domain && '; domain=' + attributes.domain,
- attributes.secure ? '; secure' : ''
- ].join(''));
- }
-
- // Read
-
- if (!key) {
- result = {};
- }
-
- // To prevent the for loop in the first place assign an empty array
- // in case there are no cookies at all. Also prevents odd result when
- // calling "get()"
- var cookies = document.cookie ? document.cookie.split('; ') : [];
- var rdecode = /(%[0-9A-Z]{2})+/g;
- var i = 0;
-
- for (; i < cookies.length; i++) {
- var parts = cookies[i].split('=');
- var cookie = parts.slice(1).join('=');
-
- if (cookie.charAt(0) === '"') {
- cookie = cookie.slice(1, -1);
- }
-
- try {
- var name = parts[0].replace(rdecode, decodeURIComponent);
- cookie = converter.read ?
- converter.read(cookie, name) : converter(cookie, name) ||
- cookie.replace(rdecode, decodeURIComponent);
-
- if (this.json) {
- try {
- cookie = JSON.parse(cookie);
- } catch (e) {}
- }
-
- if (key === name) {
- result = cookie;
- break;
- }
-
- if (!key) {
- result[name] = cookie;
- }
- } catch (e) {}
- }
-
- return result;
- }
-
- api.set = api;
- api.get = function (key) {
- return api(key);
- };
- api.getJSON = function () {
- return api.apply({
- json: true
- }, [].slice.call(arguments));
- };
- api.defaults = {};
-
- api.remove = function (key, attributes) {
- api(key, '', extend(attributes, {
- expires: -1
- }));
- };
-
- api.withConverter = init;
-
- return api;
- }
-
- return init(function () {});
-}));
diff --git a/src/hi/static/js/main.js b/src/hi/static/js/main.js
index 4244c8ba..9388107f 100644
--- a/src/hi/static/js/main.js
+++ b/src/hi/static/js/main.js
@@ -23,6 +23,12 @@
generateUniqueId: function() {
return _generateUniqueId();
},
+ setCookie: function( name, value, days = 365, sameSite = 'Lax' ) {
+ return _setCookie( name, value, days, sameSite );
+ },
+ getCookie: function( name ) {
+ return _getCookie( name );
+ },
submitForm: function( formElement ) {
return _submitForm( formElement );
},
@@ -74,6 +80,26 @@
return 'id-' + Date.now() + '-' + Math.floor(Math.random() * 1000);
}
+ function _setCookie( name, value, days, sameSite ) {
+ const expires = new Date();
+ expires.setTime( expires.getTime() + days * 24 * 60 * 60 * 1000 );
+ const secureFlag = sameSite === 'None' ? '; Secure' : '';
+ document.cookie = `${name}=${encodeURIComponent(value)}; expires=${expires.toUTCString()}; path=/; SameSite=${sameSite}${secureFlag}`;
+ return true;
+ }
+
+ function _getCookie( name ) {
+ const nameEQ = `${encodeURIComponent(name)}=`;
+ const cookies = document.cookie.split(';'); // SPlit into key-pairs
+ for ( let i = 0; i < cookies.length; i++ ) {
+ let cookie = cookies[i].trim();
+ if (cookie.startsWith( nameEQ )) {
+ return decodeURIComponent( cookie.substring( nameEQ.length ));
+ }
+ }
+ return null;
+ }
+
function _submitForm( formElement ) {
let form = $(formElement).closest('form');
if ( Hi.DEBUG ) { console.debug( 'Submitting form:', formElement, form ); }
diff --git a/src/hi/static/js/settings.js b/src/hi/static/js/settings.js
index 157c8c69..1afba056 100644
--- a/src/hi/static/js/settings.js
+++ b/src/hi/static/js/settings.js
@@ -4,13 +4,13 @@
const HiSettings = {
enableAudio: function() {
- _enableAudio( );
+ return _enableAudio( );
},
disableAudio: function() {
- _disableAudio( );
+ return _disableAudio( );
},
isAudioEnabled: function() {
- _isAudioEnabled( );
+ return _isAudioEnabled( );
}
};
@@ -27,19 +27,21 @@
const AudioStateDisabled = 'disabled';
function setConsoleSetting( name, value ) {
- $.cookie( name, value, { path: '/' } );
+ Hi.setCookie( name, value );
}
function getConsoleSetting( name ) {
- return $.cookie( name );
+ return Hi.getCookie( name );
}
function _enableAudio() {
setConsoleSetting( AudioStateSettingName, AudioStateEnabled );
+ return true;
}
function _disableAudio() {
setConsoleSetting( AudioStateSettingName, AudioStateDisabled );
+ return true;
}
function _isAudioEnabled() {
diff --git a/src/hi/static/js/status.js b/src/hi/static/js/status.js
index e25f6e42..c33e4a6f 100644
--- a/src/hi/static/js/status.js
+++ b/src/hi/static/js/status.js
@@ -59,6 +59,14 @@
if ( Hi.DEBUG ) { console.log( "Polling server..." ); }
clearServerPollingTimer();
+
+
+
+ console.log( `AUDIO ENABLED = ${Hi.settings.isAudioEnabled()}` );
+
+
+
+
let url = ServerPollingUrl;
if ( gLastServerDate ) {
const lastTimestampString = encodeURIComponent( gLastServerDate.toISOString() );
diff --git a/src/hi/templates/pages/base.html b/src/hi/templates/pages/base.html
index 0d842a25..d13c425b 100644
--- a/src/hi/templates/pages/base.html
+++ b/src/hi/templates/pages/base.html
@@ -26,7 +26,7 @@
{% block content %}{% endblock %}
- {% include "config/panes/console_settings.html" %}
+ {% include "config/panes/base_page_settings.html" %}
<div id="hi-server-error-msg">
WARNING