2024-10-28 12:02:39 -03:00
|
|
|
|
|
|
|
// Elements
|
2024-11-10 03:13:25 -04:00
|
|
|
const drone = document.getElementById("drone");
|
|
|
|
|
|
|
|
const drones = [
|
|
|
|
["1", "mu1"], ["2", "mu2"], ["3", "mu3"],
|
|
|
|
["4", "mu4"], ["5", "mu5"], ["6", "mu6"]
|
|
|
|
]
|
2024-10-28 12:02:39 -03:00
|
|
|
|
|
|
|
// Load initial settings
|
|
|
|
document.onload = initPage();
|
|
|
|
|
2024-11-16 19:38:52 -04:00
|
|
|
document.getElementById("save").addEventListener("click", saveSettings);
|
|
|
|
|
2024-11-17 00:02:56 -04:00
|
|
|
const dropdownElement = document.getElementById('dropdownMenuButton1');
|
|
|
|
new bootstrap.Dropdown(dropdownElement);
|
2024-10-28 12:02:39 -03:00
|
|
|
// Function to initialize the page
|
|
|
|
function initPage() {
|
2024-11-11 03:06:30 -04:00
|
|
|
// TODO: Replace /home/spiri/services with some root level path
|
|
|
|
// Search for drones files in the services directory and populate the dropdown with directory names
|
|
|
|
const currentDrone = getValueByKey(content, "common", "drone");
|
2024-11-10 03:13:25 -04:00
|
|
|
|
2024-11-11 03:06:30 -04:00
|
|
|
addDropDown(drone, drones, currentDrone);
|
|
|
|
}
|
|
|
|
|
2024-11-11 12:53:05 -04:00
|
|
|
function handleSelect(account) {
|
2024-11-11 14:04:12 -04:00
|
|
|
var drone1Table = "<table><tr><td>Drone1</td></tr></table>";
|
|
|
|
var drone2Table = "<table><tr><td>Drone2</td></tr></table>";
|
|
|
|
var drone3Table = "<table><tr><td>Drone3/td></tr></table>";
|
|
|
|
var drone4Table = "<table><tr><td>Drone4</td></tr></table>";
|
|
|
|
var drone5Table = "<table><tr><td>Drone5</td></tr></table>";
|
2024-11-11 12:53:05 -04:00
|
|
|
switch(account)
|
|
|
|
{
|
|
|
|
case "Drone1":
|
|
|
|
document.getElementById("myTableContainer").innerHTML = drone1Table
|
|
|
|
break;
|
2024-11-11 14:04:12 -04:00
|
|
|
case "Drone2":
|
|
|
|
document.getElementById("myTableContainer").innerHTML = drone2Table
|
|
|
|
break;
|
|
|
|
case "Drone3":
|
|
|
|
document.getElementById("myTableContainer").innerHTML = drone3Table
|
|
|
|
break;
|
|
|
|
case "Drone4":
|
|
|
|
document.getElementById("myTableContainer").innerHTML = drone4Table
|
|
|
|
break;
|
|
|
|
case "Drone5":
|
|
|
|
document.getElementById("myTableContainer").innerHTML = drone5Table
|
|
|
|
break;
|
2024-11-11 12:53:05 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-11-16 19:38:52 -04:00
|
|
|
// Save configuration values to the configuration file
|
|
|
|
function saveSettings() {
|
2024-11-10 03:13:25 -04:00
|
|
|
|
|
|
|
try {
|
2024-11-16 19:38:52 -04:00
|
|
|
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);
|
|
|
|
});
|
2024-11-10 03:13:25 -04:00
|
|
|
} catch (e) {
|
2024-11-16 19:38:52 -04:00
|
|
|
console.error("Error during update operation:", e);
|
2024-11-10 03:13:25 -04:00
|
|
|
failureReadFile(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-11-16 19:38:52 -04:00
|
|
|
|
|
|
|
// Restart drone service
|
|
|
|
function displayDroneTable() {
|
2024-11-17 00:02:56 -04:00
|
|
|
// upaate table
|
|
|
|
;
|
2024-10-28 12:02:39 -03:00
|
|
|
}
|
2024-11-16 19:38:52 -04:00
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|