From 4d9fd8638e667b4da50d938ee3a9c097ea452463 Mon Sep 17 00:00:00 2001 From: dadaloop82 Date: Mon, 16 Mar 2026 07:51:05 +0000 Subject: [PATCH] 20260316d: Sort dashboard sections - opened by remaining qty asc, expiring/expired already correct --- assets/js/app.js | 14 ++++++++++++++ data/dispensa.db | Bin 180224 -> 180224 bytes index.html | 2 +- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/assets/js/app.js b/assets/js/app.js index 38e8a58..e945724 100644 --- a/assets/js/app.js +++ b/assets/js/app.js @@ -865,6 +865,11 @@ async function loadDashboard() { const openedSection = document.getElementById('alert-opened'); const openedList = document.getElementById('opened-list'); if (statsData.opened && statsData.opened.length > 0) { + // Sort by remaining fraction ascending (least remaining first) + statsData.opened.sort((a, b) => { + const fA = openedFraction(a), fB = openedFraction(b); + return fA - fB; + }); openedSection.style.display = 'block'; openedList.innerHTML = statsData.opened.map(item => { const locInfo = LOCATIONS[item.location] || { icon: '📦', label: item.location }; @@ -918,6 +923,15 @@ async function loadDashboard() { } } +function openedFraction(item) { + const qty = parseFloat(item.quantity); + const pkgSize = parseFloat(item.default_quantity); + if (item.unit === 'conf') { + return qty - Math.floor(qty + 0.001); + } + return (qty - Math.floor(qty / pkgSize + 0.001) * pkgSize) / pkgSize; +} + function quickRecipeSuggestion() { // Navigate to chat and auto-send a prompt about expiring products showPage('chat'); diff --git a/data/dispensa.db b/data/dispensa.db index 78bcfb0a93c1db01fc14ecb003751cfc74032bc2..f8a642182121faa7fde83b0e1598b515be0d5d29 100644 GIT binary patch delta 1445 zcmZWp&2Jk;6i))OkW+~dsYoT47m3P=<*XdLO+_wIX@wL-ln@8*FT3OQ6SF(Z%xdEWfH}Czv=AECfo}aJ&{@>p6?XREh zJ$bgb{7!Y__14MKn}6R}Tm7?j^2hpH4_mYE_;zdQ)(>wFb5lquhhOw4Z`fyCW{#|( zkaA|qsi8_P{~{?+WXf7-1K-$lnHoA_@6yy!I+>Td(oyZ1?ouw!m$KO-90*OG8!rKc zP08dXHFeFOQ!qtk@rMishuQ_+ZMVDKBWJB6wzhL$rwCK(N;;O{=tB+#*V653-F}&S zlZj&5jcN@6O`W zi=$}c!Dq)O`^WpE!}-}mE3QX@t?5x^DiaZVQ$dlbxY9%@+X+#(d%#{wt{JarRC%aO zVxfjAmI<`zL>WO40(h?LW|rfRWk~P*l(h)#JQt@%4T;qzp##uzsJd>3uh(Z(s{y4L zG7%PS0jweR3Qo9(u`qNxl{p9{g7L}(jo*MV07>JEPamz^no(&iIu{EbsIwf@5HA(n z@_Nq0slvebVV{tYMgs!Z5D1Kp$q9xgKvKhPx0$pDQJV)2bdi+ISgO?UC{oHcpn$kAB9@A6mGe?GW`=9j;qU0u6`Mh3d2 zCO{yK3SWUx;gwd0(=Qv2(wQ@dS5@xgq&<8^EZn20)qy6%Jjb9M zG?Mcu>U*tJGJ0b!9`}~Jvxf)+B&{{TFqv^FtQGB2(i{}xfWSscJF+!JG{s5x0Y^xb#vGR<40F3OVIR%rA24PLT741+>)5@T?X6br4@)& X6} - +