update
This commit is contained in:
336
html/admin.html
336
html/admin.html
@@ -114,6 +114,10 @@
|
||||
</div>
|
||||
|
||||
|
||||
<div class="input-group mb-3" id="sondes_envea_div">
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
<!--<button type="submit" class="btn btn-primary">Submit</button>-->
|
||||
@@ -212,6 +216,16 @@
|
||||
|
||||
//end document.addEventListener
|
||||
|
||||
|
||||
/*
|
||||
___ _ _
|
||||
/ _ \ _ __ | | ___ __ _ __| |
|
||||
| | | | '_ \| | / _ \ / _` |/ _` |
|
||||
| |_| | | | | |__| (_) | (_| | (_| |
|
||||
\___/|_| |_|_____\___/ \__,_|\__,_|
|
||||
|
||||
*/
|
||||
|
||||
window.onload = function() {
|
||||
|
||||
//NEW way to get config (SQLite)
|
||||
@@ -267,6 +281,12 @@ window.onload = function() {
|
||||
checkbox_envea.checked = response["envea/read_value_v2.py"];
|
||||
checkbox_solar.checked = response["MPPT/read.py"];
|
||||
checkbox_wind.checked = response["windMeter/read.py"];
|
||||
|
||||
//si sonde envea is true
|
||||
if (response["envea/read_value_v2.py"]) {
|
||||
add_sondeEnveaContainer();
|
||||
|
||||
}
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
console.error('AJAX request failed:', status, error);
|
||||
@@ -368,6 +388,10 @@ window.onload = function() {
|
||||
|
||||
|
||||
} //end window.onload
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function update_config_sqlite(param, value){
|
||||
console.log("Updating sqlite ",param," : ", value);
|
||||
@@ -445,6 +469,12 @@ function update_config_scripts_sqlite(param, value) {
|
||||
Value: ${response.enabled !== undefined ? response.enabled : value}<br>
|
||||
${response.message || ''}
|
||||
`;
|
||||
|
||||
if (response.script_path == "envea/read_value_v2.py") {
|
||||
console.log("envea sondes activated");
|
||||
add_sondeEnveaContainer();
|
||||
|
||||
}
|
||||
} else {
|
||||
// Error message
|
||||
toastLiveExample.classList.remove('text-bg-success');
|
||||
@@ -558,6 +588,312 @@ function set_RTC_withBrowser(){
|
||||
}); //end ajax
|
||||
}
|
||||
|
||||
/*
|
||||
____ _ _____
|
||||
/ ___| ___ _ __ __| | ___ ___ | ____|_ ____ _____ __ _
|
||||
\___ \ / _ \| '_ \ / _` |/ _ \/ __| | _| | '_ \ \ / / _ \/ _` |
|
||||
___) | (_) | | | | (_| | __/\__ \ | |___| | | \ V / __/ (_| |
|
||||
|____/ \___/|_| |_|\__,_|\___||___/ |_____|_| |_|\_/ \___|\__,_|
|
||||
|
||||
*/
|
||||
|
||||
function add_sondeEnveaContainer() {
|
||||
console.log("Sonde Envea is true: need to add container!");
|
||||
|
||||
// Getting envea_sondes_table data
|
||||
$.ajax({
|
||||
url: 'launcher.php?type=get_envea_sondes_table_sqlite',
|
||||
dataType: 'json',
|
||||
method: 'GET',
|
||||
success: function(sondes) {
|
||||
console.log("Getting SQLite envea sondes table:");
|
||||
console.log(sondes);
|
||||
|
||||
// Create container div if it doesn't exist
|
||||
if ($('#sondes_envea_div').length === 0) {
|
||||
$('#advanced_options').append('<div id="sondes_envea_div" class="input-group mt-4 border p-3 rounded"><legend>Sondes Envea</legend></div>');
|
||||
} else {
|
||||
// Clear existing content if container exists
|
||||
$('#sondes_envea_div').html('<legend>Sondes Envea</legend>');
|
||||
}
|
||||
|
||||
// Loop through each sonde and create UI elements
|
||||
sondes.forEach(function(sonde) {
|
||||
// Create a unique ID for this sonde
|
||||
const sondeId = `sonde_${sonde.id}`;
|
||||
|
||||
// Create HTML for this sonde
|
||||
const sondeHtml = `
|
||||
<div class="input-group mb-3" id="${sondeId}_container">
|
||||
<div class="input-group-text">
|
||||
<input class="form-check-input mt-0" type="checkbox" id="${sondeId}_enabled"
|
||||
${sonde.connected ? 'checked' : ''}
|
||||
onchange="updateSondeStatus(${sonde.id}, this.checked)">
|
||||
</div>
|
||||
<input type="text" class="form-control" placeholder="Name" value="${sonde.name}"
|
||||
id="${sondeId}_name" onchange="updateSondeName(${sonde.id}, this.value)">
|
||||
<input type="text" class="form-control" placeholder="Port" value="${sonde.port}"
|
||||
id="${sondeId}_port" onchange="updateSondePort(${sonde.id}, this.value)">
|
||||
<input type="number" class="form-control" placeholder="Coefficient" value="${sonde.coefficient}"
|
||||
id="${sondeId}_coefficient" onchange="updateSondeCoefficient(${sonde.id}, this.value)">
|
||||
</div>
|
||||
`;
|
||||
|
||||
// Append this sonde to the container
|
||||
$('#sondes_envea_div').append(sondeHtml);
|
||||
});
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
console.error('AJAX request failed:', status, error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Helper functions for updating sonde properties
|
||||
function updateSondeStatus(id, connected) {
|
||||
console.log(`Updating sonde ${id} connected status to: ${connected}`);
|
||||
const toastLiveExample = document.getElementById('liveToast');
|
||||
const toastBody = toastLiveExample.querySelector('.toast-body');
|
||||
|
||||
$.ajax({
|
||||
url: `launcher.php?type=update_sonde&id=${id}&field=connected&value=${connected ? 1 : 0}`,
|
||||
dataType: 'json',
|
||||
method: 'GET',
|
||||
cache: false,
|
||||
success: function(response) {
|
||||
console.log('Sonde status updated:', response);
|
||||
|
||||
// Format the response for toast
|
||||
let formattedMessage = '';
|
||||
|
||||
if (response.success) {
|
||||
// Success message
|
||||
toastLiveExample.classList.remove('text-bg-danger');
|
||||
toastLiveExample.classList.add('text-bg-success');
|
||||
|
||||
formattedMessage = `
|
||||
<strong>Success!</strong><br>
|
||||
Sonde ID: ${response.id}<br>
|
||||
Connected: ${connected ? "Yes" : "No"}<br>
|
||||
${response.message || ''}
|
||||
`;
|
||||
} else {
|
||||
// Error message
|
||||
toastLiveExample.classList.remove('text-bg-success');
|
||||
toastLiveExample.classList.add('text-bg-danger');
|
||||
|
||||
formattedMessage = `
|
||||
<strong>Error!</strong><br>
|
||||
${response.error || 'Unknown error'}<br>
|
||||
Sonde ID: ${id}
|
||||
`;
|
||||
}
|
||||
|
||||
// Update and show toast
|
||||
toastBody.innerHTML = formattedMessage;
|
||||
const toastBootstrap = bootstrap.Toast.getOrCreateInstance(toastLiveExample);
|
||||
toastBootstrap.show();
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
console.error('Failed to update sonde status:', error);
|
||||
|
||||
// Show error toast
|
||||
toastLiveExample.classList.remove('text-bg-success');
|
||||
toastLiveExample.classList.add('text-bg-danger');
|
||||
toastBody.innerHTML = `
|
||||
<strong>Request Failed!</strong><br>
|
||||
Error: ${error}<br>
|
||||
Sonde ID: ${id}
|
||||
`;
|
||||
const toastBootstrap = bootstrap.Toast.getOrCreateInstance(toastLiveExample);
|
||||
toastBootstrap.show();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function updateSondeName(id, name) {
|
||||
console.log(`Updating sonde ${id} name to: ${name}`);
|
||||
const toastLiveExample = document.getElementById('liveToast');
|
||||
const toastBody = toastLiveExample.querySelector('.toast-body');
|
||||
|
||||
$.ajax({
|
||||
url: `launcher.php?type=update_sonde&id=${id}&field=name&value=${encodeURIComponent(name)}`,
|
||||
dataType: 'json',
|
||||
method: 'GET',
|
||||
cache: false,
|
||||
success: function(response) {
|
||||
console.log('Sonde name updated:', response);
|
||||
|
||||
// Format the response for toast
|
||||
let formattedMessage = '';
|
||||
|
||||
if (response.success) {
|
||||
// Success message
|
||||
toastLiveExample.classList.remove('text-bg-danger');
|
||||
toastLiveExample.classList.add('text-bg-success');
|
||||
|
||||
formattedMessage = `
|
||||
<strong>Success!</strong><br>
|
||||
Sonde ID: ${response.id}<br>
|
||||
Name: ${name}<br>
|
||||
${response.message || ''}
|
||||
`;
|
||||
} else {
|
||||
// Error message
|
||||
toastLiveExample.classList.remove('text-bg-success');
|
||||
toastLiveExample.classList.add('text-bg-danger');
|
||||
|
||||
formattedMessage = `
|
||||
<strong>Error!</strong><br>
|
||||
${response.error || 'Unknown error'}<br>
|
||||
Sonde ID: ${id}
|
||||
`;
|
||||
}
|
||||
|
||||
// Update and show toast
|
||||
toastBody.innerHTML = formattedMessage;
|
||||
const toastBootstrap = bootstrap.Toast.getOrCreateInstance(toastLiveExample);
|
||||
toastBootstrap.show();
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
console.error('Failed to update sonde name:', error);
|
||||
|
||||
// Show error toast
|
||||
toastLiveExample.classList.remove('text-bg-success');
|
||||
toastLiveExample.classList.add('text-bg-danger');
|
||||
toastBody.innerHTML = `
|
||||
<strong>Request Failed!</strong><br>
|
||||
Error: ${error}<br>
|
||||
Sonde ID: ${id}
|
||||
`;
|
||||
const toastBootstrap = bootstrap.Toast.getOrCreateInstance(toastLiveExample);
|
||||
toastBootstrap.show();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function updateSondePort(id, port) {
|
||||
console.log(`Updating sonde ${id} port to: ${port}`);
|
||||
const toastLiveExample = document.getElementById('liveToast');
|
||||
const toastBody = toastLiveExample.querySelector('.toast-body');
|
||||
|
||||
$.ajax({
|
||||
url: `launcher.php?type=update_sonde&id=${id}&field=port&value=${encodeURIComponent(port)}`,
|
||||
dataType: 'json',
|
||||
method: 'GET',
|
||||
cache: false,
|
||||
success: function(response) {
|
||||
console.log('Sonde port updated:', response);
|
||||
|
||||
// Format the response for toast
|
||||
let formattedMessage = '';
|
||||
|
||||
if (response.success) {
|
||||
// Success message
|
||||
toastLiveExample.classList.remove('text-bg-danger');
|
||||
toastLiveExample.classList.add('text-bg-success');
|
||||
|
||||
formattedMessage = `
|
||||
<strong>Success!</strong><br>
|
||||
Sonde ID: ${response.id}<br>
|
||||
Port: ${port}<br>
|
||||
${response.message || ''}
|
||||
`;
|
||||
} else {
|
||||
// Error message
|
||||
toastLiveExample.classList.remove('text-bg-success');
|
||||
toastLiveExample.classList.add('text-bg-danger');
|
||||
|
||||
formattedMessage = `
|
||||
<strong>Error!</strong><br>
|
||||
${response.error || 'Unknown error'}<br>
|
||||
Sonde ID: ${id}
|
||||
`;
|
||||
}
|
||||
|
||||
// Update and show toast
|
||||
toastBody.innerHTML = formattedMessage;
|
||||
const toastBootstrap = bootstrap.Toast.getOrCreateInstance(toastLiveExample);
|
||||
toastBootstrap.show();
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
console.error('Failed to update sonde port:', error);
|
||||
|
||||
// Show error toast
|
||||
toastLiveExample.classList.remove('text-bg-success');
|
||||
toastLiveExample.classList.add('text-bg-danger');
|
||||
toastBody.innerHTML = `
|
||||
<strong>Request Failed!</strong><br>
|
||||
Error: ${error}<br>
|
||||
Sonde ID: ${id}
|
||||
`;
|
||||
const toastBootstrap = bootstrap.Toast.getOrCreateInstance(toastLiveExample);
|
||||
toastBootstrap.show();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function updateSondeCoefficient(id, coefficient) {
|
||||
console.log(`Updating sonde ${id} coefficient to: ${coefficient}`);
|
||||
const toastLiveExample = document.getElementById('liveToast');
|
||||
const toastBody = toastLiveExample.querySelector('.toast-body');
|
||||
|
||||
$.ajax({
|
||||
url: `launcher.php?type=update_sonde&id=${id}&field=coefficient&value=${coefficient}`,
|
||||
dataType: 'json',
|
||||
method: 'GET',
|
||||
cache: false,
|
||||
success: function(response) {
|
||||
console.log('Sonde coefficient updated:', response);
|
||||
|
||||
// Format the response for toast
|
||||
let formattedMessage = '';
|
||||
|
||||
if (response.success) {
|
||||
// Success message
|
||||
toastLiveExample.classList.remove('text-bg-danger');
|
||||
toastLiveExample.classList.add('text-bg-success');
|
||||
|
||||
formattedMessage = `
|
||||
<strong>Success!</strong><br>
|
||||
Sonde ID: ${response.id}<br>
|
||||
Coefficient: ${coefficient}<br>
|
||||
${response.message || ''}
|
||||
`;
|
||||
} else {
|
||||
// Error message
|
||||
toastLiveExample.classList.remove('text-bg-success');
|
||||
toastLiveExample.classList.add('text-bg-danger');
|
||||
|
||||
formattedMessage = `
|
||||
<strong>Error!</strong><br>
|
||||
${response.error || 'Unknown error'}<br>
|
||||
Sonde ID: ${id}
|
||||
`;
|
||||
}
|
||||
|
||||
// Update and show toast
|
||||
toastBody.innerHTML = formattedMessage;
|
||||
const toastBootstrap = bootstrap.Toast.getOrCreateInstance(toastLiveExample);
|
||||
toastBootstrap.show();
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
console.error('Failed to update sonde coefficient:', error);
|
||||
|
||||
// Show error toast
|
||||
toastLiveExample.classList.remove('text-bg-success');
|
||||
toastLiveExample.classList.add('text-bg-danger');
|
||||
toastBody.innerHTML = `
|
||||
<strong>Request Failed!</strong><br>
|
||||
Error: ${error}<br>
|
||||
Sonde ID: ${id}
|
||||
`;
|
||||
const toastBootstrap = bootstrap.Toast.getOrCreateInstance(toastLiveExample);
|
||||
toastBootstrap.show();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user