рабочая версия публикации конфигурации

This commit is contained in:
IoT Manager
2023-10-14 17:37:42 +02:00
parent 200a6a7d08
commit d10ffd679c
3 changed files with 49 additions and 3 deletions

View File

@@ -3,8 +3,8 @@
"version": "4.2.0",
"private": true,
"scripts": {
"build": "rollup -c",
"dev": "rollup -c -w",
"build": "rollup -c",
"start": "sirv public --no-clear"
},
"devDependencies": {

View File

@@ -52,14 +52,14 @@
let preventMove = false;
let screenSize;
const blobDebug = false;
const devMode = false;
const devMode = true;
let percent;
//****************************************************variable section**********************************************************/
//******************************************************************************************************************************/
let myip = document.location.hostname;
if (devMode) myip = "192.168.1.228";
if (devMode) myip = "192.168.1.247";
//Flags
let firstDevListRequest = true;

View File

@@ -4,6 +4,8 @@
import OpenIcon from "../svg/Open.svelte";
import Alarm from "../components/Alarm.svelte";
import Cookies from "js-cookie";
export let configJson;
export let widgetsJson;
export let itemsJson;
@@ -193,6 +195,49 @@
}
export let moduleOrder = (id, key, value) => {};
const makePost = async () => {
let iotmpostDefault = {
category: "",
topic: {
ru: "",
en: "",
},
text: {
ru: "",
en: "",
},
config: configJson,
scenario: scenarioTxt,
gallery: [],
type: "iotmpost",
};
const JWT = Cookies.get("token_iotm2");
try {
let res = await fetch("https://portal.iotmanager.org/api/configurations/add", {
mode: "cors",
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${JWT}`,
},
body: JSON.stringify(iotmpostDefault),
});
const content = await res.json();
if (res.ok) {
console.log(content.result);
if (content.result.acknowledged) {
window.open("http://localhost:4000/configs", "_blank");
//insertedId
}
errors = [{ msg: "ok_success" }];
} else {
errors = content.message;
}
} catch (e) {
console.log(e);
}
};
</script>
{#if show}
@@ -295,6 +340,7 @@
{"Импорт конфигурации"}
</label>
</div>
<button class="btn-lg mt-4" on:click={() => makePost()}>{"Опубликовать конфигурацию на портале"}</button>
</Card>
</div>
{:else}