обновление виджетов

This commit is contained in:
Dmitry Borisenko
2022-02-12 23:20:10 +01:00
parent a7dbc6a3f9
commit 862dacabde
2 changed files with 28 additions and 7 deletions

View File

@@ -33,8 +33,8 @@
//****************************************************variable section**********************************************************/ //****************************************************variable section**********************************************************/
//******************************************************************************************************************************/ //******************************************************************************************************************************/
let myip = document.location.hostname; //let myip = document.location.hostname;
//let myip = "192.168.88.235"; let myip = "192.168.88.235";
//Flags //Flags
let showInput = false; let showInput = false;
@@ -132,7 +132,6 @@
sendCurrentPageName(); sendCurrentPageName();
} }
//отправляем запрос данных для данной страницы и запрос данных для всех страниц - /all
function sendCurrentPageName() { function sendCurrentPageName() {
if (selectedWs !== undefined) { if (selectedWs !== undefined) {
wsSendMsg(selectedWs, currentPageName); wsSendMsg(selectedWs, currentPageName);
@@ -233,7 +232,7 @@
if (data.includes("status")) { if (data.includes("status")) {
if (IsJsonParse(data)) { if (IsJsonParse(data)) {
let statusJson = JSON.parse(data); let statusJson = JSON.parse(data);
udatelayoutJson(statusJson); udateStatusOfWidget(statusJson);
wigetsUpdate(); wigetsUpdate();
if (debug) console.log("✔", "statusJson parced"); if (debug) console.log("✔", "statusJson parced");
onParced("status"); onParced("status");
@@ -243,8 +242,8 @@
if (data.includes("params")) { if (data.includes("params")) {
if (IsJsonParse(data)) { if (IsJsonParse(data)) {
let paramsJson = JSON.parse(data); let paramsJson = JSON.parse(data);
//udatelayoutJson(statusJson); udateStatusOfAllWidgets(paramsJson);
//wigetsUpdate(); wigetsUpdate();
if (debug) console.log("✔", "paramsJson parced"); if (debug) console.log("✔", "paramsJson parced");
onParced("params"); onParced("params");
} }
@@ -460,7 +459,7 @@
return layout; return layout;
} }
function udatelayoutJson(newStatusJson) { function udateStatusOfWidget(newStatusJson) {
for (let i = 0; i < layoutJson.length; i++) { for (let i = 0; i < layoutJson.length; i++) {
let topic = layoutJson[i].topic; let topic = layoutJson[i].topic;
if (topic === newStatusJson.topic) { if (topic === newStatusJson.topic) {
@@ -470,6 +469,20 @@
} }
} }
function udateStatusOfAllWidgets(paramsJson) {
for (const [key, value] of Object.entries(paramsJson)) {
for (let i = 0; i < layoutJson.length; i++) {
let topic = layoutJson[i].topic;
topic = topic.substring(topic.lastIndexOf("/") + 1, topic.length);
if (key === topic) {
console.log("[i]", "value " + topic + " updated");
layoutJson[i].status = value;
break;
}
}
}
}
function clearData() { function clearData() {
configJson = []; configJson = [];
configJsonBlob.clear(); configJsonBlob.clear();

View File

@@ -108,6 +108,14 @@
num: true, num: true,
}, },
}, },
jse3: {
1: {
descr: "Ошибка json",
color: "text-red-500",
txt: "Ошибка чтения файла json с виджетами",
cancel: true,
},
},
}; };
import Card from "../components/Card.svelte"; import Card from "../components/Card.svelte";