Browse Source

Moving UI strings to javascript

fastled
Xose Pérez 7 years ago
parent
commit
1373923758
6 changed files with 980 additions and 951 deletions
  1. BIN
      code/espurna/data/index.html.gz
  2. +1
    -1
      code/espurna/nofuss.ino
  3. +1
    -1
      code/espurna/ota.ino
  4. +948
    -937
      code/espurna/static/index.html.gz.h
  5. +8
    -8
      code/espurna/web.ino
  6. +22
    -4
      code/html/custom.js

BIN
code/espurna/data/index.html.gz View File


+ 1
- 1
code/espurna/nofuss.ino View File

@ -85,7 +85,7 @@ void nofussSetup() {
DEBUG_MSG_P(PSTR(" Firmware: %s\n"), (char *) NoFUSSClient.getNewFirmware().c_str()); DEBUG_MSG_P(PSTR(" Firmware: %s\n"), (char *) NoFUSSClient.getNewFirmware().c_str());
DEBUG_MSG_P(PSTR(" File System: %s\n"), (char *) NoFUSSClient.getNewFileSystem().c_str()); DEBUG_MSG_P(PSTR(" File System: %s\n"), (char *) NoFUSSClient.getNewFileSystem().c_str());
#if WEB_SUPPORT #if WEB_SUPPORT
wsSend_P(PSTR("{\"message\": \"Remote update started\"}"));
wsSend_P(PSTR("{\"message\": 1}"));
#endif #endif
} }


+ 1
- 1
code/espurna/ota.ino View File

