]> git.giorgioravera.it Git - network-manager.git/commitdiff
Moved filterData & clearSearch to common.js
authorGiorgio Ravera <giorgio.ravera@gmail.com>
Tue, 26 May 2026 19:33:07 +0000 (21:33 +0200)
committerGiorgio Ravera <giorgio.ravera@gmail.com>
Tue, 26 May 2026 19:33:07 +0000 (21:33 +0200)
frontend/js/aliases.js
frontend/js/api.js
frontend/js/common.js
frontend/js/devices.js
frontend/js/hosts.js
frontend/js/leases.js
frontend/modals.html

index b0c657e7801567614e0bb1c675c3b9c68947d2dd..44852582c3103c94b4ad5b0f615d8d827ff618dd 100644 (file)
@@ -1,5 +1,5 @@
 // Import common js
-import { loadModals, showToast, sortTable, initSortableTable, resetSorting } from './common.js';
+import { loadModals, showToast, sortTable, initSortableTable, resetSorting, filterData, clearSearch } from './common.js';
 import { reloadDNS, reloadDHCP } from './services.js';
 import { apiMap, fetchData } from './api.js';
 
@@ -500,32 +500,6 @@ async function handleDeleteAlias(e, el) {
     return false;
 }
 
-// -----------------------------
-// filter aliases in the table
-// -----------------------------
-function filterAliases() {
-    const query = document.getElementById("searchInput").value.toLowerCase();
-    const rows = document.querySelectorAll("#dataTable tbody tr");
-
-    rows.forEach(row => {
-        const text = row.textContent.toLowerCase();
-        row.style.display = text.includes(query) ? "" : "none";
-    });
-}
-
-// -----------------------------
-// Clear search on ESC key
-// -----------------------------
-async function clearSearch() {
-    const input = document.getElementById("searchInput");
-    if (input) {
-        input.value = "";
-        input.blur();
-    }
-    viewAliases = [...allAliases];
-    await loadAliases(false);
-}
-
 // -----------------------------
 // Action Handlers
 // -----------------------------
