feat: per-ingredient category selection for shopping list transfer (closes #33)

When adding ingredients in the meal editor, each ingredient now has a
category dropdown. Categories are stored on the ingredient and applied
automatically when transferring to the shopping list, so items appear
pre-grouped by category without manual re-sorting.
This commit is contained in:
Ulas
2026-04-15 07:11:49 +02:00
parent d6d2c41bfa
commit d16919ef7c
20 changed files with 97 additions and 32 deletions
+3 -1
View File
@@ -226,6 +226,8 @@
"addIngredient": "إضافة مكون",
"ingredientNamePlaceholder": "المكون",
"ingredientQtyPlaceholder": "الكمية",
"ingredientCategoryLabel": "الفئة",
"ingredientCategoryDefault": "متنوعات",
"removeIngredient": "إزالة المكون",
"transferLabel": "نقل المكونات إلى قائمة التسوق",
"transferNow": "نقل الآن",
@@ -596,4 +598,4 @@
"unitMonth": "شهر",
"unitMonths": "أشهر"
}
}
}
+2
View File
@@ -226,6 +226,8 @@
"addIngredient": "Zutat hinzufügen",
"ingredientNamePlaceholder": "Zutat",
"ingredientQtyPlaceholder": "Menge",
"ingredientCategoryLabel": "Kategorie",
"ingredientCategoryDefault": "Sonstiges",
"removeIngredient": "Zutat entfernen",
"transferLabel": "Zutaten auf Einkaufsliste übertragen",
"transferNow": "Jetzt übertragen",
+3 -1
View File
@@ -226,6 +226,8 @@
"addIngredient": "Προσθήκη υλικού",
"ingredientNamePlaceholder": "Υλικό",
"ingredientQtyPlaceholder": "Ποσότητα",
"ingredientCategoryLabel": "Κατηγορία",
"ingredientCategoryDefault": "Διάφορα",
"removeIngredient": "Αφαίρεση υλικού",
"transferLabel": "Μεταφορά υλικών στη λίστα αγορών",
"transferNow": "Μεταφορά τώρα",
@@ -596,4 +598,4 @@
"unitMonth": "μήνα",
"unitMonths": "μήνες"
}
}
}
+2
View File
@@ -226,6 +226,8 @@
"addIngredient": "Add ingredient",
"ingredientNamePlaceholder": "Ingredient",
"ingredientQtyPlaceholder": "Quantity",
"ingredientCategoryLabel": "Category",
"ingredientCategoryDefault": "Miscellaneous",
"removeIngredient": "Remove ingredient",
"transferLabel": "Transfer ingredients to shopping list",
"transferNow": "Transfer now",
+3 -1
View File
@@ -226,6 +226,8 @@
"addIngredient": "Añadir ingrediente",
"ingredientNamePlaceholder": "Ingrediente",
"ingredientQtyPlaceholder": "Cantidad",
"ingredientCategoryLabel": "Categoría",
"ingredientCategoryDefault": "Varios",
"removeIngredient": "Eliminar ingrediente",
"transferLabel": "Transferir ingredientes a la lista de compras",
"transferNow": "Transferir ahora",
@@ -596,4 +598,4 @@
"unitMonth": "mes",
"unitMonths": "meses"
}
}
}
+3 -1
View File
@@ -226,6 +226,8 @@
"addIngredient": "Ajouter un ingrédient",
"ingredientNamePlaceholder": "Ingrédient",
"ingredientQtyPlaceholder": "Quantité",
"ingredientCategoryLabel": "Catégorie",
"ingredientCategoryDefault": "Divers",
"removeIngredient": "Supprimer l'ingrédient",
"transferLabel": "Transférer les ingrédients vers la liste de courses",
"transferNow": "Transférer maintenant",
@@ -596,4 +598,4 @@
"unitMonth": "mois",
"unitMonths": "mois"
}
}
}
+3 -1
View File
@@ -226,6 +226,8 @@
"addIngredient": "सामग्री जोड़ें",
"ingredientNamePlaceholder": "सामग्री",
"ingredientQtyPlaceholder": "मात्रा",
"ingredientCategoryLabel": "श्रेणी",
"ingredientCategoryDefault": "विविध",
"removeIngredient": "सामग्री हटाएं",
"transferLabel": "सामग्री खरीदारी सूची में जोड़ें",
"transferNow": "अभी जोड़ें",
@@ -596,4 +598,4 @@
"unitMonth": "माह",
"unitMonths": "माह"
}
}
}
+3 -1
View File
@@ -226,6 +226,8 @@
"addIngredient": "Aggiungi ingrediente",
"ingredientNamePlaceholder": "Ingrediente",
"ingredientQtyPlaceholder": "Quantità",
"ingredientCategoryLabel": "Categoria",
"ingredientCategoryDefault": "Varie",
"removeIngredient": "Rimuovi ingrediente",
"transferLabel": "Trasferisci ingredienti alla lista della spesa",
"transferNow": "Trasferisci ora",
@@ -596,4 +598,4 @@
"unitMonth": "mese",
"unitMonths": "mesi"
}
}
}
+3 -1
View File
@@ -226,6 +226,8 @@
"addIngredient": "材料を追加",
"ingredientNamePlaceholder": "材料",
"ingredientQtyPlaceholder": "量",
"ingredientCategoryLabel": "カテゴリ",
"ingredientCategoryDefault": "その他",
"removeIngredient": "材料を削除",
"transferLabel": "材料を買い物リストに追加",
"transferNow": "今すぐ追加",
@@ -596,4 +598,4 @@
"unitMonth": "ヶ月",
"unitMonths": "ヶ月"
}
}
}
+3 -1
View File
@@ -226,6 +226,8 @@
"addIngredient": "Adicionar ingrediente",
"ingredientNamePlaceholder": "Ingrediente",
"ingredientQtyPlaceholder": "Qtd",
"ingredientCategoryLabel": "Categoria",
"ingredientCategoryDefault": "Outros",
"removeIngredient": "Remover ingrediente",
"transferLabel": "Transferir ingredientes para lista de compras",
"transferNow": "Transferir agora",
@@ -596,4 +598,4 @@
"unitMonth": "mês",
"unitMonths": "meses"
}
}
}
+3 -1
View File
@@ -226,6 +226,8 @@
"addIngredient": "Добавить ингредиент",
"ingredientNamePlaceholder": "Ингредиент",
"ingredientQtyPlaceholder": "Количество",
"ingredientCategoryLabel": "Категория",
"ingredientCategoryDefault": "Разное",
"removeIngredient": "Удалить ингредиент",
"transferLabel": "Перенести ингредиенты в список покупок",
"transferNow": "Перенести сейчас",
@@ -596,4 +598,4 @@
"unitMonth": "месяц",
"unitMonths": "месяцев"
}
}
}
+3 -1
View File
@@ -226,6 +226,8 @@
"addIngredient": "Tillsätt ingrediens",
"ingredientNamePlaceholder": "Ingrediens",
"ingredientQtyPlaceholder": "Kvantitet",
"ingredientCategoryLabel": "Kategori",
"ingredientCategoryDefault": "Övrigt",
"removeIngredient": "Ta bort ingrediensen",
"transferLabel": "Överför ingredienserna till inköpslistan",
"transferNow": "Överför nu",
@@ -596,4 +598,4 @@
"unitMonth": "månad",
"unitMonths": "månader"
}
}
}
+3 -1
View File
@@ -226,6 +226,8 @@
"addIngredient": "Malzeme ekle",
"ingredientNamePlaceholder": "Malzeme",
"ingredientQtyPlaceholder": "Miktar",
"ingredientCategoryLabel": "Kategori",
"ingredientCategoryDefault": "Çeşitli",
"removeIngredient": "Malzemeyi kaldır",
"transferLabel": "Malzemeleri alışveriş listesine aktar",
"transferNow": "Şimdi aktar",
@@ -596,4 +598,4 @@
"unitMonth": "ay",
"unitMonths": "ay"
}
}
}
+3 -1
View File
@@ -226,6 +226,8 @@
"addIngredient": "添加食材",
"ingredientNamePlaceholder": "食材",
"ingredientQtyPlaceholder": "数量",
"ingredientCategoryLabel": "分类",
"ingredientCategoryDefault": "其他",
"removeIngredient": "移除食材",
"transferLabel": "将食材添加到购物清单",
"transferNow": "立即添加",
@@ -596,4 +598,4 @@
"unitMonth": "个月",
"unitMonths": "个月"
}
}
}
+23 -7
View File
@@ -34,6 +34,7 @@ let state = {
currentWeek: null, // YYYY-MM-DD (Montag)
meals: [],
lists: [], // Einkaufslisten für Transfer-Dropdown
categories: [], // Einkaufskategorien für Zutaten
modal: null,
visibleMealTypes: ['breakfast', 'lunch', 'dinner', 'snack'],
};
@@ -98,6 +99,15 @@ async function loadLists() {
}
}
async function loadCategories() {
try {
const res = await api.get('/shopping/categories');
state.categories = res.data;
} catch {
state.categories = [];
}
}
async function loadPreferences() {
try {
const res = await api.get('/preferences');
@@ -137,7 +147,7 @@ export async function render(container, { user }) {
const today = new Date().toISOString().slice(0, 10);
const monday = getMondayOf(today);
await Promise.all([loadWeek(monday), loadLists(), loadPreferences()]);
await Promise.all([loadWeek(monday), loadLists(), loadPreferences(), loadCategories()]);
renderWeekGrid();
wireNav();
}
@@ -554,7 +564,7 @@ function buildModalContent({ mode, date, mealType, meal }) {
: `<option value="" disabled>${t('meals.noShoppingLists')}</option>`;
const ingRows = isEdit && meal.ingredients?.length
? meal.ingredients.map((ing) => ingredientRowHTML(ing.name, ing.quantity ?? '', ing.id)).join('')
? meal.ingredients.map((ing) => ingredientRowHTML(ing.name, ing.quantity ?? '', ing.id, ing.category ?? 'Sonstiges')).join('')
: '';
const hasIngOpen = isEdit && meal.ingredients?.some((i) => !i.on_shopping_list);
@@ -620,11 +630,16 @@ function buildModalContent({ mode, date, mealType, meal }) {
</div>`;
}
function ingredientRowHTML(name, qty, id) {
function ingredientRowHTML(name, qty, id, category = 'Sonstiges') {
const catOptions = state.categories.length
? state.categories.map((c) => `<option value="${esc(c.name)}" ${c.name === category ? 'selected' : ''}>${esc(c.name)}</option>`).join('')
: `<option value="Sonstiges" selected>${t('meals.ingredientCategoryDefault')}</option>`;
return `
<div class="ingredient-row" data-ing-id="${id ?? ''}">
<input type="text" class="form-input ingredient-row__name" placeholder="${t('meals.ingredientNamePlaceholder')}" value="${esc(name)}">
<input type="text" class="form-input ingredient-row__qty" placeholder="${t('meals.ingredientQtyPlaceholder')}" value="${esc(qty)}">
<select class="form-input ingredient-row__cat" aria-label="${t('meals.ingredientCategoryLabel')}">${catOptions}</select>
<button class="ingredient-row__remove" data-action="remove-ingredient" type="button" aria-label="${t('meals.removeIngredient')}">
<i data-lucide="x" style="width:14px;height:14px;" aria-hidden="true"></i>
</button>
@@ -652,9 +667,10 @@ async function saveModal(overlay) {
const ingredients = [];
overlay.querySelectorAll('.ingredient-row').forEach((row) => {
const name = row.querySelector('.ingredient-row__name').value.trim();
const qty = row.querySelector('.ingredient-row__qty').value.trim() || null;
if (name) ingredients.push({ name, quantity: qty, id: row.dataset.ingId || null });
const name = row.querySelector('.ingredient-row__name').value.trim();
const qty = row.querySelector('.ingredient-row__qty').value.trim() || null;
const category = row.querySelector('.ingredient-row__cat')?.value || 'Sonstiges';
if (name) ingredients.push({ name, quantity: qty, category, id: row.dataset.ingId || null });
});
saveBtn.disabled = true;
@@ -680,7 +696,7 @@ async function saveModal(overlay) {
if (!keptIds.has(id)) await api.delete(`/meals/ingredients/${id}`);
}
for (const ing of ingredients) {
if (!ing.id) await api.post(`/meals/${meal.id}/ingredients`, { name: ing.name, quantity: ing.quantity });
if (!ing.id) await api.post(`/meals/${meal.id}/ingredients`, { name: ing.name, quantity: ing.quantity, category: ing.category });
}
// Reload updated meal
+6
View File
@@ -329,6 +329,12 @@
min-width: 0;
}
.ingredient-row__cat {
flex: 1.5;
min-width: 0;
font-size: var(--text-sm);
}
.ingredient-row__remove {
width: 32px;
height: 32px;