mirror of
https://github.com/IoTManagerProject/IoTManagerWeb.git
synced 2026-03-30 03:49:17 +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
|
//configuration
|
||||||
let configJson = [];
|
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
|
//web sockets
|
||||||
let socket = [];
|
let socket = [];
|
||||||
@@ -313,14 +316,27 @@
|
|||||||
//if (debug) console.log("[i]", "log data:", data);
|
//if (debug) console.log("[i]", "log data:", data);
|
||||||
} else if (data.includes("/config.json")) {
|
} else if (data.includes("/config.json")) {
|
||||||
data = data.replace("/config.json", "");
|
data = data.replace("/config.json", "");
|
||||||
buf = buf + data;
|
configJsonBuf = configJsonBuf + data;
|
||||||
if (data.includes("]}")) {
|
if (data.includes("]}")) {
|
||||||
buf = buf.replace("]}", "]");
|
configJsonBuf = configJsonBuf.replace("]}", "]");
|
||||||
if (IsJsonParse(buf)) {
|
if (IsJsonParse(configJsonBuf)) {
|
||||||
configJson = JSON.parse(buf);
|
configJson = JSON.parse(configJsonBuf);
|
||||||
buf = [];
|
configJsonBuf = [];
|
||||||
configJson = configJson;
|
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) {
|
function wsPush(ws, topic, status) {
|
||||||
let msg = topic + " " + status;
|
let msg = topic + " " + status;
|
||||||
if (debug) console.log("[i]", "send to ws msg:", msg);
|
if (debug) console.log("[i]", "send to ws msg:", msg);
|
||||||
@@ -439,11 +479,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function clearData() {
|
|
||||||
configJson = [];
|
|
||||||
buf = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
//***********************************************************navigation************************************************************/
|
//***********************************************************navigation************************************************************/
|
||||||
function handleNavigation() {
|
function handleNavigation() {
|
||||||
clearData();
|
clearData();
|
||||||
@@ -544,18 +579,6 @@
|
|||||||
if (debug) console.log("[i]", "user open add params ", id);
|
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() {
|
function showModal() {
|
||||||
showModalFlag = !showModalFlag;
|
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"><input bind:value={element.id} class="tbl-ipt w-full" type="text" /></td>
|
||||||
<td class="tbl-bdy"
|
<td class="tbl-bdy"
|
||||||
><select bind:value={element.widget} class="tbl-ipt w-full">
|
><select bind:value={element.widget} class="tbl-ipt w-full">
|
||||||
{#each widgetCollection as widget}
|
{#each widgetsDropdown as widget}
|
||||||
<option value={widget.id}>
|
<option value={widget.id}>
|
||||||
{widget.val}
|
{widget.val}
|
||||||
</option>
|
</option>
|
||||||
|
|||||||
Reference in New Issue
Block a user