diff --git a/ui/general/health.js b/ui/general/health.js index ebb7343..56ed570 100644 --- a/ui/general/health.js +++ b/ui/general/health.js @@ -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) + } +} \ No newline at end of file