diff --git a/server.js b/server.js index 66d9d77..9b7af25 100644 --- a/server.js +++ b/server.js @@ -2733,6 +2733,78 @@ app.put('/ai-parameters', async (req, res) => { } }); +app.post('/cameras-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', + }, + data: JSON.stringify({ + "FIELDS": [ + "AR" + ] + }), + }); + + await new Promise(resolve => setTimeout(resolve, 1000)); + + const getResponse = await axios.get(`http://${process.env.SERVER_IP}:8080/http/parameters/get?serial=${serial}`); + + res.json(getResponse.data); + } catch (error) { + console.error(error); + res.status(500).json({ error: 'Internal server error' }); + } +}); + +app.put('/cameras-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 { + VEC + } = requestData; + + const requestBody = { + "AR": { + "VEC": VEC + } + }; + + + 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"); diff --git a/static/scripts/parameters-form.js b/static/scripts/parameters-form.js index 6f4deb1..aaa859f 100644 --- a/static/scripts/parameters-form.js +++ b/static/scripts/parameters-form.js @@ -6,7 +6,8 @@ const content2 = document.getElementById("ethernet"); const content3 = document.getElementById("wifi"); const content4 = document.getElementById("communication"); const content5 = document.getElementById("install"); -const content6 = document.getElementById("ai");; +const content6 = document.getElementById("ai"); +const content7 = document.getElementById("cameras"); const radioButtons = document.querySelectorAll( 'input[type="radio"][name="newStage"]' ); @@ -61,6 +62,7 @@ function fadeOut(element, callback) { } var givenData; +var camerasData; function encodeCHValue(channels) { let CH = 0; @@ -293,6 +295,8 @@ for (let radioButton of radioButtons) { document.getElementById('parameters-bg').style.display = 'none'; + document.getElementById("system-ai").value = 0; + camerasData = data; console.log(data.DATA); @@ -355,6 +359,51 @@ for (let radioButton of radioButtons) { $("select").trigger("input"); + }) + .catch(error => console.error('Ошибка:', error)); + } else if (radioButton.value === "cameras") { + switchContent(content7); + document.getElementById('parameters-bg').style.display = 'flex'; + + fetch('/cameras-parameters', { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify(requestBody) + }) + .then(response => response.json()) + .then(data => { + + document.getElementById('parameters-bg').style.display = 'none'; + + document.getElementById("cameras-id").value = 0; + + console.log(data.DATA); + + camerasData = data.DATA.AR.VEC; + + function updateFields(selectedIndex) { + const selectedData = camerasData[selectedIndex]; + + document.getElementById("cameras-quality").value = selectedData.QLT; + document.getElementById("cameras-bitrate").value = selectedData.BR; + document.getElementById("cameras-video").value = selectedData.RST; + document.getElementById("cameras-alert").value = selectedData.ALT; + document.getElementById("cameras-ven").value = selectedData.VEN; + document.getElementById("cameras-aen").value = selectedData.AEN; + document.getElementById("cameras-framerate").value = selectedData.FR; + } + + document.getElementById("cameras-id").addEventListener("change", function () { + const selectedIndex = parseInt(this.value); + updateFields(selectedIndex); + }); + + updateFields(0); + + $("select").trigger("input"); + }) .catch(error => console.error('Ошибка:', error)); } @@ -390,3 +439,19 @@ function updateDataInArray() { givenData[selectedIndex] = selectedDataRow; } + +function updateCamerasInArray() { + const selectedIndex = parseInt(document.getElementById("cameras-id").value); + const selectedDataRow = camerasData[selectedIndex]; + + + selectedDataRow.QLT = parseInt(document.getElementById("cameras-quality").value); + selectedDataRow.BR = parseInt(document.getElementById("cameras-bitrate").value); + selectedDataRow.RST = parseInt(document.getElementById("cameras-video").value); + selectedDataRow.ALT = parseInt(document.getElementById("cameras-alert").value); + selectedDataRow.VEN = parseInt(document.getElementById("cameras-ven").value); + selectedDataRow.AEN = parseInt(document.getElementById("cameras-aen").value); + selectedDataRow.FR = parseInt(document.getElementById("cameras-framerate").value); + + camerasData[selectedIndex] = selectedDataRow; +} diff --git a/static/templates/devices/system.html b/static/templates/devices/system.html index 425118d..08c4ea1 100644 --- a/static/templates/devices/system.html +++ b/static/templates/devices/system.html @@ -142,6 +142,8 @@
+ +