@ -25,7 +25,7 @@ void otaSetup() {
ArduinoOTA.onStart([]() { ArduinoOTA.onStart([]() {
DEBUG_MSG_P(PSTR("[OTA] Start\n")); DEBUG_MSG_P(PSTR("[OTA] Start\n"));
#if WEB_SUPPORT #if WEB_SUPPORT
wsSend_P(PSTR("{\"message\": \"OTA update started\"}"));
wsSend_P(PSTR("{\"message\": 2}"));
#endif #endif
}); });


+ 948
- 937
code/espurna/static/index.html.gz.h
File diff suppressed because it is too large
View File


+ 8
- 8
code/espurna/web.ino View File

@ -73,7 +73,7 @@ void _wsParse(uint32_t client_id, uint8_t * payload, size_t length) {
JsonObject& root = jsonBuffer.parseObject((char *) payload); JsonObject& root = jsonBuffer.parseObject((char *) payload);
if (!root.success()) { if (!root.success()) {
DEBUG_MSG_P(PSTR("[WEBSOCKET] Error parsing data\n")); DEBUG_MSG_P(PSTR("[WEBSOCKET] Error parsing data\n"));
wsSend_P(client_id, PSTR("{\"message\": \"Error parsing data!\"}"));
wsSend_P(client_id, PSTR("{\"message\": 3}"));
return; return;
} }
@ -108,7 +108,7 @@ void _wsParse(uint32_t client_id, uint8_t * payload, size_t length) {
JsonObject& data = root["data"]; JsonObject& data = root["data"];
if (!data.containsKey("app") || (data["app"] != APP_NAME)) { if (!data.containsKey("app") || (data["app"] != APP_NAME)) {
wsSend_P(client_id, PSTR("{\"message\": \"The file does not look like a valid configuration backup.\"}"));
wsSend_P(client_id, PSTR("{\"message\": 4}"));
return; return;
} }
@ -124,7 +124,7 @@ void _wsParse(uint32_t client_id, uint8_t * payload, size_t length) {
saveSettings(); saveSettings();
wsSend_P(client_id, PSTR("{\"message\": \"Changes saved. You should reboot your board now.\"}"));
wsSend_P(client_id, PSTR("{\"message\": 5}"));
} }
@ -171,7 +171,7 @@ void _wsParse(uint32_t client_id, uint8_t * payload, size_t length) {
String value = root["data"]; String value = root["data"];
setSetting("haPrefix", value); setSetting("haPrefix", value);
haSend(); haSend();
wsSend_P(client_id, PSTR("{\"message\": \"Home Assistant auto-discovery message sent.\"}"));
wsSend_P(client_id, PSTR("{\"message\": 6}"));
} }
#endif #endif
@ -289,7 +289,7 @@ void _wsParse(uint32_t client_id, uint8_t * payload, size_t length) {
} }
if (key == "adminPass2") { if (key == "adminPass2") {
if (!value.equals(adminPass)) { if (!value.equals(adminPass)) {
wsSend_P(client_id, PSTR("{\"message\": \"Passwords do not match!\"}"));
wsSend_P(client_id, PSTR("{\"message\": 7}"));
return; return;
} }
if (value.length() == 0) continue; if (value.length() == 0) continue;
@ -396,9 +396,9 @@ void _wsParse(uint32_t client_id, uint8_t * payload, size_t length) {
} }
if (changed) { if (changed) {
wsSend_P(client_id, PSTR("{\"message\": \"Changes saved\"}"));
wsSend_P(client_id, PSTR("{\"message\": 8}"));
} else { } else {
wsSend_P(client_id, PSTR("{\"message\": \"No changes detected\"}"));
wsSend_P(client_id, PSTR("{\"message\": 9}"));
} }
} }
@ -663,7 +663,7 @@ bool _wsAuth(AsyncWebSocketClient * client) {
if (index == WS_BUFFER_SIZE) { if (index == WS_BUFFER_SIZE) {
DEBUG_MSG_P(PSTR("[WEBSOCKET] Validation check failed\n")); DEBUG_MSG_P(PSTR("[WEBSOCKET] Validation check failed\n"));
wsSend_P(client->id(), PSTR("{\"message\": \"Session expired, please reload page...\"}"));
wsSend_P(client->id(), PSTR("{\"message\": 10}"));
return false; return false;
} }


+ 22
- 4
code/html/custom.js View File

@ -2,6 +2,8 @@ var websock;
var password = false; var password = false;
var maxNetworks; var maxNetworks;
var useWhite = false; var useWhite = false;
var messages = [];
var webhost;
// http://www.the-art-of-web.com/javascript/validate-password/ // http://www.the-art-of-web.com/javascript/validate-password/
function checkPassword(str) { function checkPassword(str) {
@ -90,7 +92,7 @@ function doUpgrade() {
$.ajax({ $.ajax({
// Your server script to process the upload // Your server script to process the upload
url: window.location.href + 'upgrade',
url: webhost + 'upgrade',
type: 'POST', type: 'POST',
// Form data // Form data
@ -165,7 +167,7 @@ function doToggle(element, value) {
} }
function backupSettings() { function backupSettings() {
document.getElementById('downloader').src = window.location.href + 'config';
document.getElementById('downloader').src = webhost + 'config';
return false; return false;
} }
@ -185,7 +187,7 @@ function onFileUpload(event) {
if (data) { if (data) {
websock.send(JSON.stringify({'action': 'restore', 'data': data})); websock.send(JSON.stringify({'action': 'restore', 'data': data}));
} else { } else {
alert("The file is not a configuration backup or is corrupted");
alert(messages[4]);
} }
}; };
reader.readAsText(inputFile); reader.readAsText(inputFile);
@ -610,7 +612,7 @@ function processData(data) {
// Messages // Messages
if (key == "message") { if (key == "message") {
window.alert(data.message);
window.alert(messages[data.message]);
return; return;
} }
@ -694,6 +696,7 @@ function connect(host) {
host = 'http://' + host + '/'; host = 'http://' + host + '/';
} }
} }
webhost = host;
wshost = host.replace('http', 'ws') + 'ws'; wshost = host.replace('http', 'ws') + 'ws';
if (websock) websock.close(); if (websock) websock.close();
@ -713,8 +716,23 @@ function connect(host) {
}; };
} }
function initMessages() {
messages[01] = "Remote update started";
messages[02] = "OTA update started";
messages[03] = "Error parsing data!";
messages[04] = "The file does not look like a valid configuration backup or is corrupted";
messages[05] = "Changes saved. You should reboot your board now";
messages[06] = "Home Assistant auto-discovery message sent";
messages[07] = "Passwords do not match!";
messages[08] = "Changes saved";
messages[09] = "No changes detected";
messages[10] = "Session expired, please reload page...";
}
function init() { function init() {
initMessages();
$("#menuLink").on('click', toggleMenu); $("#menuLink").on('click', toggleMenu);
$(".button-update").on('click', doUpdate); $(".button-update").on('click', doUpdate);
$(".button-update-password").on('click', doUpdatePassword); $(".button-update-password").on('click', doUpdatePassword);


Loading…
Cancel
Save