From 199f0de4ada5db4150f3c566d1cedd4e6938ade3 Mon Sep 17 00:00:00 2001 From: Dmitry Borisenko <67171972+IoTManagerProject@users.noreply.github.com> Date: Wed, 2 Feb 2022 00:19:57 +0100 Subject: [PATCH] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D0=BC=D0=B5=D0=BD=D1=8E=20=D0=B2=D1=8B=D0=B1=D0=BE=D1=80=D0=B0?= =?UTF-8?q?=20=D1=8D=D0=BB=D0=B5=D0=BC=D0=B5=D0=BD=D1=82=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.svelte | 76 +++++++++++++++++++++++++++++++++++--------------- 1 file changed, 54 insertions(+), 22 deletions(-) diff --git a/src/App.svelte b/src/App.svelte index 05594db..3f1068f 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -166,23 +166,9 @@ let widgetsJsonFlag = false; let itemsJson = []; + let itemsJsonFlag = false; - itemsJson = [ - { - name: "1. Аналоговый сенсор", - type: "Reading", - subtype: "AnalogAdc", - id: "t", - widget: "anydataTmp", - page: "Сенсоры", - descr: "Температура", - map: "1,1024,1,1024", - plus: 0, - multiply: 1, - pin: 0, - int: 15, - }, - ]; + let itemsJsonBind = 0; //web sockets let socket = []; @@ -229,6 +215,7 @@ let currentPageName = undefined; var configJsonBlob = new MyBlobBuilder(); var widgetsJsonBlob = new MyBlobBuilder(); + var itemsJsonBlob = new MyBlobBuilder(); router.subscribe(handleNavigation); function handleNavigation() { @@ -371,10 +358,31 @@ } }; } + //сборщик itemsJson пакетов======================================== + if (data === "/st/items.json") { + if (debug) console.log("[i]", "itemsJson start!"); + itemsJsonFlag = true; + } + if (data === "/end/items.json") { + if (debug) console.log("[i]", "itemsJson end!"); + itemsJsonFlag = false; + var bb = itemsJsonBlob.getBlob(); + let itemsJsonReader = new FileReader(); + itemsJsonReader.readAsText(bb); + itemsJsonReader.onload = () => { + let itemsJsonResult = itemsJsonReader.result; + if (IsJsonParse(itemsJsonResult)) { + itemsJson = JSON.parse(itemsJsonResult); + itemsJson = itemsJson; + if (debug) console.log("[i]", "itemsJson parced!"); + } + }; + } } if (event.data instanceof Blob) { if (configJsonFlag) configJsonBlob.append(event.data); if (widgetsJsonFlag) widgetsJsonBlob.append(event.data); + if (itemsJsonFlag) itemsJsonBlob.append(event.data); } }); socket[ws].addEventListener("close", (event) => { @@ -651,7 +659,26 @@ //************************************************elements and presets dropdown************************************************************/ - function elementsDropdownChange() {} + function elementsDropdownChange() { + //костыльный вариант предотвкащающий binding + let itemStr = JSON.stringify(getItem(itemsJsonBind)); + let item = JSON.parse(itemStr); + delete item.num; + delete item.name; + configJson.push(item); + configJson = configJson; + itemsJsonBind = 0; + if (debug) console.log("[i]", "item added"); + } + + function getItem(num) { + for (let i = 0; i < itemsJson.length; i++) { + let item = itemsJson[i]; + if (num === item.num) { + return item; + } + } + } //*******************************************************initialisation********************************************************************/ onMount(async () => { @@ -742,16 +769,21 @@
- elementsDropdownChange()}> {#each itemsJson as item} - + {#if item.header} + + {/if} + {#if !item.header} + + {/if} {/each}
- +
Тип