better check for available device #1132

This commit is contained in:
jokob-sk
2025-08-11 19:52:16 +10:00
parent 1c4e6c7e38
commit e73c8e830a
4 changed files with 12 additions and 18 deletions

View File

@@ -497,7 +497,7 @@ function updateDevicePageName(mac) {
let owner = getDevDataByMac(mac, "devOwner"); let owner = getDevDataByMac(mac, "devOwner");
// If data is missing, re-cache and retry once // If data is missing, re-cache and retry once
if (mac != 'new' && (name === "Unknown" || owner === "Unknown")) { if (mac != 'new' && (name === null|| owner === null)) {
console.warn("Device not found in cache, retrying after re-cache:", mac); console.warn("Device not found in cache, retrying after re-cache:", mac);
showSpinner(); showSpinner();
cacheDevices().then(() => { cacheDevices().then(() => {

View File

@@ -609,7 +609,7 @@ function createDeviceLink(input)
{ {
if(checkMacOrInternet(input)) if(checkMacOrInternet(input))
{ {
return `<span class="anonymizeMac"><a href="/deviceDetails.php?mac=${input}" target="_blank">${getNameByMacAddress(input)}</a><span>` return `<span class="anonymizeMac"><a href="/deviceDetails.php?mac=${input}" target="_blank">${getDevDataByMac(input, "devName")}</a><span>`
} }
return input; return input;
@@ -813,7 +813,6 @@ function forceLoadUrl(relativeUrl) {
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
function navigateToDeviceWithIp (ip) { function navigateToDeviceWithIp (ip) {
@@ -836,11 +835,6 @@ function navigateToDeviceWithIp (ip) {
}); });
} }
// -----------------------------------------------------------------------------
function getNameByMacAddress(macAddress) {
return getDevDataByMac(macAddress, "devName")
}
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// Check if MAC or Internet // Check if MAC or Internet
function checkMacOrInternet(inputStr) { function checkMacOrInternet(inputStr) {
@@ -1013,7 +1007,7 @@ function getDevDataByMac(macAddress, dbColumn) {
if (!devicesCache || devicesCache == "") { if (!devicesCache || devicesCache == "") {
console.error(`Session variable "${sessionDataKey}" not found.`); console.error(`Session variable "${sessionDataKey}" not found.`);
return "Unknown"; return null;
} }
const devices = JSON.parse(devicesCache); const devices = JSON.parse(devicesCache);
@@ -1033,7 +1027,7 @@ function getDevDataByMac(macAddress, dbColumn) {
} }
console.error("⚠ Device with MAC not found:" + macAddress) console.error("⚠ Device with MAC not found:" + macAddress)
return "Unknown"; // Return a default value if MAC address is not found return null; // Return a default value if MAC address is not found
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------

View File

@@ -782,15 +782,15 @@ function initSelect2() {
// ------------------------------------------ // ------------------------------------------
// Render a device link with hover-over functionality // Render a device link with hover-over functionality
function renderDeviceLink(data, container, useName = false) { function renderDeviceLink(data, container, useName = false) {
if (!data.id || !isValidMac(data.id)) return data.text; // default placeholder etc. // If no valid MAC, return placeholder text
if (!data.id || !isValidMac(data.id)) {
return data.text;
}
const device = getDevDataByMac(data.id); const device = getDevDataByMac(data.id);
if (!device) {
const badge = getStatusBadgeParts( return data.text;
device.devPresentLastScan, }
device.devAlertDown,
device.devMac
);
// badge class and hover-info class to container // badge class and hover-info class to container
$(container) $(container)

View File

@@ -197,7 +197,7 @@
<div class="col-sm-9"> <div class="col-sm-9">
${isRootNode ? '' : `<a class="anonymize" href="#">`} ${isRootNode ? '' : `<a class="anonymize" href="#">`}
<span my-data-mac="${node.parent_mac}" data-mac="${node.parent_mac}" data-devIsNetworkNodeDynamic="1" onclick="handleNodeClick(this)"> <span my-data-mac="${node.parent_mac}" data-mac="${node.parent_mac}" data-devIsNetworkNodeDynamic="1" onclick="handleNodeClick(this)">
${isRootNode ? getString('Network_Root') : getNameByMacAddress(node.parent_mac)} ${isRootNode ? getString('Network_Root') : getDevDataByMac(node.parent_mac, "devName")}
</span> </span>
${isRootNode ? '' : `</a>`} ${isRootNode ? '' : `</a>`}
</div> </div>