1
0
mirror of https://github.com/s00500/ESPUI.git synced 2026-01-16 18:46:21 +00:00

undo whitespace changes

This commit is contained in:
Mike Burton
2025-11-29 08:49:45 -08:00
parent dbb8774e93
commit a05bbb6d9f

91
data/js/controls.js vendored
View File

@@ -225,8 +225,8 @@ function handleVisibilityChange() {
function start() { function start() {
let location = window.location.hostname; let location = window.location.hostname;
let port = window.location.port; let port = window.location.port;
// let location = "192.168.10.198"; // let location = "192.168.10.198";
// let port = ""; // let port = "";
document.addEventListener("visibilitychange", handleVisibilityChange, false); document.addEventListener("visibilitychange", handleVisibilityChange, false);
if ( if (
@@ -234,7 +234,7 @@ function start() {
port != 80 || port != 80 ||
port != 443 port != 443
) { ) {
websock = new WebSocket("ws://" + location + ":" + port + "/ws"); websock = new WebSocket( "ws://" + location + ":" + port + "/ws" );
} else { } else {
websock = new WebSocket("ws://" + location + "/ws"); websock = new WebSocket("ws://" + location + "/ws");
} }
@@ -370,9 +370,9 @@ function start() {
if (data.visible) addToHTML(data); if (data.visible) addToHTML(data);
break; break;
/* /*
These elements must call additional functions after being added to the DOM These elements must call additional functions after being added to the DOM
*/ */
case UI_BUTTON: case UI_BUTTON:
if (data.visible) { if (data.visible) {
addToHTML(data); addToHTML(data);
@@ -482,11 +482,11 @@ function start() {
// Add touch and click handlers for tab // Add touch and click handlers for tab
$("#tablink" + data.id).on({ $("#tablink" + data.id).on({
touchend: function (e) { touchend: function(e) {
e.preventDefault(); e.preventDefault();
tabclick(data.id); tabclick(data.id);
}, },
mouseup: function (e) { mouseup: function(e) {
tabclick(data.id); tabclick(data.id);
} }
}); });
@@ -592,12 +592,12 @@ function start() {
break; break;
case UI_FILEDISPLAY: case UI_FILEDISPLAY:
if (data.visible) { if (data.visible)
{
addToHTML(data); addToHTML(data);
FileDisplayUploadFile(data); FileDisplayUploadFile(data);
} }
break; break;
/* /*
* Update messages change the value/style of a component without adding new HTML * Update messages change the value/style of a component without adding new HTML
*/ */
@@ -691,7 +691,8 @@ function start() {
// console.info("UI_FRAGMENT:Arrived '" + Arrived + "'"); // console.info("UI_FRAGMENT:Arrived '" + Arrived + "'");
// console.info("UI_FRAGMENT:FragmentFinal '" + FragmentFinal + "'"); // console.info("UI_FRAGMENT:FragmentFinal '" + FragmentFinal + "'");
if (!data.hasOwnProperty('control')) { if (!data.hasOwnProperty('control'))
{
console.error("UI_FRAGMENT:Missing control record, skipping control"); console.error("UI_FRAGMENT:Missing control record, skipping control");
// console.info("Done Fragment Processing"); // console.info("Done Fragment Processing");
break; break;
@@ -700,21 +701,23 @@ function start() {
StopFragmentAssemblyTimer(data.control.id); StopFragmentAssemblyTimer(data.control.id);
// is this the first fragment? // is this the first fragment?
if (0 === FragementOffset) { if(0 === FragementOffset)
{
// console.info("Found first fragment"); // console.info("Found first fragment");
controlAssemblyArray[control.id] = data; controlAssemblyArray[control.id] = data;
// console.info("Value: " + controlAssemblyArray[control.id].control.value); // console.info("Value: " + controlAssemblyArray[control.id].control.value);
controlAssemblyArray[control.id].offset = NextFragmentOffset; controlAssemblyArray[control.id].offset = NextFragmentOffset;
StartFragmentAssemblyTimer(control.id); StartFragmentAssemblyTimer(control.id);
let TotalRequest = JSON.stringify({ 'id': control.id, 'offset': NextFragmentOffset }); let TotalRequest = JSON.stringify({ 'id' : control.id, 'offset' : NextFragmentOffset });
websock.send("uifragmentok:" + 0 + ": " + TotalRequest + ":"); websock.send("uifragmentok:" + 0 + ": " + TotalRequest + ":");
// console.info("asked for fragment " + TotalRequest); // console.info("asked for fragment " + TotalRequest);
// console.info("Done Fragment Processing"); // console.info("Done Fragment Processing");
break; break;
} }
// not first fragment. are we assembling this control? // not first fragment. are we assembling this control?
if ("undefined" === typeof controlAssemblyArray[control.id]) { if("undefined" === typeof controlAssemblyArray[control.id])
{
// it looks like we missed the first fragment. Start the control over // it looks like we missed the first fragment. Start the control over
console.error("Missing first fragment for control: " + control.id); console.error("Missing first fragment for control: " + control.id);
StartFragmentAssemblyTimer(control.id); StartFragmentAssemblyTimer(control.id);
@@ -726,10 +729,11 @@ function start() {
} }
// is this the expected next fragment // is this the expected next fragment
if (FragementOffset !== controlAssemblyArray[control.id].offset) { if(FragementOffset !== controlAssemblyArray[control.id].offset)
{
console.error("Wrong next fragment. Expected: " + controlAssemblyArray[control.id].offset + " Got: " + FragementOffset); console.error("Wrong next fragment. Expected: " + controlAssemblyArray[control.id].offset + " Got: " + FragementOffset);
StartFragmentAssemblyTimer(control.id); StartFragmentAssemblyTimer(control.id);
let TotalRequest = JSON.stringify({ 'id': control.id, 'offset': controlAssemblyArray[control.id].length + controlAssemblyArray[control.id].offset }); let TotalRequest = JSON.stringify({ 'id' : control.id, 'offset' : controlAssemblyArray[control.id].length + controlAssemblyArray[control.id].offset });
websock.send("uifragmentok:" + 0 + ": " + TotalRequest + ":"); websock.send("uifragmentok:" + 0 + ": " + TotalRequest + ":");
// console.info("asked for the expected fragment: " + TotalRequest); // console.info("asked for the expected fragment: " + TotalRequest);
// console.info("Done Fragment Processing"); // console.info("Done Fragment Processing");
@@ -741,7 +745,8 @@ function start() {
controlAssemblyArray[control.id].offset = NextFragmentOffset; controlAssemblyArray[control.id].offset = NextFragmentOffset;
// console.info("Value: " + controlAssemblyArray[control.id].control.value); // console.info("Value: " + controlAssemblyArray[control.id].control.value);
if (true === FragmentFinal) { if(true === FragmentFinal)
{
var fauxEvent = { var fauxEvent = {
data: JSON.stringify(controlAssemblyArray[control.id].control), data: JSON.stringify(controlAssemblyArray[control.id].control),
}; };
@@ -749,10 +754,11 @@ function start() {
controlAssemblyArray[control.id] = null; controlAssemblyArray[control.id] = null;
// console.info("Found last fragment"); // console.info("Found last fragment");
} }
else { else
{
// console.info("Ask for next fragment."); // console.info("Ask for next fragment.");
StartFragmentAssemblyTimer(control.id); StartFragmentAssemblyTimer(control.id);
let TotalRequest = JSON.stringify({ 'id': control.id, 'offset': NextFragmentOffset }); let TotalRequest = JSON.stringify({ 'id' : control.id, 'offset' : NextFragmentOffset});
websock.send("uifragmentok:" + 0 + ": " + TotalRequest + ":"); websock.send("uifragmentok:" + 0 + ": " + TotalRequest + ":");
// console.info("asked for the next fragment: " + TotalRequest); // console.info("asked for the next fragment: " + TotalRequest);
} }
@@ -816,7 +822,8 @@ function start() {
websock.onmessage = handleEvent; websock.onmessage = handleEvent;
} }
async function FileDisplayUploadFile(data) { async function FileDisplayUploadFile(data)
{
let text = await downloadFile(data.value); let text = await downloadFile(data.value);
let ItemToUpdateId = "fd" + data.id; let ItemToUpdateId = "fd" + data.id;
// console.info("ItemToUpdateId: " + ItemToUpdateId); // console.info("ItemToUpdateId: " + ItemToUpdateId);
@@ -835,37 +842,45 @@ async function FileDisplayUploadFile(data) {
} // FileDisplayUploadFile } // FileDisplayUploadFile
async function downloadFile(filename) { async function downloadFile(filename)
{
let response = await fetch(filename); let response = await fetch(filename);
if(response.status != 200) {
throw new Error("File Read Server Error: '" + response.status + "'");
}
// read response stream as text
let text_data = await response.text();
if (response.status != 200) { return text_data;
throw new Error("File Read Server Error: '" + response.status + "'");
}
// read response stream as text
let text_data = await response.text();
return text_data;
} // downloadFile } // downloadFile
function StartFragmentAssemblyTimer(Id) { function StartFragmentAssemblyTimer(Id)
{
StopFragmentAssemblyTimer(Id); StopFragmentAssemblyTimer(Id);
FragmentAssemblyTimer[Id] = setInterval(function (_Id) { FragmentAssemblyTimer[Id] = setInterval(function(_Id)
{
// does the fragment assembly still exist? // does the fragment assembly still exist?
if ("undefined" !== typeof controlAssemblyArray[_Id]) { if("undefined" !== typeof controlAssemblyArray[_Id])
if (null !== controlAssemblyArray[_Id]) { {
if(null !== controlAssemblyArray[_Id])
{
// we have a valid control that is being assembled // we have a valid control that is being assembled
// ask for the next part // ask for the next part
let TotalRequest = JSON.stringify({ 'id': controlAssemblyArray[_Id].control.id, 'offset': controlAssemblyArray[_Id].offset }); let TotalRequest = JSON.stringify({ 'id' : controlAssemblyArray[_Id].control.id, 'offset' : controlAssemblyArray[_Id].offset});
websock.send("uifragmentok:" + 0 + ": " + TotalRequest + ":"); websock.send("uifragmentok:" + 0 + ": " + TotalRequest + ":");
} }
} }
}, 1000, Id); }, 1000, Id);
} }
function StopFragmentAssemblyTimer(Id) { function StopFragmentAssemblyTimer(Id)
if ("undefined" !== typeof FragmentAssemblyTimer[Id]) { {
if (FragmentAssemblyTimer[Id]) { if("undefined" !== typeof FragmentAssemblyTimer[Id])
{
if(FragmentAssemblyTimer[Id])
{
clearInterval(FragmentAssemblyTimer[Id]); clearInterval(FragmentAssemblyTimer[Id]);
} }
} }