20260319a: Auto-refresh recipe archive after save, Bring spec uses product name not brand

This commit is contained in:
dadaloop82
2026-03-19 13:18:35 +00:00
parent b8528f79a9
commit 11a703d274
4 changed files with 9 additions and 10 deletions
+2 -2
View File
@@ -742,8 +742,8 @@ function useFromInventory(PDO $db): void {
// Already on the list, skip adding
$addedToBring = false;
} else {
// Build specification from brand
$spec = $product['brand'] ? $product['brand'] : '';
// Build specification from product name (variant info, not brand)
$spec = $product['name'] ? $product['name'] : '';
$body = http_build_query([
'uuid' => $listUUID,
'purchase' => $bringName,
+5 -6
View File
@@ -3497,7 +3497,6 @@ function isLowStock(totalRemaining, unit, defaultQty) {
function showLowStockBringPrompt(result, afterCallback) {
const name = result.product_name || currentProduct?.name || '';
const brand = result.product_brand || currentProduct?.brand || '';
const unit = result.product_unit || currentProduct?.unit || 'pz';
const defaultQty = result.product_default_qty || parseFloat(currentProduct?.default_quantity) || 0;
const totalRemaining = result.total_remaining;
@@ -3517,19 +3516,18 @@ function showLowStockBringPrompt(result, afterCallback) {
remainLabel = `${Number.isInteger(totalRemaining) ? totalRemaining : totalRemaining.toFixed(1)} ${unitLabels[unit] || unit}`;
}
// Build specification from brand for Bring
const spec = brand || '';
// Build specification from product name (not brand) for Bring
const spec = name || '';
window._lowStockAfterCallback = afterCallback;
window._lowStockSpec = spec;
const brandNote = brand ? ` (${escapeHtml(brand)})` : '';
document.getElementById('modal-content').innerHTML = `
<div class="modal-header">
<h3> Sta per finire!</h3>
<button class="modal-close" onclick="closeLowStockPrompt()"></button>
</div>
<div style="padding:0 16px 16px">
<p style="margin-bottom:12px"><strong>${escapeHtml(name)}</strong>${brandNote} sta per finire rimangono solo <strong>${remainLabel}</strong>.</p>
<p style="margin-bottom:12px"><strong>${escapeHtml(name)}</strong> sta per finire rimangono solo <strong>${remainLabel}</strong>.</p>
<p style="margin-bottom:16px">Vuoi aggiungerlo alla lista della spesa?</p>
<button type="button" class="btn btn-large btn-success full-width" onclick="addLowStockToBring('${escapeHtml(name).replace(/'/g, "\\'")}')">
🛒 , aggiungi a Bring!
@@ -4912,8 +4910,9 @@ async function saveRecipeToArchive(recipe) {
const today = new Date().toISOString().slice(0, 10);
try {
await api('recipes_save', {}, 'POST', { date: today, meal: recipe.meal, recipe });
// Invalidate cache so next load fetches fresh data
// Invalidate cache and refresh the archive list
_recipeArchiveCache = null;
loadRecipeArchive();
} catch(e) { console.error('Failed to save recipe:', e); }
}
BIN
View File
Binary file not shown.
+2 -2
View File
@@ -9,7 +9,7 @@
<title>Dispensa Manager</title>
<link rel="manifest" href="manifest.json">
<link rel="icon" type="image/svg+xml" href="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'><text y='.9em' font-size='90'>🏠</text></svg>">
<link rel="stylesheet" href="assets/css/style.css?v=20260318b">
<link rel="stylesheet" href="assets/css/style.css?v=20260319a">
<!-- QuaggaJS for barcode scanning -->
<script src="https://cdn.jsdelivr.net/npm/@ericblade/quagga2@1.8.4/dist/quagga.min.js"></script>
</head>
@@ -911,6 +911,6 @@
</div>
</div>
<script src="assets/js/app.js?v=20260318b"></script>
<script src="assets/js/app.js?v=20260319a"></script>
</body>
</html>