From fef70cb97c4407ec702d8d5fc4e1199f3e009f4e Mon Sep 17 00:00:00 2001 From: morgane Date: Fri, 19 Jun 2026 16:20:53 +0000 Subject: [PATCH] Actualiser assets/js/app.js --- assets/js/app.js | 80 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 78 insertions(+), 2 deletions(-) diff --git a/assets/js/app.js b/assets/js/app.js index 26437b7..65e56bd 100644 --- a/assets/js/app.js +++ b/assets/js/app.js @@ -15405,9 +15405,85 @@ function renderRecipeLibraryList(recipes) { }).join(''); } -function openRecipeLibraryForm(id = null) { +function openRecipeLibraryImportForm() { + document.getElementById('modal-content').innerHTML = ` + +
+ + +
+ + `; + document.getElementById('modal-overlay').style.display = 'flex'; +} + +function analyzeRawRecipeText() { + const raw = document.getElementById('rl-import-raw').value; + if (!raw.trim()) { showToast('Colle un texte de recette', 'warning'); return; } + const parsed = parseRawRecipeText(raw); + openRecipeLibraryForm(null, parsed); +} + +function parseRawRecipeText(raw) { + const lines = raw.split(/\r?\n/).map(l => l.trim()).filter(l => l.length > 0); + + const ingredientHeaderRe = /^(ingr[ée]dients?)\s*:?$/i; + const equipmentHeaderRe = /^(mat[ée]riel|[ée]quipements?|ustensiles?)\s*:?$/i; + const stepsHeaderRe = /^([ée]tapes?|pr[ée]paration|instructions?)\s*:?$/i; + + let title = ''; + let section = null; + const ingredients = []; + const equipment = []; + const steps = []; + + for (const line of lines) { + if (ingredientHeaderRe.test(line)) { section = 'ingredients'; continue; } + if (equipmentHeaderRe.test(line)) { section = 'equipment'; continue; } + if (stepsHeaderRe.test(line)) { section = 'steps'; continue; } + + if (!title && !section) { title = line.replace(/^[-•*]\s*/, ''); continue; } + if (!section) continue; + + if (section === 'ingredients') { + const cleaned = line.replace(/^[-•*]\s*/, ''); + const m = cleaned.match(/^([\d,.\/]+\s*(?:g|kg|ml|cl|l|tsp|tbsp|cup|c\.à\.s|c\.à\.c|pincée|pinch)?)\s*(?:de\s+|d')?(.+)$/i); + if (m && m[1] && m[2]) { + ingredients.push({ name: m[2].trim(), qty: m[1].trim() }); + } else { + ingredients.push({ name: cleaned, qty: '' }); + } + } else if (section === 'equipment') { + equipment.push(line.replace(/^[-•*]\s*/, '')); + } else if (section === 'steps') { + steps.push(line.replace(/^(\d+[.)]\s*|[-•*]\s*)/, '')); + } + } + + return { + title: title || 'Recette importée', + ingredients: ingredients.length ? ingredients : [{ name: '', qty: '' }], + equipment, + steps: steps.length ? steps : [''], + tags: [], + persons: 1, + }; +} + +function openRecipeLibraryForm(id = null, prefill = null) { const existing = id ? _recipeLibraryCache.find(e => e.id === id) : null; - const r = existing ? existing.recipe : { title: '', ingredients: [{ name: '', qty: '' }], equipment: [], steps: [''] }; + const r = existing ? existing.recipe : (prefill || { title: '', ingredients: [{ name: '', qty: '' }], equipment: [], steps: [''] }); document.getElementById('modal-content').innerHTML = `