Fix BME280 and sensor cards not displaying
- Refactor sensor card creation to use config_table instead of non-existent config_scripts_table - Fix BME280 card check: use config.BME280 instead of response["BME280/get_data_v2.py"] - Fix NOISE card check: use config.NOISE instead of response.i2C_sound - Fix Envea card check: use config.envea instead of response["envea/read_value_v2.py"] - Create dedicated createSensorCards() function for cleaner code - Remove obsolete get_config_scripts_sqlite AJAX call Now sensor cards properly display based on config_table settings. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -273,6 +273,8 @@ function getBME280_values(){
|
|||||||
window.onload = function() {
|
window.onload = function() {
|
||||||
|
|
||||||
//NEW way to get config (SQLite)
|
//NEW way to get config (SQLite)
|
||||||
|
let mainConfig = {}; // Store main config for use in sensor card creation
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: 'launcher.php?type=get_config_sqlite',
|
url: 'launcher.php?type=get_config_sqlite',
|
||||||
dataType:'json',
|
dataType:'json',
|
||||||
@@ -282,6 +284,7 @@ $.ajax({
|
|||||||
console.log("Getting SQLite config table:");
|
console.log("Getting SQLite config table:");
|
||||||
console.log(response);
|
console.log(response);
|
||||||
|
|
||||||
|
mainConfig = response; // Store for later use
|
||||||
|
|
||||||
//device name_side bar
|
//device name_side bar
|
||||||
const elements = document.querySelectorAll('.sideBar_sensorName');
|
const elements = document.querySelectorAll('.sideBar_sensorName');
|
||||||
@@ -289,21 +292,19 @@ $.ajax({
|
|||||||
element.innerText = response.deviceName;
|
element.innerText = response.deviceName;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// After getting main config, create sensor cards
|
||||||
|
createSensorCards(mainConfig);
|
||||||
|
|
||||||
},
|
},
|
||||||
error: function(xhr, status, error) {
|
error: function(xhr, status, error) {
|
||||||
console.error('AJAX request failed:', status, error);
|
console.error('AJAX request failed:', status, error);
|
||||||
}
|
}
|
||||||
});//end AJAX
|
});//end AJAX
|
||||||
|
|
||||||
//getting config_scripts table
|
//Function to create sensor cards based on config
|
||||||
$.ajax({
|
function createSensorCards(config) {
|
||||||
url: 'launcher.php?type=get_config_scripts_sqlite',
|
console.log("Creating sensor cards with config:");
|
||||||
dataType:'json',
|
console.log(config);
|
||||||
//dataType: 'json', // Specify that you expect a JSON response
|
|
||||||
method: 'GET', // Use GET or POST depending on your needs
|
|
||||||
success: function(response) {
|
|
||||||
console.log("Getting SQLite config scripts table:");
|
|
||||||
console.log(response);
|
|
||||||
|
|
||||||
const container = document.getElementById('card-container'); // Conteneur des cartes
|
const container = document.getElementById('card-container'); // Conteneur des cartes
|
||||||
|
|
||||||
@@ -332,7 +333,7 @@ error: function(xhr, status, error) {
|
|||||||
|
|
||||||
|
|
||||||
//creates i2c BME280 card
|
//creates i2c BME280 card
|
||||||
if (response["BME280/get_data_v2.py"]) {
|
if (config.BME280) {
|
||||||
const i2C_BME_HTML = `
|
const i2C_BME_HTML = `
|
||||||
<div class="col-sm-3">
|
<div class="col-sm-3">
|
||||||
<div class="card">
|
<div class="card">
|
||||||
@@ -356,7 +357,7 @@ error: function(xhr, status, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//creates i2c sound card
|
//creates i2c sound card
|
||||||
if (response.i2C_sound) {
|
if (config.NOISE) {
|
||||||
const i2C_HTML = `
|
const i2C_HTML = `
|
||||||
<div class="col-sm-3">
|
<div class="col-sm-3">
|
||||||
<div class="card">
|
<div class="card">
|
||||||
@@ -383,7 +384,7 @@ error: function(xhr, status, error) {
|
|||||||
|
|
||||||
//Si on a des SONDES ENVEA connectée il faut faire un deuxième call dans la table envea_sondes_table
|
//Si on a des SONDES ENVEA connectée il faut faire un deuxième call dans la table envea_sondes_table
|
||||||
//creates ENVEA cards
|
//creates ENVEA cards
|
||||||
if (response["envea/read_value_v2.py"]) {
|
if (config.envea) {
|
||||||
console.log("Need to display ENVEA sondes");
|
console.log("Need to display ENVEA sondes");
|
||||||
//getting config_scripts table
|
//getting config_scripts table
|
||||||
$.ajax({
|
$.ajax({
|
||||||
@@ -429,14 +430,9 @@ error: function(xhr, status, error) {
|
|||||||
});//end AJAX envea Sondes
|
});//end AJAX envea Sondes
|
||||||
|
|
||||||
|
|
||||||
}//end if
|
}//end if envea
|
||||||
|
|
||||||
|
} // end createSensorCards function
|
||||||
},
|
|
||||||
error: function(xhr, status, error) {
|
|
||||||
console.error('AJAX request failed:', status, error);
|
|
||||||
}
|
|
||||||
});//end AJAX (config_scripts)
|
|
||||||
|
|
||||||
//get local RTC
|
//get local RTC
|
||||||
$.ajax({
|
$.ajax({
|
||||||
|
|||||||
Reference in New Issue
Block a user