2021-09-16 02:00:52 +08:00
|
|
|
|
<script>
|
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";
|
|
|
|
|
|
router.mode.hash(); // enables hash navigation method
|
|
|
|
|
|
//router.mode.memory(); // enables in-memory navigation method
|
2021-12-27 01:42:28 +01:00
|
|
|
|
import Chart from "svelte-frappe-charts";
|
2022-02-05 02:13:46 +01:00
|
|
|
|
//import { SvelteToast, toast } from "@zerodevx/svelte-toast";
|
|
|
|
|
|
|
|
|
|
|
|
//const app = new SvelteToast({
|
|
|
|
|
|
// target: document.body,
|
|
|
|
|
|
// props: {
|
|
|
|
|
|
// options: {},
|
|
|
|
|
|
// },
|
|
|
|
|
|
//});
|
2021-12-16 00:18:40 +01:00
|
|
|
|
|
2021-12-27 22:46:16 +01:00
|
|
|
|
import Card from "./components/Card.svelte";
|
2022-02-06 18:19:38 +01:00
|
|
|
|
import Alarm from "./components/Alarm.svelte";
|
2021-12-27 01:42:28 +01:00
|
|
|
|
import Modal from "./components/Modal.svelte";
|
2021-10-17 19:31:38 +08:00
|
|
|
|
import Input from "./widgets/Input.svelte";
|
2021-10-19 21:59:48 +08:00
|
|
|
|
import Toggle from "./widgets/Toggle.svelte";
|
2021-10-25 20:05:21 +07:00
|
|
|
|
import Anydata from "./widgets/Anydata.svelte";
|
2021-12-26 01:34:29 +01:00
|
|
|
|
|
|
|
|
|
|
//как ставить и удалять
|
|
|
|
|
|
//npm install --save svelte-simple-modal
|
|
|
|
|
|
//npm uninstall svelte-simple-modal
|
|
|
|
|
|
|
2021-12-28 21:18:03 +01:00
|
|
|
|
//****************************************************constants section*********************************************************/
|
|
|
|
|
|
//******************************************************************************************************************************/
|
2021-12-08 22:59:21 +01:00
|
|
|
|
let debug = true;
|
|
|
|
|
|
let LOG_MAX_MESSAGES = 10;
|
2021-12-25 00:20:49 +01:00
|
|
|
|
let reconnectTimeout = 60000;
|
2022-02-01 16:01:19 +01:00
|
|
|
|
let opened = false;
|
|
|
|
|
|
let preventMove = false;
|
2021-12-14 20:55:53 +01:00
|
|
|
|
|
2021-12-28 21:18:03 +01:00
|
|
|
|
//****************************************************variable section**********************************************************/
|
|
|
|
|
|
//******************************************************************************************************************************/
|
2021-12-05 00:49:36 +01:00
|
|
|
|
let myip = document.location.hostname;
|
2021-12-14 20:55:53 +01:00
|
|
|
|
|
2021-12-28 21:18:03 +01:00
|
|
|
|
//Flags
|
|
|
|
|
|
let showInput = false;
|
2021-12-27 02:46:05 +01:00
|
|
|
|
let showModalFlag = false;
|
2021-12-29 01:21:28 +01:00
|
|
|
|
let hideAllSubParams = true;
|
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 = [];
|
|
|
|
|
|
|
2021-12-26 00:36:28 +01:00
|
|
|
|
let datachart = {
|
|
|
|
|
|
labels: ["Sun", "Mon", "Tues", "Wed", "Thurs", "Fri", "Sat"],
|
|
|
|
|
|
datasets: [
|
|
|
|
|
|
{
|
|
|
|
|
|
values: [10, 12, 3, 9, 8, 15, 9],
|
|
|
|
|
|
},
|
|
|
|
|
|
],
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2021-12-14 20:55:53 +01:00
|
|
|
|
//configuration
|
2021-12-30 23:58:35 +01:00
|
|
|
|
let configJson = [];
|
2022-01-22 00:15:22 +01:00
|
|
|
|
let configJsonFlag = false;
|
2022-02-05 02:13:46 +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-05 02:13:46 +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-05 02:13:46 +01:00
|
|
|
|
let itemsJsonParced = false;
|
2022-02-01 16:01:19 +01:00
|
|
|
|
|
2022-02-02 00:19:57 +01:00
|
|
|
|
let itemsJsonBind = 0;
|
2022-02-01 16:01:19 +01:00
|
|
|
|
|
2022-02-02 23:37:15 +01:00
|
|
|
|
let layoutJson = [];
|
|
|
|
|
|
let layoutJsonFlag = false;
|
2022-02-05 02:13:46 +01:00
|
|
|
|
let layoutJsonParced = false;
|
2022-02-02 23:37:15 +01:00
|
|
|
|
|
|
|
|
|
|
let settingsJson = {};
|
|
|
|
|
|
let settingsJsonFlag = false;
|
2022-02-05 02:13:46 +01:00
|
|
|
|
let settingsJsonParced = false;
|
|
|
|
|
|
|
|
|
|
|
|
let ssidJson = {};
|
|
|
|
|
|
let ssidJsonParced = false;
|
2022-02-02 23:37:15 +01:00
|
|
|
|
|
2021-12-14 20:55:53 +01:00
|
|
|
|
//web sockets
|
2021-12-05 00:49:36 +01:00
|
|
|
|
let socket = [];
|
|
|
|
|
|
let socketConnected = false;
|
2021-12-26 00:04:34 +01:00
|
|
|
|
let selectedDeviceData = undefined;
|
2021-12-08 22:59:21 +01:00
|
|
|
|
let deviceList = [];
|
2021-12-10 16:07:09 +01:00
|
|
|
|
let flag = true;
|
2021-12-14 20:55:53 +01:00
|
|
|
|
let newDevice = {};
|
|
|
|
|
|
let coreMessages = [];
|
2021-12-16 00:18:40 +01:00
|
|
|
|
let wsSelected = undefined;
|
2021-12-08 22:59:21 +01:00
|
|
|
|
|
2022-02-05 02:13:46 +01:00
|
|
|
|
let oneOfJsonPackageError = false;
|
|
|
|
|
|
|
2021-12-13 02:36:26 +01:00
|
|
|
|
deviceList = [
|
|
|
|
|
|
{
|
|
|
|
|
|
name: "Устройство 1",
|
|
|
|
|
|
id: "987654321",
|
2022-02-06 18:19:38 +01:00
|
|
|
|
//ip: myip,
|
|
|
|
|
|
ip: "192.168.88.235",
|
2021-12-25 01:51:40 +01:00
|
|
|
|
status: false,
|
|
|
|
|
|
},
|
2021-12-13 02:36:26 +01:00
|
|
|
|
];
|
2021-12-12 00:20:47 +01:00
|
|
|
|
|
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) {
|
|
|
|
|
|
this.blob = new Blob(this.parts, { type: "binary" });
|
|
|
|
|
|
}
|
|
|
|
|
|
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-02 23:37:15 +01:00
|
|
|
|
var layoutJsonBlob = new MyBlobBuilder();
|
|
|
|
|
|
var settingsJsonBlob = new MyBlobBuilder();
|
2022-02-05 02:13:46 +01:00
|
|
|
|
|
2021-12-16 00:18:40 +01:00
|
|
|
|
router.subscribe(handleNavigation);
|
|
|
|
|
|
|
2022-01-30 17:44:53 +01:00
|
|
|
|
function handleNavigation() {
|
|
|
|
|
|
clearData();
|
|
|
|
|
|
currentPageName = $router.path.toString();
|
|
|
|
|
|
console.log("[i]", "user on page:", currentPageName);
|
|
|
|
|
|
sendCurrentPageName();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function sendCurrentPageName() {
|
|
|
|
|
|
if (wsSelected !== undefined) {
|
|
|
|
|
|
wsSendMsg(wsSelected, currentPageName);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
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 = [];
|
2021-12-08 22:59:21 +01:00
|
|
|
|
let ws = 0;
|
|
|
|
|
|
deviceList.forEach((device) => {
|
2021-12-10 16:07:09 +01:00
|
|
|
|
//if (debug) console.log("[i]", device.name, ws, device.ip, device.id);
|
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-10 17:37:37 +01:00
|
|
|
|
socketConnected = selectedDeviceData.status;
|
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;
|
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";
|
2021-12-25 00:20:49 +01:00
|
|
|
|
//socket[ws] = new WebSocket("ws://" + ip + "/ws");
|
2021-12-10 20:27:45 +01:00
|
|
|
|
if (debug) console.log("[i]", ip, "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);
|
|
|
|
|
|
if (debug) console.log("[i]", ip, "web socket events added");
|
2021-12-08 22:59:21 +01:00
|
|
|
|
socket[ws].addEventListener("open", function (event) {
|
2021-12-11 13:54:28 +01:00
|
|
|
|
if (debug) console.log("[i]", ip, "completed connecting");
|
2021-12-09 00:10:10 +01:00
|
|
|
|
markDeviceStatus(ws, true);
|
2021-12-16 00:18:40 +01:00
|
|
|
|
sendCurrentPageName();
|
2021-12-08 22:59:21 +01:00
|
|
|
|
//socket[ws].send("HELLO");
|
|
|
|
|
|
});
|
|
|
|
|
|
socket[ws].addEventListener("message", function (event) {
|
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-06 18:19:38 +01:00
|
|
|
|
if (debug) console.log("[i]", getIP(ws), "msg received", data); //
|
2022-02-04 00:03:52 +01:00
|
|
|
|
//сборщик statusJson сообщений======================================
|
|
|
|
|
|
if (data.includes("status")) {
|
|
|
|
|
|
if (IsJsonParse(data)) {
|
|
|
|
|
|
let statusJson = JSON.parse(data);
|
|
|
|
|
|
udatelayoutJson(statusJson);
|
|
|
|
|
|
wigetsUpdate();
|
2022-02-05 02:13:46 +01:00
|
|
|
|
if (debug) console.log("[i]", "status json parced: ", statusJson);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
//сборщик ssidJson сообщений======================================
|
|
|
|
|
|
if (data.includes("ssid")) {
|
|
|
|
|
|
if (IsJsonParse(data)) {
|
|
|
|
|
|
ssidJson = JSON.parse(data);
|
|
|
|
|
|
delete ssidJson.ssid;
|
|
|
|
|
|
ssidJson = ssidJson;
|
|
|
|
|
|
ssidJsonParced = true;
|
|
|
|
|
|
if (debug) console.log("[i]", "ssid json parced");
|
2022-02-04 00:03:52 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2022-01-30 17:44:53 +01:00
|
|
|
|
//сборщик configJson пакетов========================================
|
|
|
|
|
|
if (data === "/st/config.json") {
|
2022-02-05 02:13:46 +01:00
|
|
|
|
//if (debug) console.log("[i]", "configJson start!");
|
2022-01-30 17:44:53 +01:00
|
|
|
|
configJsonFlag = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (data === "/end/config.json") {
|
2022-02-05 02:13:46 +01:00
|
|
|
|
//if (debug) console.log("[i]", "configJson end!");
|
2022-01-30 17:44:53 +01:00
|
|
|
|
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);
|
2022-01-25 01:41:29 +01:00
|
|
|
|
configJson = configJson;
|
2022-02-05 02:13:46 +01:00
|
|
|
|
configJsonParced = true;
|
2022-01-25 01:41:29 +01:00
|
|
|
|
if (debug) console.log("[i]", "configJson parced!");
|
2022-01-24 00:57:27 +01:00
|
|
|
|
}
|
2022-01-30 17:44:53 +01:00
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
//сборщик widgetsJson пакетов========================================
|
|
|
|
|
|
if (data === "/st/widgets.json") {
|
2022-02-05 02:13:46 +01:00
|
|
|
|
//if (debug) console.log("[i]", "widgetsJson start!");
|
2022-01-30 17:44:53 +01:00
|
|
|
|
widgetsJsonFlag = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (data === "/end/widgets.json") {
|
2022-02-05 02:13:46 +01:00
|
|
|
|
//if (debug) console.log("[i]", "widgetsJson end!");
|
2022-01-30 17:44:53 +01:00
|
|
|
|
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);
|
2022-01-25 01:41:29 +01:00
|
|
|
|
widgetsJson = widgetsJson;
|
2022-02-05 02:13:46 +01:00
|
|
|
|
widgetsJsonParced = true;
|
2022-01-25 01:41:29 +01:00
|
|
|
|
if (debug) console.log("[i]", "widgetsJson parced!");
|
2022-01-24 00:57:27 +01:00
|
|
|
|
}
|
2022-01-30 17:44:53 +01:00
|
|
|
|
};
|
|
|
|
|
|
}
|
2022-02-02 00:19:57 +01:00
|
|
|
|
//сборщик itemsJson пакетов========================================
|
|
|
|
|
|
if (data === "/st/items.json") {
|
2022-02-05 02:13:46 +01:00
|
|
|
|
//if (debug) console.log("[i]", "itemsJson start!");
|
2022-02-02 00:19:57 +01:00
|
|
|
|
itemsJsonFlag = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (data === "/end/items.json") {
|
2022-02-05 02:13:46 +01:00
|
|
|
|
//if (debug) console.log("[i]", "itemsJson end!");
|
2022-02-02 00:19:57 +01:00
|
|
|
|
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;
|
2022-02-05 02:13:46 +01:00
|
|
|
|
itemsJsonParced = true;
|
2022-02-02 00:19:57 +01:00
|
|
|
|
if (debug) console.log("[i]", "itemsJson parced!");
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
2022-02-02 23:37:15 +01:00
|
|
|
|
//сборщик layoutJson пакетов========================================
|
|
|
|
|
|
if (data === "/st/layout.json") {
|
2022-02-05 02:13:46 +01:00
|
|
|
|
//if (debug) console.log("[i]", "layoutJson start!");
|
2022-02-02 23:37:15 +01:00
|
|
|
|
layoutJsonFlag = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (data === "/end/layout.json") {
|
2022-02-05 02:13:46 +01:00
|
|
|
|
//if (debug) console.log("[i]", "layoutJson end!");
|
2022-02-02 23:37:15 +01:00
|
|
|
|
layoutJsonFlag = false;
|
|
|
|
|
|
var bb = layoutJsonBlob.getBlob();
|
|
|
|
|
|
let layoutJsonReader = new FileReader();
|
|
|
|
|
|
layoutJsonReader.readAsText(bb);
|
|
|
|
|
|
layoutJsonReader.onload = () => {
|
|
|
|
|
|
let layoutJsonResult = layoutJsonReader.result;
|
|
|
|
|
|
if (IsJsonParse(layoutJsonResult)) {
|
|
|
|
|
|
layoutJson = JSON.parse(layoutJsonResult);
|
|
|
|
|
|
layoutJson = layoutJson;
|
|
|
|
|
|
wigetsUpdate();
|
2022-02-05 02:13:46 +01:00
|
|
|
|
layoutJsonParced = true;
|
2022-02-02 23:37:15 +01:00
|
|
|
|
if (debug) console.log("[i]", "layoutJson parced!");
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
//сборщик settingsJson пакетов========================================
|
|
|
|
|
|
if (data === "/st/settings.json") {
|
2022-02-05 02:13:46 +01:00
|
|
|
|
//if (debug) console.log("[i]", "settingsJson start!");
|
2022-02-02 23:37:15 +01:00
|
|
|
|
settingsJsonFlag = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (data === "/end/settings.json") {
|
2022-02-05 02:13:46 +01:00
|
|
|
|
//if (debug) console.log("[i]", "settingsJson end!");
|
2022-02-02 23:37:15 +01:00
|
|
|
|
settingsJsonFlag = false;
|
|
|
|
|
|
var bb = settingsJsonBlob.getBlob();
|
|
|
|
|
|
let settingsJsonReader = new FileReader();
|
|
|
|
|
|
settingsJsonReader.readAsText(bb);
|
|
|
|
|
|
settingsJsonReader.onload = () => {
|
|
|
|
|
|
let settingsJsonResult = settingsJsonReader.result;
|
|
|
|
|
|
if (IsJsonParse(settingsJsonResult)) {
|
|
|
|
|
|
settingsJson = JSON.parse(settingsJsonResult);
|
|
|
|
|
|
settingsJson = settingsJson;
|
|
|
|
|
|
wigetsUpdate();
|
2022-02-05 02:13:46 +01:00
|
|
|
|
settingsJsonParced = true;
|
2022-02-02 23:37:15 +01:00
|
|
|
|
if (debug) console.log("[i]", "settingsJson parced!");
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
2022-01-30 17:44:53 +01:00
|
|
|
|
}
|
|
|
|
|
|
if (event.data instanceof Blob) {
|
|
|
|
|
|
if (configJsonFlag) configJsonBlob.append(event.data);
|
|
|
|
|
|
if (widgetsJsonFlag) widgetsJsonBlob.append(event.data);
|
2022-02-02 00:19:57 +01:00
|
|
|
|
if (itemsJsonFlag) itemsJsonBlob.append(event.data);
|
2022-02-02 23:37:15 +01:00
|
|
|
|
if (layoutJsonFlag) layoutJsonBlob.append(event.data);
|
|
|
|
|
|
if (settingsJsonFlag) settingsJsonBlob.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-01-31 01:45:42 +01:00
|
|
|
|
function saveConfig() {
|
2022-02-01 00:42:28 +01:00
|
|
|
|
wsSendMsg(wsSelected, "/tuoyal" + JSON.stringify(generateLayout()));
|
2022-01-25 22:21:42 +01:00
|
|
|
|
wsSendMsg(wsSelected, "/gifnoc" + JSON.stringify(configJson));
|
2022-01-17 00:08:26 +01:00
|
|
|
|
clearData();
|
|
|
|
|
|
sendCurrentPageName();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-02-02 23:37:15 +01:00
|
|
|
|
function saveSettings() {
|
|
|
|
|
|
wsSendMsg(wsSelected, "/cennoc" + JSON.stringify(settingsJson));
|
|
|
|
|
|
clearData();
|
|
|
|
|
|
sendCurrentPageName();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
//widget.ws = wsSelected;
|
|
|
|
|
|
widget.topic = settingsJson.root + "/" + config.id;
|
2022-01-31 01:45:42 +01:00
|
|
|
|
layout.push(widget);
|
|
|
|
|
|
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-02-04 00:03:52 +01:00
|
|
|
|
function udatelayoutJson(newStatusJson) {
|
|
|
|
|
|
for (let i = 0; i < layoutJson.length; i++) {
|
|
|
|
|
|
let topic = layoutJson[i].topic;
|
|
|
|
|
|
if (topic === newStatusJson.topic) {
|
|
|
|
|
|
layoutJson[i].status = newStatusJson.status;
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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 = [];
|
|
|
|
|
|
layoutJsonBlob.clear();
|
|
|
|
|
|
|
|
|
|
|
|
settingsJson = {};
|
|
|
|
|
|
settingsJsonBlob.clear();
|
|
|
|
|
|
|
2022-02-05 02:13:46 +01:00
|
|
|
|
configJsonParced = false;
|
|
|
|
|
|
widgetsJsonParced = false;
|
|
|
|
|
|
itemsJsonParced = false;
|
|
|
|
|
|
layoutJsonParced = false;
|
|
|
|
|
|
settingsJsonParced = false;
|
|
|
|
|
|
ssidJsonParced = false;
|
|
|
|
|
|
|
|
|
|
|
|
//ssidJson = {};
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
2021-12-08 22:59:21 +01:00
|
|
|
|
function wsPush(ws, topic, status) {
|
|
|
|
|
|
let msg = topic + " " + status;
|
2021-12-09 22:35:04 +01:00
|
|
|
|
if (debug) console.log("[i]", "send to ws msg:", msg);
|
2021-12-08 22:59:21 +01:00
|
|
|
|
wsSendMsg(ws, msg);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-12-07 22:14:59 +01:00
|
|
|
|
function wsTestMsgTask() {
|
2021-12-21 00:48:44 +01:00
|
|
|
|
setTimeout(wsTestMsgTask, reconnectTimeout);
|
2021-12-10 20:27:45 +01:00
|
|
|
|
if (debug) console.log("[i]", "----timer tick----");
|
2021-12-10 16:07:09 +01:00
|
|
|
|
if (!flag) {
|
|
|
|
|
|
deviceList.forEach((device) => {
|
|
|
|
|
|
if (!getDeviceStatus(device.ws)) {
|
|
|
|
|
|
wsConnect(device.ws);
|
|
|
|
|
|
wsEventAdd(device.ws);
|
|
|
|
|
|
} else {
|
2021-12-13 02:36:26 +01:00
|
|
|
|
wsSendMsg(device.ws, "tst");
|
2021-12-10 16:07:09 +01:00
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
flag = false;
|
2021-12-08 22:59:21 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function wsSendMsg(ws, msg) {
|
|
|
|
|
|
if (socket[ws] && socket[ws].readyState === 1) {
|
|
|
|
|
|
socket[ws].send(msg);
|
2021-12-10 16:07:09 +01:00
|
|
|
|
if (debug) console.log("[i]", getIP(ws), "msg send success", msg);
|
2021-12-08 22:59:21 +01:00
|
|
|
|
} else {
|
2021-12-10 16:07:09 +01:00
|
|
|
|
if (debug) console.log("[e]", getIP(ws), "msg not send", msg);
|
2021-12-07 22:14:59 +01:00
|
|
|
|
}
|
2021-12-06 01:21:55 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-02-01 16:01:19 +01:00
|
|
|
|
//***********************************************************dashboard***************************************************************/
|
2021-10-17 07:09:55 +08:00
|
|
|
|
function findNewPage() {
|
|
|
|
|
|
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) {
|
2021-10-18 21:12:42 +08:00
|
|
|
|
pages = [...pages, JSON.parse(JSON.stringify({ page: item }))];
|
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
|
|
|
|
|
|
|
|
|
|
function wigetsUpdate() {
|
|
|
|
|
|
findNewPage();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-02-01 16:01:19 +01:00
|
|
|
|
//***********************************************************logging******************************************************************/
|
2021-12-07 22:14:59 +01:00
|
|
|
|
const addCoreMsg = (msg) => {
|
|
|
|
|
|
if (coreMessages.length > Number(LOG_MAX_MESSAGES)) {
|
|
|
|
|
|
coreMessages = coreMessages.slice(0);
|
2021-12-05 00:49:36 +01:00
|
|
|
|
}
|
2021-12-07 22:14:59 +01:00
|
|
|
|
const time = new Date().getTime();
|
|
|
|
|
|
coreMessages = [...coreMessages, { time, msg }];
|
|
|
|
|
|
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******************************************************************/
|
|
|
|
|
|
function devicesDropdownChange() {
|
2021-12-09 22:35:04 +01:00
|
|
|
|
socketConnected = selectedDeviceData.status;
|
2021-12-13 02:36:26 +01:00
|
|
|
|
wsSelected = selectedDeviceData.ws;
|
2021-12-25 00:20:49 +01:00
|
|
|
|
clearData();
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
2021-12-12 00:20:47 +01:00
|
|
|
|
function devListSave() {
|
|
|
|
|
|
if (!showInput) {
|
|
|
|
|
|
if (newDevice.name !== undefined && newDevice.ip !== undefined && newDevice.id !== undefined) {
|
|
|
|
|
|
newDevice.status = false;
|
|
|
|
|
|
deviceList.push(newDevice);
|
|
|
|
|
|
deviceList = deviceList;
|
|
|
|
|
|
newDevice = {};
|
|
|
|
|
|
connectToAllDevices();
|
2021-12-13 00:01:21 +01:00
|
|
|
|
if (debug) console.log("[i]", "selected device:", selectedDeviceData);
|
|
|
|
|
|
//socketConnected = selectedDeviceData.status;
|
|
|
|
|
|
//socketConnected = socketConnected;
|
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-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-05 02:13:46 +01:00
|
|
|
|
oneOfJsonPackageError = true;
|
|
|
|
|
|
if (debug) console.log("[e]", "json error");
|
2021-12-25 00:20:49 +01:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2022-02-05 02:13:46 +01:00
|
|
|
|
oneOfJsonPackageError = false;
|
2021-12-25 00:20:49 +01:00
|
|
|
|
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-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();
|
|
|
|
|
|
formData.append("data", new Blob([data], { type: "text/json" }), "/" + filename);
|
|
|
|
|
|
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) {
|
|
|
|
|
|
let res = await fetch(url, {
|
|
|
|
|
|
mode: "no-cors",
|
|
|
|
|
|
method: "GET",
|
|
|
|
|
|
});
|
|
|
|
|
|
if (res.ok) {
|
|
|
|
|
|
configSetupJson = await res.json();
|
|
|
|
|
|
} else {
|
|
|
|
|
|
console.log("error", res.status);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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-02 00:19:57 +01:00
|
|
|
|
function elementsDropdownChange() {
|
2022-02-02 15:42:52 +01:00
|
|
|
|
for (let i = 0; i < itemsJson.length; i++) {
|
|
|
|
|
|
let item = Object.assign({}, itemsJson[i]);
|
|
|
|
|
|
if (itemsJsonBind === item.num) {
|
|
|
|
|
|
delete item.num;
|
|
|
|
|
|
delete item.name;
|
|
|
|
|
|
configJson.push(item);
|
|
|
|
|
|
configJson = configJson;
|
|
|
|
|
|
itemsJsonBind = 0;
|
|
|
|
|
|
if (debug) console.log("[i]", "item added");
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2022-02-02 00:19:57 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-02-02 15:42:52 +01:00
|
|
|
|
function deleteLine(num) {
|
|
|
|
|
|
if (debug) console.log("[i]", num);
|
|
|
|
|
|
for (let i = 0; i < configJson.length; i++) {
|
|
|
|
|
|
if (num === i) {
|
|
|
|
|
|
configJson.splice(i, 1);
|
|
|
|
|
|
configJson = configJson;
|
|
|
|
|
|
if (debug) console.log("[i]", "item " + num + " deleted");
|
|
|
|
|
|
break;
|
2022-02-02 00:19:57 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2022-02-01 16:01:19 +01:00
|
|
|
|
|
2022-02-05 02:13:46 +01:00
|
|
|
|
function ssidDropdownClick() {
|
|
|
|
|
|
wsSendMsg(wsSelected, "/scan");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function returnError() {
|
|
|
|
|
|
let ret = false;
|
|
|
|
|
|
if (!socketConnected || oneOfJsonPackageError) {
|
|
|
|
|
|
ret = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function returnErrorName() {
|
|
|
|
|
|
if (!socketConnected) {
|
|
|
|
|
|
return "Нет соединения";
|
|
|
|
|
|
} else if (oneOfJsonPackageError) {
|
|
|
|
|
|
return "Ошибка данных";
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function configPageStatus() {
|
|
|
|
|
|
if (itemsJsonParced && widgetsJsonParced && configJsonParced && settingsJsonParced) {
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function pushGreen() {
|
|
|
|
|
|
toast.push("Saved!", {
|
|
|
|
|
|
theme: {
|
|
|
|
|
|
"--toastBackground": "#48BB78",
|
|
|
|
|
|
"--toastProgressBackground": "#2F855A",
|
|
|
|
|
|
},
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-02-01 16:01:19 +01:00
|
|
|
|
//*******************************************************initialisation********************************************************************/
|
2021-12-08 22:59:21 +01:00
|
|
|
|
onMount(async () => {
|
2021-12-09 22:35:04 +01:00
|
|
|
|
console.log("[i]", "mounted");
|
2021-12-08 22:59:21 +01:00
|
|
|
|
connectToAllDevices();
|
2021-12-10 14:44:00 +01:00
|
|
|
|
wsTestMsgTask();
|
2021-12-10 17:37:37 +01:00
|
|
|
|
socketConnected = selectedDeviceData.status;
|
2022-02-01 16:01:19 +01:00
|
|
|
|
devicesDropdownChange();
|
2021-12-08 22:59:21 +01:00
|
|
|
|
findNewPage();
|
|
|
|
|
|
});
|
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-05 02:13:46 +01:00
|
|
|
|
<Modal show={showModalFlag} />
|
2022-02-01 16:01:19 +01:00
|
|
|
|
<header class="h-10 w-full bg-gray-100 overflow-auto shadow-md">
|
2021-12-09 00:10:10 +01:00
|
|
|
|
<div class="flex justify-end content-center">
|
2022-02-05 02:13:46 +01:00
|
|
|
|
<div class="px-15 py-2 z-50">
|
2022-02-01 16:01:19 +01:00
|
|
|
|
<select bind:value={selectedDeviceData} on:change={() => devicesDropdownChange()}>
|
2021-12-09 00:10:10 +01:00
|
|
|
|
{#each deviceList as device}
|
|
|
|
|
|
<option value={device}>
|
|
|
|
|
|
{device.name}
|
|
|
|
|
|
</option>
|
|
|
|
|
|
{/each}
|
|
|
|
|
|
</select>
|
|
|
|
|
|
</div>
|
2021-12-29 01:21:28 +01:00
|
|
|
|
<div class="px-5 py-1">
|
2021-12-09 22:35:04 +01:00
|
|
|
|
<svg class="h-8 w-8 {socketConnected === true ? 'text-green-500' : 'text-red-500'}" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"> <path stroke="none" d="M0 0h24v24H0z" /> <path d="M7 18a4.6 4.4 0 0 1 0 -9h0a5 4.5 0 0 1 11 2h1a3.5 3.5 0 0 1 0 7h-12" /></svg>
|
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">
|
|
|
|
|
|
<input bind:checked={opened} on:change={() => onCheck()} id="menu__toggle" type="checkbox" />
|
|
|
|
|
|
<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="/utilities">{"Утилиты"}</a>
|
|
|
|
|
|
</li>
|
|
|
|
|
|
<li>
|
|
|
|
|
|
<a class="menu__item" href="/log">{"Лог"}</a>
|
|
|
|
|
|
</li>
|
|
|
|
|
|
<li>
|
|
|
|
|
|
<a class="menu__item" href="/list">{"Устройства"}</a>
|
|
|
|
|
|
</li>
|
|
|
|
|
|
<li>
|
|
|
|
|
|
<a class="menu__item" href="/about">{"О проекте"}</a>
|
|
|
|
|
|
</li>
|
|
|
|
|
|
</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}
|
|
|
|
|
|
<div class="flex justify-center items-center">
|
|
|
|
|
|
<div style="border-top-color:transparent" class="w-20 h-20 border-4 border-blue-400 border-solid rounded-full animate-spin" />
|
2022-02-01 16:01:19 +01:00
|
|
|
|
</div>
|
2022-02-05 02:13:46 +01:00
|
|
|
|
{:else}
|
|
|
|
|
|
<Route path="/">
|
|
|
|
|
|
<div class="grd-3cols">
|
|
|
|
|
|
{#if layoutJson === []}
|
|
|
|
|
|
<Card title={"Ваша панель управления пуста, вначале добавьте новые элементы в конфигураторе!"} />
|
|
|
|
|
|
{/if}
|
|
|
|
|
|
{#each pages as pagesName, i}
|
|
|
|
|
|
<Card title={pagesName.page}>
|
|
|
|
|
|
{#each layoutJson as widget, i}
|
|
|
|
|
|
{#if widget.page === pagesName.page}
|
|
|
|
|
|
{#if widget.widget === "input"}
|
|
|
|
|
|
<Input bind:value={widget.status} widget={widget} wsPushProp={(ws, topic, status) => wsPush(ws, topic, status)} />
|
|
|
|
|
|
{/if}
|
|
|
|
|
|
{#if widget.widget === "toggle"}
|
|
|
|
|
|
<Toggle bind:value={widget.status} widget={widget} wsPushProp={(ws, topic, status) => wsPush(ws, topic, status)} />
|
|
|
|
|
|
{/if}
|
|
|
|
|
|
{#if widget.widget === "anydata"}
|
|
|
|
|
|
<Anydata bind:value={widget.status} widget={widget} />
|
|
|
|
|
|
{/if}
|
2022-02-02 00:19:57 +01:00
|
|
|
|
{/if}
|
2022-02-01 16:01:19 +01:00
|
|
|
|
{/each}
|
2022-02-05 02:13:46 +01:00
|
|
|
|
</Card>
|
|
|
|
|
|
{/each}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</Route>
|
|
|
|
|
|
<Route path="/config">
|
|
|
|
|
|
<!--{#if itemsJsonParced && widgetsJsonParced && configJsonParced && settingsJsonParced}-->
|
|
|
|
|
|
<div class="grd-1cols">
|
|
|
|
|
|
<Card>
|
|
|
|
|
|
<div class="grd-2colsfx">
|
|
|
|
|
|
<select class="slct-lg" bind:value={itemsJsonBind} on:change={() => elementsDropdownChange()}>
|
|
|
|
|
|
{#each itemsJson as item}
|
|
|
|
|
|
{#if item.header}
|
|
|
|
|
|
<optgroup label={item.header} />
|
|
|
|
|
|
{/if}
|
|
|
|
|
|
{#if !item.header}
|
|
|
|
|
|
<option value={item.num}>
|
|
|
|
|
|
{item.name}
|
|
|
|
|
|
</option>
|
|
|
|
|
|
{/if}
|
|
|
|
|
|
{/each}
|
|
|
|
|
|
</select>
|
|
|
|
|
|
<select class="slct-lg"><option>{"Выберите пресет"}</option></select>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<table class="table-fixed w-full select-none my-2 ">
|
|
|
|
|
|
<thead class="bg-gray-100">
|
2022-02-01 16:01:19 +01:00
|
|
|
|
<tr class="tbl-txt-sz tbl-txt-p">
|
2022-02-05 02:13:46 +01:00
|
|
|
|
<th class="tbl-hd">Тип</th>
|
|
|
|
|
|
<th class="tbl-hd">Id</th>
|
|
|
|
|
|
<th class="tbl-hd">Виджет</th>
|
|
|
|
|
|
<th class="tbl-hd">Вкладка</th>
|
|
|
|
|
|
<th class="tbl-hd">Название</th>
|
|
|
|
|
|
<th class="tbl-hd w-7" />
|
|
|
|
|
|
<th class="tbl-hd w-7" />
|
2022-02-01 16:01:19 +01:00
|
|
|
|
</tr>
|
2022-02-05 02:13:46 +01:00
|
|
|
|
</thead>
|
|
|
|
|
|
<tbody class="bg-white">
|
|
|
|
|
|
{#each configJson as element, i}
|
|
|
|
|
|
<tr class="tbl-txt-sz tbl-txt-p">
|
|
|
|
|
|
<td class="tbl-bdy">{element.subtype}</td>
|
|
|
|
|
|
<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 widgetsJson as select}
|
|
|
|
|
|
<option value={select.name}>
|
|
|
|
|
|
{select.label}
|
|
|
|
|
|
</option>
|
|
|
|
|
|
{/each}
|
|
|
|
|
|
</select></td>
|
|
|
|
|
|
<td class="tbl-bdy"><input bind:value={element.page} class="tbl-ipt w-full" type="text" /></td>
|
|
|
|
|
|
<td class="tbl-bdy"><input bind:value={element.descr} class="tbl-ipt w-full" type="text" /></td>
|
|
|
|
|
|
<td class="tbl-bdy"><svg on:click={() => (hideAllSubParams = !hideAllSubParams)} class="h-6 w-6 text-green-400 cursor-pointer" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"> <path stroke="none" d="M0 0h24v24H0z" /> <circle cx="5" cy="12" r="1" /> <circle cx="12" cy="12" r="1" /> <circle cx="19" cy="12" r="1" /></svg></td>
|
|
|
|
|
|
<td class="tbl-bdy"><svg on:click={() => deleteLine(i)} class="h-6 w-6 text-red-400 cursor-pointer" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <line x1="18" y1="6" x2="6" y2="18" /> <line x1="6" y1="6" x2="18" y2="18" /></svg></td>
|
|
|
|
|
|
</tr>
|
|
|
|
|
|
{#if !hideAllSubParams}
|
|
|
|
|
|
{#each Object.entries(element) as [key, param]}
|
|
|
|
|
|
{#if key != "type" && key != "subtype" && key != "id" && key != "widget" && key != "page" && key != "descr"}
|
|
|
|
|
|
<tr class="tbl-txt-sz tbl-txt-p">
|
|
|
|
|
|
<td />
|
|
|
|
|
|
<td />
|
|
|
|
|
|
<td />
|
|
|
|
|
|
<td class="tbl-s-bdy text-right">
|
|
|
|
|
|
<p class="tbl-s-txt">{key}</p>
|
|
|
|
|
|
</td>
|
|
|
|
|
|
<td class="tbl-s-bdy text-center">
|
|
|
|
|
|
<input bind:value={element[key]} class="tbl-s-ipt w-full" type="text" />
|
|
|
|
|
|
</td>
|
|
|
|
|
|
</tr>
|
|
|
|
|
|
{/if}
|
|
|
|
|
|
{/each}
|
|
|
|
|
|
<!--<br />-->
|
|
|
|
|
|
{/if}
|
|
|
|
|
|
{/each}
|
|
|
|
|
|
</tbody>
|
|
|
|
|
|
</table>
|
|
|
|
|
|
<button class="btn-lg" on:click={() => saveConfig()}>{"Сохранить"}</button>
|
|
|
|
|
|
</Card>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<!--{:else if !itemsJsonParced && !widgetsJsonParced && !configJsonParced && !settingsJsonParced}-->
|
|
|
|
|
|
<!--<div class="flex justify-center items-center">-->
|
|
|
|
|
|
<!--<div style="border-top-color:transparent" class="w-20 h-20 border-4 border-blue-400 border-solid rounded-full animate-spin" />-->
|
|
|
|
|
|
<!--</div>-->
|
|
|
|
|
|
<!--{/if}-->
|
|
|
|
|
|
</Route>
|
|
|
|
|
|
<Route path="/connection">
|
|
|
|
|
|
<div class="grd-2cols">
|
|
|
|
|
|
<Card title="Подключение к WiFi роутеру">
|
|
|
|
|
|
<div class="crd-itm-psn">
|
|
|
|
|
|
<div class="wgt-dscr-w">
|
|
|
|
|
|
<p class="wgt-dscr-stl">Название устройства</p>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div class="wgt-w">
|
|
|
|
|
|
<input bind:value={settingsJson.name} class="wgt-ipt text-left focus:border-indigo-500" type="text" />
|
|
|
|
|
|
</div>
|
2022-02-02 23:37:15 +01:00
|
|
|
|
</div>
|
2022-02-05 02:13:46 +01:00
|
|
|
|
<div class="crd-itm-psn">
|
|
|
|
|
|
<div class="wgt-dscr-w">
|
|
|
|
|
|
<p class="wgt-dscr-stl">Точка доступа</p>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div class="wgt-w">
|
|
|
|
|
|
<input bind:value={settingsJson.apssid} class="wgt-ipt text-left focus:border-indigo-500" type="text" />
|
|
|
|
|
|
</div>
|
2022-02-02 23:37:15 +01:00
|
|
|
|
</div>
|
2022-02-05 02:13:46 +01:00
|
|
|
|
<div class="crd-itm-psn">
|
|
|
|
|
|
<div class="wgt-dscr-w">
|
|
|
|
|
|
<p class="wgt-dscr-stl">Пароль точки доступа</p>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div class="wgt-w">
|
|
|
|
|
|
<input bind:value={settingsJson.appass} class="wgt-ipt text-left focus:border-indigo-500" type="text" />
|
|
|
|
|
|
</div>
|
2022-02-02 23:37:15 +01:00
|
|
|
|
</div>
|
2022-02-05 02:13:46 +01:00
|
|
|
|
<div class="crd-itm-psn">
|
|
|
|
|
|
<div class="wgt-dscr-w">
|
|
|
|
|
|
<p class="wgt-dscr-stl">Название wifi сети</p>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div class="wgt-w">
|
|
|
|
|
|
<select class="wgt-ipt text-left focus:border-indigo-500" bind:value={settingsJson.routerssid} on:click={() => ssidDropdownClick()}>
|
|
|
|
|
|
{#each Object.entries(ssidJson) as [num, ssid]}
|
|
|
|
|
|
<option value={ssid}>
|
|
|
|
|
|
{ssid}
|
|
|
|
|
|
</option>
|
|
|
|
|
|
{/each}
|
|
|
|
|
|
</select>
|
|
|
|
|
|
</div>
|
2022-02-02 23:37:15 +01:00
|
|
|
|
</div>
|
2022-02-05 02:13:46 +01:00
|
|
|
|
<div class="crd-itm-psn">
|
|
|
|
|
|
<div class="wgt-dscr-w">
|
|
|
|
|
|
<p class="wgt-dscr-stl">Пароль</p>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div class="wgt-w">
|
|
|
|
|
|
<input bind:value={settingsJson.routerpass} class="wgt-ipt text-left focus:border-indigo-500" type="text" />
|
|
|
|
|
|
</div>
|
2022-02-02 23:37:15 +01:00
|
|
|
|
</div>
|
2022-02-06 18:19:38 +01:00
|
|
|
|
{#if settingsJson.pass_status === 1}
|
|
|
|
|
|
<div class="grd-1cols">
|
|
|
|
|
|
<Alarm title="Введен неправильный пароль" />
|
|
|
|
|
|
</div>
|
|
|
|
|
|
{/if}
|
|
|
|
|
|
<button class="btn-lg" on:click={() => saveSettings()}>{"Сохранить и перезагрузить"}</button>
|
2022-02-05 02:13:46 +01:00
|
|
|
|
</Card>
|
|
|
|
|
|
<Card title="Подключение к MQTT брокеру">
|
|
|
|
|
|
<div class="crd-itm-psn">
|
|
|
|
|
|
<div class="wgt-dscr-w">
|
|
|
|
|
|
<p class="wgt-dscr-stl">Название сервера</p>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div class="wgt-w">
|
|
|
|
|
|
<input bind:value={settingsJson.mqttServer} class="wgt-ipt text-left focus:border-indigo-500" type="text" />
|
|
|
|
|
|
</div>
|
2022-02-02 23:37:15 +01:00
|
|
|
|
</div>
|
2022-02-05 02:13:46 +01:00
|
|
|
|
<div class="crd-itm-psn">
|
|
|
|
|
|
<div class="wgt-dscr-w">
|
|
|
|
|
|
<p class="wgt-dscr-stl">Порт</p>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div class="wgt-w">
|
|
|
|
|
|
<input bind:value={settingsJson.mqttPort} class="wgt-ipt text-left focus:border-indigo-500" type="text" />
|
|
|
|
|
|
</div>
|
2022-02-02 23:37:15 +01:00
|
|
|
|
</div>
|
2022-02-05 02:13:46 +01:00
|
|
|
|
<div class="crd-itm-psn">
|
|
|
|
|
|
<div class="wgt-dscr-w">
|
|
|
|
|
|
<p class="wgt-dscr-stl">Префикс</p>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div class="wgt-w">
|
|
|
|
|
|
<input bind:value={settingsJson.mqttPrefix} class="wgt-ipt text-left focus:border-indigo-500" type="text" />
|
|
|
|
|
|
</div>
|
2022-02-02 23:37:15 +01:00
|
|
|
|
</div>
|
2022-02-05 02:13:46 +01:00
|
|
|
|
<div class="crd-itm-psn">
|
|
|
|
|
|
<div class="wgt-dscr-w">
|
|
|
|
|
|
<p class="wgt-dscr-stl">Имя пользователя</p>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div class="wgt-w">
|
|
|
|
|
|
<input bind:value={settingsJson.mqttUser} class="wgt-ipt text-left focus:border-indigo-500" type="text" />
|
|
|
|
|
|
</div>
|
2022-02-02 23:37:15 +01:00
|
|
|
|
</div>
|
2022-02-05 02:13:46 +01:00
|
|
|
|
<div class="crd-itm-psn">
|
|
|
|
|
|
<div class="wgt-dscr-w">
|
|
|
|
|
|
<p class="wgt-dscr-stl">Пароль</p>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div class="wgt-w">
|
|
|
|
|
|
<input bind:value={settingsJson.mqttPass} class="wgt-ipt text-left focus:border-indigo-500" type="text" />
|
|
|
|
|
|
</div>
|
2022-02-02 23:37:15 +01:00
|
|
|
|
</div>
|
2022-02-06 18:19:38 +01:00
|
|
|
|
<button class="btn-lg" on:click={() => saveSettings()}>{"Сохранить и проверить подключение"}</button>
|
2022-02-05 02:13:46 +01:00
|
|
|
|
</Card>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</Route>
|
|
|
|
|
|
<Route path="/utilities">
|
|
|
|
|
|
<Card title={"Пример графика"}>
|
|
|
|
|
|
<Chart data={datachart} type="line" />
|
2022-02-02 23:37:15 +01:00
|
|
|
|
</Card>
|
2022-02-05 02:13:46 +01:00
|
|
|
|
</Route>
|
|
|
|
|
|
<Route path="/log">
|
|
|
|
|
|
<Card title={"Лог"}>
|
|
|
|
|
|
{#each coreMessages as message, i}
|
|
|
|
|
|
<div class={message.msg.toString().includes("[E]") ? "text-red-500" : "text-black"}>{message.msg}</div>
|
|
|
|
|
|
{/each}
|
2022-02-02 23:37:15 +01:00
|
|
|
|
</Card>
|
2022-02-05 02:13:46 +01:00
|
|
|
|
</Route>
|
|
|
|
|
|
<Route path="/list">
|
|
|
|
|
|
<Card title={"Список устройств"}>
|
|
|
|
|
|
<table class="table-fixed gap-4 w-full">
|
|
|
|
|
|
<thead class="bg-gray-50 ">
|
2022-02-01 16:01:19 +01:00
|
|
|
|
<tr class="tbl-txt-sz tbl-txt-p">
|
2022-02-05 02:13:46 +01:00
|
|
|
|
<th class="tbl-hd">Название устройства</th>
|
|
|
|
|
|
<th class="tbl-hd">IP адрес</th>
|
|
|
|
|
|
<th class="tbl-hd">Идентификатор</th>
|
|
|
|
|
|
<th class="tbl-hd">Состояние</th>
|
2022-02-01 16:01:19 +01:00
|
|
|
|
</tr>
|
2022-02-05 02:13:46 +01:00
|
|
|
|
</thead>
|
|
|
|
|
|
<tbody class="bg-white">
|
|
|
|
|
|
{#each deviceList as device}
|
|
|
|
|
|
<tr class="tbl-txt-sz tbl-txt-p">
|
|
|
|
|
|
<td class="tbl-bdy">{device.name}</td>
|
|
|
|
|
|
<td class="tbl-bdy"><a href={"http://" + device.ip}>{device.ip}</a></td>
|
|
|
|
|
|
<td class="tbl-bdy">{device.id}</td>
|
|
|
|
|
|
<td class="tbl-bdy {device.status ? 'bg-green-50' : 'bg-red-50'}">{device.status ? "online" : "offline"}</td>
|
|
|
|
|
|
</tr>
|
|
|
|
|
|
{/each}
|
|
|
|
|
|
{#if showInput}
|
|
|
|
|
|
<tr class="tbl-txt-sz tbl-txt-p">
|
|
|
|
|
|
<td class="tbl-bdy"><input bind:value={newDevice.name} class="tbl-ipt w-full" type="text" /></td>
|
|
|
|
|
|
<td class="tbl-bdy"><input bind:value={newDevice.ip} class="tbl-ipt w-full" type="text" /></td>
|
|
|
|
|
|
<td class="tbl-bdy"><input bind:value={newDevice.id} class="tbl-ipt w-full" type="text" /></td>
|
|
|
|
|
|
<td class="tbl-bdy" />
|
|
|
|
|
|
</tr>
|
|
|
|
|
|
{/if}
|
|
|
|
|
|
</tbody>
|
|
|
|
|
|
</table>
|
|
|
|
|
|
<button class="btn-lg" on:click={() => ((showInput = !showInput), devListSave())}>{showInput ? "Сохранить" : "Добавить устройство"}</button>
|
|
|
|
|
|
</Card>
|
|
|
|
|
|
</Route>
|
|
|
|
|
|
<Route path="/about">
|
|
|
|
|
|
<button on:click={() => showModal()} type="button"> Toggle modal </button>
|
|
|
|
|
|
<Card title="Редактор JSON">
|
|
|
|
|
|
<textarea on:input={wigetsUpdate} rows="10" class="jsn-ipt w-full" id="text1">{syntaxHighlight(JSON.stringify(layoutJson))}</textarea>
|
|
|
|
|
|
</Card>
|
|
|
|
|
|
</Route>
|
|
|
|
|
|
{/if}
|
2022-02-01 16:01:19 +01:00
|
|
|
|
</div>
|
|
|
|
|
|
</ul>
|
|
|
|
|
|
</main>
|
2022-02-05 02:13:46 +01:00
|
|
|
|
|
2022-02-01 16:01:19 +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>
|
|
|
|
|
|
</div>
|
2021-09-16 02:00:52 +08:00
|
|
|
|
|
|
|
|
|
|
<style lang="postcss" global>
|
|
|
|
|
|
@tailwind base;
|
|
|
|
|
|
@tailwind components;
|
|
|
|
|
|
@tailwind utilities;
|
|
|
|
|
|
|
|
|
|
|
|
@layer components {
|
2021-10-25 16:50:31 +07:00
|
|
|
|
/*==================================================cards grid=====================================================*/
|
|
|
|
|
|
/* grid for cards */
|
2022-02-01 16:01:19 +01:00
|
|
|
|
.grd-3cols {
|
2021-10-18 20:42:01 +08:00
|
|
|
|
@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-09-17 23:18:06 +08:00
|
|
|
|
}
|
2021-10-25 16:50:31 +07:00
|
|
|
|
/* grid for cards for full screen */
|
2022-02-01 16:01:19 +01:00
|
|
|
|
.grd-1cols {
|
2021-10-16 20:49:17 +00:00
|
|
|
|
@apply grid grid-cols-1 justify-items-center;
|
|
|
|
|
|
}
|
2021-10-20 20:53:07 +08:00
|
|
|
|
/*=============================================card and items inside===============================================*/
|
|
|
|
|
|
/* 3. card items positioning*/
|
2021-12-28 23:55:14 +01:00
|
|
|
|
.crd-itm-psn {
|
2022-02-05 02:13:46 +01:00
|
|
|
|
@apply flex mb-3 h-8 items-center;
|
2021-10-20 20:53:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
/* 4. widget description width*/
|
2021-12-28 23:55:14 +01:00
|
|
|
|
.wgt-dscr-w {
|
2021-10-20 20:53:07 +08:00
|
|
|
|
@apply w-2/3;
|
|
|
|
|
|
}
|
|
|
|
|
|
/* 5. widget descr style*/
|
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;
|
|
|
|
|
|
}
|
|
|
|
|
|
/* 6. widget width*/
|
2021-12-28 23:55:14 +01:00
|
|
|
|
.wgt-w {
|
2021-10-25 16:50:31 +07:00
|
|
|
|
@apply flex justify-end w-1/3;
|
|
|
|
|
|
}
|
|
|
|
|
|
/*====================================================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-ipt {
|
2022-02-05 02:13:46 +01:00
|
|
|
|
@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;
|
2021-10-25 16:50:31 +07:00
|
|
|
|
}
|
2021-12-28 23:55:14 +01:00
|
|
|
|
.jsn-ipt {
|
2022-02-05 02:13:46 +01:00
|
|
|
|
@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-09-16 02:00:52 +08:00
|
|
|
|
}
|
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=====================================================*/
|
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
|
|
|
|
}
|
2021-12-28 23:55:14 +01:00
|
|
|
|
.tbl-bdy {
|
2022-02-05 02:13:46 +01:00
|
|
|
|
@apply text-center px-1 break-words;
|
2021-12-11 13:54:28 +01:00
|
|
|
|
}
|
2021-12-28 23:55:14 +01:00
|
|
|
|
.tbl-s-bdy {
|
2022-02-05 02:13:46 +01:00
|
|
|
|
@apply px-1 break-words;
|
2021-12-28 01:06:01 +01:00
|
|
|
|
}
|
2021-12-28 23:55:14 +01:00
|
|
|
|
.tbl-ipt {
|
2022-02-05 02:13:46 +01:00
|
|
|
|
@apply content-center mt-2 h-7 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;
|
2021-12-27 22:46:16 +01:00
|
|
|
|
}
|
2021-12-28 23:55:14 +01:00
|
|
|
|
.tbl-s-ipt {
|
2022-02-05 02:13:46 +01:00
|
|
|
|
@apply content-center h-6 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-29 01:21:28 +01:00
|
|
|
|
}
|
|
|
|
|
|
.tbl-s-txt {
|
|
|
|
|
|
@apply inline-block italic align-top text-right text-gray-500;
|
2021-12-12 00:20:47 +01:00
|
|
|
|
}
|
2021-12-28 23:55:14 +01:00
|
|
|
|
.tbl-txt-p {
|
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;
|
|
|
|
|
|
}
|
2021-12-28 23:55:14 +01:00
|
|
|
|
.tbl-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-01 16:01:19 +01:00
|
|
|
|
@apply flex justify-center break-words content-center bg-blue-100 hover:bg-blue-200 text-gray-500 font-bold 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=====================================================*/
|
2022-02-02 23:37:15 +01:00
|
|
|
|
.grd-2colsfx {
|
2022-02-01 16:01:19 +01:00
|
|
|
|
@apply grid gap-4 grid-cols-2 sm:grid-cols-2 lg:grid-cols-2 xl:grid-cols-2 2xl:grid-cols-2 justify-items-center;
|
|
|
|
|
|
}
|
2022-02-02 23:37:15 +01:00
|
|
|
|
.grd-2cols {
|
|
|
|
|
|
@apply grid gap-4 grid-cols-1 sm:grid-cols-1 lg:grid-cols-2 xl:grid-cols-2 2xl:grid-cols-2 justify-items-center;
|
|
|
|
|
|
}
|
2021-12-28 23:55:14 +01:00
|
|
|
|
.slct-lg {
|
2022-02-01 16:01:19 +01:00
|
|
|
|
@apply flex w-full justify-center break-words content-center bg-blue-100 hover:bg-blue-200 text-gray-500 font-bold 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;
|
|
|
|
|
|
z-index: 1;
|
|
|
|
|
|
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;
|
|
|
|
|
|
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>
|