diff --git a/public/index.html b/public/index.html index 4cbb28a..3366770 100644 --- a/public/index.html +++ b/public/index.html @@ -4,12 +4,12 @@ - IoT Manager 4.3.8 + IoT Manager 4.3.9 - + - + diff --git a/src/App.svelte b/src/App.svelte index 4161ddf..661b8d7 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -37,7 +37,7 @@ let updatingTimeout = 120000; let opened = false; let preventMove = false; - let devMode = false; + let devMode = true; //****************************************************variable section**********************************************************/ //******************************************************************************************************************************/ diff --git a/src/pages/Config.svelte b/src/pages/Config.svelte index 6d27a9e..828ec9f 100644 --- a/src/pages/Config.svelte +++ b/src/pages/Config.svelte @@ -60,11 +60,11 @@ function windowHeight() { console.log("test", scenarioTxt); let scenStr = scenarioTxt; - height = scenStr.split("\n").length; + height = scenStr.split("\n").length + 1; } // Function to download data to a file - function download(data, filename, type) { + function saveFile2(data, filename, type) { var file = new Blob([data], { type: type }); if (window.navigator.msSaveOrOpenBlob) // IE10+ @@ -77,6 +77,7 @@ a.download = filename; document.body.appendChild(a); a.click(); + setTimeout(function () { document.body.removeChild(a); window.URL.revokeObjectURL(url); @@ -84,6 +85,24 @@ } } + function saveFile(data, filename, type) { + var file = new Blob([data], { type: type }); + if (window.navigator.msSaveOrOpenBlob) { + window.navigator.msSaveOrOpenBlob(file, filename); + } else { + const a = document.createElement("a"); + document.body.appendChild(a); + const url = window.URL.createObjectURL(file); + a.href = url; + a.download = filename; + a.click(); + setTimeout(() => { + window.URL.revokeObjectURL(url); + document.body.removeChild(a); + }, 0); + } + } + const syntaxHighlight = (json) => { try { json = JSON.stringify(JSON.parse(json), null, 4); @@ -100,7 +119,11 @@ function createExportFile() { exportJson.mark = "iotm"; exportJson.config = configJson; - exportJson.scenario = scenarioTxt; + + let exportAsText = syntaxHighlight(JSON.stringify(exportJson)); + + exportAsText = exportAsText + "\n\nscenario=>" + scenarioTxt; + saveFile(exportAsText, "export.json", "application/json"); } let template = null; @@ -113,23 +136,33 @@ const fileText = files[0].text(); fileText.then((text) => { template = text; - if (IsJsonParse(template)) { - let json = JSON.parse(template); - if (json.mark === "iotm") { - if (window.confirm(alertOk)) { - configJson = []; - scenarioTxt = ""; - configJson = json.config; - scenarioTxt = json.scenario; - - console.log("config updated"); - } - } else { - window.alert(alertErr); - } - } else { + if (!template.includes("scenario=>")) { window.alert(alertErr); + return; + } + + let jsonPart = selectToMarker(template, "scenario=>"); + let txtPart = deleteBeforeDelimiter(template, "scenario=>"); + + if (!IsJsonParse(jsonPart)) { + window.alert(alertErr); + return; + } + + let json = JSON.parse(jsonPart); + + if (json.mark !== "iotm") { + window.alert(alertErr); + return; + } + + if (window.confirm(alertOk)) { + configJson = []; + scenarioTxt = ""; + configJson = json.config; + scenarioTxt = txtPart; + console.log("config updated"); } }); files = null; @@ -149,6 +182,16 @@ } return true; } + + function selectToMarker(str, found) { + let p = str.indexOf(found); + return str.substring(0, p); + } + + function deleteBeforeDelimiter(str, found) { + let p = str.indexOf(found) + found.length; + return str.substring(p); + } {#if show} @@ -231,7 +274,7 @@
- +