update
This commit is contained in:
@@ -57,12 +57,9 @@
|
||||
<div class="col-sm-4">
|
||||
<div class="card text-dark bg-light">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">Consulter Base de donnée</h5>
|
||||
<p class="card-text">General information.</p>
|
||||
<button class="btn btn-primary" onclick="get_internet()">Get Data</button>
|
||||
<table class="table table-striped-columns">
|
||||
<tbody id="data-table-body_internet_general"></tbody>
|
||||
</table>
|
||||
<h5 class="card-title">Consulter la base de donnée</h5>
|
||||
<button class="btn btn-primary" onclick="get_data_sqlite('data_NPM',10,false)">Mesures PM</button>
|
||||
<button class="btn btn-primary" onclick="get_data_sqlite('data_BME280',10,false)">Mesures Temp/Hum</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -71,19 +68,19 @@
|
||||
<div class="card text-dark bg-light">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">Télécharger les données</h5>
|
||||
<p class="card-text">Scan des réseaux WIFI disponibles.</p>
|
||||
<button class="btn btn-primary" onclick="wifi_scan()">Download</button>
|
||||
<table class="table">
|
||||
<tbody id="data-table-body_wifi_scan"></tbody>
|
||||
</table>
|
||||
<button class="btn btn-primary" onclick="get_data_sqlite('data_NPM',10,true)">Mesures PM</button>
|
||||
<button class="btn btn-primary" onclick="get_data_sqlite('data_BME280',10,true)">Mesures Temp/Hum</button>
|
||||
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<div>
|
||||
|
||||
<div class="row mt-2">
|
||||
<div id="table_data"></div>
|
||||
</div>
|
||||
|
||||
</main>
|
||||
</div>
|
||||
@@ -164,11 +161,125 @@
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
})
|
||||
.catch(error => console.error('Error loading config.json:', error));
|
||||
}
|
||||
|
||||
|
||||
|
||||
// TABLE PM
|
||||
function get_data_sqlite(table, limit, download) {
|
||||
console.log("Getting data for table mesure PM");
|
||||
|
||||
$.ajax({
|
||||
url: 'launcher.php?type=table_mesurePM&table='+table+'&limit='+limit+'&download='+download,
|
||||
dataType: 'text', // Specify that you expect a JSON response
|
||||
method: 'GET', // Use GET or POST depending on your needs
|
||||
success: function(response) {
|
||||
console.log(response);
|
||||
|
||||
// If download is true, generate and trigger CSV download
|
||||
if (download) {
|
||||
downloadCSV(response, table);
|
||||
return; // Exit function after triggering download
|
||||
}
|
||||
|
||||
let rows = response.trim().split("\n");
|
||||
// Generate Bootstrap table
|
||||
|
||||
let tableHTML = `<table class="table table-striped table-bordered">
|
||||
<thead class="table-dark"><tr>`;
|
||||
|
||||
// Define column headers dynamically based on the table type
|
||||
if (table === "data_NPM") {
|
||||
tableHTML += `
|
||||
<th>Timestamp</th>
|
||||
<th>PM1</th>
|
||||
<th>PM2.5</th>
|
||||
<th>PM10</th>
|
||||
<th>Temperature (°C)</th>
|
||||
<th>Humidity (%)</th>
|
||||
`;
|
||||
} else if (table === "data_BME280") {
|
||||
tableHTML += `
|
||||
<th>Timestamp</th>
|
||||
<th>Temperature (°C)</th>
|
||||
<th>Humidity (%)</th>
|
||||
<th>Pressure (hPa)</th>
|
||||
`;
|
||||
}
|
||||
|
||||
tableHTML += `</tr></thead><tbody>`;
|
||||
|
||||
// Loop through rows and create table rows
|
||||
rows.forEach(row => {
|
||||
let columns = row.replace(/[()]/g, "").split(", "); // Remove parentheses and split
|
||||
tableHTML += "<tr>";
|
||||
|
||||
if (table === "data_NPM") {
|
||||
tableHTML += `
|
||||
<td>${columns[0]}</td>
|
||||
<td>${columns[1]}</td>
|
||||
<td>${columns[2]}</td>
|
||||
<td>${columns[3]}</td>
|
||||
<td>${columns[4]}</td>
|
||||
<td>${columns[5]}</td>
|
||||
`;
|
||||
} else if (table === "data_BME280") {
|
||||
tableHTML += `
|
||||
<td>${columns[0]}</td>
|
||||
<td>${columns[1]}</td>
|
||||
<td>${columns[2]}</td>
|
||||
<td>${columns[3]}</td>
|
||||
`;
|
||||
}
|
||||
|
||||
tableHTML += "</tr>";
|
||||
});
|
||||
|
||||
tableHTML += `</tbody></table>`;
|
||||
|
||||
// Update the #table_data div with the generated table
|
||||
document.getElementById("table_data").innerHTML = tableHTML;
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
console.error('AJAX request failed:', status, error);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
function downloadCSV(response, table) {
|
||||
let rows = response.trim().split("\n");
|
||||
|
||||
let csvContent = "";
|
||||
|
||||
// Add headers based on table type
|
||||
if (table === "data_NPM") {
|
||||
csvContent += "Timestamp,PM1,PM2.5,PM10,Temperature (°C),Humidity (%)\n";
|
||||
} else if (table === "data_BME280") {
|
||||
csvContent += "Timestamp,Temperature (°C),Humidity (%),Pressure (hPa)\n";
|
||||
}
|
||||
|
||||
// Format rows as CSV
|
||||
rows.forEach(row => {
|
||||
let columns = row.replace(/[()]/g, "").split(", ");
|
||||
csvContent += columns.join(",") + "\n";
|
||||
});
|
||||
|
||||
// Create a downloadable file
|
||||
let blob = new Blob([csvContent], { type: "text/csv" });
|
||||
let url = window.URL.createObjectURL(blob);
|
||||
let a = document.createElement("a");
|
||||
a.href = url;
|
||||
a.download = table + "_data.csv"; // File name
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
document.body.removeChild(a);
|
||||
}
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
</body>
|
||||
|
||||
Reference in New Issue
Block a user