Bug fixes

This commit is contained in:
2025-05-31 10:10:18 +02:00
parent f1cfd0c77e
commit 05a8baed4f
6 changed files with 246 additions and 204 deletions
+71 -73
View File
@@ -9,6 +9,77 @@ const map_description = document.getElementById("map_description");
var changes = 0;
function setEventListeners(element, cb) {
element.onmouseenter = async function () {
this.style.backgroundColor = "blue";
};
element.onmouseleave = async function () {
this.style.backgroundColor = "";
};
element.onmousedown = async function () {
this.style.backgroundColor = "red";
};
element.ondblclick = async function () {
cb();
this.style.backgroundColor = "blue";
};
}
setEventListeners(commit, async () => {
if (changes) {
let req_body = {};
req_body["meta"] = {};
req_body["throttle"] = {};
req_body["motor"] = { 0: {}, 1: {} };
if (map_name.style.backgroundColor == "blue") {
req_body["meta"]["name"] = map_name.value;
}
if (map_id.style.backgroundColor == "blue") {
req_body["meta"]["id"] = map_id.value;
}
if (map_description.style.backgroundColor == "blue") {
req_body["meta"]["description"] = map_description.value;
}
for (let i = 1; i < throttle_table.rows[1].cells.length; i++) {
let e = throttle_table.rows[1].cells[i].firstChild;
req_body["throttle"][i - 1] = (e.value ? e.value : e.placeholder);
}
for (let i = 1; i < motor_table.rows[1].cells.length; i++) {
let e = motor_table.rows[1].cells[i].firstChild;
req_body["motor"][0][i - 1] = (e.value ? e.value : e.placeholder);
}
for (let i = 1; i < motor_table.rows[2].cells.length; i++) {
let e = motor_table.rows[2].cells[i].firstChild;
req_body["motor"][1][i - 1] = (e.value ? e.value : e.placeholder);
}
try {
const response = await fetch("/app/add", {
method: "POST",
body: JSON.stringify(req_body),
headers: {
"Content-Type": "application/json",
}
});
if (!response.ok) {
throw new Error(`Response status: ${response.status}`);
} else {
window.location.href = "/app";
}
} catch (error) {
alert(`Add unsuccessful. ${error.message}`);
console.error(error.message);
}
} else {
alert("Nothing to commit.");
}
});
(function () {
let data = [];
@@ -305,76 +376,3 @@ var changes = 0;
}
}
})();
function setEventListeners(element, cb) {
element.onmouseenter = async function () {
this.style.backgroundColor = "blue";
};
element.onmouseleave = async function () {
this.style.backgroundColor = "";
};
element.onmousedown = async function () {
this.style.backgroundColor = "red";
};
element.ondblclick = async function () {
cb();
this.style.backgroundColor = "blue";
};
}
setEventListeners(commit, async () => {
if (changes) {
let req_body = {};
req_body["meta"] = {};
req_body["throttle"] = {};
req_body["motor"] = { 0: {}, 1: {} };
if (map_name.style.backgroundColor == "blue") {
req_body["meta"]["name"] = map_name.value;
}
if (map_id.style.backgroundColor == "blue") {
req_body["meta"]["id"] = map_id.value;
}
if (map_description.style.backgroundColor == "blue") {
req_body["meta"]["description"] = map_description.value;
}
for (let i = 1; i < throttle_table.rows[1].cells.length; i++) {
let e = throttle_table.rows[1].cells[i].firstChild;
req_body["throttle"][i - 1] = (e.value ? e.value : e.placeholder);
}
for (let i = 1; i < motor_table.rows[1].cells.length; i++) {
let e = motor_table.rows[1].cells[i].firstChild;
req_body["motor"][0][i - 1] = (e.value ? e.value : e.placeholder);
}
for (let i = 1; i < motor_table.rows[2].cells.length; i++) {
let e = motor_table.rows[2].cells[i].firstChild;
req_body["motor"][1][i - 1] = (e.value ? e.value : e.placeholder);
}
try {
const response = await fetch("/app/add", {
method: "POST",
body: JSON.stringify(req_body),
headers: {
"Content-Type": "application/json",
}
});
if (!response.ok) {
throw new Error(`Response status: ${response.status}`);
} else {
window.location.href = "/app";
}
} catch (error) {
alert(`Add unsuccessful. ${error.message}`);
console.error(error.message);
}
} else {
alert("Nothing to commit.");
}
});