From ed983279d5c9ac8966b18f0e909c2a92b750ce27 Mon Sep 17 00:00:00 2001 From: jokob-sk Date: Sat, 13 Apr 2024 12:58:10 +1000 Subject: [PATCH] Filter applied on <> arrows #627 --- front/deviceDetails.php | 20 ++++++++++++++++++++ front/devices.php | 38 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 56 insertions(+), 2 deletions(-) diff --git a/front/deviceDetails.php b/front/deviceDetails.php index 6a8bfb83..2d1af76d 100755 --- a/front/deviceDetails.php +++ b/front/deviceDetails.php @@ -654,6 +654,26 @@ if ($ENABLED_DARKMODE === True) { devicesList = []; } + // only loop thru the filtered down list + visibleDevices = getCache("ntx_visible_macs") + + if(visibleDevices != "") { + visibleDevicesMACs = visibleDevices.split(','); + + devicesList_tmp = []; + + // Iterate through the data and filter only visible devices + $.each(devicesList, function(index, item) { + // Check if the current item's MAC exists in visibleDevicesMACs + if (visibleDevicesMACs.includes(item.dev_MAC)) { + devicesList_tmp.push(item); + } + }); + + // Update devicesList with the filtered items + devicesList = devicesList_tmp; + } + return devicesList; } diff --git a/front/devices.php b/front/devices.php index 36f7ed72..29685d4e 100755 --- a/front/devices.php +++ b/front/devices.php @@ -795,7 +795,7 @@ function multiEditDevices() // Initialize an empty array to store selected rows var selectedRows = []; - console.log($('#tableDevices')[0].rows); + // console.log($('#tableDevices')[0].rows); // Loop through each row in the HTML collection for (var i = 0; i < rows.length; i++) { @@ -819,7 +819,7 @@ function multiEditDevices() } // Now, selectedDevices contains all selected devices - console.log(selectedDevices); + // console.log(selectedDevices); macs = "" @@ -831,5 +831,39 @@ function multiEditDevices() window.location.href = window.location.origin + '/maintenance.php#tab_multiEdit?macs=' + macs.slice(0, -1); } + +// ----------------------------------------------------------------------------- +// Function collects shown devices from the DataTable +function getMacsOfShownDevices() { + + rows = $('#tableDevices')[0].rows + macs = [] + + var devicesDataTableData = $('#tableDevices').dataTable().fnGetData(); + + var selectedDevices = []; + + for (var i = 0; i < rows.length; i++) { + selectedDevices.push(devicesDataTableData[rows[i]._DT_RowIndex]); + } + + for (var i = 1; i < selectedDevices.length; i++) { + macs.push(selectedDevices[i][mapIndx(11)]); // mapIndx(11) == MAC + } + + return macs; + +} + +// ----------------------------------------------------------------------------- +// Update cahce with shown devices before navigating away +window.addEventListener('beforeunload', function(event) { + // Call your function here + macs = getMacsOfShownDevices(); + + setCache("ntx_visible_macs", macs) + +}); +