chore:Settings DB table refactor

This commit is contained in:
jokob-sk
2024-11-23 09:28:40 +11:00
parent 0e438ffd57
commit f1f40021ee
19 changed files with 201 additions and 193 deletions

View File

@@ -15,8 +15,6 @@
<?php
require 'php/templates/header.php';
require 'php/components/graph_online_history.php';
// check permissions
$dbPath = "../db/app.db";
$confPath = "../config/app.conf";
@@ -56,8 +54,10 @@
<div class="box-body">
<div class="chart">
<script src="lib/AdminLTE/bower_components/chart.js/Chart.js?v=<?php include 'php/templates/version.php'; ?>"></script>
<!-- The online history chart is rendered here -->
<canvas id="OnlineChart" style="width:100%; height: 150px; margin-bottom: 15px;"></canvas>
<!-- presence chart -->
<?php
require 'php/components/graph_online_history.php';
?>
</div>
</div>
<!-- /.box-body -->
@@ -195,36 +195,30 @@ function mapIndx(oldIndex)
// Query total numbers of Devices by status
//------------------------------------------------------------------------------
function getDevicesTotals() {
// Check cache first
let resultJSON = getCache("getDevicesTotals");
if (resultJSON !== "") {
resultJSON = JSON.parse(resultJSON);
processDeviceTotals(resultJSON);
} else {
// Fetch data via AJAX
$.ajax({
url: "/api/table_devices_tiles.json",
type: "GET",
dataType: "json",
success: function(response) {
if (response && response.data) {
resultJSON = response.data[0]; // Assuming the structure {"data": [ ... ]}
// Save the result to cache
setCache("getDevicesTotals", JSON.stringify(resultJSON));
// Fetch data via AJAX
$.ajax({
url: '/api/table_devices_tiles.json?nocache=' + Date.now(),
type: "GET",
dataType: "json",
success: function(response) {
if (response && response.data) {
resultJSON = response.data[0]; // Assuming the structure {"data": [ ... ]}
// Save the result to cache
setCache("getDevicesTotals", JSON.stringify(resultJSON));
// Process the fetched data
processDeviceTotals(resultJSON);
} else {
console.error("Invalid response format from API");
}
},
error: function(xhr, status, error) {
console.error("Failed to fetch devices data:", error);
// Process the fetched data
processDeviceTotals(resultJSON);
} else {
console.error("Invalid response format from API");
}
});
}
},
error: function(xhr, status, error) {
console.error("Failed to fetch devices data:", error);
}
});
}
function processDeviceTotals(devicesData) {