mirror of
https://github.com/sergeyyarkov/modbus-logger.git
synced 2026-10-11 02:18:51 +03:00
refactor
This commit is contained in:
parent
da4cd16ade
commit
80ba7b0887
@ -102,25 +102,12 @@ export const modbusController = {
|
||||
await db.run(`UPDATE "modbus_slaves" SET
|
||||
id = ?,
|
||||
name = ?,
|
||||
g_display_reg_addr = NULL,
|
||||
g_display_reg_type = NULL,
|
||||
g_display_reg_format = NULL,
|
||||
g_y_label = NULL
|
||||
WHERE id = ? `,
|
||||
[newId, name, id]);
|
||||
|
||||
if (g_display_reg_addr !== null &&
|
||||
g_display_reg_type !== null &&
|
||||
g_display_reg_format !== null &&
|
||||
g_y_label !== null
|
||||
) {
|
||||
await db.run(`UPDATE "modbus_slaves" SET
|
||||
g_display_reg_addr = ?,
|
||||
g_display_reg_type = ?,
|
||||
g_display_reg_format = ?,
|
||||
g_y_label = ? WHERE id = ?`,
|
||||
[g_display_reg_addr, g_display_reg_type, g_display_reg_format, g_y_label, id]);
|
||||
}
|
||||
g_y_label = ?
|
||||
WHERE id = ? `,
|
||||
[newId, name, g_display_reg_addr, g_display_reg_type, g_display_reg_format, g_y_label, id]);
|
||||
|
||||
return res.status(200).json({ message: 'Updated.' })
|
||||
} catch (error) {
|
||||
@ -145,6 +132,7 @@ export const modbusController = {
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* Create display value for modbus slave device
|
||||
* @param {import('express').Request} req
|
||||
|
||||
@ -219,10 +219,9 @@
|
||||
actionType: 'EDIT'
|
||||
})"
|
||||
href="#">Edit</a>
|
||||
<a
|
||||
@click="$dispatch('dialog', {
|
||||
<a @click="$dispatch('dialog', {
|
||||
title: 'Remove device',
|
||||
body: `Remove ${selectedDevice.name}? All logs will be cleared.`,
|
||||
body: `Remove ${selectedDevice.name}?`,
|
||||
isOpen: true,
|
||||
onConfirm: async () => await removeDevice(selectedDevice.id)
|
||||
});"
|
||||
|
||||
@ -67,7 +67,7 @@ document.addEventListener("alpine:init", async () => {
|
||||
oldId: null,
|
||||
id: null,
|
||||
name: "",
|
||||
g_display_reg_addr: 0,
|
||||
g_display_reg_addr: null,
|
||||
g_display_reg_format: "UI16",
|
||||
g_display_reg_type: "IR",
|
||||
g_y_label: "",
|
||||
@ -91,8 +91,7 @@ document.addEventListener("alpine:init", async () => {
|
||||
this.isLoading = true;
|
||||
this.error = null;
|
||||
await api.post("/modbus/create_device", utils.dellNullableKeys({ ...this.data }));
|
||||
this.$dispatch("add-device", { ...this.data }); // add device to state
|
||||
this.resetDataFields();
|
||||
this.$dispatch("add-device", { ...this.data, display_values: [] }); // add device to state
|
||||
this.close();
|
||||
cb && cb();
|
||||
} catch (error) {
|
||||
@ -106,11 +105,11 @@ document.addEventListener("alpine:init", async () => {
|
||||
try {
|
||||
this.isLoading = true;
|
||||
this.error = null;
|
||||
if (this.graphView === 'none') {
|
||||
if (this.graphView !== 'new-value') {
|
||||
this.data.g_display_reg_addr = null;
|
||||
this.data.g_display_reg_format = null;
|
||||
this.data.g_display_reg_type = null;
|
||||
this.data.g_y_label = null;
|
||||
this.data.g_display_reg_type = null;
|
||||
}
|
||||
await api.post('/modbus/update_device', utils.dellNullableKeys({ ...this.data, id: this.data.oldId, newId: this.data.id }));
|
||||
window.location.reload();
|
||||
@ -147,11 +146,13 @@ document.addEventListener("alpine:init", async () => {
|
||||
this.data.oldId = detail.device.id;
|
||||
this.data.id = detail.device.id;
|
||||
this.data.name = detail.device.name;
|
||||
this.data.g_display_reg_addr = detail.device.g_display_reg_addr || 0;
|
||||
this.data.g_display_reg_format = detail.device.g_display_reg_format || 'UI16';
|
||||
this.data.g_display_reg_type = detail.device.g_display_reg_type || 'IR';
|
||||
this.data.g_y_label = detail.device.g_y_label || '';
|
||||
if (detail.device.g_display_reg_addr !== null) this.graphView = 'new-value'
|
||||
if (detail.device.g_display_reg_addr !== null) {
|
||||
this.graphView = 'new-value'
|
||||
this.data.g_display_reg_addr = detail.device.g_display_reg_addr;
|
||||
this.data.g_display_reg_format = detail.device.g_display_reg_format;
|
||||
this.data.g_display_reg_type = detail.device.g_display_reg_type;
|
||||
this.data.g_y_label = detail.device.g_y_label;
|
||||
}
|
||||
}
|
||||
this.isOpen = true;
|
||||
},
|
||||
@ -380,6 +381,6 @@ document.addEventListener("alpine:init", async () => {
|
||||
this.isOpen = detail.isOpen;
|
||||
this.onConfirm = detail.onConfirm;
|
||||
this.labels = { title: detail.title, body: detail.body };
|
||||
},
|
||||
}
|
||||
}));
|
||||
});
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { object, number, boolean, string } from 'yup';
|
||||
import { object, number, string } from 'yup';
|
||||
|
||||
export const modbusDeviceSchema = object({
|
||||
id: number().required(),
|
||||
@ -12,4 +12,4 @@ export const modbusDeviceSchema = object({
|
||||
export const removeModbusDeviceSchema = modbusDeviceSchema.pick(['id']);
|
||||
export const editModbusDeviceSchema = modbusDeviceSchema.shape({
|
||||
newId: number().required()
|
||||
})
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user