mirror of
https://github.com/IoTManagerProject/IoTManagerWeb.git
synced 2026-03-26 23:12:34 +03:00
добавил прием виджетов и формирование массива выпадающего списка
This commit is contained in:
131
src/App.svelte
131
src/App.svelte
@@ -156,38 +156,41 @@
|
||||
],
|
||||
};
|
||||
|
||||
let widgetCollection = [];
|
||||
|
||||
widgetCollection = [
|
||||
{
|
||||
id: "toggle",
|
||||
val: "Переключатель",
|
||||
},
|
||||
{
|
||||
id: "btn",
|
||||
val: "Кнопка",
|
||||
},
|
||||
{
|
||||
id: "select",
|
||||
val: "Кнопка переключатель",
|
||||
},
|
||||
{
|
||||
id: "range",
|
||||
val: "Ползунок",
|
||||
},
|
||||
{
|
||||
id: "anydata",
|
||||
val: "Текст",
|
||||
},
|
||||
{
|
||||
id: "inputDigit",
|
||||
val: "Ввод цифры",
|
||||
},
|
||||
];
|
||||
|
||||
//configuration
|
||||
let configJson = [];
|
||||
let buf = [];
|
||||
let configJsonBuf = [];
|
||||
|
||||
let widgetCollection = [];
|
||||
let widgetCollectionBuf = [];
|
||||
|
||||
let widgetsDropdown = [];
|
||||
|
||||
//widgetsDropdown = [
|
||||
// {
|
||||
// id: "toggle",
|
||||
// val: "Переключатель",
|
||||
// },
|
||||
// {
|
||||
// id: "btn",
|
||||
// val: "Кнопка",
|
||||
// },
|
||||
// {
|
||||
// id: "select",
|
||||
// val: "Кнопка переключатель",
|
||||
// },
|
||||
// {
|
||||
// id: "range",
|
||||
// val: "Ползунок",
|
||||
// },
|
||||
// {
|
||||
// id: "anydata",
|
||||
// val: "Текст",
|
||||
// },
|
||||
// {
|
||||
// id: "inputDigit",
|
||||
// val: "Ввод цифры",
|
||||
// },
|
||||
//];
|
||||
|
||||
//web sockets
|
||||
let socket = [];
|
||||
@@ -313,14 +316,27 @@
|
||||
//if (debug) console.log("[i]", "log data:", data);
|
||||
} else if (data.includes("/config.json")) {
|
||||
data = data.replace("/config.json", "");
|
||||
buf = buf + data;
|
||||
configJsonBuf = configJsonBuf + data;
|
||||
if (data.includes("]}")) {
|
||||
buf = buf.replace("]}", "]");
|
||||
if (IsJsonParse(buf)) {
|
||||
configJson = JSON.parse(buf);
|
||||
buf = [];
|
||||
configJsonBuf = configJsonBuf.replace("]}", "]");
|
||||
if (IsJsonParse(configJsonBuf)) {
|
||||
configJson = JSON.parse(configJsonBuf);
|
||||
configJsonBuf = [];
|
||||
configJson = configJson;
|
||||
if (debug) console.log("[i]", "parsed");
|
||||
if (debug) console.log("[i]", "configJson parsed");
|
||||
}
|
||||
}
|
||||
} else if (data.includes("/widgets.json")) {
|
||||
data = data.replace("/widgets.json", "");
|
||||
widgetCollectionBuf = widgetCollectionBuf + data;
|
||||
if (data.includes("]}")) {
|
||||
widgetCollectionBuf = widgetCollectionBuf.replace("]}", "]");
|
||||
if (IsJsonParse(widgetCollectionBuf)) {
|
||||
widgetCollection = JSON.parse(widgetCollectionBuf);
|
||||
widgetCollectionBuf = [];
|
||||
widgetCollection = widgetCollection;
|
||||
createWidgetsDropdown();
|
||||
if (debug) console.log("[i]", "widgetCollection parsed");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -338,6 +354,30 @@
|
||||
}
|
||||
}
|
||||
|
||||
function sendConfigJson() {
|
||||
wsSendMsg(wsSelected, "/gifnoc.json" + JSON.stringify(configJson));
|
||||
clearData();
|
||||
sendCurrentPageName();
|
||||
}
|
||||
|
||||
function createWidgetsDropdown() {
|
||||
widgetCollection.forEach((widget) => {
|
||||
widgetsDropdown.push({
|
||||
id: widget.name,
|
||||
val: widget.rus,
|
||||
});
|
||||
});
|
||||
widgetsDropdown = widgetsDropdown;
|
||||
if (debug) console.log("[i]", widgetsDropdown);
|
||||
}
|
||||
|
||||
function clearData() {
|
||||
configJson = [];
|
||||
configJsonBuf = [];
|
||||
widgetCollection = [];
|
||||
widgetCollectionBuf = [];
|
||||
}
|
||||
|
||||
function wsPush(ws, topic, status) {
|
||||
let msg = topic + " " + status;
|
||||
if (debug) console.log("[i]", "send to ws msg:", msg);
|
||||
@@ -439,11 +479,6 @@
|
||||
}
|
||||
}
|
||||
|
||||
function clearData() {
|
||||
configJson = [];
|
||||
buf = [];
|
||||
}
|
||||
|
||||
//***********************************************************navigation************************************************************/
|
||||
function handleNavigation() {
|
||||
clearData();
|
||||
@@ -544,18 +579,6 @@
|
||||
if (debug) console.log("[i]", "user open add params ", id);
|
||||
}
|
||||
|
||||
function checkConfigJson() {
|
||||
//configJson.forEach((element) => {
|
||||
//});
|
||||
}
|
||||
|
||||
function sendConfigJson() {
|
||||
checkConfigJson();
|
||||
wsSendMsg(wsSelected, "/gifnoc.json" + JSON.stringify(configJson));
|
||||
clearData();
|
||||
sendCurrentPageName();
|
||||
}
|
||||
|
||||
function showModal() {
|
||||
showModalFlag = !showModalFlag;
|
||||
}
|
||||
@@ -670,7 +693,7 @@
|
||||
<td class="tbl-bdy"><input bind:value={element.id} class="tbl-ipt w-full" type="text" /></td>
|
||||
<td class="tbl-bdy"
|
||||
><select bind:value={element.widget} class="tbl-ipt w-full">
|
||||
{#each widgetCollection as widget}
|
||||
{#each widgetsDropdown as widget}
|
||||
<option value={widget.id}>
|
||||
{widget.val}
|
||||
</option>
|
||||
|
||||
Reference in New Issue
Block a user