alarms parameters (NOT READY)

This commit is contained in:
Ivan
2023-09-26 00:45:53 +03:00
parent 817f3e8b71
commit 4b91a9fd93
4 changed files with 307 additions and 4 deletions

View File

@ -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));
}
});
}