From 0e109848304f56831913d6aee76c376fb466b6c1 Mon Sep 17 00:00:00 2001 From: sergeyyarkov Date: Thu, 26 Oct 2023 23:03:09 +0300 Subject: [PATCH] progress --- data.db | Bin 20480 -> 20480 bytes migrations/001-init.sql | 15 +++++++++ public/index.html | 72 +++++++++++++++++++++++++--------------- public/js/app.js | 44 +++++++++++------------- 4 files changed, 80 insertions(+), 51 deletions(-) diff --git a/data.db b/data.db index 3027c9172cb245eddaa422b7c3365acdca01d27f..7ab0cfc11f91cbc778b7487c8651f9dbfda1b6e8 100644 GIT binary patch delta 70 zcmV-M0J;BwpaFoO0gxL3;*lIf0phV>rXK{<01wo&5g^JBBPsw3023zy6#^9j2?A6@ cP%$|&E-^MZE-)@JFf#%6b7XU5v-d9vAm~~X)c^nh delta 41 zcmV+^0M`G2paFoO0gxL3*^wMW0ok!&rXK{{01w==5irXSkx&Pd+&?I@1Tg#`NzV_# diff --git a/migrations/001-init.sql b/migrations/001-init.sql index 0d1c201..da9ecae 100644 --- a/migrations/001-init.sql +++ b/migrations/001-init.sql @@ -39,6 +39,21 @@ CREATE TABLE IF NOT EXISTS "display_values" ( FOREIGN KEY("slave_id") REFERENCES modbus_slaves("id") ON DELETE CASCADE ); +-- CREATE TABLE IF NOT EXISTS "modbus_log" ( +-- "id" INTEGER, +-- "date" DATE NOT NULL, +-- "slave_id" INTEGER NOT NULL, + +-- -- JSON Format: +-- -- { +-- -- graph: [{ reg_addr: 1 value: 4 }], +-- -- display_values: [{ reg_addr: 1, name: "CV1" }] +-- -- } +-- "data" TEXT NOT NULL, +-- PRIMARY KEY("id"), +-- FOREIGN KEY("slave_id") REFERENCES modbus_slaves("id") ON DELETE CASCADE +-- ) + INSERT INTO "modbus_slaves" ( "id", "name", "g_display_reg_addr", "g_display_reg_format", "g_y_label", "is_logging" ) VALUES diff --git a/public/index.html b/public/index.html index e1c06ac..3fc467e 100644 --- a/public/index.html +++ b/public/index.html @@ -28,30 +28,35 @@
Devices: - No devices added. + No devices added.
-

- Connection: -
- Status: - Opened - Closed - - - Reconfigurate - -
+ Connection: +
+ Status: + Opened + Closed + + Reconfigurate +
@@ -60,7 +65,12 @@

Edit - Delete + Delete
@@ -101,7 +111,7 @@
- +
@@ -114,7 +124,7 @@ x-bind:required="$store.app.config.mb_connection_type === 'TCP'" />
- +
- +
@@ -140,7 +150,7 @@ x-bind:required="$store.app.config.mb_connection_type === 'RTU'" />
- +
- +
- +
- +
- +
-
+

diff --git a/public/js/app.js b/public/js/app.js index 157ff87..b3784d1 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -4,13 +4,7 @@ import api from "./api.js"; import * as utils from "./utils/index.js"; const pages = ["loading", "monitoring", "configuration", "404"]; -let graphData = []; -const t = new Date(); - -for (var i = 10; i >= 0; i--) { - var x = new Date(t.getTime() - i * 1000); - graphData.push([x, Math.random()]); -} +let graphData = [[0, 0]]; document.addEventListener("alpine:init", async () => { Alpine.store("app", { @@ -31,7 +25,7 @@ document.addEventListener("alpine:init", async () => { error: null, async init() { try { - const connStatusEventSource = new EventSource('/api/modbus/status'); + const connStatusEventSource = new EventSource("/api/modbus/status"); const { config } = await api.get("/app/config"); const { is_configured } = await api.get("/app/is_configured"); @@ -39,7 +33,7 @@ document.addEventListener("alpine:init", async () => { if (config) this.config = config; if (is_configured) { - connStatusEventSource.onmessage = (e) => (this.is_opened = e.data === 'true'); + connStatusEventSource.onmessage = (e) => (this.is_opened = e.data === "true"); await utils.wait(500); this.currentPage = "monitoring"; return; @@ -63,28 +57,28 @@ document.addEventListener("alpine:init", async () => { }, }); - Alpine.data('monitoringPage', () => ({ + Alpine.data("monitoringPage", () => ({ selectedDevice: null, devices: [], async init() { try { - this.$store.app.currentPage = 'loading' + this.$store.app.currentPage = "loading"; var g = new Dygraph(document.getElementById("div_g"), graphData, { drawPoints: false, showRoller: false, - ylabel: 'Y Label', + ylabel: "Y Label", valueRange: [0.0, 1.8], //labels: ["Time", "Random"], }); - this.devices = await api.get('/modbus/devices'); + this.devices = await api.get("/modbus/devices"); window.intervalId = setInterval(() => { graphData.push([new Date(), Math.random()]); - g.updateOptions({ file: graphData }) - }, 500) + g.updateOptions({ file: graphData }); + }, 500); } catch (error) { this.$store.app.error = error; } finally { - this.$store.app.currentPage = 'monitoring' + this.$store.app.currentPage = "monitoring"; } }, selectDevice(device) { @@ -95,13 +89,13 @@ document.addEventListener("alpine:init", async () => { async removeDevice(id, ctx) { try { //await api.post('/modbus/remove_device', { id }); - this.devices = _this.devices.filter(d => d.id != id); + this.devices = _this.devices.filter((d) => d.id != id); this.selectedDevice = null; } catch (error) { - console.error('Error while removing device.', error) + console.error("Error while removing device.", error); } - } - })) + }, + })); Alpine.data("configAppPage", () => ({ selectedConnectionType: "TCP", @@ -137,12 +131,12 @@ document.addEventListener("alpine:init", async () => { Alpine.store("confirmDialog", { isOpen: false, labels: { - title: 'Confirm dialog', - body: 'Are you sure you want to perform this action?', + title: "Confirm dialog", + body: "Are you sure you want to perform this action?", }, cb: { fn: null, - args: [] + args: [], }, open(title, body, cb, ...args) { this.isOpen = true; @@ -156,6 +150,6 @@ document.addEventListener("alpine:init", async () => { }, close() { this.isOpen = false; - } - }) + }, + }); });