From ff00b88fd798976131b67680c26fa11ebf603733 Mon Sep 17 00:00:00 2001 From: RubenPX Date: Mon, 9 May 2022 14:18:41 +0200 Subject: [PATCH 1/2] fix indeterminated checkbox --- ereuse_devicehub/static/js/main_inventory.js | 28 +++++++++++++------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/ereuse_devicehub/static/js/main_inventory.js b/ereuse_devicehub/static/js/main_inventory.js index 848c72e4..c8159c83 100644 --- a/ereuse_devicehub/static/js/main_inventory.js +++ b/ereuse_devicehub/static/js/main_inventory.js @@ -90,11 +90,10 @@ window.addEventListener("DOMContentLoaded", () => { 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" - }`; + ${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; @@ -315,19 +314,30 @@ async function processSelectedDevices() { const lotID = lot.id; const srcElement = event.srcElement.parentElement.children[0] const checked = !srcElement.checked; + const { indeterminate } = srcElement const found = this.list.filter(list => list.lot.id == lotID)[0]; if (checked) { if (found && found.type == "Remove") { - found.type = "Add"; + const affectedDevices = found.devices.filter(dev => found.lot.devices.includes(dev.id)) + if (affectedDevices.length > 0 && found.indeterminate == false) { // Remove action from list + actions.list = actions.list.filter(x => x.lot.id != found.lot.id) + } else { + found.type = "Add"; + } } else { - this.list.push({ type: "Add", lot, devices: selectedDevices }); + this.list.push({ type: "Add", lot, devices: selectedDevices, indeterminate }); } } else if (found && found.type == "Add") { - found.type = "Remove"; + const affectedDevices = found.devices.filter(dev => !found.lot.devices.includes(dev.id)) + if (affectedDevices.length > 0 && found.indeterminate == false) { // Remove action from list + actions.list = actions.list.filter(x => x.lot.id != found.lot.id) + } else { + found.type = "Remove"; + } } else { - this.list.push({ type: "Remove", lot, devices: selectedDevices }); + this.list.push({ type: "Remove", lot, devices: selectedDevices, indeterminate }); } if (this.list.length > 0) { From 42760e5b9eed4150eb00f03154a307b73b6a33bc Mon Sep 17 00:00:00 2001 From: RubenPX Date: Wed, 11 May 2022 18:42:29 +0200 Subject: [PATCH 2/2] Fix print labels devices --- ereuse_devicehub/static/js/main_inventory.js | 2 ++ ereuse_devicehub/templates/inventory/device_list.html | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/ereuse_devicehub/static/js/main_inventory.js b/ereuse_devicehub/static/js/main_inventory.js index 5db11bdd..9479fc48 100644 --- a/ereuse_devicehub/static/js/main_inventory.js +++ b/ereuse_devicehub/static/js/main_inventory.js @@ -111,6 +111,8 @@ window.addEventListener("DOMContentLoaded", () => { } else { btnSelectAll.disabled = false; } + + get_device_list(); } TableController.getAllDevices().forEach(item => { diff --git a/ereuse_devicehub/templates/inventory/device_list.html b/ereuse_devicehub/templates/inventory/device_list.html index 2b1d5cec..b457b080 100644 --- a/ereuse_devicehub/templates/inventory/device_list.html +++ b/ereuse_devicehub/templates/inventory/device_list.html @@ -392,7 +392,7 @@ {% for doc in lot.trade.documents %} - {% if doc.url.to_text() %} + {% if doc.url %} {{ doc.file_name}} {% else %} {{ doc.file_name}}