diff --git a/server.js b/server.js
index 1a892ef..316ac39 100644
--- a/server.js
+++ b/server.js
@@ -2127,6 +2127,10 @@ app.post('/update-group', async (req, res) => {
if (req.session.userId === undefined) {
return res.redirect("/signin");
}
+ const userInfo = await getUserInfo(req.session.userId);
+ if (!userInfo.EditTransport) {
+ return res.redirect("/devices");
+ }
try {
const { groupId, newName } = req.body;
@@ -2162,6 +2166,9 @@ async function getParameters(serial) {
]
}),
});
+
+ await new Promise(resolve => setTimeout(resolve, 300));
+
const requestResponse2 = await axios.get(`http://${process.env.SERVER_IP}:8080/http/parameters/request?serial=${serial}`, {
headers: {
@@ -2174,6 +2181,9 @@ async function getParameters(serial) {
}),
});
+ await new Promise(resolve => setTimeout(resolve, 300));
+
+
const requestResponse3 = await axios.get(`http://${process.env.SERVER_IP}:8080/http/parameters/request?serial=${serial}`, {
headers: {
'Content-Type': 'application/json',
@@ -2185,6 +2195,9 @@ async function getParameters(serial) {
}),
});
+ await new Promise(resolve => setTimeout(resolve, 300));
+
+
const requestResponse4 = await axios.get(`http://${process.env.SERVER_IP}:8080/http/parameters/request?serial=${serial}`, {
headers: {
'Content-Type': 'application/json',
@@ -2196,6 +2209,8 @@ async function getParameters(serial) {
}),
});
+ await new Promise(resolve => setTimeout(resolve, 300));
+
const requestResponse5 = await axios.get(`http://${process.env.SERVER_IP}:8080/http/parameters/request?serial=${serial}`, {
headers: {
'Content-Type': 'application/json',
@@ -2219,9 +2234,15 @@ app.post('/main-parameters', async (req, res) => {
if (req.session.userId === undefined) {
return res.redirect("/signin");
}
+ const userInfo = await getUserInfo(req.session.userId);
+ if (!userInfo.EditTransport) {
+ return res.redirect("/devices");
+ }
try {
const { serial } = req.body;
+ await new Promise(resolve => setTimeout(resolve, 1000));
+
const requestResponse = await axios.get(`http://${process.env.SERVER_IP}:8080/http/parameters/request?serial=${serial}`, {
headers: {
'Content-Type': 'application/json',
@@ -2234,7 +2255,7 @@ app.post('/main-parameters', async (req, res) => {
}),
});
- await new Promise(resolve => setTimeout(resolve, 300));
+ await new Promise(resolve => setTimeout(resolve, 1000));
const getResponse = await axios.get(`http://${process.env.SERVER_IP}:8080/http/parameters/get?serial=${serial}`);
@@ -2249,6 +2270,10 @@ app.put('/main-parameters', async (req, res) => {
if (req.session.userId === undefined) {
return res.redirect("/signin");
}
+ const userInfo = await getUserInfo(req.session.userId);
+ if (!userInfo.EditTransport) {
+ return res.redirect("/devices");
+ }
const requestData = req.body;
const { serial } = req.query;
@@ -2287,9 +2312,14 @@ app.post('/device-parameters', async (req, res) => {
if (req.session.userId === undefined) {
return res.redirect("/signin");
}
+ const userInfo = await getUserInfo(req.session.userId);
+ if (!userInfo.EditTransport) {
+ return res.redirect("/devices");
+ }
try {
const { serial } = req.body;
+ await new Promise(resolve => setTimeout(resolve, 1000));
const responseData = await getParameters(serial);
@@ -2306,9 +2336,15 @@ app.post('/ethernet-parameters', async (req, res) => {
if (req.session.userId === undefined) {
return res.redirect("/signin");
}
+ const userInfo = await getUserInfo(req.session.userId);
+ if (!userInfo.EditTransport) {
+ return res.redirect("/devices");
+ }
try {
const { serial } = req.body;
+ await new Promise(resolve => setTimeout(resolve, 1000));
+
const requestResponse = await axios.get(`http://${process.env.SERVER_IP}:8080/http/parameters/request?serial=${serial}`, {
headers: {
'Content-Type': 'application/json',
@@ -2321,7 +2357,7 @@ app.post('/ethernet-parameters', async (req, res) => {
}),
});
- await new Promise(resolve => setTimeout(resolve, 300));
+ await new Promise(resolve => setTimeout(resolve, 1000));
const getResponse = await axios.get(`http://${process.env.SERVER_IP}:8080/http/parameters/get?serial=${serial}`);
@@ -2336,6 +2372,10 @@ app.put('/ethernet-parameters', async (req, res) => {
if (req.session.userId === undefined) {
return res.redirect("/signin");
}
+ const userInfo = await getUserInfo(req.session.userId);
+ if (!userInfo.EditTransport) {
+ return res.redirect("/devices");
+ }
const requestData = req.body;
const { serial } = req.query;
@@ -2387,9 +2427,15 @@ app.post('/wifi-parameters', async (req, res) => {
if (req.session.userId === undefined) {
return res.redirect("/signin");
}
+ const userInfo = await getUserInfo(req.session.userId);
+ if (!userInfo.EditTransport) {
+ return res.redirect("/devices");
+ }
try {
const { serial } = req.body;
+ await new Promise(resolve => setTimeout(resolve, 1000));
+
const requestResponse = await axios.get(`http://${process.env.SERVER_IP}:8080/http/parameters/request?serial=${serial}`, {
headers: {
'Content-Type': 'application/json',
@@ -2401,7 +2447,7 @@ app.post('/wifi-parameters', async (req, res) => {
}),
});
- await new Promise(resolve => setTimeout(resolve, 300));
+ await new Promise(resolve => setTimeout(resolve, 1000));
const getResponse = await axios.get(`http://${process.env.SERVER_IP}:8080/http/parameters/get?serial=${serial}`);
@@ -2416,6 +2462,10 @@ app.put('/wifi-parameters', async (req, res) => {
if (req.session.userId === undefined) {
return res.redirect("/signin");
}
+ const userInfo = await getUserInfo(req.session.userId);
+ if (!userInfo.EditTransport) {
+ return res.redirect("/devices");
+ }
const requestData = req.body;
const { serial } = req.query;
@@ -2463,9 +2513,15 @@ app.post('/communication-parameters', async (req, res) => {
if (req.session.userId === undefined) {
return res.redirect("/signin");
}
+ const userInfo = await getUserInfo(req.session.userId);
+ if (!userInfo.EditTransport) {
+ return res.redirect("/devices");
+ }
try {
const { serial } = req.body;
+ await new Promise(resolve => setTimeout(resolve, 1000));
+
const requestResponse = await axios.get(`http://${process.env.SERVER_IP}:8080/http/parameters/request?serial=${serial}`, {
headers: {
'Content-Type': 'application/json',
@@ -2477,7 +2533,7 @@ app.post('/communication-parameters', async (req, res) => {
}),
});
- await new Promise(resolve => setTimeout(resolve, 300));
+ await new Promise(resolve => setTimeout(resolve, 1000));
const getResponse = await axios.get(`http://${process.env.SERVER_IP}:8080/http/parameters/get?serial=${serial}`);
@@ -2492,6 +2548,10 @@ app.put('/communication-parameters', async (req, res) => {
if (req.session.userId === undefined) {
return res.redirect("/signin");
}
+ const userInfo = await getUserInfo(req.session.userId);
+ if (!userInfo.EditTransport) {
+ return res.redirect("/devices");
+ }
const requestData = req.body;
const { serial } = req.query;
@@ -2552,9 +2612,15 @@ app.post('/install-parameters', async (req, res) => {
if (req.session.userId === undefined) {
return res.redirect("/signin");
}
+ const userInfo = await getUserInfo(req.session.userId);
+ if (!userInfo.EditTransport) {
+ return res.redirect("/devices");
+ }
try {
const { serial } = req.body;
+ await new Promise(resolve => setTimeout(resolve, 1000));
+
const requestResponse = await axios.get(`http://${process.env.SERVER_IP}:8080/http/parameters/request?serial=${serial}`, {
headers: {
'Content-Type': 'application/json',
@@ -2566,7 +2632,7 @@ app.post('/install-parameters', async (req, res) => {
}),
});
- await new Promise(resolve => setTimeout(resolve, 300));
+ await new Promise(resolve => setTimeout(resolve, 1000));
const getResponse = await axios.get(`http://${process.env.SERVER_IP}:8080/http/parameters/get?serial=${serial}`);
@@ -2581,9 +2647,16 @@ app.post('/ai-parameters', async (req, res) => {
if (req.session.userId === undefined) {
return res.redirect("/signin");
}
+ const userInfo = await getUserInfo(req.session.userId);
+ if (!userInfo.EditTransport) {
+ return res.redirect("/devices");
+ }
try {
const { serial } = req.body;
+ await new Promise(resolve => setTimeout(resolve, 1000));
+
+
const requestResponse = await axios.get(`http://${process.env.SERVER_IP}:8080/http/parameters/request?serial=${serial}`, {
headers: {
'Content-Type': 'application/json',
@@ -2595,7 +2668,7 @@ app.post('/ai-parameters', async (req, res) => {
}),
});
- await new Promise(resolve => setTimeout(resolve, 300));
+ await new Promise(resolve => setTimeout(resolve, 1000));
const getResponse = await axios.get(`http://${process.env.SERVER_IP}:8080/http/parameters/get?serial=${serial}`);
@@ -2606,10 +2679,50 @@ app.post('/ai-parameters', async (req, res) => {
}
});
+app.put('/ai-parameters', async (req, res) => {
+ if (req.session.userId === undefined) {
+ return res.redirect("/signin");
+ }
+ const userInfo = await getUserInfo(req.session.userId);
+ if (!userInfo.EditTransport) {
+ return res.redirect("/devices");
+ }
+
+ const requestData = req.body;
+ const { serial } = req.query;
+
+ const {
+ DSMA
+ } = requestData;
+
+ const requestBody = {
+ "DSM": {
+ "DSMA": DSMA
+ }
+ };
+
+
+ try {
+ const response = await axios.get(`http://${process.env.SERVER_IP}:8080/http/parameters/set?serial=${serial}`, {
+ data: JSON.stringify(requestBody),
+ headers: {
+ 'Content-Type': 'application/json'
+ }
+ });
+ res.status(response.status).send(response.data);
+ } catch (error) {
+ res.status(500).send('Произошла ошибка при отправке GET запроса.');
+ }
+});
+
app.put('/install-parameters', async (req, res) => {
if (req.session.userId === undefined) {
return res.redirect("/signin");
}
+ const userInfo = await getUserInfo(req.session.userId);
+ if (!userInfo.EditTransport) {
+ return res.redirect("/devices");
+ }
const requestData = req.body;
const { serial } = req.query;
@@ -2643,6 +2756,10 @@ app.put('/device-parameters', async (req, res) => {
if (req.session.userId === undefined) {
return res.redirect("/signin");
}
+ const userInfo = await getUserInfo(req.session.userId);
+ if (!userInfo.EditTransport) {
+ return res.redirect("/devices");
+ }
// Получаем данные из PUT запроса
const requestData = req.body;
const { serial } = req.query;
@@ -2719,6 +2836,10 @@ app.put('/camera-parameters', async (req, res) => {
if (req.session.userId === undefined) {
return res.redirect("/signin");
}
+ const userInfo = await getUserInfo(req.session.userId);
+ if (!userInfo.EditTransport) {
+ return res.redirect("/devices");
+ }
// Получаем данные из PUT запроса
const camerasData = req.body;
const { serial } = req.query;
@@ -2773,6 +2894,10 @@ app.post("/updatedevice", async (req, res) => {
if (req.session.userId === undefined) {
return res.redirect("/signin");
}
+ const userInfo = await getUserInfo(req.session.userId);
+ if (!userInfo.EditTransport) {
+ return res.redirect("/devices");
+ }
const pool = new Pool({
user: DB_User,
host: DB_Host,
@@ -2969,6 +3094,10 @@ app.post("/deletedevice", async (req, res) => {
if (req.session.userId === undefined) {
return res.redirect("/signin");
}
+ const userInfo = await getUserInfo(req.session.userId);
+ if (!userInfo.DeleteTransport) {
+ return res.redirect("/devices");
+ }
const id = req.body.id;
const pool = new Pool({
@@ -2996,6 +3125,9 @@ app.post("/deleteuser", async (req, res) => {
if (req.session.userId === undefined) {
return res.redirect("/signin");
}
+ if (req.session.userId != "admin") {
+ return res.redirect("/signin");
+ }
const id = req.body.id;
const pool = new Pool({
@@ -3023,6 +3155,10 @@ app.post("/deletegroup", async (req, res) => {
if (req.session.userId === undefined) {
return res.redirect("/signin");
}
+ const userInfo = await getUserInfo(req.session.userId);
+ if (!userInfo.EditTransport) {
+ return res.redirect("/devices");
+ }
const id = req.body.id;
const pool = new Pool({
@@ -3050,6 +3186,10 @@ app.post("/add-group", async (req, res) => {
if (req.session.userId === undefined) {
return res.redirect("/signin");
}
+ const userInfo = await getUserInfo(req.session.userId);
+ if (!userInfo.EditTransport) {
+ return res.redirect("/devices");
+ }
const { name } = req.body;
try {
diff --git a/static/scripts/parameters-form.js b/static/scripts/parameters-form.js
index ee3a89a..71322c6 100644
--- a/static/scripts/parameters-form.js
+++ b/static/scripts/parameters-form.js
@@ -62,6 +62,44 @@ function fadeOut(element, callback) {
var givenData;
+function encodeCHValue(channels) {
+ let CH = 0;
+ for (const channelNumber of channels) {
+ if (channelNumber >= 1 && channelNumber <= 32) {
+ const channelBit = 1 << (channelNumber - 1);
+ CH |= channelBit;
+ }
+ }
+ return CH;
+}
+
+let selectedCameras;
+
+function checkSelectedCameras() {
+ const checkboxes = document.querySelectorAll('.checkbox-input');
+ selectedCameras = [];
+
+ checkboxes.forEach((checkbox) => {
+ if (checkbox.checked) {
+ const cameraNumber = checkbox.id.replace('camera', '');
+ selectedCameras.push(cameraNumber);
+ }
+ });
+
+}
+
+function decodeCHValue(CH) {
+ const channels = [];
+ for (let i = 0; i < 32; i++) {
+ const channelBit = (CH >> i) & 1;
+ if (channelBit === 1) {
+ const channelNumber = i + 1;
+ channels.push(channelNumber);
+ }
+ }
+ return channels;
+}
+
for (let radioButton of radioButtons) {
radioButton.addEventListener("change", () => {
if (radioButton.value === "parameters") {
@@ -260,46 +298,6 @@ for (let radioButton of radioButtons) {
console.log(data.DATA);
givenData = data.DATA.DSM.DSMA;
- console.log(givenData);
-
- function encodeCHValue(channels) {
- let CH = 0;
- for (const channelNumber of channels) {
- if (channelNumber >= 1 && channelNumber <= 32) {
- const channelBit = 1 << (channelNumber - 1);
- CH |= channelBit;
- }
- }
- return CH;
- }
-
- let selectedCameras;
-
- function checkSelectedCameras() {
- const checkboxes = document.querySelectorAll('.checkbox-input');
- selectedCameras = [];
-
- checkboxes.forEach((checkbox) => {
- if (checkbox.checked) {
- const cameraNumber = checkbox.id.replace('camera', '');
- selectedCameras.push(cameraNumber);
- }
- });
-
- }
-
- function decodeCHValue(CH) {
- const channels = [];
- for (let i = 0; i < 32; i++) {
- const channelBit = (CH >> i) & 1;
- if (channelBit === 1) {
- const channelNumber = i + 1;
- channels.push(channelNumber);
- }
- }
- return channels;
- }
-
var desiredCameras;
function updateCheckboxes() {
@@ -338,7 +336,6 @@ for (let radioButton of radioButtons) {
checkSelectedCameras();
newCH = encodeCHValue(selectedCameras);
- console.log('Выбранные камеры:', newCH);
}
document.getElementById("system-ai").addEventListener("change", function () {
@@ -349,28 +346,8 @@ for (let radioButton of radioButtons) {
document.getElementById("checkboxContainer").addEventListener("change", function () {
checkSelectedCameras();
newCH = encodeCHValue(selectedCameras);
- console.log('Выбранные камеры:', newCH);
});
- function updateDataInArray(selectedIndex) {
- const selectedDataRow = data.DATA.DSM.DSMA[selectedIndex];
- selectedDataRow.EN = document.getElementById("system-ai-en1").value;
- selectedDataRow.AS = document.getElementById("system-ai-as1").value;
- selectedDataRow.APR.ENSP = document.getElementById("system-ai-ensp1").value;
- selectedDataRow.FGMS = document.getElementById("system-ai-fgms1").value;
- selectedDataRow.SGMS = document.getElementById("system-ai-sgms1").value;
- selectedDataRow.ESST = document.getElementById("system-ai-esst1").value;
- selectedDataRow.UDT = document.getElementById("system-ai-udt1").value;
- selectedDataRow.VT = document.getElementById("system-ai-vt1").value;
- selectedDataRow.SDT = document.getElementById("system-ai-sdt1").value;
- selectedDataRow.APR.ET = document.getElementById("system-ai-et1").value;
- selectedDataRow.APR.SS.EN = document.getElementById("system-ai-ss-en1").value;
- selectedDataRow.APR.AR.D = document.getElementById("system-ai-ar-d1").value;
-
- selectedDataRow.APR.AR.CH = encodeCHValue(selectedCameras);
-
- console.log(selectedDataRow);
- }
updateFields(0);
@@ -389,3 +366,25 @@ function truncateText(select) {
option.text = option.text.substring(0, maxLength) + "...";
}
}
+
+function updateDataInArray() {
+ const selectedIndex = parseInt(document.getElementById("system-ai").value);
+ const selectedDataRow = givenData[selectedIndex];
+
+ selectedDataRow.EN = parseInt(document.getElementById("system-ai-en1").value);
+ selectedDataRow.AS = parseInt(document.getElementById("system-ai-as1").value);
+ selectedDataRow.APR.ENSP = parseInt(document.getElementById("system-ai-ensp1").value);
+ selectedDataRow.FGMS = parseInt(document.getElementById("system-ai-fgms1").value);
+ selectedDataRow.SGMS = parseInt(document.getElementById("system-ai-sgms1").value);
+ selectedDataRow.ESST = parseInt(document.getElementById("system-ai-esst1").value);
+ selectedDataRow.UDT = parseInt(document.getElementById("system-ai-udt1").value);
+ selectedDataRow.VT = parseInt(document.getElementById("system-ai-vt1").value);
+ selectedDataRow.SDT = parseInt(document.getElementById("system-ai-sdt1").value);
+ selectedDataRow.APR.ET = parseInt(document.getElementById("system-ai-et1").value);
+ selectedDataRow.APR.SS.EN = parseInt(document.getElementById("system-ai-ss-en1").value);
+ selectedDataRow.APR.AR.D = parseInt(document.getElementById("system-ai-ar-d1").value);
+
+ selectedDataRow.APR.AR.CH = parseInt(encodeCHValue(selectedCameras));
+
+ givenData[selectedIndex] = selectedDataRow;
+}
diff --git a/static/templates/devices/system.html b/static/templates/devices/system.html
index 8d56b15..c98afd8 100644
--- a/static/templates/devices/system.html
+++ b/static/templates/devices/system.html
@@ -131,17 +131,17 @@