cache fix on details page, small css fixes

This commit is contained in:
jokob-sk
2025-07-29 20:01:50 +10:00
parent 4b4b2f914f
commit a84f0d4faf
17 changed files with 70 additions and 36 deletions

View File

@@ -225,13 +225,6 @@ switch ($UI_THEME) {
var selectedTab = 'tabDetails';
var emptyArr = ['undefined', "", undefined, null];
// Call renderSmallBoxes, then main
(async () => {
await renderSmallBoxes();
main();
})();
// -----------------------------------------------------------------------------
function main () {
@@ -299,17 +292,32 @@ function recordSwitch(direction) {
function updateChevrons(currentMac) {
const devicesList = getDevicesList();
// Find the index of the device by MAC
pos = devicesList.findIndex(item => item.devMac == currentMac);
pos = devicesList.findIndex(item => item.devMac === currentMac);
// If device not found, optionally add it or handle error
if (pos === -1) {
// If you want to add a placeholder or handle missing device:
// devicesList.push({ mac: currentMac, name: 'Unknown', type: 'Unknown' });
// pos = devicesList.length - 1;
console.warn('Device not found in cache. Re-caching devices...', currentMac);
showSpinner();
cacheDevices().then(() => {
hideSpinner();
// Retry after re-caching
const refreshedList = getDevicesList();
pos = refreshedList.findIndex(item => item.devMac === currentMac);
if (pos === -1) {
console.error('Still not found after re-cache:', currentMac);
return;
}
console.log('Device found after re-cache:', refreshedList[pos]);
// Proceed with using `refreshedList[pos]`
}).catch((err) => {
hideSpinner();
console.error('Failed to cache devices:', err);
});
// Or just return early if device not found
console.warn('Device with MAC not found:', currentMac);
return;
}
@@ -345,7 +353,7 @@ function performSwitch(direction)
// Update the global position in the devices list variable 'pos'
if (direction === "next") {
console.log("direction" + direction);
console.log("direction:" + direction);
if (pos < devicesList.length) {
pos++;
@@ -485,34 +493,58 @@ async function renderSmallBoxes() {
}
function updateDevicePageName(mac) {
let name = getDevDataByMac(mac, "devName");
let owner = getDevDataByMac(mac, "devOwner");
name = getDevDataByMac(mac, "devName")
owner = getDevDataByMac(mac, "devOwner")
// If data is missing, re-cache and retry once
if (name === "Unknown" || owner === "Unknown") {
console.warn("Device not found in cache, retrying after re-cache:", mac);
showSpinner();
cacheDevices().then(() => {
hideSpinner();
// Retry after successful cache
updateDevicePageName(mac);
}).catch((err) => {
hideSpinner();
console.error("Failed to refresh devices:", err);
});
return; // Exit early to avoid showing bad data
}
// Page title - Name
if (mac == "new") {
$('#pageTitle').html(`<i title="${getString("Gen_create_new_device")}" class="fa fa-square-plus"></i> ` + getString("Gen_create_new_device"));
$('#devicePageInfoPlc .inner').html(`<i class="fa fa-circle-info"></i> ` + getString("Gen_create_new_device_info"));
$('#devicePageInfoPlc').show();
} else if (owner == null || owner == '' ||
(name.toString()).indexOf(owner) != -1) {
$('#pageTitle').html(name);
$('#devicePageInfoPlc').hide();
$('#pageTitle').html(
`<i title="${getString("Gen_create_new_device")}" class="fa fa-square-plus"></i> ` + getString("Gen_create_new_device")
);
$('#devicePageInfoPlc .inner').html(
`<i class="fa fa-circle-info"></i> ` + getString("Gen_create_new_device_info")
);
$('#devicePageInfoPlc').show();
} else if (!owner || (name.toString()).indexOf(owner) !== -1) {
$('#pageTitle').html(name);
$('#devicePageInfoPlc').hide();
} else {
$('#pageTitle').html(name + ' (' + owner + ')');
$('#devicePageInfoPlc').hide();
$('#pageTitle').html(name + ' (' + owner + ')');
$('#devicePageInfoPlc').hide();
}
}
//-----------------------------------------------------------------------------------
// Call renderSmallBoxes, then main
(async () => {
await renderSmallBoxes();
main();
})();
window.onload = function async()
{
initializeTabs();
updateChevrons(mac);
updateDevicePageName(mac);
}
</script>