From 3da1bdcad17ad68c7635715c95f101607b12319f Mon Sep 17 00:00:00 2001 From: RubenPX Date: Mon, 9 May 2022 14:40:28 +0200 Subject: [PATCH 1/5] Show selected devices notify instead page select --- ereuse_devicehub/static/js/main_inventory.js | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/ereuse_devicehub/static/js/main_inventory.js b/ereuse_devicehub/static/js/main_inventory.js index 848c72e4..3d355574 100644 --- a/ereuse_devicehub/static/js/main_inventory.js +++ b/ereuse_devicehub/static/js/main_inventory.js @@ -85,24 +85,26 @@ window.addEventListener("DOMContentLoaded", () => { function itemListCheckChanged() { const listDevices = TableController.getAllDevicesInCurrentPage() const isAllChecked = listDevices.map(itm => itm.checked); + alertInfoDevices.innerHTML = `Selected devices: ${TableController.getSelectedDevices().length} + ${TableController.getAllDevices().length != TableController.getSelectedDevices().length + ? `Select all devices (${TableController.getAllDevices().length})` + : "Cancel selection" + }`; + + if (TableController.getAllDevices().length > 0) { + alertInfoDevices.classList.remove("d-none"); + } else { + alertInfoDevices.classList.add("d-none") + } if (isAllChecked.every(bool => bool == true)) { btnSelectAll.checked = true; btnSelectAll.indeterminate = false; - alertInfoDevices.innerHTML = `Selected devices: ${TableController.getSelectedDevices().length} - ${ - TableController.getAllDevices().length != TableController.getSelectedDevices().length - ? `Select all devices (${TableController.getAllDevices().length})` - : "Cancel selection" - }`; - alertInfoDevices.classList.remove("d-none"); } else if (isAllChecked.every(bool => bool == false)) { btnSelectAll.checked = false; btnSelectAll.indeterminate = false; - alertInfoDevices.classList.add("d-none") } else { btnSelectAll.indeterminate = true; - alertInfoDevices.classList.add("d-none") } } From 881f56e3e479c630837c84773abbad10e2630243 Mon Sep 17 00:00:00 2001 From: RubenPX Date: Wed, 11 May 2022 10:42:32 +0200 Subject: [PATCH 2/5] Fix devices length comparation --- ereuse_devicehub/static/js/main_inventory.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ereuse_devicehub/static/js/main_inventory.js b/ereuse_devicehub/static/js/main_inventory.js index 3d355574..3bae4ce3 100644 --- a/ereuse_devicehub/static/js/main_inventory.js +++ b/ereuse_devicehub/static/js/main_inventory.js @@ -91,10 +91,10 @@ window.addEventListener("DOMContentLoaded", () => { : "Cancel selection" }`; - if (TableController.getAllDevices().length > 0) { - alertInfoDevices.classList.remove("d-none"); - } else { + if (TableController.getSelectedDevices().length <= 0) { alertInfoDevices.classList.add("d-none") + } else { + alertInfoDevices.classList.remove("d-none"); } if (isAllChecked.every(bool => bool == true)) { From d27cc46f64d30f49bd45ac3086cd45e47adf16c0 Mon Sep 17 00:00:00 2001 From: RubenPX Date: Wed, 11 May 2022 11:09:38 +0200 Subject: [PATCH 3/5] refactor device selection --- ereuse_devicehub/static/js/main_inventory.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/ereuse_devicehub/static/js/main_inventory.js b/ereuse_devicehub/static/js/main_inventory.js index 3bae4ce3..0f1d9b7e 100644 --- a/ereuse_devicehub/static/js/main_inventory.js +++ b/ereuse_devicehub/static/js/main_inventory.js @@ -83,8 +83,6 @@ window.addEventListener("DOMContentLoaded", () => { const alertInfoDevices = document.getElementById("select-devices-info"); function itemListCheckChanged() { - const listDevices = TableController.getAllDevicesInCurrentPage() - const isAllChecked = listDevices.map(itm => itm.checked); alertInfoDevices.innerHTML = `Selected devices: ${TableController.getSelectedDevices().length} ${TableController.getAllDevices().length != TableController.getSelectedDevices().length ? `Select all devices (${TableController.getAllDevices().length})` @@ -97,14 +95,14 @@ window.addEventListener("DOMContentLoaded", () => { alertInfoDevices.classList.remove("d-none"); } - if (isAllChecked.every(bool => bool == true)) { + if (TableController.getAllDevices().length == TableController.getSelectedDevices().length) { btnSelectAll.checked = true; btnSelectAll.indeterminate = false; - } else if (isAllChecked.every(bool => bool == false)) { + } else if(TableController.getAllDevices().length < TableController.getSelectedDevices().length) { + btnSelectAll.indeterminate = true; + } else { btnSelectAll.checked = false; btnSelectAll.indeterminate = false; - } else { - btnSelectAll.indeterminate = true; } } From cc7b453c062d052cda8f160524d884235856e859 Mon Sep 17 00:00:00 2001 From: RubenPX Date: Wed, 11 May 2022 11:19:56 +0200 Subject: [PATCH 4/5] Check initial state on dom loaded & check if has devices --- ereuse_devicehub/static/js/main_inventory.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/ereuse_devicehub/static/js/main_inventory.js b/ereuse_devicehub/static/js/main_inventory.js index 0f1d9b7e..f48dfe99 100644 --- a/ereuse_devicehub/static/js/main_inventory.js +++ b/ereuse_devicehub/static/js/main_inventory.js @@ -104,6 +104,13 @@ window.addEventListener("DOMContentLoaded", () => { btnSelectAll.checked = false; btnSelectAll.indeterminate = false; } + + if (TableController.getAllDevices().length == 0) { + btnSelectAll.checked = false; + btnSelectAll.disabled = true; + } else { + btnSelectAll.disabled = false; + } } TableController.getAllDevices().forEach(item => { @@ -126,6 +133,8 @@ window.addEventListener("DOMContentLoaded", () => { table.on("datatable.page", () => itemListCheckChanged()); table.on("datatable.perpage", () => itemListCheckChanged()); table.on("datatable.update", () => itemListCheckChanged()); + + itemListCheckChanged(); }) function deviceSelect() { From 411fe85b19df8b218ef9c3b3c594f59c2c466510 Mon Sep 17 00:00:00 2001 From: RubenPX Date: Wed, 11 May 2022 11:20:25 +0200 Subject: [PATCH 5/5] Check devices in current page --- ereuse_devicehub/static/js/main_inventory.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ereuse_devicehub/static/js/main_inventory.js b/ereuse_devicehub/static/js/main_inventory.js index f48dfe99..1b911579 100644 --- a/ereuse_devicehub/static/js/main_inventory.js +++ b/ereuse_devicehub/static/js/main_inventory.js @@ -98,7 +98,7 @@ window.addEventListener("DOMContentLoaded", () => { if (TableController.getAllDevices().length == TableController.getSelectedDevices().length) { btnSelectAll.checked = true; btnSelectAll.indeterminate = false; - } else if(TableController.getAllDevices().length < TableController.getSelectedDevices().length) { + } else if(TableController.getAllSelectedDevicesInCurrentPage().length > 0) { btnSelectAll.indeterminate = true; } else { btnSelectAll.checked = false;