mirror of
https://github.com/s00500/ESPUI.git
synced 2024-11-21 22:50:55 +00:00
Chunk updates
This commit is contained in:
parent
1d78608786
commit
78317ce5f2
13
data/js/controls.js
vendored
13
data/js/controls.js
vendored
@ -2,6 +2,8 @@ const UI_INITIAL_GUI = 200;
|
||||
const UI_RELOAD = 201;
|
||||
const UPDATE_OFFSET = 100;
|
||||
|
||||
const UI_EXTEND_GUI = 210;
|
||||
|
||||
const UI_TITEL = 0;
|
||||
|
||||
const UI_PAD = 1;
|
||||
@ -230,6 +232,7 @@ function start() {
|
||||
var data = JSON.parse(evt.data);
|
||||
var e = document.body;
|
||||
var center = "";
|
||||
|
||||
switch (data.type) {
|
||||
case UI_INITIAL_GUI:
|
||||
// Clear current elements
|
||||
@ -247,6 +250,16 @@ function start() {
|
||||
handleEvent(fauxEvent);
|
||||
});
|
||||
break;
|
||||
|
||||
case UI_EXTEND_GUI:
|
||||
data.controls.forEach(element => {
|
||||
var fauxEvent = {
|
||||
data: JSON.stringify(element),
|
||||
};
|
||||
handleEvent(fauxEvent);
|
||||
});
|
||||
break;
|
||||
|
||||
case UI_RELOAD:
|
||||
window.location.reload();
|
||||
break;
|
||||
|
4
data/js/controls.min.js
vendored
4
data/js/controls.min.js
vendored
@ -1,4 +1,4 @@
|
||||
const UI_INITIAL_GUI=200;const UI_RELOAD=201;const UPDATE_OFFSET=100;const UI_TITEL=0;const UI_PAD=1;const UPDATE_PAD=101;const UI_CPAD=2;const UPDATE_CPAD=102;const UI_BUTTON=3;const UPDATE_BUTTON=103;const UI_LABEL=4;const UPDATE_LABEL=104;const UI_SWITCHER=5;const UPDATE_SWITCHER=105;const UI_SLIDER=6;const UPDATE_SLIDER=106;const UI_NUMBER=7;const UPDATE_NUMBER=107;const UI_TEXT_INPUT=8;const UPDATE_TEXT_INPUT=108;const UI_GRAPH=9;const ADD_GRAPH_POINT=10;const CLEAR_GRAPH=109;const UI_TAB=11;const UPDATE_TAB=111;const UI_SELECT=12;const UPDATE_SELECT=112;const UI_OPTION=13;const UPDATE_OPTION=113;const UI_MIN=14;const UPDATE_MIN=114;const UI_MAX=15;const UPDATE_MAX=115;const UI_STEP=16;const UPDATE_STEP=116;const UI_GAUGE=17;const UPDATE_GAUGE=117;const UI_ACCEL=18;const UPTDATE_ACCEL=117;const UP=0;const DOWN=1;const LEFT=2;const RIGHT=3;const CENTER=4;const C_TURQUOISE=0;const C_EMERALD=1;const C_PETERRIVER=2;const C_WETASPHALT=3;const C_SUNFLOWER=4;const C_CARROT=5;const C_ALIZARIN=6;const C_DARK=7;const C_NONE=255;var graphData=new Array();var hasAccel=false;var sliderContinuous=false;function colorClass(colorId){colorId=Number(colorId);switch(colorId){case C_TURQUOISE:return"turquoise";case C_EMERALD:return"emerald";case C_PETERRIVER:return"peterriver";case C_WETASPHALT:return"wetasphalt";case C_SUNFLOWER:return"sunflower";case C_CARROT:return"carrot";case C_ALIZARIN:return"alizarin";case C_NONE:return"dark";default:return"";}}
|
||||
const UI_INITIAL_GUI=200;const UI_RELOAD=201;const UPDATE_OFFSET=100;const UI_EXTEND_GUI=210;const UI_TITEL=0;const UI_PAD=1;const UPDATE_PAD=101;const UI_CPAD=2;const UPDATE_CPAD=102;const UI_BUTTON=3;const UPDATE_BUTTON=103;const UI_LABEL=4;const UPDATE_LABEL=104;const UI_SWITCHER=5;const UPDATE_SWITCHER=105;const UI_SLIDER=6;const UPDATE_SLIDER=106;const UI_NUMBER=7;const UPDATE_NUMBER=107;const UI_TEXT_INPUT=8;const UPDATE_TEXT_INPUT=108;const UI_GRAPH=9;const ADD_GRAPH_POINT=10;const CLEAR_GRAPH=109;const UI_TAB=11;const UPDATE_TAB=111;const UI_SELECT=12;const UPDATE_SELECT=112;const UI_OPTION=13;const UPDATE_OPTION=113;const UI_MIN=14;const UPDATE_MIN=114;const UI_MAX=15;const UPDATE_MAX=115;const UI_STEP=16;const UPDATE_STEP=116;const UI_GAUGE=17;const UPDATE_GAUGE=117;const UI_ACCEL=18;const UPTDATE_ACCEL=117;const UP=0;const DOWN=1;const LEFT=2;const RIGHT=3;const CENTER=4;const C_TURQUOISE=0;const C_EMERALD=1;const C_PETERRIVER=2;const C_WETASPHALT=3;const C_SUNFLOWER=4;const C_CARROT=5;const C_ALIZARIN=6;const C_DARK=7;const C_NONE=255;var graphData=new Array();var hasAccel=false;var sliderContinuous=false;function colorClass(colorId){colorId=Number(colorId);switch(colorId){case C_TURQUOISE:return"turquoise";case C_EMERALD:return"emerald";case C_PETERRIVER:return"peterriver";case C_WETASPHALT:return"wetasphalt";case C_SUNFLOWER:return"sunflower";case C_CARROT:return"carrot";case C_ALIZARIN:return"alizarin";case C_NONE:return"dark";default:return"";}}
|
||||
var websock;var websockConnected=false;function requestOrientationPermission(){}
|
||||
function saveGraphData(){localStorage.setItem("espuigraphs",JSON.stringify(graphData));}
|
||||
function restoreGraphData(id){var savedData=localStorage.getItem("espuigraphs",graphData);if(savedData!=null){savedData=JSON.parse(savedData);return savedData[id];}
|
||||
@ -8,7 +8,7 @@ function conStatusError(){websockConnected=false;$("#conStatus").removeClass("co
|
||||
function handleVisibilityChange(){if(!websockConnected&&!document.hidden){restart();}}
|
||||
function start(){document.addEventListener("visibilitychange",handleVisibilityChange,false);if(window.location.port!=""||window.location.port!=80||window.location.port!=443){websock=new WebSocket("ws://"+window.location.hostname+":"+window.location.port+"/ws");}else{websock=new WebSocket("ws://"+window.location.hostname+"/ws");}
|
||||
websock.onopen=function(evt){console.log("websock open");$("#conStatus").addClass("color-green");$("#conStatus").text("Connected");websockConnected=true;};websock.onclose=function(evt){console.log("websock close");conStatusError();};websock.onerror=function(evt){console.log(evt);conStatusError();};var handleEvent=function(evt){console.log(evt);var data=JSON.parse(evt.data);var e=document.body;var center="";switch(data.type){case UI_INITIAL_GUI:$("#row").html("");$("#tabsnav").html("");$("#tabscontent").html("");if(data.sliderContinuous){sliderContinuous=data.sliderContinuous;}
|
||||
data.controls.forEach(element=>{var fauxEvent={data:JSON.stringify(element),};handleEvent(fauxEvent);});break;case UI_RELOAD:window.location.reload();break;case UI_TITEL:document.title=data.label;$("#mainHeader").html(data.label);break;case UI_LABEL:var parent;if(data.parentControl){parent=$("#tab"+data.parentControl);}else{parent=$("#row");}
|
||||
data.controls.forEach(element=>{var fauxEvent={data:JSON.stringify(element),};handleEvent(fauxEvent);});break;case UI_EXTEND_GUI:data.controls.forEach(element=>{var fauxEvent={data:JSON.stringify(element),};handleEvent(fauxEvent);});break;case UI_RELOAD:window.location.reload();break;case UI_TITEL:document.title=data.label;$("#mainHeader").html(data.label);break;case UI_LABEL:var parent;if(data.parentControl){parent=$("#tab"+data.parentControl);}else{parent=$("#row");}
|
||||
if(data.visible){parent.append("<div id='id"+
|
||||
data.id+
|
||||
"' class='two columns card tcenter "+
|
||||
|
@ -946,9 +946,8 @@ Initially this function used to send the control element data individually.
|
||||
Due to a change in the ESPAsyncWebserver library this had top be changed to be
|
||||
sent as one blob at the beginning. Therefore a new type is used as well
|
||||
*/
|
||||
void ESPUIClass::jsonDom(AsyncWebSocketClient* client)
|
||||
{
|
||||
String json;
|
||||
void ESPUIClass::jsonDom(AsyncWebSocketClient* client) {
|
||||
|
||||
DynamicJsonDocument document(jsonInitialDocumentSize);
|
||||
document["type"] = (int)UI_INITIAL_GUI;
|
||||
document["sliderContinuous"] = sliderContinuous;
|
||||
@ -960,9 +959,38 @@ void ESPUIClass::jsonDom(AsyncWebSocketClient* client)
|
||||
titleItem["type"] = (int)UI_TITLE;
|
||||
titleItem["label"] = ui_title;
|
||||
|
||||
while (control != nullptr)
|
||||
{
|
||||
JsonObject item = items.createNestedObject();
|
||||
while(1) {
|
||||
control = prepareJSONChunk(client, control, &items);
|
||||
|
||||
String json;
|
||||
serializeJson(document, json);
|
||||
#if defined(DEBUG_ESPUI)
|
||||
if (this->verbosity >= Verbosity::VerboseJSON) {
|
||||
Serial.println("Sending elements --------->");
|
||||
Serial.println(json);
|
||||
}
|
||||
#endif
|
||||
if (client != nullptr) client->text(json);
|
||||
else this->ws->textAll(json);
|
||||
|
||||
if(control == nullptr) break;
|
||||
|
||||
document.clear();
|
||||
items.clear();
|
||||
document["type"] = (int) UI_EXTEND_GUI;
|
||||
items = document.createNestedArray("controls");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Prepare a chunk of elements as a single JSON string. If the allowed number of elements is greater than the total number
|
||||
this will represent the entire UI and this function will return null. If a control pointer is returned then the limit
|
||||
was reached, the currently serialised must be sent, and then processing resumed to send the next chunk. */
|
||||
Control *ESPUIClass::prepareJSONChunk(AsyncWebSocketClient* client, Control* control, JsonArray *items) {
|
||||
int elementcount = 0;
|
||||
|
||||
while (control != nullptr && elementcount < 10) {
|
||||
JsonObject item = items->createNestedObject();
|
||||
|
||||
item["id"] = String(control->id);
|
||||
item["type"] = (int)control->type;
|
||||
@ -971,46 +999,25 @@ void ESPUIClass::jsonDom(AsyncWebSocketClient* client)
|
||||
item["color"] = (int)control->color;
|
||||
item["visible"] = control->visible;
|
||||
|
||||
if (control->parentControl != Control::noParent)
|
||||
{
|
||||
if (control->parentControl != Control::noParent) {
|
||||
item["parentControl"] = String(control->parentControl);
|
||||
}
|
||||
|
||||
// special case for selects: to preselect an option, you have to add
|
||||
// "selected" to <option>
|
||||
if (control->type == ControlType::Option)
|
||||
{
|
||||
if (ESPUI.getControl(control->parentControl)->value == control->value)
|
||||
{
|
||||
if (control->type == ControlType::Option) {
|
||||
if (ESPUI.getControl(control->parentControl)->value == control->value) {
|
||||
item["selected"] = "selected";
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
item["selected"] = "";
|
||||
}
|
||||
}
|
||||
|
||||
control = control->next;
|
||||
elementcount++;
|
||||
}
|
||||
|
||||
// Send as one big bunch
|
||||
serializeJson(document, json);
|
||||
|
||||
#if defined(DEBUG_ESPUI)
|
||||
if (this->verbosity >= Verbosity::VerboseJSON)
|
||||
{
|
||||
Serial.println(json);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (client != nullptr)
|
||||
{
|
||||
client->text(json);
|
||||
}
|
||||
else
|
||||
{
|
||||
this->ws->textAll(json);
|
||||
}
|
||||
return control;
|
||||
}
|
||||
|
||||
void ESPUIClass::jsonReload()
|
||||
|
@ -77,11 +77,13 @@ enum ControlType : uint8_t
|
||||
UpdateAccel,
|
||||
|
||||
InitialGui = 200,
|
||||
Reload = 201
|
||||
Reload = 201,
|
||||
ExtendGUI = 210
|
||||
};
|
||||
|
||||
#define UI_INITIAL_GUI ControlType::InitialGui
|
||||
#define UI_RELOAD ControlType::Reload
|
||||
#define UI_EXTEND_GUI ControlType::ExtendGUI
|
||||
|
||||
#define UI_TITLE ControlType::Title
|
||||
#define UI_LABEL ControlType::Label
|
||||
@ -294,6 +296,8 @@ private:
|
||||
const char* basicAuthUsername = nullptr;
|
||||
const char* basicAuthPassword = nullptr;
|
||||
bool basicAuth = true;
|
||||
|
||||
Control *prepareJSONChunk(AsyncWebSocketClient* client, Control *control, JsonArray *items);
|
||||
};
|
||||
|
||||
extern ESPUIClass ESPUI;
|
||||
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user