@@ -617,7 +591,7 @@ function initSearch() {
     // clean input on load
     input.value = "";
     // live filter for each keystroke
-    input.addEventListener("input", filterAliases);
+    input.addEventListener("input", filterData);
     // Escape management when focus is in the input
     input.addEventListener("keydown", (e) => {
         if (e.key === "Escape") {
@@ -625,7 +599,9 @@ function initSearch() {
             e.stopPropagation();      // evita che arrivi al listener globale
             resetSorting(sortState);
             clearSearch();            // svuota input e ricarica tabella (come definito nella tua funzione)
-            filterAliases('');        // ripristina tabella
+            viewAliases = [...allAliases];
+            loadAliases(false);
+            filterData('');           // ripristina tabella'');
         }
     });
 }
@@ -732,7 +708,9 @@ function handleKeyboard(e) {
         e.preventDefault();       // evita side-effect (es. chiusure di modali del browser)
         resetSorting(sortState);
         clearSearch();            // svuota input e ricarica tabella (come definito nella tua funzione)
-        filterAliases('');        // ripristina tabella
+        viewAliases = [...allAliases];
+        loadAliases(false);
+        filterData('');           // ripristina tabella'');
     }
 
     // Button event delegation (Enter, Space)
index 0b6c4d2adcaf7c28513b15d119404467ba64fdd3..b23156766935627028a33b2d78328f4dd2e45bed 100644 (file)
@@ -57,4 +57,4 @@ export async function fetchData(api) {
         throw err;
     }
     return items;
-}
\ No newline at end of file
+}
index fad618b86d2560aabb6ca90641da93cba74e5b38..ae2f0bf9d58425981296028af2261b9298f7bdaf 100644 (file)
@@ -320,7 +320,7 @@ export function resetSorting(state, tableId = 'dataTable') {
 }
 
 /**
- * Opzionale: inizializza aria-sort='none'
+  * Optional: set aria-sort='none' on all headers on page load for better accessibility.
  */
 export function initSortableTable() {
     const table = document.getElementById("dataTable");
@@ -328,3 +328,27 @@ export function initSortableTable() {
     const ths = table.querySelectorAll("thead th");
     ths.forEach(th => th.setAttribute("aria-sort", "none"));
 }
+
+/**
+  * Live filter: mostra solo le righe che contengono il testo di ricerca (case-insensitive)
+ */
+export function filterData() {
+    const query = document.getElementById("searchInput").value.toLowerCase();
+    const rows = document.querySelectorAll("#dataTable tbody tr");
+
+    rows.forEach(row => {
+        const text = row.textContent.toLowerCase();
+        row.style.display = text.includes(query) ? "" : "none";
+    });
+}
+
+/**
+ * Clear search input and reset table filter
+ */
+export function clearSearch() {
+    const input = document.getElementById("searchInput");
+    if (input) {
+        input.value = "";
+        input.blur();
+    }
+}
index 78db81f0a6572e8c383455aaf128f16e39ecce4d..72c5a1f7fac610cbafd579a87e8fbad37413f116 100644 (file)
@@ -1,5 +1,5 @@
 // Import common js
-import { loadModals, isValidIPv4, isValidIPv6, isValidMAC, showToast, sortTable, initSortableTable, resetSorting } from './common.js';
+import { loadModals, isValidIPv4, isValidIPv6, isValidMAC, showToast, sortTable, initSortableTable, resetSorting, filterData, clearSearch } from './common.js';
 import { reloadDNS, reloadDHCP } from './services.js';
 import { apiMap, fetchData } from './api.js';
 
@@ -617,32 +617,6 @@ async function handleDeleteDevice(e, el) {
     return false;
 }
 
-// -----------------------------
-// filter devices in the table
-// -----------------------------
-function filterDevices() {
-    const query = document.getElementById("searchInput").value.toLowerCase();
-    const rows = document.querySelectorAll("#dataTable tbody tr");
-
-    rows.forEach(row => {
-        const text = row.textContent.toLowerCase();
-        row.style.display = text.includes(query) ? "" : "none";
-    });
-}
-
-// -----------------------------
-// Clear search on ESC key
-// -----------------------------
-async function clearSearch() {
-    const input = document.getElementById("searchInput");
-    if (input) {
-        input.value = "";
-        input.blur();
-    }
-    viewDevices = [...allDevices];
-    await loadDevices(false);
-}
-
 // -----------------------------
 // Action Handlers
 // -----------------------------
@@ -734,7 +708,7 @@ function initSearch() {
     // clean input on load
     input.value = "";
     // live filter for each keystroke
-    input.addEventListener("input", filterDevices);
+    input.addEventListener("input", filterData);
     // Escape management when focus is in the input
     input.addEventListener("keydown", (e) => {
         if (e.key === "Escape") {
@@ -742,7 +716,9 @@ function initSearch() {
             e.stopPropagation();      // evita che arrivi al listener globale
             resetSorting(sortState);
             clearSearch();            // svuota input e ricarica tabella (come definito nella tua funzione)
-            filterDevices('');        // ripristina tabella
+            viewDevices = [...allDevices];
+            loadDevices(false);
+            filterData('');           // ripristina tabella'');
         }
     });
 }
@@ -849,7 +825,9 @@ function handleKeyboard(e) {
         e.preventDefault();       // evita side-effect (es. chiusure di modali del browser)
         resetSorting(sortState);
         clearSearch();            // svuota input e ricarica tabella (come definito nella tua funzione)
-        filterDevices('');        // ripristina tabella
+        viewDevices = [...allDevices];
+        loadDevices(false);
+        filterData('');           // ripristina tabella'');
     }
 
     // Button event delegation (Enter, Space)
index 2efdd77d958c6fd19c608f1e27e06cbbdb517d34..408c0d3de195131cad769aa0e05e8f61395d15c0 100644 (file)
@@ -1,5 +1,5 @@
 // Import common js
-import { loadModals, isValidIPv4, isValidIPv6, isValidMAC, showToast, sortTable, initSortableTable, resetSorting } from './common.js';
+import { loadModals, isValidIPv4, isValidIPv6, isValidMAC, showToast, sortTable, initSortableTable, resetSorting, filterData, clearSearch } from './common.js';
 import { reloadDNS, reloadDHCP } from './services.js';
 import { apiMap, fetchData } from './api.js';
 
@@ -524,32 +524,6 @@ async function handleDeleteHost(e, el) {
     return false;
 }
 
-// -----------------------------
-// filter hosts in the table
-// -----------------------------
-function filterHosts() {
-    const query = document.getElementById("searchInput").value.toLowerCase();
-    const rows = document.querySelectorAll("#dataTable tbody tr");
-
-    rows.forEach(row => {
-        const text = row.textContent.toLowerCase();
-        row.style.display = text.includes(query) ? "" : "none";
-    });
-}
-
-// -----------------------------
-// Clear search on ESC key
-// -----------------------------
-async function clearSearch() {
-    const input = document.getElementById("searchInput");
-    if (input) {
-        input.value = "";
-        input.blur();
-    }
-    viewHosts = [...allHosts];
-    await loadHosts(false);
-}
-
 // -----------------------------
 // Action Handlers
 // -----------------------------
@@ -641,7 +615,7 @@ function initSearch() {
     // clean input on load
     input.value = "";
     // live filter for each keystroke
-    input.addEventListener("input", filterHosts);
+    input.addEventListener("input", filterData);
     // Escape management when focus is in the input
     input.addEventListener("keydown", (e) => {
         if (e.key === "Escape") {
@@ -649,7 +623,9 @@ function initSearch() {
             e.stopPropagation();      // evita che arrivi al listener globale
             resetSorting(sortState);
             clearSearch();            // svuota input e ricarica tabella (come definito nella tua funzione)
-            filterHosts('');          // ripristina tabella
+            viewHosts = [...allHosts];
+            loadHosts(false);
+            filterData('');           // ripristina tabella
         }
     });
 }
@@ -756,7 +732,9 @@ function handleKeyboard(e) {
         e.preventDefault();       // evita side-effect (es. chiusure di modali del browser)
         resetSorting(sortState);
         clearSearch();            // svuota input e ricarica tabella (come definito nella tua funzione)
-        filterHosts('');          // ripristina tabella
+        viewHosts = [...allHosts];
+        loadHosts(false);
+        filterData('');           // ripristina tabella
     }
 
     // Button event delegation (Enter, Space)
index dd2db98f3b8165990aba9d1ce92e9d0ecb14f7e5..0056a38e304b1a0948f9a1261000aa19f0ab3c09 100644 (file)
@@ -1,5 +1,5 @@
 // Import common js
-import { loadModals, isValidIPv4, isValidIPv6, isValidMAC, showToast, sortTable, initSortableTable, resetSorting } from './common.js';
+import { loadModals, isValidIPv4, isValidIPv6, isValidMAC, showToast, sortTable, initSortableTable, resetSorting, filterData, clearSearch } from './common.js';
 import { reloadDNS, reloadDHCP } from './services.js';
 import { apiMap, fetchData } from './api.js';
 
@@ -488,32 +488,6 @@ async function handleDeleteLease(e, el) {
     return false;
 }
 
-// -----------------------------
-// filter dhcp leases in the table
-// -----------------------------
-function filterLeases() {
-    const query = document.getElementById("searchInput").value.toLowerCase();
-    const rows = document.querySelectorAll("#dataTable tbody tr");
-
-    rows.forEach(row => {
-        const text = row.textContent.toLowerCase();
-        row.style.display = text.includes(query) ? "" : "none";
-    });
-}
-
-// -----------------------------
-// Clear search on ESC key
-// -----------------------------
-async function clearSearch() {
-    const input = document.getElementById("searchInput");
-    if (input) {
-        input.value = "";
-        input.blur();
-    }
-    viewLeases = [...allLeases];
-    await loadLeases(false);
-}
-
 // -----------------------------
 // Action Handlers
 // -----------------------------
@@ -605,7 +579,7 @@ function initSearch() {
     // clean input on load
     input.value = "";
     // live filter for each keystroke
-    input.addEventListener("input", filterLeases);
+    input.addEventListener("input", filterData);
     // Escape management when focus is in the input
     input.addEventListener("keydown", (e) => {
         if (e.key === "Escape") {
@@ -613,7 +587,9 @@ function initSearch() {
             e.stopPropagation();      // evita che arrivi al listener globale
             resetSorting(sortState);
             clearSearch();            // svuota input e ricarica tabella (come definito nella tua funzione)
-            filterLeases('');         // ripristina tabella
+            viewLeases = [...allLeases];
+            loadLeases(false);
+            filterData('');           // ripristina tabella'');
         }
     });
 }
@@ -712,7 +688,9 @@ function handleKeyboard(e) {
         e.preventDefault();       // evita side-effect (es. chiusure di modali del browser)
         resetSorting(sortState);
         clearSearch();            // svuota input e ricarica tabella (come definito nella tua funzione)
-        filterLeases('');         // ripristina tabella
+        viewLeases = [...allLeases];
+        loadLeases(false);
+        filterData('');           // ripristina tabella'');
     }
 
     // Button event delegation (Enter, Space)
index 3d4cf7036c235778b478e0d0ebb4d75663e3f86d..adcd026a4b6a5859b357928a5ec1604d697fa40c 100644 (file)
             </div>
         </div>
     </div>
-</div>
\ No newline at end of file
+</div>