Deleted some code for one of the dropdowns so it no longer works, and the new code copied over also doesn't work

This commit is contained in:
Alice Sedgwick 2024-11-16 18:38:52 -05:00
parent beef00e14a
commit a8c2d628e0
1 changed files with 45 additions and 25 deletions

View File

@ -10,6 +10,8 @@ const drones = [
// Load initial settings
document.onload = initPage();
document.getElementById("save").addEventListener("click", saveSettings);
// Function to initialize the page
function initPage() {
// TODO: Replace /home/spiri/services with some root level path
@ -45,36 +47,54 @@ function handleSelect(account) {
}
}
function dockerComposeFileChanged() {
if (composeFileSelection.value === "") {
populateEditor("");
return;
}
const composeLocation = composeFileSelection.value + "/docker-compose.yaml";
cockpit.file(composeLocation)
.read().then((content) => successReadFile(content))
.catch(error => failureReadFile(error));
}
// Save configuration values to the configuration file
function saveSettings() {
function successReadFile(content) {
try {
// Drone selection
const currentDrone = getValueByKey(content, "common", "drone");
addDropDown(drone, drones, currentDrone);
cockpit.file(confLocation)
.read()
.then((content) => {
// WiFi & Temperature Configuration
content = setValueByKey(content, "[common]", "drone_channel", drone_channel.value);
cockpit.file(confLocation, { superuser: "try" }).replace(content)
.then(() => {
displayDroneTable();
displaySuccess("table updated successfully.");
})
.catch((error) => {
displayFail("Failed to update table: " + error.message);
});
})
.catch(error => {
displayFail("Failed to update table: " + error.message);
});
} catch (e) {
console.error("Error during update operation:", e);
failureReadFile(e);
}
}
// Restart wifibroadcast service
function restartDroneDisplayService() {
cockpit.spawn(["systemctl", "restart", "dronedisplay@drone"], { superuser: "require" })
.then(() => {
displaySuccess("dronedisplay@drone service restarted.");
})
.catch((error) => {
console.error("Failed to restart dronedisplay@drone service:", error);
displayFail("Failed to restart dronedisplay@drone service: " + error);
});
// Restart drone service
function displayDroneTable() {
upaate table
}
function addDropDown(box, pairs, defaultValue) {
try {
for(let i = 0; i < pairs.length; i++){
if (pairs[i].length == 0 || pairs[i][0] === "" || pairs[i][1] === "") continue;
const option = document.createElement("option");
option.value = pairs[i][0];
option.text = pairs[i][1];
box.add(option);
if (defaultValue === option.value) {
box.value = option.value;
}
}
}
catch(e) {
displayFail(e)
}
}