Bug fixes
This commit is contained in:
+100
-101
@@ -11,7 +11,107 @@ 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(remove, async () => {
|
||||
const map_filename = (new URLSearchParams(window.location.search)).get("element");
|
||||
|
||||
try {
|
||||
const response = await fetch(`/app/remove?element=${map_filename}`, {
|
||||
method: "DELETE"
|
||||
});
|
||||
if (!response.ok) {
|
||||
throw new Error(`Response status: ${response.status}`);
|
||||
} else {
|
||||
window.location.href = "/app";
|
||||
}
|
||||
} catch (error) {
|
||||
alert(`Remove unsuccessful. ${error.message}`);
|
||||
console.error(error.message);
|
||||
}
|
||||
});
|
||||
|
||||
setEventListeners(commit, async () => {
|
||||
if (changes) {
|
||||
const map_filename = (new URLSearchParams(window.location.search)).get("element");
|
||||
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++) {
|
||||
if (throttle_table.rows[1].cells[i].style.backgroundColor == "blue") {
|
||||
req_body["throttle"][i - 1] = throttle_table.rows[1].cells[i].firstChild.value;
|
||||
}
|
||||
}
|
||||
|
||||
for (let i = 1; i < motor_table.rows[1].cells.length; i++) {
|
||||
if (motor_table.rows[1].cells[i].style.backgroundColor == "blue") {
|
||||
req_body["motor"][0][i - 1] = motor_table.rows[1].cells[i].firstChild.value;
|
||||
}
|
||||
}
|
||||
|
||||
for (let i = 1; i < motor_table.rows[2].cells.length; i++) {
|
||||
if (motor_table.rows[2].cells[i].style.backgroundColor == "blue") {
|
||||
req_body["motor"][1][i - 1] = motor_table.rows[2].cells[i].firstChild.value;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch(`/app/edit?element=${map_filename}`, {
|
||||
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(`Edit unsuccessful. ${error.message}`);
|
||||
console.error(error.message);
|
||||
}
|
||||
} else {
|
||||
alert("Nothing to commit.");
|
||||
}
|
||||
});
|
||||
|
||||
setEventListeners(download, () => {
|
||||
const map_filename = (new URLSearchParams(window.location.search)).get("element");
|
||||
|
||||
window.location.href = `/app/download?element=${map_filename}`;
|
||||
});
|
||||
|
||||
var parsed_map = JSON.parse(map);
|
||||
|
||||
(function () {
|
||||
let data = [];
|
||||
|
||||
@@ -323,104 +423,3 @@ var parsed_map = JSON.parse(map);
|
||||
}
|
||||
}
|
||||
})();
|
||||
|
||||
|
||||
|
||||
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(remove, async () => {
|
||||
const map_filename = (new URLSearchParams(window.location.search)).get("element");
|
||||
|
||||
try {
|
||||
const response = await fetch(`/app/remove?element=${map_filename}`, {
|
||||
method: "DELETE"
|
||||
});
|
||||
if (!response.ok) {
|
||||
throw new Error(`Response status: ${response.status}`);
|
||||
} else {
|
||||
window.location.href = "/app";
|
||||
}
|
||||
} catch (error) {
|
||||
alert(`Remove unsuccessful. ${error.message}`);
|
||||
console.error(error.message);
|
||||
}
|
||||
});
|
||||
|
||||
setEventListeners(commit, async () => {
|
||||
if (changes) {
|
||||
const map_filename = (new URLSearchParams(window.location.search)).get("element");
|
||||
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++) {
|
||||
if (throttle_table.rows[1].cells[i].style.backgroundColor == "blue") {
|
||||
req_body["throttle"][i - 1] = throttle_table.rows[1].cells[i].firstChild.value;
|
||||
}
|
||||
}
|
||||
|
||||
for (let i = 1; i < motor_table.rows[1].cells.length; i++) {
|
||||
if (motor_table.rows[1].cells[i].style.backgroundColor == "blue") {
|
||||
req_body["motor"][0][i - 1] = motor_table.rows[1].cells[i].firstChild.value;
|
||||
}
|
||||
}
|
||||
|
||||
for (let i = 1; i < motor_table.rows[2].cells.length; i++) {
|
||||
if (motor_table.rows[2].cells[i].style.backgroundColor == "blue") {
|
||||
req_body["motor"][1][i - 1] = motor_table.rows[2].cells[i].firstChild.value;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch(`/app/edit?element=${map_filename}`, {
|
||||
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(`Edit unsuccessful. ${error.message}`);
|
||||
console.error(error.message);
|
||||
}
|
||||
} else {
|
||||
alert("Nothing to commit.");
|
||||
}
|
||||
});
|
||||
|
||||
setEventListeners(download, () => {
|
||||
const map_filename = (new URLSearchParams(window.location.search)).get("element");
|
||||
|
||||
window.location.href = `/app/download?element=${map_filename}`;
|
||||
});
|
||||
Reference in New Issue
Block a user