Actualiser assets/js/app.js
CI / PHP Syntax Check (push) Has been cancelled
CI / JavaScript Lint (push) Has been cancelled
CI / Docker Build Test (push) Has been cancelled
CI / Validate Translation Files (push) Has been cancelled
CI / Auto-merge develop → main (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / PHP Syntax Check (push) Has been cancelled
CI / JavaScript Lint (push) Has been cancelled
CI / Docker Build Test (push) Has been cancelled
CI / Validate Translation Files (push) Has been cancelled
CI / Auto-merge develop → main (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
This commit is contained in:
+78
-2
@@ -15405,9 +15405,85 @@ function renderRecipeLibraryList(recipes) {
|
|||||||
}).join('');
|
}).join('');
|
||||||
}
|
}
|
||||||
|
|
||||||
function openRecipeLibraryForm(id = null) {
|
function openRecipeLibraryImportForm() {
|
||||||
|
document.getElementById('modal-content').innerHTML = `
|
||||||
|
<div class="modal-header">
|
||||||
|
<h3>📋 Importer une recette (texte brut)</h3>
|
||||||
|
<button class="modal-close" onclick="closeModal()">✕</button>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label>Colle le texte de la recette ci-dessous</label>
|
||||||
|
<textarea id="rl-import-raw" class="form-input" rows="14" placeholder="Titre de la recette
|
||||||
|
|
||||||
|
Ingrédients :
|
||||||
|
- 200g de farine
|
||||||
|
- 3 œufs
|
||||||
|
|
||||||
|
Étapes :
|
||||||
|
1. Mélanger...
|
||||||
|
2. Cuire..."></textarea>
|
||||||
|
</div>
|
||||||
|
<button type="button" class="btn btn-large btn-primary full-width" onclick="analyzeRawRecipeText()">🔍 Analyser</button>
|
||||||
|
`;
|
||||||
|
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 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 = `
|
document.getElementById('modal-content').innerHTML = `
|
||||||
<div class="modal-header">
|
<div class="modal-header">
|
||||||
|
|||||||
Reference in New Issue
Block a user