From c3d503d8b24836a647ca91c8f263a3c18c210199 Mon Sep 17 00:00:00 2001 From: Dmitry Borisenko <49808844+DmitryBorisenko33@users.noreply.github.com> Date: Thu, 29 Sep 2022 23:34:21 +0200 Subject: [PATCH] =?UTF-8?q?=D0=BF=D0=BE=D1=81=D0=BB=D0=B5=D0=B4=D0=BD?= =?UTF-8?q?=D0=B8=D0=B9=20=D0=BD=D0=B0=20=D1=81=D0=B5=D0=B3=D0=BE=D0=B4?= =?UTF-8?q?=D0=BD=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/index.html | 6 +++--- src/App.svelte | 39 ++++++++++++++++++++++++--------------- src/pages/Config.svelte | 37 +++++++++++++++++++------------------ 3 files changed, 46 insertions(+), 36 deletions(-) diff --git a/public/index.html b/public/index.html index 7ac403b..4cbb28a 100644 --- a/public/index.html +++ b/public/index.html @@ -4,12 +4,12 @@ - IoT Manager 4.3.6 + IoT Manager 4.3.8 - + - + diff --git a/src/App.svelte b/src/App.svelte index d2084f5..4161ddf 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -37,12 +37,12 @@ let updatingTimeout = 120000; let opened = false; let preventMove = false; - let devMode = true; + let devMode = false; //****************************************************variable section**********************************************************/ //******************************************************************************************************************************/ let myip = document.location.hostname; - if (devMode) myip = "192.168.88.242"; + if (devMode) myip = "192.168.88.238"; //Flags let firstDevListRequest = true; @@ -84,7 +84,7 @@ let configJson = []; let widgetsJson = []; let itemsJson = []; - let scenarioJson = {}; + let scenarioTxt = ""; let chartJsonFlag = {}; let layoutJsonFlag = {}; @@ -149,7 +149,7 @@ var layoutJsonBlobArray = []; class blobToJson { - constructor(st, end, logMsg) { + constructor(st, end, logMsg, jsonMode) { this.st = st; this.end = end; this.logMsg = logMsg; @@ -158,6 +158,7 @@ this.blob = new MyBlobBuilder(); this.out; this.ws = 0; + this.jsonMode = jsonMode; } handle(data) { @@ -180,10 +181,17 @@ reader.readAsText(bb); reader.onload = () => { let result = reader.result; - if (IsJsonParse(result)) { + if (this.jsonMode) { + if (IsJsonParse(result)) { + this.parced = true; + this.out = JSON.parse(result); + if (debug) console.log("✔ B", this.logMsg + " blob parced"); + onParced(); + } + } else { this.parced = true; - this.out = JSON.parse(result); - if (debug) console.log("✔ B", this.logMsg + " blob parced"); + this.out = result; + if (debug) console.log("✔ S", this.logMsg + " text parced", this.out); onParced(); } }; @@ -210,10 +218,10 @@ } } - let configJsonPacket = new blobToJson("/st/config.json", "/end/config.json", "config.json"); - let itemsJsonPacket = new blobToJson("/st/items.json", "/end/items.json", "items.json"); - let widgetsJsonPacket = new blobToJson("/st/widgets.json", "/end/widgets.json", "widgets.json"); - let scenarioJsonPacket = new blobToJson("/st/scenario.json", "/end/scenario.json", "scenario.json"); + let configJsonPacket = new blobToJson("/st/config.json", "/end/config.json", "config.json", true); + let itemsJsonPacket = new blobToJson("/st/items.json", "/end/items.json", "items.json", true); + let widgetsJsonPacket = new blobToJson("/st/widgets.json", "/end/widgets.json", "widgets.json", true); + let scenarioJsonPacket = new blobToJson("/st/scenario.txt", "/end/scenario.txt", "scenario.json.txt", false); router.subscribe(handleNavigation); @@ -527,7 +535,7 @@ itemsJson = itemsJsonPacket.getData; widgetsJson = widgetsJsonPacket.getData; configJson = configJsonPacket.getData; - scenarioJson = scenarioJsonPacket.getData; + scenarioTxt = scenarioJsonPacket.getData; pageReady.config = true; @@ -698,7 +706,8 @@ wsSendMsg(selectedWs, "/tuoyal|" + JSON.stringify(generateLayout())); modify(); wsSendMsg(selectedWs, "/gifnoc|" + JSON.stringify(configJson)); - wsSendMsg(selectedWs, "/oiranecs|" + JSON.stringify(scenarioJson)); + + wsSendMsg(selectedWs, "/oiranecs|" + scenarioTxt); clearData(); sendCurrentPageName(); } @@ -797,7 +806,7 @@ layoutJson = []; layoutJsonBlobArray = []; - scenarioJson = {}; + scenarioTxt = ""; settingsJson = {}; errorsJson = {}; @@ -1249,7 +1258,7 @@ wsPush(ws, topic, status)} /> - saveConfig()} cleanLogs={() => cleanLogs()} rebootEsp={() => rebootEsp()} scenarioJson={scenarioJson} /> + saveConfig()} cleanLogs={() => cleanLogs()} rebootEsp={() => rebootEsp()} /> rebootEsp()} ssidClick={() => ssidClick()} saveSett={() => saveSett()} saveMqtt={() => saveMqtt()} settingsJson={settingsJson} errorsJson={errorsJson} ssidJson={ssidJson} /> diff --git a/src/pages/Config.svelte b/src/pages/Config.svelte index a879cdd..6d27a9e 100644 --- a/src/pages/Config.svelte +++ b/src/pages/Config.svelte @@ -7,7 +7,7 @@ export let configJson; export let widgetsJson; export let itemsJson; - export let scenarioJson; + export let scenarioTxt; export let show; @@ -53,11 +53,14 @@ } } - $: scenarioJson, windowHeight(); + $: scenarioTxt, windowHeight(); + let height; + function windowHeight() { - let scenStr = JSON.stringify(scenarioJson); - height = scenStr.split("\\n").length; + console.log("test", scenarioTxt); + let scenStr = scenarioTxt; + height = scenStr.split("\n").length; } // Function to download data to a file @@ -97,15 +100,14 @@ function createExportFile() { exportJson.mark = "iotm"; exportJson.config = configJson; - exportJson.scenario = scenarioJson; - //exportJson.settings = settingsJson; + exportJson.scenario = scenarioTxt; } let template = null; let files = null; const alertErr = "Файл не является файлом конфигурации"; - const alertOk = "Применить конфигурацию?\nне забудьте нажать кнопку 'сохранить'"; + const alertOk = "Применить конфигурацию?\nне забудьте нажать кнопку 'сохранить на устройстве'"; $: if (files) { const fileText = files[0].text(); @@ -116,13 +118,12 @@ if (json.mark === "iotm") { if (window.confirm(alertOk)) { configJson = []; - scenarioJson = {}; - configJson = json.config; - scenarioJson = json.scenario; - configJson = configJson; - scenarioJson = scenarioJson; + scenarioTxt = ""; - console.log(JSON.stringify(configJson)); + configJson = json.config; + scenarioTxt = json.scenario; + + console.log("config updated"); } } else { window.alert(alertErr); @@ -222,18 +223,18 @@ -