mirror of
https://github.com/IoTManagerProject/IoTManagerWeb.git
synced 2026-03-30 20:09:24 +03:00
комментирование
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
<script>
|
<script>
|
||||||
|
//==============================components import section====================================
|
||||||
import { onMount } from "svelte";
|
import { onMount } from "svelte";
|
||||||
import { Route, router, active } from "tinro";
|
import { Route, router, active } from "tinro";
|
||||||
router.mode.hash(); // enables hash navigation method
|
router.mode.hash(); // enables hash navigation method
|
||||||
@@ -7,19 +8,23 @@
|
|||||||
router.subscribe(handleNavigation);
|
router.subscribe(handleNavigation);
|
||||||
//import Chart from "svelte-frappe-charts";
|
//import Chart from "svelte-frappe-charts";
|
||||||
|
|
||||||
//import components
|
|
||||||
import Card from "./widgets/Card.svelte";
|
import Card from "./widgets/Card.svelte";
|
||||||
import Input from "./widgets/Input.svelte";
|
import Input from "./widgets/Input.svelte";
|
||||||
import Toggle from "./widgets/Toggle.svelte";
|
import Toggle from "./widgets/Toggle.svelte";
|
||||||
import Anydata from "./widgets/Anydata.svelte";
|
import Anydata from "./widgets/Anydata.svelte";
|
||||||
|
|
||||||
//секция переменных==========================================================================
|
//==================================constants section========================================
|
||||||
let debug = true;
|
let debug = true;
|
||||||
let LOG_MAX_MESSAGES = 10;
|
let LOG_MAX_MESSAGES = 10;
|
||||||
//===========================================================================================
|
|
||||||
let showInput = false;
|
//=================================variable section==========================================
|
||||||
let myip = document.location.hostname;
|
let myip = document.location.hostname;
|
||||||
|
let showInput = false;
|
||||||
|
|
||||||
|
//dashboard
|
||||||
let wigets = [];
|
let wigets = [];
|
||||||
|
let pages = [];
|
||||||
|
|
||||||
wigets = [
|
wigets = [
|
||||||
{
|
{
|
||||||
widget: "input",
|
widget: "input",
|
||||||
@@ -129,12 +134,18 @@
|
|||||||
ws: 0,
|
ws: 0,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
//configuration
|
||||||
let config = [];
|
let config = [];
|
||||||
|
|
||||||
|
//web sockets
|
||||||
let socket = [];
|
let socket = [];
|
||||||
let socketConnected = false;
|
let socketConnected = false;
|
||||||
let selectedDeviceData = {};
|
let selectedDeviceData = {};
|
||||||
let deviceList = [];
|
let deviceList = [];
|
||||||
let flag = true;
|
let flag = true;
|
||||||
|
let newDevice = {};
|
||||||
|
let coreMessages = [];
|
||||||
|
|
||||||
deviceList = [
|
deviceList = [
|
||||||
{
|
{
|
||||||
@@ -151,12 +162,8 @@
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
let newDevice = {};
|
//=================================functions section========================================
|
||||||
|
//web socket functions======================================================================
|
||||||
let pages = [];
|
|
||||||
let coreMessages = [];
|
|
||||||
|
|
||||||
//секция функций==========================================================================
|
|
||||||
function connectToAllDevices() {
|
function connectToAllDevices() {
|
||||||
//closeAllConnection();
|
//closeAllConnection();
|
||||||
//socket = [];
|
//socket = [];
|
||||||
@@ -181,18 +188,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getJsonObject(array, number) {
|
|
||||||
let num = 0;
|
|
||||||
let out = {};
|
|
||||||
array.forEach((object) => {
|
|
||||||
if (num === number) {
|
|
||||||
out = object;
|
|
||||||
}
|
|
||||||
num++;
|
|
||||||
});
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
function markDeviceStatus(ws, status) {
|
function markDeviceStatus(ws, status) {
|
||||||
deviceList.forEach((device) => {
|
deviceList.forEach((device) => {
|
||||||
if (device.ws === ws) {
|
if (device.ws === ws) {
|
||||||
@@ -301,19 +296,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const syntaxHighlight = (json) => {
|
//dashboard functions====================================================================================
|
||||||
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;
|
|
||||||
};
|
|
||||||
|
|
||||||
function findNewPage() {
|
function findNewPage() {
|
||||||
pages = [];
|
pages = [];
|
||||||
const newPage = Array.from(new Set(Array.from(wigets, ({ page }) => page)));
|
const newPage = Array.from(new Set(Array.from(wigets, ({ page }) => page)));
|
||||||
@@ -336,6 +319,7 @@
|
|||||||
findNewPage();
|
findNewPage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//logging execution======================================================================================
|
||||||
const addCoreMsg = (msg) => {
|
const addCoreMsg = (msg) => {
|
||||||
if (coreMessages.length > Number(LOG_MAX_MESSAGES)) {
|
if (coreMessages.length > Number(LOG_MAX_MESSAGES)) {
|
||||||
coreMessages = coreMessages.slice(0);
|
coreMessages = coreMessages.slice(0);
|
||||||
@@ -353,6 +337,7 @@
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//device list handle======================================================================================
|
||||||
function dropdownChange() {
|
function dropdownChange() {
|
||||||
socketConnected = selectedDeviceData.status;
|
socketConnected = selectedDeviceData.status;
|
||||||
wsSelected = selectedDeviceData.ws;
|
wsSelected = selectedDeviceData.ws;
|
||||||
@@ -379,6 +364,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//navigation===========================================================================================
|
||||||
function handleNavigation() {
|
function handleNavigation() {
|
||||||
let page = $router.path.toString();
|
let page = $router.path.toString();
|
||||||
console.log("[i]", "user on page:", page);
|
console.log("[i]", "user on page:", page);
|
||||||
@@ -389,6 +375,33 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//json=================================================================================================
|
||||||
|
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;
|
||||||
|
};
|
||||||
|
|
||||||
|
//initialisation=======================================================================================
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
console.log("[i]", "mounted");
|
console.log("[i]", "mounted");
|
||||||
connectToAllDevices();
|
connectToAllDevices();
|
||||||
|
|||||||
Reference in New Issue
Block a user