Added a check which verifies the data in the timing data block editor
This commit is contained in:
parent
db6dff5a97
commit
b95c73cfb5
1 changed files with 36 additions and 11 deletions
|
@ -557,26 +557,51 @@ function fillTableFromJson() {
|
||||||
function createJsonFromTable() {
|
function createJsonFromTable() {
|
||||||
var tableRows = document.querySelectorAll("table tr");
|
var tableRows = document.querySelectorAll("table tr");
|
||||||
var tcdata = [];
|
var tcdata = [];
|
||||||
|
|
||||||
|
// Speichert die Zeitangaben (hour, minute) in einem Array
|
||||||
|
var timeArr = [];
|
||||||
for (var i = 1; i <= 10; i++) {
|
for (var i = 1; i <= 10; i++) {
|
||||||
|
var row = document.getElementById("hour" + i).parentNode;
|
||||||
var row = document.getElementById("hour" + i).parentNode;
|
var hour = parseInt(row.cells[0].childNodes[0].value);
|
||||||
var hour = parseInt(row.cells[0].childNodes[0].value);
|
var min = parseInt(row.cells[1].childNodes[0].value);
|
||||||
var min = parseInt(row.cells[1].childNodes[0].value);
|
timeArr.push(hour * 60 + min); // Speichert die Zeitangaben als Minuten seit Mitternacht
|
||||||
var ch1 = Math.round(parseInt(row.cells[2].childNodes[0].value) * 2.55);
|
var ch1 = Math.round(parseInt(row.cells[2].childNodes[0].value) * 2.55);
|
||||||
var ch2 = Math.round(parseInt(row.cells[3].childNodes[0].value) * 2.55);
|
var ch2 = Math.round(parseInt(row.cells[3].childNodes[0].value) * 2.55);
|
||||||
var ch3 = Math.round(parseInt(row.cells[4].childNodes[0].value) * 2.55);
|
var ch3 = Math.round(parseInt(row.cells[4].childNodes[0].value) * 2.55);
|
||||||
var ch4 = Math.round(parseInt(row.cells[5].childNodes[0].value) * 2.55);
|
var ch4 = Math.round(parseInt(row.cells[5].childNodes[0].value) * 2.55);
|
||||||
|
tcdata.push({hour: hour, min: min, ch1: ch1, ch2: ch2, ch3: ch3, ch4: ch4});
|
||||||
tcdata.push({hour: hour, min: min, ch1: ch1, ch2: ch2, ch3: ch3, ch4: ch4});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Überprüft, ob die Zeitangaben von datensatz i=0 bis i=9 aufsteigend sind
|
||||||
|
for (var i = 0; i < timeArr.length - 1; i++) {
|
||||||
|
if (timeArr[i] >= timeArr[i + 1]) {
|
||||||
|
console.log("Fehler: Zeitangaben sind nicht aufsteigend.");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var currentTime = {hour: new Date().getHours(), min: new Date().getMinutes()};
|
var currentTime = {hour: new Date().getHours(), min: new Date().getMinutes()};
|
||||||
var jsonData = {tcdata: tcdata, currenttime: currentTime};
|
var jsonData = {tcdata: tcdata, currenttime: currentTime};
|
||||||
//console.log("jsonData = " + JSON.stringify(jsonData));
|
//console.log("jsonData = " + JSON.stringify(jsonData));
|
||||||
return JSON.stringify(jsonData);
|
return JSON.stringify(jsonData);
|
||||||
}
|
}
|
||||||
|
|
||||||
function sendDataToServer() {
|
function sendDataToServer() {
|
||||||
var jsonData = createJsonFromTable();
|
var jsonData = createJsonFromTable();
|
||||||
|
|
||||||
|
if (!jsonData) {
|
||||||
|
button.classList.remove("pure-button-primary");
|
||||||
|
button.classList.add("error");
|
||||||
|
button.innerHTML = "Error!";
|
||||||
|
setTimeout(function () {
|
||||||
|
button.classList.remove("error");
|
||||||
|
button.classList.add("pure-button-primary");
|
||||||
|
button.innerHTML = "save";
|
||||||
|
}, 2000);
|
||||||
|
console.log('Error while sending data to server.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var urlEncodedData = encodeURIComponent(jsonData);
|
var urlEncodedData = encodeURIComponent(jsonData);
|
||||||
var url = 'http://{{IP_ADDRESS}}/tc_data_blocks_store?data=' + urlEncodedData;
|
var url = 'http://{{IP_ADDRESS}}/tc_data_blocks_store?data=' + urlEncodedData;
|
||||||
var xhr = new XMLHttpRequest();
|
var xhr = new XMLHttpRequest();
|
||||||
|
|
Loading…
Reference in a new issue