Device list rework v0.4 🔨

This commit is contained in:
Jokob-sk
2023-10-13 22:16:31 +11:00
parent f3b64748aa
commit 3e3e8fa797
2 changed files with 42 additions and 25 deletions

View File

@@ -330,8 +330,35 @@ function filterDataByStatus(data, status) {
} }
}); });
} }
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
function getDeviceStatus(item)
{
if(item.dev_PresentLastScan === 1)
{
return 'On-line';
}
else if(item.dev_PresentLastScan === 0 && item.dev_AlertDeviceDown === 1)
{
return 'Down';
}
else if(item.dev_NewDevice === 1)
{
return 'New';
}
else if(item.dev_Archived === 1)
{
return 'Archived';
}
else if(item.dev_PresentLastScan === 0)
{
return 'Off-line';
}
return "Unknown status"
}
// -----------------------------------------------------------------------------
function initializeDatatable (status) { function initializeDatatable (status) {
// Save status selected // Save status selected
@@ -354,7 +381,6 @@ function initializeDatatable (status) {
$('#tableDevicesTitle').html (tableTitle); $('#tableDevicesTitle').html (tableTitle);
for(i = 0; i < tableColumnOrder.length; i++) for(i = 0; i < tableColumnOrder.length; i++)
{ {
// hide this column if not in the tableColumnVisible variable (we need to keep the MAC address (index 11) for functionality reasons) // hide this column if not in the tableColumnVisible variable (we need to keep the MAC address (index 11) for functionality reasons)
@@ -364,14 +390,6 @@ function initializeDatatable (status) {
} }
} }
console.log("tableColumnOrder")
console.log(tableColumnOrder)
console.log("tableColumnVisible")
console.log(tableColumnVisible)
console.log("tableColumnHide")
console.log(tableColumnHide)
console.log(headersDefaultOrder)
$.get('api/table_devices.json', function(result) { $.get('api/table_devices.json', function(result) {
// Filter the data based on deviceStatus // Filter the data based on deviceStatus
@@ -380,7 +398,7 @@ function initializeDatatable (status) {
// Convert JSON data into the desired format // Convert JSON data into the desired format
var dataArray = { var dataArray = {
data: filteredData.map(function(item) { data: filteredData.map(function(item) {
return [ var originalRow = [
item.dev_Name || "", item.dev_Name || "",
item.dev_Owner || "", item.dev_Owner || "",
item.dev_DeviceType || "", item.dev_DeviceType || "",
@@ -392,7 +410,7 @@ function initializeDatatable (status) {
item.dev_LastConnection || "", item.dev_LastConnection || "",
item.dev_LastIP || "", item.dev_LastIP || "",
item.dev_MAC || "", // TODO handle internet node mac item.dev_MAC || "", // TODO handle internet node mac
"status", getDeviceStatus(item) || "",
item.dev_MAC || "", // hidden item.dev_MAC || "", // hidden
item.dev_LastIP || "", // IP orderable item.dev_LastIP || "", // IP orderable
item.rowid || "", item.rowid || "",
@@ -401,14 +419,19 @@ function initializeDatatable (status) {
item.dev_Location || "", item.dev_Location || "",
item.dev_Vendor || "", item.dev_Vendor || "",
item.dev_Network_Node_port || 0 item.dev_Network_Node_port || 0
].map(function(value, oldIndex, arr) { ]
const newIndex = mapIndx(oldIndex); // Get the new index for this column
return arr[newIndex]; // Reorder the values based on the new index var newRow = []
});
// reorder data based on user-definer columns order
for(index = 0; index < tableColumnOrder.length; index++)
{
newRow.push(originalRow[tableColumnOrder[index]]);
}
return newRow;
}) })
}; };
console.log(dataArray["data"])
// TODO displayed columns // TODO displayed columns
@@ -527,7 +550,7 @@ function initializeDatatable (status) {
default: color='aqua'; break; default: color='aqua'; break;
}; };
// $(td).html ('<a href="deviceDetails.php?mac='+ rowData[mapIndx(11)] +'" class="badge bg-'+ color +'">'+ cellData.replace('-', '') +'</a>'); $(td).html ('<a href="deviceDetails.php?mac='+ rowData[mapIndx(11)] +'" class="badge bg-'+ color +'">'+ cellData.replace('-', '') +'</a>');
} }, } },
], ],

View File

@@ -19,15 +19,9 @@ vendorsPath9 = '/usr/share/arp-scan/ieee-iab.txt'
#=============================================================================== #===============================================================================
# SQL queries # SQL queries
#=============================================================================== #===============================================================================
# sql_devices_all = """select dev_MAC, dev_Name, dev_DeviceType, dev_Vendor, dev_Group,
# dev_FirstConnection, dev_LastConnection, dev_LastIP, dev_StaticIP,
# dev_PresentLastScan, dev_LastNotification, dev_NewDevice,
# dev_Network_Node_MAC_ADDR, dev_Network_Node_port,
# dev_Icon from Devices"""
sql_devices_all = """select rowid, * from Devices""" sql_devices_all = """select rowid, * from Devices"""
sql_devices_stats = """SELECT Online_Devices as online, Down_Devices as down, All_Devices as 'all', Archived_Devices as archived, sql_devices_stats = """SELECT Online_Devices as online, Down_Devices as down, All_Devices as 'all', Archived_Devices as archived,
(select count(*) from Devices a where dev_NewDevice = 1 ) as new, (select count(*) from Devices a where dev_NewDevice = 1 ) as new,