большие изменения

This commit is contained in:
Dmitry Borisenko
2021-12-16 00:18:40 +01:00
parent 01f8611cea
commit 2f78cab315

View File

@@ -4,8 +4,7 @@
import { Route, router, active } from "tinro"; import { Route, router, active } from "tinro";
router.mode.hash(); // enables hash navigation method router.mode.hash(); // enables hash navigation method
//router.mode.memory(); // enables in-memory navigation method //router.mode.memory(); // enables in-memory navigation method
let wsSelected = undefined;
router.subscribe(handleNavigation);
//import Chart from "svelte-frappe-charts"; //import Chart from "svelte-frappe-charts";
import Card from "./widgets/Card.svelte"; import Card from "./widgets/Card.svelte";
@@ -146,22 +145,21 @@
let flag = true; let flag = true;
let newDevice = {}; let newDevice = {};
let coreMessages = []; let coreMessages = [];
let wsSelected = undefined;
deviceList = [ deviceList = [
{ {
name: "Устройство 1", name: "Устройство 1",
id: "987654321", id: "987654321",
ip: "192.168.88.230", ip: "192.168.88.235",
status: false,
},
{
name: "Устройство 2",
id: "987654321",
ip: "192.168.88.231",
status: false, status: false,
}, },
]; ];
//navigation
let currentPageName = undefined;
router.subscribe(handleNavigation);
//=================================functions section======================================== //=================================functions section========================================
//web socket functions====================================================================== //web socket functions======================================================================
function connectToAllDevices() { function connectToAllDevices() {
@@ -242,14 +240,21 @@
socket[ws].addEventListener("open", function (event) { socket[ws].addEventListener("open", function (event) {
if (debug) console.log("[i]", ip, "completed connecting"); if (debug) console.log("[i]", ip, "completed connecting");
markDeviceStatus(ws, true); markDeviceStatus(ws, true);
sendCurrentPageName();
//socket[ws].send("HELLO"); //socket[ws].send("HELLO");
}); });
socket[ws].addEventListener("message", function (event) { socket[ws].addEventListener("message", function (event) {
let data = event.data.toString(); let data = event.data.toString();
if (debug) console.log("[i]", "new data:", event.data); if (data.includes("[log]")) {
if (data.includes("/core/")) { data = data.replace("[log]", "");
data = data.replace("/core/", "");
addCoreMsg(data); addCoreMsg(data);
//if (debug) console.log("[i]", "log data:", data);
} else if (data.includes("[config]")) {
data = data.replace("[config]", "");
data = JSON.parse(data);
config.push(data);
config = config;
//if (debug) console.log("[i]", "config data:", data);
} }
}); });
socket[ws].addEventListener("close", (event) => { socket[ws].addEventListener("close", (event) => {
@@ -366,12 +371,15 @@
//navigation=========================================================================================== //navigation===========================================================================================
function handleNavigation() { function handleNavigation() {
let page = $router.path.toString(); config = [];
console.log("[i]", "user on page:", page); currentPageName = $router.path.toString();
if (page === "/config") { console.log("[i]", "user on page:", currentPageName);
if (wsSelected !== undefined) { sendCurrentPageName();
wsSendMsg(wsSelected, "config");
} }
function sendCurrentPageName() {
if (wsSelected !== undefined) {
wsSendMsg(wsSelected, currentPageName);
} }
} }
@@ -489,7 +497,29 @@
<Route path="/config"> <Route path="/config">
<div class="cards-grid-inline"> <div class="cards-grid-inline">
<Card title="Здесь будет конфигуратор" /> <Card title="Конфигуратор">
<table class="table-fixed w-full">
<thead>
<tr>
<th class="table-head-element">Тип</th>
<th class="table-head-element">Подтип</th>
<th class="table-head-element">Id</th>
<th class="table-head-element">4</th>
</tr>
</thead>
<tbody>
{#each config as element}
<tr>
<td class="table-body-element">{element.type}</td>
<td class="table-body-element">{element.subtype}</td>
<td class="table-body-element">{element.id}</td>
<td class="table-body-element">4</td>
</tr>
{/each}
</tbody>
</table>
<button class="long-button">{"Сохранить"}</button>
</Card>
</div> </div>
</Route> </Route>