From fd10b3f8f7e844cae6788b2883b192d7483342e1 Mon Sep 17 00:00:00 2001 From: kdeterme Date: Fri, 11 Sep 2026 11:00:46 +0200 Subject: [PATCH] feat: implement per-order toggle-all material status and real-time usage statistics UI --- .../interventions/detail/card_stock.html | 26 +++++--- .../interventions/detail/scripts.html | 35 ++++++++++- .../intervention_detail_mobile.html | 63 +++++++++++++++---- loko/interventions/views/detail.py | 4 ++ 4 files changed, 105 insertions(+), 23 deletions(-) diff --git a/loko/interventions/templates/interventions/detail/card_stock.html b/loko/interventions/templates/interventions/detail/card_stock.html index 25a502d..62cda9f 100644 --- a/loko/interventions/templates/interventions/detail/card_stock.html +++ b/loko/interventions/templates/interventions/detail/card_stock.html @@ -68,14 +68,9 @@
{% with items=order.preparationorderitem_set.all other_items=order.other_items.all %} {% if items or other_items %} - + + {{ order.used_items_count }} / {{ order.total_items_count }} {% translate "utilisé(s)" %} + {% endif %} {% endwith %} - {% translate "Utilisé ?" %} + + +
{% translate "Utilisé ?" %}
+ {% translate "Article" %} {% translate "Référence" %} {% translate "Quantité" %} diff --git a/loko/interventions/templates/interventions/detail/scripts.html b/loko/interventions/templates/interventions/detail/scripts.html index 5db1bc5..c397211 100644 --- a/loko/interventions/templates/interventions/detail/scripts.html +++ b/loko/interventions/templates/interventions/detail/scripts.html @@ -612,6 +612,18 @@ function updateMaterialUI(data) { el.textContent = data.all_used ? "{% translate 'Tout décocher' %}" : "{% translate 'Tout cocher' %}"; }); + if (data.order_id) { + const orderAllUsed = data.order_all_used !== undefined ? data.order_all_used : data.all_used; + const orderBtnTexts = document.querySelectorAll(`#btn-order-toggle-all-text-${data.order_id}, #btn-mobile-order-toggle-all-text-${data.order_id}`); + orderBtnTexts.forEach(el => { + el.textContent = orderAllUsed ? "{% translate 'Tout décocher' %}" : "{% translate 'Tout cocher' %}"; + }); + if (data.order_used_count !== undefined) { + const orderUsedCountEls = document.querySelectorAll(`#order-used-count-${data.order_id}, #mobile-order-used-count-${data.order_id}`); + orderUsedCountEls.forEach(el => el.textContent = data.order_used_count); + } + } + if (data.item_id !== undefined && data.is_other !== undefined) { const prefix = data.is_other ? 'other-' : 'item-'; const badges = document.querySelectorAll(`#material-badge-${prefix}${data.item_id}, #mobile-material-item-badge-${prefix}${data.item_id}`); @@ -670,7 +682,7 @@ function toggleAllMaterialUsed(interventionId, orderId) { const csrfToken = document.querySelector('[name=csrfmiddlewaretoken]')?.value || document.cookie.split('; ').find(r => r.startsWith('csrftoken='))?.split('=')[1] || ''; - const buttons = document.querySelectorAll('#btn-desktop-toggle-all-material, #btn-mobile-toggle-all-material'); + const buttons = document.querySelectorAll('#btn-desktop-toggle-all-material, #btn-mobile-toggle-all-material, .btn-order-toggle-all'); buttons.forEach(b => b.disabled = true); const formData = new FormData(); @@ -712,6 +724,27 @@ function toggleAllMaterialUsed(interventionId, orderId) { }); }); + if (orderId) { + const orderBtnTexts = document.querySelectorAll(`#btn-order-toggle-all-text-${orderId}, #btn-mobile-order-toggle-all-text-${orderId}`); + orderBtnTexts.forEach(el => { + el.textContent = isAllUsed ? "{% translate 'Tout décocher' %}" : "{% translate 'Tout cocher' %}"; + }); + if (data.order_used_count !== undefined) { + const orderUsedCountEls = document.querySelectorAll(`#order-used-count-${orderId}, #mobile-order-used-count-${orderId}`); + orderUsedCountEls.forEach(el => el.textContent = data.order_used_count); + } + } else { + document.querySelectorAll('.btn-order-toggle-all-text').forEach(el => { + el.textContent = isAllUsed ? "{% translate 'Tout décocher' %}" : "{% translate 'Tout cocher' %}"; + }); + document.querySelectorAll('.btn-order-toggle-all').forEach(btn => { + const id = btn.id.replace('btn-order-toggle-all-', '').replace('btn-mobile-order-toggle-all-', ''); + const totalCheckboxes = document.querySelectorAll(`.material-used-checkbox[data-order-id="${id}"]`).length; + const orderUsedCountEls = document.querySelectorAll(`#order-used-count-${id}, #mobile-order-used-count-${id}`); + orderUsedCountEls.forEach(el => el.textContent = isAllUsed ? totalCheckboxes : 0); + }); + } + updateMaterialUI({ used_count: data.used_count, total_count: data.total_count, diff --git a/loko/interventions/templates/interventions/intervention_detail_mobile.html b/loko/interventions/templates/interventions/intervention_detail_mobile.html index a28e679..ba7ecbe 100644 --- a/loko/interventions/templates/interventions/intervention_detail_mobile.html +++ b/loko/interventions/templates/interventions/intervention_detail_mobile.html @@ -1156,18 +1156,6 @@
- {% with items=order.preparationorderitem_set.all other_items=order.other_items.all %} - {% if items or other_items %} - - {% endif %} - {% endwith %} @@ -1179,6 +1167,22 @@ {% with items=order.preparationorderitem_set.all other_items=order.other_items.all %} {% if items or other_items %}
+
+ + + {{ order.used_items_count }} / {{ order.total_items_count }} {% translate "utilisé(s)" %} + +
{% for item in items %}
@@ -6933,6 +6937,18 @@ function updateMaterialUI(data) { el.textContent = data.all_used ? "{% translate 'Tout décocher' %}" : "{% translate 'Tout cocher' %}"; }); + if (data.order_id) { + const orderAllUsed = data.order_all_used !== undefined ? data.order_all_used : data.all_used; + const orderBtnTexts = document.querySelectorAll(`#btn-order-toggle-all-text-${data.order_id}, #btn-mobile-order-toggle-all-text-${data.order_id}`); + orderBtnTexts.forEach(el => { + el.textContent = orderAllUsed ? "{% translate 'Tout décocher' %}" : "{% translate 'Tout cocher' %}"; + }); + if (data.order_used_count !== undefined) { + const orderUsedCountEls = document.querySelectorAll(`#order-used-count-${data.order_id}, #mobile-order-used-count-${data.order_id}`); + orderUsedCountEls.forEach(el => el.textContent = data.order_used_count); + } + } + if (data.item_id !== undefined && data.is_other !== undefined) { const prefix = data.is_other ? 'other-' : 'item-'; const badges = document.querySelectorAll(`#material-badge-${prefix}${data.item_id}, #mobile-material-item-badge-${prefix}${data.item_id}`); @@ -6995,7 +7011,7 @@ function toggleAllMaterialUsed(interventionId, orderId) { || document.cookie.split('; ').find(r => r.startsWith('csrftoken='))?.split('=')[1] || ''; - const buttons = document.querySelectorAll('#btn-desktop-toggle-all-material, #btn-mobile-toggle-all-material'); + const buttons = document.querySelectorAll('#btn-desktop-toggle-all-material, #btn-mobile-toggle-all-material, .btn-order-toggle-all'); buttons.forEach(b => b.disabled = true); const formData = new FormData(); @@ -7037,6 +7053,27 @@ function toggleAllMaterialUsed(interventionId, orderId) { }); }); + if (orderId) { + const orderBtnTexts = document.querySelectorAll(`#btn-order-toggle-all-text-${orderId}, #btn-mobile-order-toggle-all-text-${orderId}`); + orderBtnTexts.forEach(el => { + el.textContent = isAllUsed ? "{% translate 'Tout décocher' %}" : "{% translate 'Tout cocher' %}"; + }); + if (data.order_used_count !== undefined) { + const orderUsedCountEls = document.querySelectorAll(`#order-used-count-${orderId}, #mobile-order-used-count-${orderId}`); + orderUsedCountEls.forEach(el => el.textContent = data.order_used_count); + } + } else { + document.querySelectorAll('.btn-order-toggle-all-text').forEach(el => { + el.textContent = isAllUsed ? "{% translate 'Tout décocher' %}" : "{% translate 'Tout cocher' %}"; + }); + document.querySelectorAll('.btn-order-toggle-all').forEach(btn => { + const id = btn.id.replace('btn-order-toggle-all-', '').replace('btn-mobile-order-toggle-all-', ''); + const totalCheckboxes = document.querySelectorAll(`.material-used-checkbox[data-order-id="${id}"]`).length; + const orderUsedCountEls = document.querySelectorAll(`#order-used-count-${id}, #mobile-order-used-count-${id}`); + orderUsedCountEls.forEach(el => el.textContent = isAllUsed ? totalCheckboxes : 0); + }); + } + updateMaterialUI({ used_count: data.used_count, total_count: data.total_count, diff --git a/loko/interventions/views/detail.py b/loko/interventions/views/detail.py index 628b61a..02928fe 100644 --- a/loko/interventions/views/detail.py +++ b/loko/interventions/views/detail.py @@ -3834,6 +3834,8 @@ def toggle_material_used(request, intervention_id, item_id): 'is_used': item.is_used, 'order_id': order.id, 'order_all_used': order_all_used, + 'order_used_count': order.used_items_count, + 'order_total_count': order.total_items_count, 'used_count': stats['used'], 'total_count': stats['total'], 'all_used': stats['all_used'], @@ -3891,5 +3893,7 @@ def toggle_all_material_used(request, intervention_id): 'used_count': stats['used'], 'total_count': stats['total'], 'order_id': int(order_id) if order_id else None, + 'order_used_count': total_target if target_state else 0, + 'order_total_count': total_target, })