diff --git a/server.js b/server.js index 71231eb..1a892ef 100644 --- a/server.js +++ b/server.js @@ -2577,6 +2577,35 @@ app.post('/install-parameters', async (req, res) => { } }); +app.post('/ai-parameters', async (req, res) => { + if (req.session.userId === undefined) { + return res.redirect("/signin"); + } + try { + const { serial } = req.body; + + 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": [ + "DSM" + ] + }), + }); + + await new Promise(resolve => setTimeout(resolve, 300)); + + 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('/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 5a22474..ee3a89a 100644 --- a/static/scripts/parameters-form.js +++ b/static/scripts/parameters-form.js @@ -6,7 +6,7 @@ const content2 = document.getElementById("ethernet"); const content3 = document.getElementById("wifi"); const content4 = document.getElementById("communication"); const content5 = document.getElementById("install"); -const content6 = document.getElementById("cameras");; +const content6 = document.getElementById("ai");; const radioButtons = document.querySelectorAll( 'input[type="radio"][name="newStage"]' ); @@ -60,6 +60,7 @@ function fadeOut(element, callback) { requestAnimationFrame(animate); } +var givenData; for (let radioButton of radioButtons) { radioButton.addEventListener("change", () => { @@ -238,8 +239,145 @@ for (let radioButton of radioButtons) { }) .catch(error => console.error('Ошибка:', error)); - } else if (radioButton.value === "cameras") { + } else if (radioButton.value === "ai") { switchContent(content6); + document.getElementById('parameters-bg').style.display = 'flex'; + + fetch('/ai-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'; + + camerasData = data; + + 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() { + var checkboxes = document.querySelectorAll('.checkbox-input'); + + checkboxes.forEach(function (checkbox) { + var cameraNumber = parseInt(checkbox.id.replace('camera', ''), 10); + + checkbox.checked = desiredCameras.includes(cameraNumber); + }); + } + + let newCH; + + + + function updateFields(selectedIndex) { + const selectedData = givenData[selectedIndex]; + console.log(selectedData); + + document.getElementById("system-ai-en1").value = selectedData.EN; + document.getElementById("system-ai-as1").value = selectedData.AS; + document.getElementById("system-ai-ensp1").value = selectedData.APR.ENSP; + document.getElementById("system-ai-fgms1").value = selectedData.FGMS; + document.getElementById("system-ai-sgms1").value = selectedData.SGMS; + document.getElementById("system-ai-esst1").value = selectedData.ESST; + document.getElementById("system-ai-udt1").value = selectedData.UDT; + document.getElementById("system-ai-vt1").value = selectedData.VT; + document.getElementById("system-ai-sdt1").value = selectedData.SDT; + document.getElementById("system-ai-et1").value = selectedData.APR.ET; + document.getElementById("system-ai-ss-en1").value = selectedData.APR.SS.EN; + document.getElementById("system-ai-ar-d1").value = selectedData.APR.AR.D; + + desiredCameras = decodeCHValue(selectedData.APR.AR.CH); + updateCheckboxes(); + + checkSelectedCameras(); + newCH = encodeCHValue(selectedCameras); + console.log('Выбранные камеры:', newCH); + } + + document.getElementById("system-ai").addEventListener("change", function () { + const selectedIndex = parseInt(this.value); + updateFields(selectedIndex); + }); + + 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); + + $("select").trigger("input"); + + }) + .catch(error => console.error('Ошибка:', error)); } }); } diff --git a/static/styles/main.css b/static/styles/main.css index 97285df..81a5bb5 100644 --- a/static/styles/main.css +++ b/static/styles/main.css @@ -526,6 +526,7 @@ header img { .organisation label, #parameters label, +#ai label, .permission-group label { color: rgba(0, 0, 0, 0.5); cursor: pointer !important; @@ -807,11 +808,13 @@ td { } .table input[type="checkbox"], -#parameters input[type="checkbox"] { +#parameters input[type="checkbox"], +#ai input[type="checkbox"] { display: none; } -#parameters .checkbox-label { +#parameters .checkbox-label, +#ai .checkbox-label { margin-top: 10px; } @@ -831,6 +834,11 @@ td { background: url(../img/checkbox-table-check.svg); } +#checkboxContainer .checkbox-label { + width: fit-content !important; + padding: 10px; +} + .table .trash, #adminTable .trash { height: 22px; diff --git a/static/templates/devices/system.html b/static/templates/devices/system.html index 421a74d..8d56b15 100644 --- a/static/templates/devices/system.html +++ b/static/templates/devices/system.html @@ -140,6 +140,8 @@
+ +