mirror of
https://github.com/IoTManagerProject/IoTManagerWeb.git
synced 2026-03-26 15:02:21 +03:00
рабочая версия
This commit is contained in:
198
src/App.svelte
198
src/App.svelte
@@ -31,14 +31,15 @@
|
|||||||
|
|
||||||
//****************************************************constants section*********************************************************/
|
//****************************************************constants section*********************************************************/
|
||||||
//******************************************************************************************************************************/
|
//******************************************************************************************************************************/
|
||||||
let debug = true;
|
const debug = true;
|
||||||
let LOG_MAX_MESSAGES = 100;
|
const LOG_MAX_MESSAGES = 100;
|
||||||
let reconnectTimeout = 20000;
|
const reconnectTimeout = 20000;
|
||||||
let rebootingTimeout = 18000;
|
const rebootingTimeout = 18000;
|
||||||
let updatingTimeout = 120000;
|
const updatingTimeout = 120000;
|
||||||
let opened = false;
|
let opened = false;
|
||||||
let preventMove = false;
|
let preventMove = false;
|
||||||
let devMode = true;
|
const blobDebug = false;
|
||||||
|
const devMode = true;
|
||||||
|
|
||||||
//****************************************************variable section**********************************************************/
|
//****************************************************variable section**********************************************************/
|
||||||
//******************************************************************************************************************************/
|
//******************************************************************************************************************************/
|
||||||
@@ -94,7 +95,6 @@
|
|||||||
|
|
||||||
//////////////////////////////////
|
//////////////////////////////////
|
||||||
let layoutJson = [];
|
let layoutJson = [];
|
||||||
|
|
||||||
let paramsJson = {};
|
let paramsJson = {};
|
||||||
|
|
||||||
let parsed = {
|
let parsed = {
|
||||||
@@ -158,81 +158,6 @@
|
|||||||
var chartJsonBlob = new MyBlobBuilder();
|
var chartJsonBlob = new MyBlobBuilder();
|
||||||
var layoutJsonBlobArray = [];
|
var layoutJsonBlobArray = [];
|
||||||
|
|
||||||
class blobToJson {
|
|
||||||
constructor(st, end, logMsg, jsonMode) {
|
|
||||||
this.st = st;
|
|
||||||
this.end = end;
|
|
||||||
this.logMsg = logMsg;
|
|
||||||
this.flag = false;
|
|
||||||
this.parced = false;
|
|
||||||
this.blob = new MyBlobBuilder();
|
|
||||||
this.out;
|
|
||||||
this.ws = 0;
|
|
||||||
this.jsonMode = jsonMode;
|
|
||||||
}
|
|
||||||
|
|
||||||
handle(data) {
|
|
||||||
this.data = data;
|
|
||||||
this.stEvent();
|
|
||||||
this.endEvent();
|
|
||||||
}
|
|
||||||
|
|
||||||
stEvent() {
|
|
||||||
if (this.data === this.st) {
|
|
||||||
this.flag = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
endEvent() {
|
|
||||||
if (this.data === this.end) {
|
|
||||||
this.flag = false;
|
|
||||||
var bb = this.blob.getBlob();
|
|
||||||
let reader = new FileReader();
|
|
||||||
reader.readAsText(bb);
|
|
||||||
reader.onload = () => {
|
|
||||||
let result = reader.result;
|
|
||||||
if (this.jsonMode) {
|
|
||||||
if (IsJsonParse(result)) {
|
|
||||||
this.parced = true;
|
|
||||||
this.out = JSON.parse(result);
|
|
||||||
if (debug) console.log("✔ B", this.logMsg + " blob parced");
|
|
||||||
onParced();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
this.parced = true;
|
|
||||||
this.out = result;
|
|
||||||
if (debug) console.log("✔ S", this.logMsg + " text parced", this.out);
|
|
||||||
onParced();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
this.blob.clear();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
setAsNotParced() {
|
|
||||||
this.parced = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
get isParced() {
|
|
||||||
return this.parced;
|
|
||||||
}
|
|
||||||
|
|
||||||
//после того как забрали данные класс более считается как не parced
|
|
||||||
get getData() {
|
|
||||||
this.parced = false;
|
|
||||||
return this.out;
|
|
||||||
}
|
|
||||||
|
|
||||||
append(data) {
|
|
||||||
if (this.flag) this.blob.append(data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let configJsonPacket = new blobToJson("/st/config.json", "/end/config.json", "config.json", true);
|
|
||||||
let itemsJsonPacket = new blobToJson("/st/items.json", "/end/items.json", "items.json", true);
|
|
||||||
let widgetsJsonPacket = new blobToJson("/st/widgets.json", "/end/widgets.json", "widgets.json", true);
|
|
||||||
let scenarioJsonPacket = new blobToJson("/st/scenario.txt", "/end/scenario.txt", "scenario.json.txt", false);
|
|
||||||
|
|
||||||
router.subscribe(handleNavigation);
|
router.subscribe(handleNavigation);
|
||||||
|
|
||||||
function handleNavigation() {
|
function handleNavigation() {
|
||||||
@@ -366,68 +291,11 @@
|
|||||||
if (typeof event.data === "string") {
|
if (typeof event.data === "string") {
|
||||||
let data = event.data;
|
let data = event.data;
|
||||||
if (ws === selectedWs) {
|
if (ws === selectedWs) {
|
||||||
//сборщик deviceList сообщений
|
|
||||||
//if (data.includes('devicelist_":"')) {
|
|
||||||
// if (IsJsonParse(data)) {
|
|
||||||
// incDeviceList = JSON.parse(data);
|
|
||||||
// incDeviceList = incDeviceList;
|
|
||||||
// if (firstDevListRequest) {
|
|
||||||
// deviceList = incDeviceList;
|
|
||||||
// deviceList[0].status = true;
|
|
||||||
// } else {
|
|
||||||
// deviceList = combineArrays(deviceList, incDeviceList);
|
|
||||||
// }
|
|
||||||
// firstDevListRequest = false;
|
|
||||||
// deviceList = deviceList;
|
|
||||||
// parsed.deviceListJson = true;
|
|
||||||
// if (debug) console.log("✔ S", "deviceList parced");
|
|
||||||
// onParced();
|
|
||||||
// whenDeviceListWasUpdated();
|
|
||||||
// connectToAllDevices();
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
//сборщик ssidJson сообщений
|
|
||||||
//if (data.includes('ssids_":"')) {
|
|
||||||
// if (IsJsonParse(data)) {
|
|
||||||
// ssidJson = JSON.parse(data);
|
|
||||||
// ssidJson = ssidJson;
|
|
||||||
// if (debug) console.log("✔ S", "ssidJson parced");
|
|
||||||
// parsed.ssidJson = true;
|
|
||||||
//
|
|
||||||
// onParced();
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
//сборщик errorsJson сообщений
|
|
||||||
//if (data.includes('errors_":"')) {
|
|
||||||
// if (IsJsonParse(data)) {
|
|
||||||
// errorsJson = JSON.parse(data);
|
|
||||||
// errorsJson = errorsJson;
|
|
||||||
// parsed.errorsJson = true;
|
|
||||||
// if (debug) console.log("✔ S", "errorsJson parced");
|
|
||||||
// onParced();
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
//сборщик settingsJson сообщений
|
|
||||||
//if (data.includes('settings_":"')) {
|
|
||||||
// if (IsJsonParse(data)) {
|
|
||||||
// settingsJson = JSON.parse(data);
|
|
||||||
// settingsJson = settingsJson;
|
|
||||||
// //sortingLayout();
|
|
||||||
// parsed.settingsJson = true;
|
|
||||||
// if (debug) console.log("✔ S", "settingsJson parced");
|
|
||||||
// onParced();
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
//сборщик log сообщений
|
//сборщик log сообщений
|
||||||
if (data.includes("/log|")) {
|
//if (data.includes("/log|")) {
|
||||||
data = data.replace("/log|", "");
|
// data = data.replace("/log|", "");
|
||||||
addCoreMsg(data);
|
// addCoreMsg(data);
|
||||||
}
|
//}
|
||||||
//метки начала конца пакетов для Blob--------------------------------------------------------------------------//
|
|
||||||
//configJsonPacket.handle(data);
|
|
||||||
//itemsJsonPacket.handle(data);
|
|
||||||
//widgetsJsonPacket.handle(data);
|
|
||||||
//scenarioJsonPacket.handle(data);
|
|
||||||
}
|
}
|
||||||
//прием от всех устройств
|
//прием от всех устройств
|
||||||
//сборщик paramsJson сообщений
|
//сборщик paramsJson сообщений
|
||||||
@@ -552,10 +420,10 @@
|
|||||||
if (await getPayloadAsJson(blob, size, out)) {
|
if (await getPayloadAsJson(blob, size, out)) {
|
||||||
itemsJson = out.json;
|
itemsJson = out.json;
|
||||||
parsed.itemsJson = true;
|
parsed.itemsJson = true;
|
||||||
console.log("[✔]", "itemsJson: ", itemsJson);
|
if (blobDebug) console.log("[✔]", "itemsJson: ", itemsJson);
|
||||||
} else {
|
} else {
|
||||||
parsed.itemsJson = false;
|
parsed.itemsJson = false;
|
||||||
console.log("[e]", "itemsJson parse error");
|
if (blobDebug) console.log("[e]", "itemsJson parse error");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (header === "widget") {
|
if (header === "widget") {
|
||||||
@@ -563,10 +431,10 @@
|
|||||||
if (await getPayloadAsJson(blob, size, out)) {
|
if (await getPayloadAsJson(blob, size, out)) {
|
||||||
widgetsJson = out.json;
|
widgetsJson = out.json;
|
||||||
parsed.widgetsJson = true;
|
parsed.widgetsJson = true;
|
||||||
console.log("[✔]", "widgetsJson: ", widgetsJson);
|
if (blobDebug) console.log("[✔]", "widgetsJson: ", widgetsJson);
|
||||||
} else {
|
} else {
|
||||||
parsed.widgetsJson = false;
|
parsed.widgetsJson = false;
|
||||||
console.log("[e]", "widgetsJson parse error");
|
if (blobDebug) console.log("[e]", "widgetsJson parse error");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (header === "config") {
|
if (header === "config") {
|
||||||
@@ -574,25 +442,25 @@
|
|||||||
if (await getPayloadAsJson(blob, size, out)) {
|
if (await getPayloadAsJson(blob, size, out)) {
|
||||||
configJson = out.json;
|
configJson = out.json;
|
||||||
parsed.configJson = true;
|
parsed.configJson = true;
|
||||||
console.log("[✔]", "configJson: ", configJson);
|
if (blobDebug) console.log("[✔]", "configJson: ", configJson);
|
||||||
} else {
|
} else {
|
||||||
parsed.configJson = false;
|
parsed.configJson = false;
|
||||||
console.log("[e]", "configJson parse error");
|
if (blobDebug) console.log("[e]", "configJson parse error");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (header === "scenar") {
|
if (header === "scenar") {
|
||||||
scenarioTxt = await getPayloadAsTxt(blob, size);
|
scenarioTxt = await getPayloadAsTxt(blob, size);
|
||||||
console.log("[i]", "scenarioTxt: ", scenarioTxt);
|
if (blobDebug) console.log("[i]", "scenarioTxt: ", scenarioTxt);
|
||||||
}
|
}
|
||||||
if (header === "settin") {
|
if (header === "settin") {
|
||||||
let out = {};
|
let out = {};
|
||||||
if (await getPayloadAsJson(blob, size, out)) {
|
if (await getPayloadAsJson(blob, size, out)) {
|
||||||
settingsJson = out.json;
|
settingsJson = out.json;
|
||||||
parsed.settingsJson = true;
|
parsed.settingsJson = true;
|
||||||
console.log("[✔]", "settingsJson: ", settingsJson);
|
if (blobDebug) console.log("[✔]", "settingsJson: ", settingsJson);
|
||||||
} else {
|
} else {
|
||||||
parsed.settingsJson = false;
|
parsed.settingsJson = false;
|
||||||
console.log("[e]", "settingsJson parse error");
|
if (blobDebug) console.log("[e]", "settingsJson parse error");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (header === "ssidli") {
|
if (header === "ssidli") {
|
||||||
@@ -600,10 +468,10 @@
|
|||||||
if (await getPayloadAsJson(blob, size, out)) {
|
if (await getPayloadAsJson(blob, size, out)) {
|
||||||
ssidJson = out.json;
|
ssidJson = out.json;
|
||||||
parsed.ssidJson = true;
|
parsed.ssidJson = true;
|
||||||
console.log("[✔]", "ssidJson: ", ssidJson);
|
if (blobDebug) console.log("[✔]", "ssidJson: ", ssidJson);
|
||||||
} else {
|
} else {
|
||||||
parsed.ssidJson = false;
|
parsed.ssidJson = false;
|
||||||
console.log("[e]", "ssidJson parse error");
|
if (blobDebug) console.log("[e]", "ssidJson parse error");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (header === "errors") {
|
if (header === "errors") {
|
||||||
@@ -611,10 +479,10 @@
|
|||||||
if (await getPayloadAsJson(blob, size, out)) {
|
if (await getPayloadAsJson(blob, size, out)) {
|
||||||
errorsJson = out.json;
|
errorsJson = out.json;
|
||||||
parsed.errorsJson = true;
|
parsed.errorsJson = true;
|
||||||
console.log("[✔]", "errorsJson: ", errorsJson);
|
if (blobDebug) console.log("[✔]", "errorsJson: ", errorsJson);
|
||||||
} else {
|
} else {
|
||||||
parsed.errorsJson = false;
|
parsed.errorsJson = false;
|
||||||
console.log("[e]", "errorsJson parse error");
|
if (blobDebug) console.log("[e]", "errorsJson parse error");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (header === "devlis") {
|
if (header === "devlis") {
|
||||||
@@ -622,13 +490,17 @@
|
|||||||
if (await getPayloadAsJson(blob, size, out)) {
|
if (await getPayloadAsJson(blob, size, out)) {
|
||||||
incDeviceList = out.json;
|
incDeviceList = out.json;
|
||||||
parsed.incDeviceList = true;
|
parsed.incDeviceList = true;
|
||||||
console.log("[✔]", "incDeviceList: ", incDeviceList);
|
if (blobDebug) console.log("[✔]", "incDeviceList: ", incDeviceList);
|
||||||
handleDeviseList();
|
handleDeviseList();
|
||||||
} else {
|
} else {
|
||||||
parsed.incDeviceList = false;
|
parsed.incDeviceList = false;
|
||||||
console.log("[e]", "incDeviceList parse error");
|
if (blobDebug) console.log("[e]", "incDeviceList parse error");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (header === "corelg") {
|
||||||
|
let txt = await getPayloadAsTxt(blob, size);
|
||||||
|
addCoreMsg(txt);
|
||||||
|
}
|
||||||
|
|
||||||
onParced();
|
onParced();
|
||||||
}
|
}
|
||||||
@@ -660,9 +532,9 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function getPayloadAsTxt(blob, size) {
|
async function getPayloadAsTxt(blob, size) {
|
||||||
let payloadBlob = blob.slice(size, blob.length);
|
let txtBlob = blob.slice(size, blob.length);
|
||||||
let payload = await payloadBlob.text();
|
let txt = await txtBlob.text();
|
||||||
return payload;
|
return txt;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function onParced() {
|
async function onParced() {
|
||||||
@@ -715,7 +587,7 @@
|
|||||||
firstDevListRequest = false;
|
firstDevListRequest = false;
|
||||||
deviceList = deviceList;
|
deviceList = deviceList;
|
||||||
parsed.deviceListJson = true;
|
parsed.deviceListJson = true;
|
||||||
if (debug) console.log("[✔]", "deviceList parced");
|
if (blobDebug) console.log("[✔]", "deviceList parced");
|
||||||
onParced();
|
onParced();
|
||||||
whenDeviceListWasUpdated();
|
whenDeviceListWasUpdated();
|
||||||
connectToAllDevices();
|
connectToAllDevices();
|
||||||
@@ -998,7 +870,7 @@
|
|||||||
|
|
||||||
clearParcedFlags();
|
clearParcedFlags();
|
||||||
|
|
||||||
if (debug) console.log("[i]", "all app data cleared");
|
if (debug) console.log("[i]", "all json files cleared");
|
||||||
}
|
}
|
||||||
|
|
||||||
function clearParcedFlags() {
|
function clearParcedFlags() {
|
||||||
|
|||||||
@@ -58,7 +58,6 @@
|
|||||||
let height;
|
let height;
|
||||||
|
|
||||||
function windowHeight() {
|
function windowHeight() {
|
||||||
console.log("test", scenarioTxt);
|
|
||||||
let scenStr = scenarioTxt;
|
let scenStr = scenarioTxt;
|
||||||
height = scenStr.split("\n").length + 1;
|
height = scenStr.split("\n").length + 1;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user