2021-09-16 02:00:52 +08:00
|
|
|
<script>
|
2022-02-22 20:20:59 +01:00
|
|
|
/*
|
|
|
|
|
Svelte IoT Manager app
|
|
|
|
|
created by Dmitry Borisenko
|
|
|
|
|
Sandgasse 46/4, Vienna 1190, Austria
|
|
|
|
|
*/
|
2022-02-19 23:35:30 +01:00
|
|
|
|
2021-12-28 21:18:03 +01:00
|
|
|
//******************************************************import section*********************************************************/
|
|
|
|
|
//*****************************************************************************************************************************/
|
2021-09-16 02:00:52 +08:00
|
|
|
import { onMount } from "svelte";
|
|
|
|
|
import { Route, router, active } from "tinro";
|
2022-02-06 23:02:20 +01:00
|
|
|
router.mode.hash();
|
|
|
|
|
|
2022-02-07 02:08:21 +01:00
|
|
|
import Alarm from "./components/Alarm.svelte";
|
2022-02-08 16:47:26 +01:00
|
|
|
import Progress from "./components/Progress.svelte";
|
2021-12-26 01:34:29 +01:00
|
|
|
|
2022-02-12 03:07:59 +01:00
|
|
|
//import Modal from "./components/Modal.svelte";
|
2022-02-06 23:02:20 +01:00
|
|
|
import DashboardPage from "./pages/Dashboard.svelte";
|
|
|
|
|
import ConfigPage from "./pages/Config.svelte";
|
|
|
|
|
import ConnectionPage from "./pages/Connection.svelte";
|
2022-02-08 21:42:40 +01:00
|
|
|
import ListPage from "./pages/List.svelte";
|
|
|
|
|
import SystemPage from "./pages/System.svelte";
|
2022-09-10 02:59:03 +02:00
|
|
|
import DevPage from "./pages/Dev.svelte";
|
2022-09-13 22:44:37 +02:00
|
|
|
import FilesPage from "./pages/Files.svelte";
|
2022-02-08 21:42:40 +01:00
|
|
|
|
2022-02-12 03:07:59 +01:00
|
|
|
//import UtilitiesPage from "./pages/Utilities.svelte";
|
|
|
|
|
//import LogPage from "./pages/Log.svelte";
|
|
|
|
|
//import AboutPage from "./pages/About.svelte";
|
2021-12-26 01:34:29 +01:00
|
|
|
|
2022-02-07 16:36:43 +01:00
|
|
|
import CloudIcon from "./svg/Cloud.svelte";
|
2022-08-31 22:25:22 +02:00
|
|
|
import BookIcon from "./svg/Book.svelte";
|
2022-02-07 16:36:43 +01:00
|
|
|
|
2021-12-28 21:18:03 +01:00
|
|
|
//****************************************************constants section*********************************************************/
|
|
|
|
|
//******************************************************************************************************************************/
|
2021-12-08 22:59:21 +01:00
|
|
|
let debug = true;
|
2022-02-19 23:35:30 +01:00
|
|
|
let LOG_MAX_MESSAGES = 100;
|
2022-02-11 00:22:41 +01:00
|
|
|
let reconnectTimeout = 20000;
|
2022-02-24 00:59:10 +01:00
|
|
|
let rebootingTimeout = 18000;
|
2022-02-18 22:53:39 +01:00
|
|
|
let updatingTimeout = 80000;
|
2022-02-01 16:01:19 +01:00
|
|
|
let opened = false;
|
|
|
|
|
let preventMove = false;
|
2022-09-14 18:20:07 +02:00
|
|
|
let devMode = true;
|
2021-12-14 20:55:53 +01:00
|
|
|
|
2021-12-28 21:18:03 +01:00
|
|
|
//****************************************************variable section**********************************************************/
|
|
|
|
|
//******************************************************************************************************************************/
|
2022-08-16 00:56:12 +02:00
|
|
|
let myip = document.location.hostname;
|
2022-09-14 18:20:07 +02:00
|
|
|
if (devMode) myip = "192.168.1.117";
|
2021-12-14 20:55:53 +01:00
|
|
|
|
2021-12-28 21:18:03 +01:00
|
|
|
//Flags
|
2022-02-13 23:13:08 +01:00
|
|
|
let firstDevListRequest = true;
|
2021-12-28 21:18:03 +01:00
|
|
|
let showInput = false;
|
2021-12-27 02:46:05 +01:00
|
|
|
let showModalFlag = false;
|
2022-02-06 23:02:20 +01:00
|
|
|
|
2022-02-24 00:59:10 +01:00
|
|
|
let rebootingUpdatingInProgress = false;
|
|
|
|
|
const myTimeout = undefined;
|
|
|
|
|
|
2021-12-28 21:18:03 +01:00
|
|
|
let additionalParams = false;
|
2021-12-28 01:06:01 +01:00
|
|
|
|
2021-12-14 20:55:53 +01:00
|
|
|
//dashboard
|
|
|
|
|
let pages = [];
|
|
|
|
|
|
2022-02-13 00:37:58 +01:00
|
|
|
//ready flags
|
|
|
|
|
let dashReady = false;
|
|
|
|
|
let configReady = false;
|
|
|
|
|
let connectionReady = false;
|
|
|
|
|
let listReady = false;
|
|
|
|
|
let systemReady = false;
|
2022-09-13 22:44:37 +02:00
|
|
|
let devReady = false;
|
2022-02-13 00:37:58 +01:00
|
|
|
|
2022-02-18 19:48:15 +01:00
|
|
|
//update esp
|
|
|
|
|
let versionsList = {};
|
|
|
|
|
let choosingVersion = undefined;
|
|
|
|
|
|
2022-08-23 15:13:50 +02:00
|
|
|
//JSON Files====================================
|
2021-12-30 23:58:35 +01:00
|
|
|
let configJson = [];
|
2022-01-22 00:15:22 +01:00
|
|
|
let configJsonFlag = false;
|
2022-02-13 00:37:58 +01:00
|
|
|
let configJsonParced = false;
|
2022-01-17 00:08:26 +01:00
|
|
|
|
2022-01-22 00:15:22 +01:00
|
|
|
let widgetsJson = [];
|
|
|
|
|
let widgetsJsonFlag = false;
|
2022-02-13 00:37:58 +01:00
|
|
|
let widgetsJsonParced = false;
|
2022-01-17 00:08:26 +01:00
|
|
|
|
2022-02-01 16:01:19 +01:00
|
|
|
let itemsJson = [];
|
2022-02-02 00:19:57 +01:00
|
|
|
let itemsJsonFlag = false;
|
2022-02-13 00:37:58 +01:00
|
|
|
let itemsJsonParced = false;
|
2022-02-01 16:01:19 +01:00
|
|
|
|
2022-08-23 15:13:50 +02:00
|
|
|
let scenarioJson = {};
|
|
|
|
|
let scenarioJsonFlag = false;
|
|
|
|
|
let scenarioJsonParced = false;
|
|
|
|
|
|
|
|
|
|
//===============================================
|
|
|
|
|
|
2022-02-02 23:37:15 +01:00
|
|
|
let layoutJson = [];
|
2022-02-26 01:09:17 +01:00
|
|
|
let layoutJsonArrayParced = false;
|
2022-02-02 23:37:15 +01:00
|
|
|
|
|
|
|
|
let settingsJson = {};
|
2022-02-13 00:37:58 +01:00
|
|
|
let settingsJsonParced = false;
|
2022-02-05 02:13:46 +01:00
|
|
|
|
2022-02-08 16:47:26 +01:00
|
|
|
let errorsJson = {};
|
2022-02-13 00:37:58 +01:00
|
|
|
let errorsJsonParced = false;
|
2022-02-08 16:47:26 +01:00
|
|
|
|
2022-02-05 02:13:46 +01:00
|
|
|
let ssidJson = {};
|
2022-02-13 00:37:58 +01:00
|
|
|
let ssidJsonParced = false;
|
2022-02-02 23:37:15 +01:00
|
|
|
|
2022-02-13 00:37:58 +01:00
|
|
|
let paramsJson = {};
|
|
|
|
|
let paramsJsonParced = false;
|
2022-02-07 23:40:00 +01:00
|
|
|
|
2022-02-13 00:37:58 +01:00
|
|
|
let incDeviceList = [];
|
2022-02-23 22:56:17 +01:00
|
|
|
let deviceListParced = false;
|
2022-02-05 02:13:46 +01:00
|
|
|
|
2022-08-23 15:13:50 +02:00
|
|
|
let statusJsonParced = false;
|
2022-02-23 01:38:43 +01:00
|
|
|
|
2022-02-07 23:40:00 +01:00
|
|
|
let deviceList = [];
|
2021-12-13 02:36:26 +01:00
|
|
|
deviceList = [
|
|
|
|
|
{
|
2022-02-07 23:40:00 +01:00
|
|
|
name: "--",
|
|
|
|
|
id: "--",
|
|
|
|
|
ip: myip,
|
2022-02-13 23:13:08 +01:00
|
|
|
ws: 0,
|
2022-02-07 02:08:21 +01:00
|
|
|
status: false,
|
|
|
|
|
},
|
2021-12-13 02:36:26 +01:00
|
|
|
];
|
2021-12-12 00:20:47 +01:00
|
|
|
|
2022-02-13 00:37:58 +01:00
|
|
|
//web sockets
|
|
|
|
|
let socket = [];
|
|
|
|
|
let socketConnected = false;
|
|
|
|
|
let selectedDeviceData = undefined;
|
|
|
|
|
let selectedWs = 0;
|
|
|
|
|
|
2022-02-24 00:59:10 +01:00
|
|
|
let firstTime = true;
|
2022-02-13 00:37:58 +01:00
|
|
|
let newDevice = {};
|
|
|
|
|
let coreMessages = [];
|
|
|
|
|
|
2022-01-30 17:44:53 +01:00
|
|
|
//***********************************************************blob**************************************************************/
|
|
|
|
|
var MyBlobBuilder = function () {
|
|
|
|
|
this.parts = [];
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
MyBlobBuilder.prototype.append = function (part) {
|
|
|
|
|
this.parts.push(part);
|
|
|
|
|
this.blob = undefined; // Invalidate the blob
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
MyBlobBuilder.prototype.getBlob = function () {
|
|
|
|
|
if (!this.blob) {
|
2022-02-07 16:36:43 +01:00
|
|
|
this.blob = new Blob(this.parts, {
|
|
|
|
|
type: "binary",
|
|
|
|
|
});
|
2022-01-30 17:44:53 +01:00
|
|
|
}
|
|
|
|
|
return this.blob;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
MyBlobBuilder.prototype.clear = function () {
|
|
|
|
|
this.parts = [];
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//***********************************************************navigation********************************************************/
|
2021-12-16 00:18:40 +01:00
|
|
|
let currentPageName = undefined;
|
2022-01-30 17:44:53 +01:00
|
|
|
var configJsonBlob = new MyBlobBuilder();
|
|
|
|
|
var widgetsJsonBlob = new MyBlobBuilder();
|
2022-02-02 00:19:57 +01:00
|
|
|
var itemsJsonBlob = new MyBlobBuilder();
|
2022-02-23 01:38:43 +01:00
|
|
|
var scenarioTxtBlob = new MyBlobBuilder();
|
2022-02-05 02:13:46 +01:00
|
|
|
|
2022-02-25 17:57:47 +01:00
|
|
|
var layoutJsonArray = [];
|
2022-02-15 00:02:30 +01:00
|
|
|
|
2021-12-16 00:18:40 +01:00
|
|
|
router.subscribe(handleNavigation);
|
|
|
|
|
|
2022-01-30 17:44:53 +01:00
|
|
|
function handleNavigation() {
|
2022-02-23 22:56:17 +01:00
|
|
|
console.log("[i]", "handle navigation");
|
2022-09-10 02:59:03 +02:00
|
|
|
|
2022-01-30 17:44:53 +01:00
|
|
|
currentPageName = $router.path.toString();
|
2022-09-10 02:59:03 +02:00
|
|
|
|
|
|
|
|
//не нужно очищать переменные когда переходим на страницу разработчика
|
|
|
|
|
if (currentPageName != "/dev") {
|
|
|
|
|
clearData();
|
|
|
|
|
}
|
2022-02-09 16:43:24 +01:00
|
|
|
currentPageName = currentPageName + "|";
|
2022-01-30 17:44:53 +01:00
|
|
|
console.log("[i]", "user on page:", currentPageName);
|
2022-02-26 01:09:17 +01:00
|
|
|
|
|
|
|
|
if (currentPageName === "/|") {
|
|
|
|
|
sendToAllDevices(currentPageName);
|
|
|
|
|
} else {
|
|
|
|
|
sendCurrentPageName();
|
|
|
|
|
}
|
2022-01-30 17:44:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function sendCurrentPageName() {
|
2022-02-07 23:40:00 +01:00
|
|
|
if (selectedWs !== undefined) {
|
|
|
|
|
wsSendMsg(selectedWs, currentPageName);
|
2022-01-30 17:44:53 +01:00
|
|
|
}
|
|
|
|
|
}
|
2021-12-28 21:18:03 +01:00
|
|
|
|
2022-02-23 22:56:17 +01:00
|
|
|
//*******************************************************initialisation********************************************************************/
|
|
|
|
|
onMount(async () => {
|
|
|
|
|
console.log("[i]", "mounted");
|
|
|
|
|
whenDeviceListWasUpdated();
|
|
|
|
|
firstDevListRequest = true;
|
|
|
|
|
connectToAllDevices();
|
|
|
|
|
wsTestMsgTask();
|
2022-02-26 01:09:17 +01:00
|
|
|
sortingLayout();
|
2022-02-23 22:56:17 +01:00
|
|
|
});
|
|
|
|
|
|
2021-12-28 21:18:03 +01:00
|
|
|
//****************************************************web sockets section******************************************************/
|
2021-12-08 22:59:21 +01:00
|
|
|
function connectToAllDevices() {
|
2021-12-13 00:01:21 +01:00
|
|
|
//closeAllConnection();
|
|
|
|
|
//socket = [];
|
2022-02-07 23:40:00 +01:00
|
|
|
getSelectedDeviceData(selectedWs);
|
2021-12-08 22:59:21 +01:00
|
|
|
let ws = 0;
|
|
|
|
|
deviceList.forEach((device) => {
|
2021-12-09 00:10:10 +01:00
|
|
|
device.ws = ws;
|
2021-12-13 00:01:21 +01:00
|
|
|
if (!device.status) {
|
|
|
|
|
wsConnect(ws);
|
|
|
|
|
wsEventAdd(ws);
|
|
|
|
|
}
|
2021-12-08 22:59:21 +01:00
|
|
|
ws++;
|
2021-12-05 00:49:36 +01:00
|
|
|
});
|
2021-12-10 14:44:00 +01:00
|
|
|
deviceList = deviceList;
|
2021-12-05 00:49:36 +01:00
|
|
|
}
|
|
|
|
|
|
2021-12-13 00:01:21 +01:00
|
|
|
function closeAllConnection() {
|
|
|
|
|
let s;
|
|
|
|
|
for (s in socket) {
|
|
|
|
|
socket[s].close();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-09 00:10:10 +01:00
|
|
|
function markDeviceStatus(ws, status) {
|
|
|
|
|
deviceList.forEach((device) => {
|
|
|
|
|
if (device.ws === ws) {
|
|
|
|
|
device.status = status;
|
2021-12-09 22:35:04 +01:00
|
|
|
if (debug) {
|
|
|
|
|
if (device.status) {
|
2021-12-10 16:07:55 +01:00
|
|
|
console.log("[i]", device.ip, "status online");
|
2021-12-09 22:35:04 +01:00
|
|
|
} else {
|
2021-12-10 16:07:55 +01:00
|
|
|
console.log("[i]", device.ip, "status offline");
|
2021-12-09 22:35:04 +01:00
|
|
|
}
|
|
|
|
|
}
|
2021-12-09 00:10:10 +01:00
|
|
|
}
|
|
|
|
|
});
|
2021-12-09 22:35:04 +01:00
|
|
|
deviceList = deviceList;
|
2022-02-07 23:40:00 +01:00
|
|
|
getSelectedDeviceData(selectedWs);
|
2021-12-10 17:37:37 +01:00
|
|
|
socketConnected = selectedDeviceData.status;
|
2021-12-09 00:10:10 +01:00
|
|
|
}
|
|
|
|
|
|
2021-12-10 16:07:09 +01:00
|
|
|
function getDeviceStatus(ws) {
|
|
|
|
|
let ret = false;
|
|
|
|
|
deviceList.forEach((device) => {
|
|
|
|
|
if (ws === device.ws) {
|
|
|
|
|
ret = device.status;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-10 14:44:00 +01:00
|
|
|
function wsConnect(ws) {
|
|
|
|
|
let ip = getIP(ws);
|
|
|
|
|
if (ip === "error") {
|
|
|
|
|
if (debug) console.log("[e]", "device list wrong");
|
|
|
|
|
} else {
|
2021-12-25 00:20:49 +01:00
|
|
|
socket[ws] = new WebSocket("ws://" + ip + ":81");
|
2022-01-24 00:57:27 +01:00
|
|
|
socket.binaryType = "blob";
|
2022-02-15 15:22:54 +01:00
|
|
|
if (debug) console.log("[i]", ip, ws, "started connecting...");
|
2021-12-10 14:44:00 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getIP(ws) {
|
|
|
|
|
let ret = "error";
|
|
|
|
|
deviceList.forEach((device) => {
|
|
|
|
|
if (ws === device.ws) {
|
|
|
|
|
ret = device.ip;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
return ret;
|
2021-12-06 01:21:55 +01:00
|
|
|
}
|
2021-12-07 22:14:59 +01:00
|
|
|
|
2021-12-08 22:59:21 +01:00
|
|
|
function wsEventAdd(ws) {
|
|
|
|
|
if (socket[ws]) {
|
2021-12-11 13:54:28 +01:00
|
|
|
let ip = getIP(ws);
|
2022-02-15 15:22:54 +01:00
|
|
|
if (debug) console.log("[i]", ip, ws, "web socket events added");
|
2021-12-08 22:59:21 +01:00
|
|
|
socket[ws].addEventListener("open", function (event) {
|
2022-02-15 15:22:54 +01:00
|
|
|
if (debug) console.log("[i]", ip, ws, "completed connecting");
|
2021-12-09 00:10:10 +01:00
|
|
|
markDeviceStatus(ws, true);
|
2022-02-13 23:13:08 +01:00
|
|
|
if (firstDevListRequest) wsSendMsg(0, "/list|");
|
2022-02-26 01:09:17 +01:00
|
|
|
//при подключении отправляем название страницы
|
2022-02-25 17:57:47 +01:00
|
|
|
if (currentPageName === "/|") {
|
2022-02-26 01:09:17 +01:00
|
|
|
//всем устройствам
|
2022-02-25 17:57:47 +01:00
|
|
|
wsSendMsg(ws, currentPageName);
|
|
|
|
|
} else {
|
2022-02-26 01:09:17 +01:00
|
|
|
//только выбранному
|
2022-02-25 17:57:47 +01:00
|
|
|
if (ws === selectedWs) {
|
|
|
|
|
sendCurrentPageName();
|
|
|
|
|
}
|
2022-02-15 15:22:54 +01:00
|
|
|
}
|
2021-12-08 22:59:21 +01:00
|
|
|
});
|
2022-09-01 12:51:17 +02:00
|
|
|
|
|
|
|
|
//события веб сокетов
|
2021-12-08 22:59:21 +01:00
|
|
|
socket[ws].addEventListener("message", function (event) {
|
2022-09-01 12:51:17 +02:00
|
|
|
//сообщения типа String-----------------------------------------------------------------------------------//
|
2022-01-24 00:57:27 +01:00
|
|
|
if (typeof event.data === "string") {
|
2022-01-25 01:41:29 +01:00
|
|
|
let data = event.data;
|
2022-02-15 15:22:54 +01:00
|
|
|
if (ws === selectedWs) {
|
2022-09-01 12:51:17 +02:00
|
|
|
//сборщик deviceList сообщений
|
2022-02-27 01:49:03 +01:00
|
|
|
if (data.includes('devicelist":"')) {
|
2022-02-15 15:22:54 +01:00
|
|
|
if (IsJsonParse(data)) {
|
|
|
|
|
incDeviceList = JSON.parse(data);
|
|
|
|
|
incDeviceList = incDeviceList;
|
|
|
|
|
if (firstDevListRequest) {
|
|
|
|
|
deviceList = incDeviceList;
|
|
|
|
|
deviceList[0].status = true;
|
|
|
|
|
} else {
|
|
|
|
|
deviceList = combineArrays(deviceList, incDeviceList);
|
|
|
|
|
}
|
|
|
|
|
firstDevListRequest = false;
|
2022-02-23 22:56:17 +01:00
|
|
|
|
2022-02-15 15:22:54 +01:00
|
|
|
deviceList = deviceList;
|
2022-02-23 22:56:17 +01:00
|
|
|
deviceListParced = true;
|
|
|
|
|
if (debug) console.log("✔", "deviceList json parced");
|
|
|
|
|
onParced();
|
2022-02-15 15:22:54 +01:00
|
|
|
whenDeviceListWasUpdated();
|
|
|
|
|
connectToAllDevices();
|
2022-02-13 23:13:08 +01:00
|
|
|
}
|
2022-02-08 00:20:55 +01:00
|
|
|
}
|
2022-02-26 01:09:17 +01:00
|
|
|
|
2022-09-01 12:51:17 +02:00
|
|
|
//сборщик ssidJson сообщений
|
2022-02-27 01:49:03 +01:00
|
|
|
if (data.includes('ssid":"')) {
|
2022-02-15 15:22:54 +01:00
|
|
|
if (IsJsonParse(data)) {
|
|
|
|
|
ssidJson = JSON.parse(data);
|
|
|
|
|
ssidJson = ssidJson;
|
|
|
|
|
if (debug) console.log("✔", "ssidJson parced");
|
|
|
|
|
ssidJsonParced = true;
|
2022-02-23 22:56:17 +01:00
|
|
|
onParced();
|
2022-02-02 23:37:15 +01:00
|
|
|
}
|
2022-02-15 15:22:54 +01:00
|
|
|
}
|
2022-09-01 12:51:17 +02:00
|
|
|
//сборщик errorsJson сообщений
|
2022-02-27 01:49:03 +01:00
|
|
|
if (data.includes('errors":"')) {
|
2022-02-15 15:22:54 +01:00
|
|
|
if (IsJsonParse(data)) {
|
|
|
|
|
errorsJson = JSON.parse(data);
|
|
|
|
|
errorsJson = errorsJson;
|
|
|
|
|
errorsJsonParced = true;
|
|
|
|
|
if (debug) console.log("✔", "errorsJson json parced");
|
2022-02-23 22:56:17 +01:00
|
|
|
onParced();
|
2022-02-02 23:37:15 +01:00
|
|
|
}
|
2022-02-15 15:22:54 +01:00
|
|
|
}
|
2022-09-01 12:51:17 +02:00
|
|
|
//сборщик settingsJson сообщений
|
2022-02-27 01:49:03 +01:00
|
|
|
if (data.includes('settings":"')) {
|
2022-02-16 00:11:57 +01:00
|
|
|
if (IsJsonParse(data)) {
|
|
|
|
|
settingsJson = JSON.parse(data);
|
|
|
|
|
settingsJson = settingsJson;
|
2022-02-26 01:09:17 +01:00
|
|
|
//sortingLayout();
|
2022-02-16 00:11:57 +01:00
|
|
|
settingsJsonParced = true;
|
|
|
|
|
if (debug) console.log("✔", "settingsJson json parced");
|
2022-02-23 22:56:17 +01:00
|
|
|
onParced();
|
2022-02-16 00:11:57 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-01 12:51:17 +02:00
|
|
|
//сборщик log сообщений
|
2022-02-19 23:35:30 +01:00
|
|
|
if (data.includes("/log|")) {
|
|
|
|
|
data = data.replace("/log|", "");
|
|
|
|
|
//let msg = data.toString();
|
|
|
|
|
if (debug) console.log("", data);
|
|
|
|
|
addCoreMsg(data);
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-01 12:51:17 +02:00
|
|
|
//метки начала конца пакетов для Blob--------------------------------------------------------------------------//
|
|
|
|
|
//сборщик scenarioJson пакетов
|
2022-08-23 15:13:50 +02:00
|
|
|
if (data === "/st/scenario.json") {
|
|
|
|
|
scenarioJsonFlag = true;
|
2022-02-23 01:38:43 +01:00
|
|
|
}
|
2022-08-23 15:13:50 +02:00
|
|
|
if (data === "/end/scenario.json") {
|
|
|
|
|
scenarioJsonFlag = false;
|
2022-02-23 01:38:43 +01:00
|
|
|
var bb = scenarioTxtBlob.getBlob();
|
2022-08-23 15:13:50 +02:00
|
|
|
let scenarioJsonReader = new FileReader();
|
|
|
|
|
scenarioJsonReader.readAsText(bb);
|
|
|
|
|
scenarioJsonReader.onload = () => {
|
|
|
|
|
let scenarioJsonResult = scenarioJsonReader.result;
|
|
|
|
|
if (IsJsonParse(scenarioJsonResult)) {
|
|
|
|
|
scenarioJson = JSON.parse(scenarioJsonResult);
|
|
|
|
|
scenarioJson = scenarioJson;
|
|
|
|
|
scenarioJsonParced = true;
|
|
|
|
|
if (debug) console.log("✔", "scenarioJson parced", scenarioJson);
|
|
|
|
|
onParced();
|
|
|
|
|
}
|
2022-02-23 01:38:43 +01:00
|
|
|
};
|
|
|
|
|
}
|
2022-09-01 12:51:17 +02:00
|
|
|
//сборщик configJson пакетов
|
2022-02-15 15:22:54 +01:00
|
|
|
if (data === "/st/config.json") {
|
|
|
|
|
configJsonFlag = true;
|
|
|
|
|
}
|
|
|
|
|
if (data === "/end/config.json") {
|
|
|
|
|
configJsonFlag = false;
|
|
|
|
|
var bb = configJsonBlob.getBlob();
|
|
|
|
|
let configJsonReader = new FileReader();
|
|
|
|
|
configJsonReader.readAsText(bb);
|
|
|
|
|
configJsonReader.onload = () => {
|
|
|
|
|
let configJsonResult = configJsonReader.result;
|
|
|
|
|
if (IsJsonParse(configJsonResult)) {
|
|
|
|
|
configJson = JSON.parse(configJsonResult);
|
|
|
|
|
configJson = configJson;
|
|
|
|
|
configJsonParced = true;
|
|
|
|
|
if (debug) console.log("✔", "configJson parced");
|
2022-02-23 22:56:17 +01:00
|
|
|
onParced();
|
2022-02-15 15:22:54 +01:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
2022-09-01 12:51:17 +02:00
|
|
|
//сборщик widgetsJson пакетов
|
2022-02-15 15:22:54 +01:00
|
|
|
if (data === "/st/widgets.json") {
|
|
|
|
|
widgetsJsonFlag = true;
|
|
|
|
|
}
|
|
|
|
|
if (data === "/end/widgets.json") {
|
|
|
|
|
widgetsJsonFlag = false;
|
|
|
|
|
var bb = widgetsJsonBlob.getBlob();
|
|
|
|
|
let widgetsJsonReader = new FileReader();
|
|
|
|
|
widgetsJsonReader.readAsText(bb);
|
|
|
|
|
widgetsJsonReader.onload = () => {
|
|
|
|
|
let widgetsJsonResult = widgetsJsonReader.result;
|
|
|
|
|
if (IsJsonParse(widgetsJsonResult)) {
|
|
|
|
|
widgetsJson = JSON.parse(widgetsJsonResult);
|
|
|
|
|
widgetsJson = widgetsJson;
|
|
|
|
|
widgetsJsonParced = true;
|
|
|
|
|
if (debug) console.log("✔", "widgetsJson parced");
|
2022-02-23 22:56:17 +01:00
|
|
|
onParced();
|
2022-02-15 15:22:54 +01:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
2022-09-01 12:51:17 +02:00
|
|
|
//сборщик itemsJson пакетов
|
2022-02-15 15:22:54 +01:00
|
|
|
if (data === "/st/items.json") {
|
|
|
|
|
itemsJsonFlag = true;
|
|
|
|
|
}
|
|
|
|
|
if (data === "/end/items.json") {
|
|
|
|
|
itemsJsonFlag = false;
|
|
|
|
|
var bb = itemsJsonBlob.getBlob();
|
|
|
|
|
let itemsJsonReader = new FileReader();
|
|
|
|
|
itemsJsonReader.readAsText(bb);
|
|
|
|
|
itemsJsonReader.onload = () => {
|
|
|
|
|
let itemsJsonResult = itemsJsonReader.result;
|
|
|
|
|
if (IsJsonParse(itemsJsonResult)) {
|
|
|
|
|
itemsJson = JSON.parse(itemsJsonResult);
|
|
|
|
|
itemsJson = itemsJson;
|
|
|
|
|
itemsJsonParced = true;
|
|
|
|
|
if (debug) console.log("✔", "itemsJson parced");
|
2022-02-23 22:56:17 +01:00
|
|
|
onParced();
|
2022-02-15 15:22:54 +01:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
2022-02-25 17:57:47 +01:00
|
|
|
}
|
2022-09-01 12:51:17 +02:00
|
|
|
//сборщик layoutJson пакетов
|
2022-02-25 17:57:47 +01:00
|
|
|
if (data === "/st/layout.json") {
|
|
|
|
|
}
|
|
|
|
|
if (data === "/end/layout.json") {
|
2022-09-11 14:14:16 +02:00
|
|
|
//createLayoutUnderLoading(ws);
|
2022-02-26 01:09:17 +01:00
|
|
|
}
|
2022-09-01 12:51:17 +02:00
|
|
|
//сборщик paramsJson сообщений
|
2022-02-27 01:49:03 +01:00
|
|
|
if (data.includes('"params":"')) {
|
2022-02-26 01:09:17 +01:00
|
|
|
if (IsJsonParse(data)) {
|
2022-03-02 00:42:55 +01:00
|
|
|
//как добавить в объект json новый объект
|
2022-02-26 01:09:17 +01:00
|
|
|
paramsJson = {
|
|
|
|
|
...paramsJson,
|
|
|
|
|
...JSON.parse(data),
|
|
|
|
|
};
|
|
|
|
|
paramsJson = paramsJson;
|
2022-09-11 14:14:16 +02:00
|
|
|
console.log("[i] paramsJson:", paramsJson);
|
|
|
|
|
createLayoutUnderLoading(ws);
|
2022-02-26 01:09:17 +01:00
|
|
|
onParced();
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-09-01 12:51:17 +02:00
|
|
|
//сборщик statusJson сообщений
|
|
|
|
|
if (data.includes('"status":')) {
|
2022-02-26 01:09:17 +01:00
|
|
|
if (IsJsonParse(data)) {
|
|
|
|
|
let statusJson = JSON.parse(data);
|
|
|
|
|
udateStatusOfWidget(statusJson);
|
2022-09-14 18:20:07 +02:00
|
|
|
if (debug) console.log("[i] status", ip, ws, statusJson);
|
2022-02-26 01:09:17 +01:00
|
|
|
}
|
2022-02-02 23:37:15 +01:00
|
|
|
}
|
2022-01-30 17:44:53 +01:00
|
|
|
}
|
2022-09-01 12:51:17 +02:00
|
|
|
|
|
|
|
|
//сообщения типа Blob-------------------------------------------------------------------------------------//
|
2022-01-30 17:44:53 +01:00
|
|
|
if (event.data instanceof Blob) {
|
2022-02-15 15:22:54 +01:00
|
|
|
//принимаем данные только для выбранного устройства
|
|
|
|
|
if (ws === selectedWs) {
|
|
|
|
|
if (configJsonFlag) configJsonBlob.append(event.data);
|
|
|
|
|
if (widgetsJsonFlag) widgetsJsonBlob.append(event.data);
|
|
|
|
|
if (itemsJsonFlag) itemsJsonBlob.append(event.data);
|
2022-08-23 15:13:50 +02:00
|
|
|
if (scenarioJsonFlag) scenarioTxtBlob.append(event.data);
|
2022-02-15 15:22:54 +01:00
|
|
|
}
|
2022-02-26 01:09:17 +01:00
|
|
|
//принимаем данные от всех устройств
|
2022-02-25 17:57:47 +01:00
|
|
|
if (!layoutJsonArray[ws]) layoutJsonArray[ws] = new MyBlobBuilder();
|
|
|
|
|
layoutJsonArray[ws].append(event.data);
|
2022-01-24 00:57:27 +01:00
|
|
|
}
|
2021-12-08 22:59:21 +01:00
|
|
|
});
|
|
|
|
|
socket[ws].addEventListener("close", (event) => {
|
2021-12-11 13:54:28 +01:00
|
|
|
if (debug) console.log("[e]", ip, "connection closed");
|
2021-12-09 00:10:10 +01:00
|
|
|
markDeviceStatus(ws, false);
|
2021-12-08 22:59:21 +01:00
|
|
|
});
|
|
|
|
|
socket[ws].addEventListener("error", function (event) {
|
2021-12-11 13:54:28 +01:00
|
|
|
if (debug) console.log("[e]", ip, "connection error");
|
2021-12-09 00:10:10 +01:00
|
|
|
markDeviceStatus(ws, false);
|
2021-12-08 22:59:21 +01:00
|
|
|
});
|
2021-12-10 14:44:00 +01:00
|
|
|
} else {
|
|
|
|
|
if (debug) console.log("[e]", "socket not exist");
|
2021-12-06 01:21:55 +01:00
|
|
|
}
|
|
|
|
|
}
|
2021-12-07 22:14:59 +01:00
|
|
|
|
2022-09-01 12:51:17 +02:00
|
|
|
//функция создающая общий json всех виджетов под загрузкой (не имеющая события завершения)
|
2022-03-01 01:43:55 +01:00
|
|
|
async function createLayoutUnderLoading(ws) {
|
|
|
|
|
var bb = layoutJsonArray[ws].getBlob();
|
|
|
|
|
let reader = new FileReader();
|
|
|
|
|
reader.readAsText(bb);
|
|
|
|
|
reader.onload = () => {
|
|
|
|
|
let devLayout = JSON.parse(reader.result);
|
2022-08-14 17:13:49 +02:00
|
|
|
udateStatusOfDevWidgets(devLayout, ws);
|
2022-03-01 01:43:55 +01:00
|
|
|
layoutJson = layoutJson.concat(devLayout);
|
|
|
|
|
sortingLayout();
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-01 12:51:17 +02:00
|
|
|
//данная функция обновляет статусы виджетов одного устройства при загрузке страницы dashboard
|
2022-08-14 17:13:49 +02:00
|
|
|
function udateStatusOfDevWidgets(devLayout, ws) {
|
2022-03-01 01:43:55 +01:00
|
|
|
for (const [key, value] of Object.entries(paramsJson)) {
|
|
|
|
|
for (let i = 0; i < devLayout.length; i++) {
|
|
|
|
|
let topic = devLayout[i].topic;
|
2022-09-10 02:59:03 +02:00
|
|
|
if (topic) {
|
|
|
|
|
devLayout[i].ws = ws;
|
|
|
|
|
topic = topic.substring(topic.lastIndexOf("/") + 1, topic.length);
|
|
|
|
|
if (key === topic) {
|
2022-09-11 14:14:16 +02:00
|
|
|
console.log("[i]", "updated " + topic, value);
|
2022-09-10 02:59:03 +02:00
|
|
|
devLayout[i].status = value;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2022-02-27 01:49:03 +01:00
|
|
|
}
|
2022-03-01 01:43:55 +01:00
|
|
|
}
|
2022-02-25 17:57:47 +01:00
|
|
|
}
|
2022-02-26 01:09:17 +01:00
|
|
|
}
|
|
|
|
|
|
2022-09-01 12:51:17 +02:00
|
|
|
//данная функция обновляет статусы всех виджетов хранящихся в layoutJson
|
2022-02-26 01:09:17 +01:00
|
|
|
function udateStatusOfWidget(newStatusJson) {
|
|
|
|
|
for (let i = 0; i < layoutJson.length; i++) {
|
|
|
|
|
let topic = layoutJson[i].topic;
|
|
|
|
|
if (topic === newStatusJson.topic) {
|
2022-09-11 01:30:38 +02:00
|
|
|
layoutJson[i] = jsonConcat(layoutJson[i], newStatusJson);
|
|
|
|
|
//layoutJson[i].status = newStatusJson.status;
|
2022-08-16 00:54:14 +02:00
|
|
|
//получен ответ - выключаем красный цвет
|
|
|
|
|
layoutJson[i].sent = false;
|
2022-02-26 01:09:17 +01:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-02-25 17:57:47 +01:00
|
|
|
}
|
|
|
|
|
|
2022-09-11 01:30:38 +02:00
|
|
|
function jsonConcat(o1, o2) {
|
|
|
|
|
for (var key in o2) {
|
|
|
|
|
o1[key] = o2[key];
|
|
|
|
|
}
|
|
|
|
|
return o1;
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-26 01:09:17 +01:00
|
|
|
async function onParced() {
|
2022-03-02 00:42:55 +01:00
|
|
|
if (currentPageName === "/|") {
|
2022-02-13 00:37:58 +01:00
|
|
|
clearParcedFlags();
|
2022-03-02 00:42:55 +01:00
|
|
|
if (debug) console.log("✔", "dashboard packet received");
|
|
|
|
|
dashReady = true;
|
2022-02-13 00:37:58 +01:00
|
|
|
}
|
2022-08-23 15:13:50 +02:00
|
|
|
if (currentPageName === "/config|" && itemsJsonParced && widgetsJsonParced && configJsonParced && settingsJsonParced && scenarioJsonParced) {
|
2022-02-13 00:37:58 +01:00
|
|
|
clearParcedFlags();
|
|
|
|
|
if (debug) console.log("✔✔", "config data parced");
|
|
|
|
|
configReady = true;
|
|
|
|
|
}
|
|
|
|
|
if (currentPageName === "/connection|" && ssidJsonParced && settingsJsonParced && errorsJsonParced) {
|
|
|
|
|
clearParcedFlags();
|
|
|
|
|
if (debug) console.log("✔✔", "connection data parced");
|
|
|
|
|
connectionReady = true;
|
|
|
|
|
}
|
2022-02-23 22:56:17 +01:00
|
|
|
if (currentPageName === "/list|" && deviceListParced) {
|
2022-02-13 00:37:58 +01:00
|
|
|
clearParcedFlags();
|
|
|
|
|
if (debug) console.log("✔✔", "list data parced");
|
|
|
|
|
listReady = true;
|
|
|
|
|
}
|
2022-02-18 19:48:15 +01:00
|
|
|
if (currentPageName === "/system|" && errorsJsonParced && settingsJsonParced) {
|
2022-02-13 00:37:58 +01:00
|
|
|
clearParcedFlags();
|
2022-02-18 19:48:15 +01:00
|
|
|
getVersionsList();
|
2022-02-13 00:37:58 +01:00
|
|
|
if (debug) console.log("✔✔", "system data parced");
|
|
|
|
|
systemReady = true;
|
|
|
|
|
}
|
2022-09-13 22:44:37 +02:00
|
|
|
if (currentPageName === "/dev|" && errorsJsonParced && settingsJsonParced && configJsonParced && itemsJsonParced) {
|
|
|
|
|
clearParcedFlags();
|
|
|
|
|
getVersionsList();
|
|
|
|
|
if (debug) console.log("✔✔", "dev data parced");
|
|
|
|
|
devReady = true;
|
|
|
|
|
}
|
2022-02-13 00:37:58 +01:00
|
|
|
}
|
|
|
|
|
|
2022-01-31 01:45:42 +01:00
|
|
|
function saveConfig() {
|
2022-02-09 16:43:24 +01:00
|
|
|
wsSendMsg(selectedWs, "/tuoyal|" + JSON.stringify(generateLayout()));
|
2022-09-14 18:20:07 +02:00
|
|
|
del();
|
2022-02-09 16:43:24 +01:00
|
|
|
wsSendMsg(selectedWs, "/gifnoc|" + JSON.stringify(configJson));
|
2022-08-23 15:13:50 +02:00
|
|
|
wsSendMsg(selectedWs, "/oiranecs|" + JSON.stringify(scenarioJson));
|
2022-01-17 00:08:26 +01:00
|
|
|
clearData();
|
|
|
|
|
sendCurrentPageName();
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-12 03:07:59 +01:00
|
|
|
function saveSett() {
|
|
|
|
|
var size = Object.keys(settingsJson).length;
|
|
|
|
|
console.log("[i]", "settingsJson length: " + size);
|
|
|
|
|
if (size > 5) {
|
2022-02-15 15:22:54 +01:00
|
|
|
jsonArrWrite(deviceList, "ip", getIP(selectedWs), "name", settingsJson.name);
|
|
|
|
|
deviceList = deviceList;
|
2022-02-12 03:07:59 +01:00
|
|
|
wsSendMsg(selectedWs, "/sgnittes|" + JSON.stringify(settingsJson));
|
|
|
|
|
} else {
|
|
|
|
|
window.alert("Ошибка");
|
|
|
|
|
}
|
2022-02-02 23:37:15 +01:00
|
|
|
clearData();
|
|
|
|
|
sendCurrentPageName();
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-26 00:01:29 +02:00
|
|
|
function cleanLogs() {
|
2022-09-14 18:20:07 +02:00
|
|
|
wsSendMsg(selectedWs, "/clean1|");
|
2022-08-26 00:01:29 +02:00
|
|
|
}
|
|
|
|
|
|
2022-02-12 03:07:59 +01:00
|
|
|
function saveMqtt() {
|
|
|
|
|
var size = Object.keys(settingsJson).length;
|
|
|
|
|
console.log("[i]", "settingsJson length: " + size);
|
|
|
|
|
if (size > 5) {
|
|
|
|
|
wsSendMsg(selectedWs, "/sgnittes|" + JSON.stringify(settingsJson));
|
|
|
|
|
} else {
|
|
|
|
|
window.alert("Ошибка");
|
|
|
|
|
}
|
|
|
|
|
clearData();
|
|
|
|
|
wsSendMsg(selectedWs, "/mqtt|");
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-11 14:14:16 +02:00
|
|
|
function getInput() {
|
|
|
|
|
let input = {
|
|
|
|
|
name: "inputDate",
|
2022-09-13 22:44:37 +02:00
|
|
|
//descr: "Выберите дату",
|
2022-09-11 14:14:16 +02:00
|
|
|
widget: "input",
|
|
|
|
|
size: "small",
|
|
|
|
|
color: "orange",
|
|
|
|
|
type: "date",
|
|
|
|
|
};
|
|
|
|
|
return input;
|
|
|
|
|
}
|
2022-09-10 02:59:03 +02:00
|
|
|
|
2022-09-14 18:20:07 +02:00
|
|
|
function del() {
|
|
|
|
|
for (let i = 0; i < configJson.length; i++) {
|
|
|
|
|
let config = configJson[i];
|
|
|
|
|
delete config["show"];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//по конфигу делаем виджеты
|
2022-01-31 01:45:42 +01:00
|
|
|
function generateLayout() {
|
|
|
|
|
let layout = [];
|
|
|
|
|
for (let i = 0; i < configJson.length; i++) {
|
2022-02-02 23:37:15 +01:00
|
|
|
let config = Object.assign({}, configJson[i]);
|
2022-01-31 01:45:42 +01:00
|
|
|
let setWidget = config.widget;
|
|
|
|
|
let error = true;
|
|
|
|
|
for (let w = 0; w < widgetsJson.length; w++) {
|
|
|
|
|
if (setWidget === widgetsJson[w].name) {
|
2022-02-02 23:37:15 +01:00
|
|
|
let widget = Object.assign({}, widgetsJson[w]);
|
2022-01-31 01:45:42 +01:00
|
|
|
widget.page = config.page;
|
|
|
|
|
widget.descr = config.descr;
|
2022-02-04 00:03:52 +01:00
|
|
|
//widget.id = config.id;
|
2022-02-07 23:40:00 +01:00
|
|
|
//widget.ws = selectedWs;
|
2022-09-11 14:14:16 +02:00
|
|
|
|
2022-02-04 00:03:52 +01:00
|
|
|
widget.topic = settingsJson.root + "/" + config.id;
|
2022-01-31 01:45:42 +01:00
|
|
|
layout.push(widget);
|
2022-09-10 02:59:03 +02:00
|
|
|
if (widget.widget === "chart") {
|
2022-09-11 14:14:16 +02:00
|
|
|
let input = getInput();
|
2022-09-10 02:59:03 +02:00
|
|
|
input.page = config.page;
|
2022-09-13 22:44:37 +02:00
|
|
|
input.topic = settingsJson.root + "/" + config.id + "-date";
|
|
|
|
|
input.descr = config.descr;
|
|
|
|
|
console.log("[i]", "topic ", widget.topic);
|
2022-09-10 02:59:03 +02:00
|
|
|
layout.push(input);
|
|
|
|
|
}
|
2022-01-31 01:45:42 +01:00
|
|
|
error = false;
|
|
|
|
|
break;
|
|
|
|
|
} else {
|
|
|
|
|
error = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (error) console.log("[e]", "error, widget not found: " + setWidget);
|
|
|
|
|
}
|
2022-02-02 23:37:15 +01:00
|
|
|
if (debug) console.log("[i] layout:", JSON.stringify(layout));
|
2022-02-01 00:42:28 +01:00
|
|
|
return layout;
|
2022-01-31 01:45:42 +01:00
|
|
|
}
|
|
|
|
|
|
2022-01-17 00:08:26 +01:00
|
|
|
function clearData() {
|
|
|
|
|
configJson = [];
|
2022-01-30 17:44:53 +01:00
|
|
|
configJsonBlob.clear();
|
2022-02-02 23:37:15 +01:00
|
|
|
|
2022-01-22 00:15:22 +01:00
|
|
|
widgetsJson = [];
|
2022-01-30 17:44:53 +01:00
|
|
|
widgetsJsonBlob.clear();
|
|
|
|
|
|
2022-02-02 23:37:15 +01:00
|
|
|
itemsJson = [];
|
|
|
|
|
itemsJsonBlob.clear();
|
|
|
|
|
|
|
|
|
|
layoutJson = [];
|
2022-02-26 01:09:17 +01:00
|
|
|
layoutJsonArray = [];
|
2022-02-02 23:37:15 +01:00
|
|
|
|
2022-08-23 15:13:50 +02:00
|
|
|
scenarioJson = "";
|
2022-02-23 22:56:17 +01:00
|
|
|
scenarioTxtBlob.clear();
|
2022-02-02 23:37:15 +01:00
|
|
|
|
2022-02-23 22:56:17 +01:00
|
|
|
settingsJson = {};
|
2022-02-08 16:47:26 +01:00
|
|
|
errorsJson = {};
|
2022-09-10 02:59:03 +02:00
|
|
|
//coreMessages = [];
|
2022-02-19 23:35:30 +01:00
|
|
|
|
2022-02-13 00:37:58 +01:00
|
|
|
dashReady = false;
|
|
|
|
|
configReady = false;
|
|
|
|
|
connectionReady = false;
|
|
|
|
|
listReady = false;
|
|
|
|
|
systemReady = false;
|
|
|
|
|
|
|
|
|
|
clearParcedFlags();
|
|
|
|
|
|
2022-01-30 17:44:53 +01:00
|
|
|
if (debug) console.log("[i]", "all app data cleared");
|
2022-01-17 00:08:26 +01:00
|
|
|
}
|
|
|
|
|
|
2022-02-13 00:37:58 +01:00
|
|
|
function clearParcedFlags() {
|
|
|
|
|
configJsonParced = false;
|
|
|
|
|
widgetsJsonParced = false;
|
|
|
|
|
itemsJsonParced = false;
|
2022-02-26 01:09:17 +01:00
|
|
|
layoutJsonArrayParced = false;
|
2022-02-13 00:37:58 +01:00
|
|
|
settingsJsonParced = false;
|
|
|
|
|
errorsJsonParced = false;
|
|
|
|
|
ssidJsonParced = false;
|
|
|
|
|
paramsJsonParced = false;
|
|
|
|
|
statusJsonParced = false;
|
2022-02-23 22:56:17 +01:00
|
|
|
deviceListParced = false;
|
2022-08-23 15:13:50 +02:00
|
|
|
scenarioJsonParced = false;
|
2022-02-26 01:09:17 +01:00
|
|
|
clearFlags();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function clearFlags() {
|
|
|
|
|
for (let i = 0; i < deviceList.length; i++) {
|
|
|
|
|
deviceList[i].pp = false;
|
|
|
|
|
deviceList[i].lp = false;
|
|
|
|
|
}
|
2022-02-13 00:37:58 +01:00
|
|
|
}
|
|
|
|
|
|
2021-12-08 22:59:21 +01:00
|
|
|
function wsPush(ws, topic, status) {
|
|
|
|
|
let msg = topic + " " + status;
|
2022-08-14 17:13:49 +02:00
|
|
|
if (debug) console.log("[i]", "ws: ", ws, msg);
|
2022-08-15 01:30:59 +02:00
|
|
|
layoutJson = layoutJson;
|
|
|
|
|
let key = topic.substring(topic.lastIndexOf("/") + 1, topic.length);
|
|
|
|
|
wsSendMsg(ws, "/control|" + key + "/" + status);
|
2021-12-08 22:59:21 +01:00
|
|
|
}
|
|
|
|
|
|
2021-12-07 22:14:59 +01:00
|
|
|
function wsTestMsgTask() {
|
2021-12-21 00:48:44 +01:00
|
|
|
setTimeout(wsTestMsgTask, reconnectTimeout);
|
2022-02-24 00:59:10 +01:00
|
|
|
if (!rebootingUpdatingInProgress) {
|
|
|
|
|
if (debug) console.log("[i]", "----timer tick----");
|
|
|
|
|
if (!firstTime) {
|
|
|
|
|
deviceList.forEach((device) => {
|
|
|
|
|
if (!getDeviceStatus(device.ws)) {
|
|
|
|
|
wsConnect(device.ws);
|
|
|
|
|
wsEventAdd(device.ws);
|
|
|
|
|
} else {
|
|
|
|
|
wsSendMsg(device.ws, "/tst|");
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
firstTime = false;
|
|
|
|
|
} else {
|
|
|
|
|
if (debug) console.log("[i]", "----timer skipped----");
|
2021-12-10 16:07:09 +01:00
|
|
|
}
|
2021-12-08 22:59:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function wsSendMsg(ws, msg) {
|
|
|
|
|
if (socket[ws] && socket[ws].readyState === 1) {
|
|
|
|
|
socket[ws].send(msg);
|
2022-02-15 15:22:54 +01:00
|
|
|
if (debug) console.log("[i]", getIP(ws), ws, "msg send success", msg);
|
2021-12-08 22:59:21 +01:00
|
|
|
} else {
|
2022-02-15 15:22:54 +01:00
|
|
|
if (debug) console.log("[e]", getIP(ws), ws, "msg not send", msg);
|
2021-12-07 22:14:59 +01:00
|
|
|
}
|
2021-12-06 01:21:55 +01:00
|
|
|
}
|
|
|
|
|
|
2022-02-15 00:02:30 +01:00
|
|
|
function sendToAllDevices(msg) {
|
|
|
|
|
deviceList.forEach((device) => {
|
|
|
|
|
if (device.status) {
|
|
|
|
|
wsSendMsg(device.ws, msg);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-01 16:01:19 +01:00
|
|
|
//***********************************************************dashboard***************************************************************/
|
2022-02-26 01:09:17 +01:00
|
|
|
function sortingLayout() {
|
2022-03-02 00:42:55 +01:00
|
|
|
//сортируем весь layout по алфавиту
|
|
|
|
|
layoutJson.sort(function (a, b) {
|
|
|
|
|
if (a.descr < b.descr) {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
if (a.descr > b.descr) {
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
});
|
|
|
|
|
//формируем json всех карточек
|
2021-10-17 07:09:55 +08:00
|
|
|
pages = [];
|
2022-02-02 23:37:15 +01:00
|
|
|
const newPage = Array.from(new Set(Array.from(layoutJson, ({ page }) => page)));
|
2021-10-17 07:09:55 +08:00
|
|
|
newPage.forEach(function (item, i, arr) {
|
2022-02-07 16:36:43 +01:00
|
|
|
pages = [
|
|
|
|
|
...pages,
|
|
|
|
|
JSON.parse(
|
|
|
|
|
JSON.stringify({
|
|
|
|
|
page: item,
|
|
|
|
|
})
|
|
|
|
|
),
|
|
|
|
|
];
|
2021-10-17 07:09:55 +08:00
|
|
|
});
|
2022-03-02 00:42:55 +01:00
|
|
|
//сортируем карточки по алфавиту
|
2021-10-17 07:09:55 +08:00
|
|
|
pages.sort(function (a, b) {
|
|
|
|
|
if (a.page < b.page) {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
if (a.page > b.page) {
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
});
|
|
|
|
|
}
|
2021-12-05 00:49:36 +01:00
|
|
|
|
2022-02-01 16:01:19 +01:00
|
|
|
//***********************************************************logging******************************************************************/
|
2021-12-07 22:14:59 +01:00
|
|
|
const addCoreMsg = (msg) => {
|
2022-02-19 23:35:30 +01:00
|
|
|
if (coreMessages.length >= LOG_MAX_MESSAGES) {
|
|
|
|
|
coreMessages.shift();
|
2021-12-05 00:49:36 +01:00
|
|
|
}
|
2022-02-19 23:35:30 +01:00
|
|
|
//const time = new Date().getTime();
|
2022-02-07 16:36:43 +01:00
|
|
|
coreMessages = [
|
|
|
|
|
...coreMessages,
|
|
|
|
|
{
|
|
|
|
|
msg,
|
|
|
|
|
},
|
|
|
|
|
];
|
2021-12-07 22:14:59 +01:00
|
|
|
coreMessages.sort(function (a, b) {
|
2021-12-05 00:49:36 +01:00
|
|
|
if (a.time > b.time) {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
if (a.time < b.time) {
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
});
|
|
|
|
|
};
|
2021-12-08 22:59:21 +01:00
|
|
|
|
2022-02-01 16:01:19 +01:00
|
|
|
//***********************************************************dev list******************************************************************/
|
2022-02-07 23:40:00 +01:00
|
|
|
|
|
|
|
|
function combineArrays(A, B) {
|
|
|
|
|
var ids = new Set(A.map((d) => d.ip));
|
|
|
|
|
let output = [...A, ...B.filter((d) => !ids.has(d.ip))];
|
|
|
|
|
return output;
|
2022-02-07 16:36:43 +01:00
|
|
|
}
|
|
|
|
|
|
2022-02-07 23:40:00 +01:00
|
|
|
function whenDeviceListWasUpdated() {
|
|
|
|
|
getSelectedDeviceData(selectedWs);
|
2021-12-09 22:35:04 +01:00
|
|
|
socketConnected = selectedDeviceData.status;
|
2022-02-07 23:40:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function devicesDropdownChange() {
|
|
|
|
|
whenDeviceListWasUpdated();
|
2021-12-25 00:20:49 +01:00
|
|
|
clearData();
|
2022-08-23 15:43:30 +02:00
|
|
|
handleNavigation();
|
|
|
|
|
//sendCurrentPageName();
|
2021-12-11 13:54:28 +01:00
|
|
|
if (debug) console.log("[i]", "user selected device:", selectedDeviceData.name);
|
2021-12-13 00:01:21 +01:00
|
|
|
if (selectedDeviceData.ip === myip) {
|
|
|
|
|
if (debug) console.log("[i]", "user selected original device", selectedDeviceData.name);
|
|
|
|
|
}
|
2021-12-09 22:35:04 +01:00
|
|
|
}
|
|
|
|
|
|
2022-02-07 23:40:00 +01:00
|
|
|
function getSelectedDeviceData(ws) {
|
|
|
|
|
for (let i = 0; i < deviceList.length; i++) {
|
|
|
|
|
let device = deviceList[i];
|
|
|
|
|
if (device.ws === ws) {
|
|
|
|
|
selectedDeviceData = device;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-12 03:07:59 +01:00
|
|
|
function addDevInList() {
|
2022-02-07 16:36:43 +01:00
|
|
|
//createDefaultDevice();
|
2021-12-12 00:20:47 +01:00
|
|
|
if (!showInput) {
|
|
|
|
|
if (newDevice.name !== undefined && newDevice.ip !== undefined && newDevice.id !== undefined) {
|
|
|
|
|
newDevice.status = false;
|
|
|
|
|
deviceList.push(newDevice);
|
|
|
|
|
deviceList = deviceList;
|
|
|
|
|
newDevice = {};
|
2022-02-07 23:40:00 +01:00
|
|
|
whenDeviceListWasUpdated();
|
2021-12-12 00:20:47 +01:00
|
|
|
connectToAllDevices();
|
2021-12-13 00:01:21 +01:00
|
|
|
if (debug) console.log("[i]", "selected device:", selectedDeviceData);
|
2021-12-12 00:20:47 +01:00
|
|
|
} else {
|
|
|
|
|
if (debug) console.log("[e]", "wrong data");
|
|
|
|
|
}
|
2021-12-13 02:36:26 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-07 23:40:00 +01:00
|
|
|
function updateThisDeviceInList() {
|
|
|
|
|
for (let i = 0; i < deviceList.length; i++) {
|
|
|
|
|
let device = deviceList[i];
|
|
|
|
|
if (device.ip === myip) {
|
|
|
|
|
device.name = settingsJson.name;
|
|
|
|
|
device.id = settingsJson.id;
|
|
|
|
|
settingsJson = settingsJson;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-01 16:01:19 +01:00
|
|
|
//****************************************************************json******************************************************************/
|
2021-12-14 20:55:53 +01:00
|
|
|
function getJsonObject(array, number) {
|
|
|
|
|
let num = 0;
|
|
|
|
|
let out = {};
|
|
|
|
|
array.forEach((object) => {
|
|
|
|
|
if (num === number) {
|
|
|
|
|
out = object;
|
|
|
|
|
}
|
|
|
|
|
num++;
|
|
|
|
|
});
|
|
|
|
|
return out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const syntaxHighlight = (json) => {
|
|
|
|
|
try {
|
|
|
|
|
json = JSON.stringify(JSON.parse(json), null, 4);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
return json;
|
|
|
|
|
}
|
|
|
|
|
json = json.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
|
|
|
json = json.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, function (match) {
|
|
|
|
|
return match;
|
|
|
|
|
});
|
|
|
|
|
return json;
|
|
|
|
|
};
|
|
|
|
|
|
2021-12-25 00:20:49 +01:00
|
|
|
function IsJsonParse(str) {
|
|
|
|
|
try {
|
|
|
|
|
JSON.parse(str);
|
|
|
|
|
} catch (e) {
|
2022-02-27 01:49:03 +01:00
|
|
|
if (debug) console.log("[e]", "json parce error: ", str);
|
2021-12-25 00:20:49 +01:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-17 22:19:14 +01:00
|
|
|
//пример как формировать массив json
|
|
|
|
|
function createWidgetsDropdown() {
|
|
|
|
|
let widgetsDropdown = [];
|
2022-01-22 00:15:22 +01:00
|
|
|
widgetsJson.forEach((widget) => {
|
2022-01-17 22:19:14 +01:00
|
|
|
widgetsDropdown.push({
|
|
|
|
|
id: widget.name,
|
|
|
|
|
val: widget.rus,
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
widgetsDropdown = widgetsDropdown;
|
|
|
|
|
if (debug) console.log("[i]", widgetsDropdown);
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-15 15:22:54 +01:00
|
|
|
function jsonArrWrite(jsonArr, idKey, idValue, paramKey, paramValue) {
|
|
|
|
|
for (let i = 0; i < jsonArr.length; i++) {
|
|
|
|
|
let obj = jsonArr[i];
|
|
|
|
|
for (const [key, value] of Object.entries(obj)) {
|
|
|
|
|
if (key == idKey && value == idValue) {
|
|
|
|
|
obj[paramKey] = paramValue;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-01 16:01:19 +01:00
|
|
|
//**********************************************************post and get*****************************************************************/
|
2021-12-22 00:28:00 +01:00
|
|
|
//editRequest("192.168.88.235", "data data data data", "file.json")
|
|
|
|
|
|
|
|
|
|
function editRequest(url, data, filename) {
|
|
|
|
|
if (debug) console.log("[i]", "request for edit file");
|
|
|
|
|
var xmlHttp = new XMLHttpRequest();
|
|
|
|
|
var formData = new FormData();
|
2022-02-07 16:36:43 +01:00
|
|
|
formData.append(
|
|
|
|
|
"data",
|
|
|
|
|
new Blob([data], {
|
|
|
|
|
type: "text/json",
|
|
|
|
|
}),
|
|
|
|
|
"/" + filename
|
|
|
|
|
);
|
2021-12-22 00:28:00 +01:00
|
|
|
xmlHttp.open("POST", "http://" + url + "/edit");
|
|
|
|
|
xmlHttp.onload = function () {
|
|
|
|
|
//во время загрузки
|
|
|
|
|
};
|
|
|
|
|
xmlHttp.send(formData);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function handleSubmit(url) {
|
|
|
|
|
try {
|
|
|
|
|
console.log(url);
|
|
|
|
|
let res = await fetch(url, {
|
|
|
|
|
mode: "no-cors",
|
|
|
|
|
method: "GET",
|
|
|
|
|
});
|
|
|
|
|
if (res.ok) {
|
|
|
|
|
console.log("OK", res.status);
|
|
|
|
|
//console.log(url);
|
|
|
|
|
} else {
|
|
|
|
|
console.log("error", res.status);
|
|
|
|
|
//console.log(url);
|
|
|
|
|
}
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.log(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function getRequestJson(url) {
|
2022-02-18 19:48:15 +01:00
|
|
|
try {
|
|
|
|
|
let res = await fetch(url, {
|
|
|
|
|
mode: "no-cors",
|
|
|
|
|
method: "GET",
|
|
|
|
|
});
|
|
|
|
|
if (res.ok) {
|
|
|
|
|
configSetupJson = await res.json();
|
|
|
|
|
} else {
|
|
|
|
|
console.log("error", res.status);
|
|
|
|
|
}
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.log(e);
|
2021-12-22 00:28:00 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-26 00:04:34 +01:00
|
|
|
function showAdditionalParams(id) {
|
2021-12-26 01:34:29 +01:00
|
|
|
additionalParams = true;
|
2021-12-26 00:04:34 +01:00
|
|
|
if (debug) console.log("[i]", "user open add params ", id);
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-01 16:01:19 +01:00
|
|
|
//**********************************************************modal*************************************************************************/
|
2021-12-27 02:46:05 +01:00
|
|
|
function showModal() {
|
|
|
|
|
showModalFlag = !showModalFlag;
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-01 16:01:19 +01:00
|
|
|
function onCheck() {
|
|
|
|
|
let width = screen.width;
|
|
|
|
|
console.log("width", width);
|
|
|
|
|
if (width < 900) {
|
|
|
|
|
preventMove = true;
|
|
|
|
|
} else {
|
|
|
|
|
preventMove = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//************************************************elements and presets dropdown************************************************************/
|
|
|
|
|
|
2022-02-12 03:07:59 +01:00
|
|
|
function ssidClick() {
|
2022-02-09 16:43:24 +01:00
|
|
|
wsSendMsg(selectedWs, "/scan|");
|
2022-02-05 02:13:46 +01:00
|
|
|
}
|
|
|
|
|
|
2022-02-08 16:47:26 +01:00
|
|
|
function rebootEsp() {
|
|
|
|
|
if (debug) console.log("[i]", "reboot...");
|
2022-02-09 16:43:24 +01:00
|
|
|
wsSendMsg(selectedWs, "/reboot|");
|
2022-02-24 00:59:10 +01:00
|
|
|
rebootingUpdatingInProgress = true;
|
2022-02-08 16:47:26 +01:00
|
|
|
myTimeout = setTimeout(rebootingTask, rebootingTimeout);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function rebootingTask() {
|
|
|
|
|
clearTimeout(myTimeout);
|
2022-02-23 22:56:17 +01:00
|
|
|
clearData();
|
2022-02-08 16:47:26 +01:00
|
|
|
connectToAllDevices();
|
2022-02-24 00:59:10 +01:00
|
|
|
rebootingUpdatingInProgress = false;
|
2022-02-08 16:47:26 +01:00
|
|
|
}
|
2022-02-09 16:43:24 +01:00
|
|
|
|
|
|
|
|
function cancelAlarm(alarmKey) {
|
|
|
|
|
console.log("[x]", alarmKey);
|
2022-02-11 16:49:34 +01:00
|
|
|
errorsJson[alarmKey] = 0;
|
|
|
|
|
wsSendMsg(selectedWs, '/rorre|{"' + alarmKey + '":0}');
|
2022-02-09 16:43:24 +01:00
|
|
|
}
|
2022-02-11 19:32:05 +01:00
|
|
|
|
2022-02-18 19:48:15 +01:00
|
|
|
//************************************************update esp firm************************************************************//
|
|
|
|
|
|
|
|
|
|
async function getVersionsList() {
|
|
|
|
|
try {
|
|
|
|
|
let url = settingsJson.serverip + "/iotm/ver.json";
|
|
|
|
|
console.log("url", url);
|
|
|
|
|
let res = await fetch(url, {
|
|
|
|
|
mode: "cors",
|
|
|
|
|
method: "GET",
|
|
|
|
|
});
|
|
|
|
|
if (res.ok) {
|
|
|
|
|
versionsList = await res.json();
|
|
|
|
|
versionsList = versionsList[errorsJson.bn];
|
|
|
|
|
choosingVersion = errorsJson.bver;
|
|
|
|
|
console.log(JSON.stringify(versionsList));
|
|
|
|
|
} else {
|
|
|
|
|
choosingVersion = undefined;
|
|
|
|
|
console.log("error, versions list not received", res.statusText);
|
|
|
|
|
}
|
|
|
|
|
} catch (e) {
|
|
|
|
|
choosingVersion = undefined;
|
|
|
|
|
console.log("error, versions list not received");
|
|
|
|
|
console.log(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function startUpdate() {
|
|
|
|
|
if (choosingVersion !== undefined) {
|
|
|
|
|
if (choosingVersion === errorsJson.bver) {
|
|
|
|
|
window.alert("Эта версия уже установленна");
|
|
|
|
|
} else {
|
|
|
|
|
if (confirm("Запустить обновление?")) {
|
|
|
|
|
console.log("start update...");
|
|
|
|
|
//запишем выбранную версию в файл на esp
|
|
|
|
|
wsSendMsg(selectedWs, '/rorre|{"chver":' + choosingVersion + "}");
|
|
|
|
|
//начнем обновление
|
|
|
|
|
wsSendMsg(selectedWs, "/update|");
|
2022-02-24 00:59:10 +01:00
|
|
|
rebootingUpdatingInProgress = true;
|
2022-02-18 22:53:39 +01:00
|
|
|
myTimeout = setTimeout(rebootingTask, updatingTimeout);
|
2022-02-18 19:48:15 +01:00
|
|
|
} else {
|
|
|
|
|
console.log("update canceled");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
window.alert("Версия не выбрана или сервер недоступен");
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-09-16 02:00:52 +08:00
|
|
|
</script>
|
|
|
|
|
|
2022-02-01 16:01:19 +01:00
|
|
|
<div class="flex flex-col h-screen bg-gray-50">
|
2022-02-24 00:59:10 +01:00
|
|
|
{#if rebootingUpdatingInProgress}
|
2022-02-08 16:47:26 +01:00
|
|
|
<Progress />
|
|
|
|
|
{/if}
|
2022-02-01 16:01:19 +01:00
|
|
|
<header class="h-10 w-full bg-gray-100 overflow-auto shadow-md">
|
2022-02-07 16:36:43 +01:00
|
|
|
<div class="flex content-center items-center justify-end">
|
2022-02-08 16:47:26 +01:00
|
|
|
<div class="px-15 py-1">
|
2022-02-07 23:40:00 +01:00
|
|
|
<select class="border border-indigo-500 border-4" bind:value={selectedWs} on:change={() => devicesDropdownChange()}>
|
2021-12-09 00:10:10 +01:00
|
|
|
{#each deviceList as device}
|
2022-02-07 23:40:00 +01:00
|
|
|
<option value={device.ws}>
|
2021-12-09 00:10:10 +01:00
|
|
|
{device.name}
|
|
|
|
|
</option>
|
|
|
|
|
{/each}
|
|
|
|
|
</select>
|
|
|
|
|
</div>
|
2022-08-31 22:25:22 +02:00
|
|
|
<!--<div class="pl-4 pr-1 py-1">-->
|
|
|
|
|
<!--<BookIcon color={socketConnected === true ? "text-green-500" : "text-red-500"} />-->
|
|
|
|
|
<!--</div>-->
|
2022-02-07 16:36:43 +01:00
|
|
|
<div class="pl-4 pr-4 py-1">
|
|
|
|
|
<CloudIcon color={socketConnected === true ? "text-green-500" : "text-red-500"} />
|
2021-12-09 00:10:10 +01:00
|
|
|
</div>
|
2021-12-06 01:21:55 +01:00
|
|
|
</div>
|
2022-02-01 16:01:19 +01:00
|
|
|
</header>
|
|
|
|
|
|
|
|
|
|
<nav class="flex">
|
2022-02-24 00:59:10 +01:00
|
|
|
<input class="w-0 h-0" bind:checked={opened} on:change={() => onCheck()} id="menu__toggle" type="checkbox" />
|
|
|
|
|
|
2022-02-01 16:01:19 +01:00
|
|
|
<label class="menu__btn" for="menu__toggle">
|
|
|
|
|
<span />
|
|
|
|
|
</label>
|
|
|
|
|
|
|
|
|
|
<ul class="menu__box">
|
|
|
|
|
<li>
|
|
|
|
|
<a class="menu__item" href="/">{"Управление"}</a>
|
|
|
|
|
</li>
|
|
|
|
|
<li>
|
|
|
|
|
<a class="menu__item" href="/config">{"Конфигуратор"}</a>
|
|
|
|
|
</li>
|
|
|
|
|
<li>
|
|
|
|
|
<a class="menu__item" href="/connection">{"Подключение"}</a>
|
|
|
|
|
</li>
|
|
|
|
|
<li>
|
|
|
|
|
<a class="menu__item" href="/list">{"Устройства"}</a>
|
|
|
|
|
</li>
|
|
|
|
|
<li>
|
2022-02-08 21:42:40 +01:00
|
|
|
<a class="menu__item" href="/system">{"Системные"}</a>
|
2022-02-01 16:01:19 +01:00
|
|
|
</li>
|
2022-09-10 02:59:03 +02:00
|
|
|
{#if devMode}
|
|
|
|
|
<li>
|
|
|
|
|
<a class="menu__item" href="/dev">{"Разработчик"}</a>
|
|
|
|
|
</li>
|
2022-09-13 22:44:37 +02:00
|
|
|
<li>
|
|
|
|
|
<a class="menu__item" href="/files">{"Файлы"}</a>
|
|
|
|
|
</li>
|
2022-09-10 02:59:03 +02:00
|
|
|
{/if}
|
2022-02-01 16:01:19 +01:00
|
|
|
</ul>
|
|
|
|
|
</nav>
|
|
|
|
|
|
|
|
|
|
<main class="flex-1 overflow-y-auto p-0 {opened === true && !preventMove ? 'ml-36' : 'ml-0'}">
|
|
|
|
|
<ul class="menu__main">
|
|
|
|
|
<div class="bg-cover pt-0 px-4">
|
2022-02-05 02:13:46 +01:00
|
|
|
{#if !socketConnected}
|
2022-02-07 02:08:21 +01:00
|
|
|
<Alarm title="Нет соединения" />
|
2022-02-05 02:13:46 +01:00
|
|
|
{:else}
|
|
|
|
|
<Route path="/">
|
2022-02-13 00:37:58 +01:00
|
|
|
<DashboardPage show={dashReady} layoutJson={layoutJson} pages={pages} wsPush={(ws, topic, status) => wsPush(ws, topic, status)} />
|
2022-02-05 02:13:46 +01:00
|
|
|
</Route>
|
|
|
|
|
<Route path="/config">
|
2022-08-30 21:29:05 +02:00
|
|
|
<ConfigPage show={configReady} configJson={configJson} widgetsJson={widgetsJson} itemsJson={itemsJson} saveConfig={() => saveConfig()} cleanLogs={() => cleanLogs()} rebootEsp={() => rebootEsp()} scenarioJson={scenarioJson} />
|
2022-02-05 02:13:46 +01:00
|
|
|
</Route>
|
|
|
|
|
<Route path="/connection">
|
2022-02-13 00:37:58 +01:00
|
|
|
<ConnectionPage show={connectionReady} rebootEsp={() => rebootEsp()} ssidClick={() => ssidClick()} saveSett={() => saveSett()} saveMqtt={() => saveMqtt()} settingsJson={settingsJson} errorsJson={errorsJson} ssidJson={ssidJson} />
|
|
|
|
|
</Route>
|
|
|
|
|
<Route path="/list">
|
2022-02-15 00:02:30 +01:00
|
|
|
<ListPage show={listReady} deviceList={deviceList} showInput={showInput} addDevInList={() => addDevInList()} newDevice={newDevice} sendToAllDevices={(msg) => sendToAllDevices(msg)} />
|
2022-02-05 02:13:46 +01:00
|
|
|
</Route>
|
2022-02-08 21:42:40 +01:00
|
|
|
<Route path="/system">
|
2022-08-26 00:01:29 +02:00
|
|
|
<SystemPage show={systemReady} errorsJson={errorsJson} settingsJson={settingsJson} saveSett={() => saveSett()} cleanLogs={() => cleanLogs()} cancelAlarm={(alarmKey) => cancelAlarm(alarmKey)} versionsList={versionsList} bind:choosingVersion startUpdate={() => startUpdate()} coreMessages={coreMessages} />
|
2022-02-05 02:13:46 +01:00
|
|
|
</Route>
|
2022-09-10 02:59:03 +02:00
|
|
|
{#if devMode}
|
|
|
|
|
<Route path="/dev">
|
2022-09-13 22:44:37 +02:00
|
|
|
<DevPage show={devReady} layoutJson={layoutJson} errorsJson={errorsJson} settingsJson={settingsJson} configJson={configJson} itemsJson={itemsJson} />
|
|
|
|
|
</Route>
|
|
|
|
|
<Route path="/files">
|
|
|
|
|
<FilesPage show={systemReady} />
|
2022-09-10 02:59:03 +02:00
|
|
|
</Route>
|
|
|
|
|
{/if}
|
2022-02-05 02:13:46 +01:00
|
|
|
{/if}
|
2022-02-01 16:01:19 +01:00
|
|
|
</div>
|
|
|
|
|
</ul>
|
|
|
|
|
</main>
|
2022-02-05 02:13:46 +01:00
|
|
|
|
2022-02-07 16:36:43 +01:00
|
|
|
<footer class="h-4 bg-gray-100 border-gray-200 shadow-lg">
|
|
|
|
|
<div class="flex justify-center content-center text-xxs text-gray-500">Developed by Dmitry Borisenko</div>
|
|
|
|
|
</footer>
|
2022-02-01 16:01:19 +01:00
|
|
|
</div>
|
2021-09-16 02:00:52 +08:00
|
|
|
|
|
|
|
|
<style lang="postcss" global>
|
|
|
|
|
@tailwind base;
|
|
|
|
|
@tailwind components;
|
|
|
|
|
@tailwind utilities;
|
|
|
|
|
|
|
|
|
|
@layer components {
|
2022-02-07 16:36:43 +01:00
|
|
|
/*==================================================grids=====================================================*/
|
|
|
|
|
.grd-1col1 {
|
2021-10-16 20:49:17 +00:00
|
|
|
@apply grid grid-cols-1 justify-items-center;
|
|
|
|
|
}
|
2022-02-07 16:36:43 +01:00
|
|
|
.grd-2col1 {
|
2022-02-08 16:47:26 +01:00
|
|
|
@apply grid gap-4 grid-cols-1 sm:grid-cols-2 lg:grid-cols-2 xl:grid-cols-2 2xl:grid-cols-2 justify-items-center;
|
2022-02-07 16:36:43 +01:00
|
|
|
}
|
|
|
|
|
.grd-2col2 {
|
|
|
|
|
@apply grid gap-4 grid-cols-2 justify-items-center;
|
|
|
|
|
}
|
|
|
|
|
.grd-3col1 {
|
|
|
|
|
@apply grid gap-4 grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-3 2xl:grid-cols-3 justify-items-center;
|
|
|
|
|
}
|
2021-10-20 20:53:07 +08:00
|
|
|
/*=============================================card and items inside===============================================*/
|
2021-12-28 23:55:14 +01:00
|
|
|
.crd-itm-psn {
|
2022-02-16 00:11:57 +01:00
|
|
|
@apply flex mb-2 h-8 items-center;
|
2021-10-20 20:53:07 +08:00
|
|
|
}
|
2021-12-28 23:55:14 +01:00
|
|
|
.wgt-dscr-stl {
|
2021-10-20 20:53:07 +08:00
|
|
|
@apply pr-4 text-gray-500 font-bold;
|
|
|
|
|
}
|
2021-10-25 16:50:31 +07:00
|
|
|
/*====================================================others=====================================================*/
|
2021-12-28 23:55:14 +01:00
|
|
|
.btn-i {
|
2021-10-25 16:50:31 +07:00
|
|
|
@apply py-2 px-4 bg-indigo-500 text-white font-semibold rounded-lg shadow-md hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-indigo-400 focus:ring-opacity-75;
|
|
|
|
|
}
|
2021-12-28 23:55:14 +01:00
|
|
|
.wgt-adt-stl {
|
2021-10-27 05:11:28 +07:00
|
|
|
@apply text-center text-gray-500 font-bold;
|
2021-10-25 20:05:21 +07:00
|
|
|
}
|
2021-12-11 13:54:28 +01:00
|
|
|
/*====================================================table=====================================================*/
|
2022-02-07 02:08:21 +01:00
|
|
|
.tbl {
|
|
|
|
|
@apply table-fixed w-full select-none my-2;
|
|
|
|
|
}
|
2021-12-28 23:55:14 +01:00
|
|
|
.tbl-hd {
|
2022-02-05 02:13:46 +01:00
|
|
|
@apply text-center px-1 break-words text-gray-500 font-bold;
|
2021-12-11 13:54:28 +01:00
|
|
|
}
|
2022-02-07 16:36:43 +01:00
|
|
|
.tbl-bdy-lg {
|
2022-02-05 02:13:46 +01:00
|
|
|
@apply text-center px-1 break-words;
|
2021-12-11 13:54:28 +01:00
|
|
|
}
|
2022-02-07 16:36:43 +01:00
|
|
|
.tbl-bdy-sm {
|
2022-02-05 02:13:46 +01:00
|
|
|
@apply px-1 break-words;
|
2021-12-28 01:06:01 +01:00
|
|
|
}
|
2022-02-07 16:36:43 +01:00
|
|
|
/*====================================================inputs=====================================================*/
|
|
|
|
|
.ipt-lg {
|
|
|
|
|
@apply h-4 sm:h-7 md:h-7 lg:h-7 xl:h-7 2xl:h-7 content-center mt-2 bg-gray-50 focus:bg-white border-2 border-gray-100 text-gray-700 leading-tight focus:outline-none text-center focus:border-indigo-500;
|
|
|
|
|
}
|
|
|
|
|
.ipt-sm {
|
|
|
|
|
@apply h-3 sm:h-6 md:h-6 lg:h-6 xl:h-6 2xl:h-6 content-center bg-gray-50 focus:bg-white border-2 border-gray-100 text-gray-700 leading-tight focus:outline-none text-center focus:border-indigo-500 rounded-sm;
|
2021-12-27 22:46:16 +01:00
|
|
|
}
|
2022-02-07 16:36:43 +01:00
|
|
|
.ipt-rnd {
|
|
|
|
|
@apply content-center px-2 h-8 bg-gray-50 border-2 border-gray-200 rounded w-full text-gray-700 leading-tight focus:outline-none focus:bg-white;
|
|
|
|
|
}
|
|
|
|
|
.ipt-big {
|
|
|
|
|
@apply content-center px-2 h-8 bg-gray-50 border-2 border-gray-200 rounded w-full text-gray-700 leading-tight focus:outline-none focus:bg-white focus:border-indigo-500;
|
2021-12-29 01:21:28 +01:00
|
|
|
}
|
2022-02-07 16:36:43 +01:00
|
|
|
/*====================================================text=====================================================*/
|
|
|
|
|
.txt-ita {
|
2021-12-29 01:21:28 +01:00
|
|
|
@apply inline-block italic align-top text-right text-gray-500;
|
2021-12-12 00:20:47 +01:00
|
|
|
}
|
2022-02-07 16:36:43 +01:00
|
|
|
.txt-pad {
|
2021-12-28 22:09:44 +01:00
|
|
|
@apply px-2 py-0 sm:py-0 md:py-0 lg:py-1 xl:py-2 2xl:py-2;
|
|
|
|
|
}
|
2022-02-07 16:36:43 +01:00
|
|
|
.txt-sz {
|
2021-12-29 01:21:28 +01:00
|
|
|
@apply text-xxs sm:text-base md:text-base lg:text-base xl:text-base 2xl:text-base;
|
2021-12-28 22:09:44 +01:00
|
|
|
}
|
2021-12-12 00:20:47 +01:00
|
|
|
/*====================================================buttons=====================================================*/
|
2021-12-28 23:55:14 +01:00
|
|
|
.btn-lg {
|
2022-02-08 16:47:26 +01:00
|
|
|
@apply flex justify-center break-words content-center bg-blue-100 hover:bg-blue-200 text-gray-500 font-bold text-sm sm:text-base md:text-base lg:text-base xl:text-base 2xl:text-base h-6 sm:h-8 md:h-8 lg:h-8 xl:h-8 2xl:h-8 w-full mt-0 border border-gray-300 rounded;
|
2021-12-12 00:20:47 +01:00
|
|
|
}
|
2021-12-28 23:55:14 +01:00
|
|
|
.btn-tbl {
|
2021-12-29 01:21:28 +01:00
|
|
|
@apply flex justify-center content-center text-gray-500 font-bold w-6 h-auto border border-gray-300;
|
2021-12-25 23:13:15 +01:00
|
|
|
}
|
2021-12-28 01:06:01 +01:00
|
|
|
/*====================================================select=====================================================*/
|
2021-12-28 23:55:14 +01:00
|
|
|
.slct-lg {
|
2022-02-08 16:47:26 +01:00
|
|
|
@apply flex w-full justify-center break-words content-center bg-blue-100 hover:bg-blue-200 text-gray-500 font-bold text-sm sm:text-base md:text-base lg:text-base xl:text-base 2xl:text-base h-6 sm:h-8 md:h-8 lg:h-8 xl:h-8 2xl:h-8 mb-0 border border-gray-300 rounded;
|
2021-12-28 01:06:01 +01:00
|
|
|
}
|
2021-09-16 02:00:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#menu__toggle {
|
2022-02-01 16:01:19 +01:00
|
|
|
position: relative;
|
2021-09-16 02:00:52 +08:00
|
|
|
opacity: 0;
|
|
|
|
|
}
|
|
|
|
|
#menu__toggle:checked ~ .menu__btn > span {
|
|
|
|
|
transform: rotate(45deg);
|
|
|
|
|
}
|
|
|
|
|
#menu__toggle:checked ~ .menu__btn > span::before {
|
|
|
|
|
top: 0;
|
|
|
|
|
transform: rotate(0);
|
|
|
|
|
}
|
|
|
|
|
#menu__toggle:checked ~ .menu__btn > span::after {
|
|
|
|
|
top: 0;
|
|
|
|
|
transform: rotate(90deg);
|
|
|
|
|
}
|
|
|
|
|
#menu__toggle:checked ~ .menu__box {
|
|
|
|
|
visibility: visible;
|
|
|
|
|
left: 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#menu__toggle:checked ~ .menu__main {
|
2021-10-10 23:46:18 +08:00
|
|
|
margin-left: 150px; /* насколько сужать правую часть */
|
2021-10-16 06:33:15 +08:00
|
|
|
transition-duration: 0.25s;
|
2021-09-16 02:00:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.menu__btn {
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
position: fixed;
|
2022-09-08 23:35:58 +02:00
|
|
|
z-index: 2;
|
2021-09-16 02:00:52 +08:00
|
|
|
top: 10px;
|
|
|
|
|
left: 20px;
|
|
|
|
|
width: 20px;
|
|
|
|
|
height: 20px;
|
|
|
|
|
cursor: pointer;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.menu__btn > span,
|
|
|
|
|
.menu__btn > span::before,
|
|
|
|
|
.menu__btn > span::after {
|
|
|
|
|
display: block;
|
|
|
|
|
position: absolute;
|
|
|
|
|
width: 100%;
|
|
|
|
|
height: 2px;
|
|
|
|
|
background-color: #616161;
|
|
|
|
|
transition-duration: 0.25s;
|
|
|
|
|
}
|
|
|
|
|
.menu__btn > span::before {
|
|
|
|
|
content: "";
|
|
|
|
|
top: -8px;
|
|
|
|
|
}
|
|
|
|
|
.menu__btn > span::after {
|
|
|
|
|
content: "";
|
|
|
|
|
top: 8px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.menu__box {
|
|
|
|
|
display: block;
|
|
|
|
|
position: fixed;
|
|
|
|
|
visibility: hidden;
|
2022-09-08 23:35:58 +02:00
|
|
|
z-index: 1;
|
2021-09-16 02:00:52 +08:00
|
|
|
top: 0;
|
|
|
|
|
left: -100%;
|
|
|
|
|
width: 150px; /* размер выхода бокового меню */
|
|
|
|
|
height: 100%;
|
|
|
|
|
margin: 0;
|
|
|
|
|
padding: 80px 0;
|
|
|
|
|
list-style: none;
|
|
|
|
|
background-color: #eceff1;
|
|
|
|
|
box-shadow: 1px 0px 6px rgba(0, 0, 0, 0.2);
|
|
|
|
|
transition-duration: 0.25s;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.menu__item {
|
|
|
|
|
display: block;
|
|
|
|
|
padding: 12px 24px;
|
|
|
|
|
color: rgba(51, 51, 51, 0.788);
|
|
|
|
|
font-family: "Roboto", sans-serif;
|
|
|
|
|
font-size: 15px; /* размер шрифта бокового меню */
|
|
|
|
|
font-weight: 600;
|
|
|
|
|
text-decoration: none;
|
|
|
|
|
transition-duration: 0.25s;
|
|
|
|
|
}
|
|
|
|
|
.menu__item:hover {
|
|
|
|
|
background-color: #cfd8dc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.upper__bar {
|
|
|
|
|
background-color: rgba(51, 51, 51, 0.144);
|
|
|
|
|
height: 70px;
|
|
|
|
|
position: fixed;
|
|
|
|
|
z-index: -1;
|
|
|
|
|
top: 0px;
|
|
|
|
|
left: 0;
|
|
|
|
|
width: 100%;
|
|
|
|
|
margin: 0;
|
|
|
|
|
padding: 0;
|
|
|
|
|
box-shadow: 1px 0px 3px rgba(0, 0, 0, 0.2);
|
|
|
|
|
}
|
2021-09-16 03:36:40 +08:00
|
|
|
|
|
|
|
|
input[type="date"]::-webkit-calendar-picker-indicator {
|
2021-09-17 03:35:49 +08:00
|
|
|
margin-left: 5px;
|
|
|
|
|
margin-right: -8px;
|
2021-09-16 03:36:40 +08:00
|
|
|
}
|
|
|
|
|
input[type="time"]::-webkit-calendar-picker-indicator {
|
2021-09-17 03:35:49 +08:00
|
|
|
margin-left: 5px;
|
|
|
|
|
margin-right: -8px;
|
2021-09-16 03:36:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
input[type="number"]::-webkit-outer-spin-button,
|
|
|
|
|
input[type="number"]::-webkit-inner-spin-button {
|
2021-09-17 03:35:49 +08:00
|
|
|
margin-left: 7px;
|
|
|
|
|
margin-right: -6px;
|
2021-09-16 03:36:40 +08:00
|
|
|
width: 30px;
|
|
|
|
|
height: 30px;
|
|
|
|
|
opacity: 1;
|
|
|
|
|
}
|
2021-10-19 05:54:52 +08:00
|
|
|
|
2021-10-19 21:59:48 +08:00
|
|
|
/* Toggle */
|
2021-10-19 05:54:52 +08:00
|
|
|
input:checked ~ .dot {
|
|
|
|
|
transform: translateX(100%);
|
2021-10-25 16:50:31 +07:00
|
|
|
/* background-color: #48bb78;*/
|
2021-10-19 05:54:52 +08:00
|
|
|
}
|
2021-09-16 02:00:52 +08:00
|
|
|
</style>
|