Recipes phase 3

This commit is contained in:
Joren de Graaf
2026-10-12 09:37:04 +02:00
parent 13cd65622e
commit b0e95c62f5
15 changed files with 788 additions and 13 deletions
+1 -1
View File
@@ -1,7 +1,7 @@
{% extends 'planner/base.html' %}{% load static %}
{% block title %}{% if creating %}New recipe{% else %}Edit {{ recipe.title }}{% endif %} · Tasknest{% endblock %}
{% block page_class %}recipes-page-content{% endblock %}
{% block content %}<link rel="stylesheet" href="{% static 'recipes/vendor/toastui-editor.min.css' %}"><link rel="stylesheet" href="{% static 'recipes/recipes.css' %}?v=3">
{% block content %}<link rel="stylesheet" href="{% static 'recipes/vendor/toastui-editor.min.css' %}"><link rel="stylesheet" href="{% static 'recipes/recipes.css' %}?v=4">
<div class="recipes-layout recipes-layout--form"><header class="recipes-form-header"><a href="{% if creating %}{% url 'recipes:list' %}{% else %}{% url 'recipes:detail' recipe.api_id %}{% endif %}">← Back to recipes</a><h1>{% if creating %}New recipe{% else %}Edit recipe{% endif %}</h1><p>Keep ingredients structured and instructions in Markdown.</p></header>
<form method="post" enctype="multipart/form-data" class="recipes-edit-card" data-recipe-form data-autosave-url="{% if creating %}{% url 'recipes:autosave-new' %}{% else %}{% url 'recipes:autosave' recipe.api_id %}{% endif %}"{% if creating %} data-draft-id="{{ new_draft_id }}"{% endif %}>{% csrf_token %}
{% if creating %}<input type="hidden" name="draft_id" value="{{ new_draft_id }}">{% endif %}
@@ -1,6 +1,7 @@
<div class="recipes-ingredient-form" data-ingredient-row>
{% for hidden in ingredient.hidden_fields %}{{ hidden }}{% endfor %}
<div class="recipes-ingredient-form__main"><div class="recipes-field"><label for="{{ ingredient.name.id_for_label }}">Ingredient name</label>{{ ingredient.name }}{{ ingredient.name.errors }}</div><div class="recipes-field"><label for="{{ ingredient.quantity.id_for_label }}">Quantity</label>{{ ingredient.quantity }}{{ ingredient.quantity.errors }}</div><div class="recipes-field"><label for="{{ ingredient.unit.id_for_label }}">Unit</label>{{ ingredient.unit }}{{ ingredient.unit.errors }}</div></div>
<details class="recipes-ingredient-form__more"><summary>Ingredient details</summary><div class="recipes-form-grid"><div class="recipes-field"><label for="{{ ingredient.preparation_note.id_for_label }}">Preparation note</label>{{ ingredient.preparation_note }}{{ ingredient.preparation_note.errors }}</div><div class="recipes-field"><label for="{{ ingredient.display_order.id_for_label }}">Display order</label>{{ ingredient.display_order }}{{ ingredient.display_order.errors }}</div><div class="recipes-field"><label for="{{ ingredient.inventory_product.id_for_label }}">Inventory product</label>{{ ingredient.inventory_product }}{{ ingredient.inventory_product.errors }}</div><div class="recipes-field"><label for="{{ ingredient.nutrition_product.id_for_label }}">Nutrition product</label>{{ ingredient.nutrition_product }}{{ ingredient.nutrition_product.errors }}</div><label class="recipes-checkbox">{{ ingredient.is_optional }} Optional ingredient</label>{% if ingredient.DELETE %}<label class="recipes-checkbox">{{ ingredient.DELETE }} Remove ingredient</label>{% endif %}</div></details>
<details class="recipes-ingredient-form__more"><summary>Ingredient details</summary><div class="recipes-form-grid"><div class="recipes-field"><label for="{{ ingredient.preparation_note.id_for_label }}">Preparation note</label>{{ ingredient.preparation_note }}{{ ingredient.preparation_note.errors }}</div><div class="recipes-field"><label for="{{ ingredient.display_order.id_for_label }}">Display order</label>{{ ingredient.display_order }}{{ ingredient.display_order.errors }}</div><div class="recipes-field"><label for="{{ ingredient.inventory_product.id_for_label }}">Inventory product</label>{{ ingredient.inventory_product }}{{ ingredient.inventory_product.errors }}</div><div class="recipes-field"><label for="{{ ingredient.nutrition_product.id_for_label }}">Nutrition product</label>{{ ingredient.nutrition_product }}{{ ingredient.nutrition_product.errors }}</div><div class="recipes-field"><label for="{{ ingredient.amount_per_unit.id_for_label }}">Amount per piece or measure</label>{{ ingredient.amount_per_unit }}{{ ingredient.amount_per_unit.errors }}<small>Use only when the recipe unit needs an explicit weight or volume conversion.</small></div><div class="recipes-field"><label for="{{ ingredient.amount_per_unit_unit.id_for_label }}">Conversion unit</label>{{ ingredient.amount_per_unit_unit }}{{ ingredient.amount_per_unit_unit.errors }}</div><label class="recipes-checkbox">{{ ingredient.is_optional }} Optional ingredient</label>{% if ingredient.DELETE %}<label class="recipes-checkbox">{{ ingredient.DELETE }} Remove ingredient</label>{% endif %}</div></details>
{% if ingredient.instance.pk %}<p class="recipes-substitute-link"><a href="{% url 'recipes:substitution-add' recipe.api_id ingredient.instance.pk %}">Manage substitutes{% if ingredient.instance.substitutions.count %} ({{ ingredient.instance.substitutions.count }}){% endif %}</a></p>{% endif %}
{% if ingredient.non_field_errors %}<div class="recipes-form-error" role="alert">{{ ingredient.non_field_errors }}</div>{% endif %}
</div>
+8 -4
View File
@@ -2,7 +2,7 @@
{% block title %}Recipes · Tasknest{% endblock %}
{% block page_class %}recipes-page-content{% endblock %}
{% block content %}
<link rel="stylesheet" href="{% static 'recipes/recipes.css' %}?v=3">
<link rel="stylesheet" href="{% static 'recipes/recipes.css' %}?v=4">
<div class="recipes-layout {% if explicit_detail %}recipes-layout--detail{% else %}recipes-layout--list{% endif %}">
<aside class="recipes-browser" aria-label="Recipe browser">
<div class="recipes-browser__heading">
@@ -39,8 +39,10 @@
{% if selected.photo %}<img src="{% url 'recipes:photo' selected.api_id %}" alt="Photo of {{ selected.title }}">{% else %}<div class="recipes-photo-placeholder" role="img" aria-label="No recipe photo yet"><span>No photo yet</span></div>{% endif %}
<div class="recipes-hero__copy"><p class="recipes-eyebrow">{% if selected.status == 'draft' %}Draft recipe{% else %}Recipe{% endif %}</p><h2>{{ selected.title }}</h2><p class="recipes-hero__meta">{{ selected.total_minutes }} min total · {{ selected.default_servings|floatformat:-2 }} servings</p><div class="recipes-chips">{% if selected.category %}<span>{{ selected.category }}</span>{% endif %}{% for value in selected.tags %}<span>{{ value }}</span>{% endfor %}</div>{% if selected.description %}<p class="recipes-hero__description">{{ selected.description }}</p>{% endif %}</div>
</div>
<form class="recipes-serving-form" method="get" action="{% url 'recipes:detail' selected.api_id %}"><label for="recipe-servings">Servings</label><input id="recipe-servings" type="number" name="servings" min="0.01" max="99999.99" step="0.01" value="{{ analysis.servings|floatformat:-2 }}"><label class="recipes-checkbox"><input type="checkbox" name="optional" value="1"{% if analysis.include_optional %} checked{% endif %}> Include optional ingredients</label><button type="submit" class="recipes-outline-button">Update</button></form>
{% if analysis_error %}<p class="recipes-form-error" role="alert">{{ analysis_error }}</p>{% endif %}
<div class="recipes-content-grid">
<section class="recipes-panel" aria-labelledby="recipe-ingredients-heading"><h3 id="recipe-ingredients-heading">Ingredients</h3><ul class="recipes-ingredient-list">{% for ingredient in selected.ingredients.all %}<li><span>{{ ingredient.name }}{% if ingredient.preparation_note %}<small>{{ ingredient.preparation_note }}</small>{% endif %}</span><strong>{{ ingredient.quantity|floatformat:-3 }} {{ ingredient.unit }}</strong>{% if ingredient.is_optional %}<em>Optional</em>{% endif %}</li>{% empty %}<li class="recipes-muted">No ingredients added yet.</li>{% endfor %}</ul></section>
<section class="recipes-panel" aria-labelledby="recipe-ingredients-heading"><h3 id="recipe-ingredients-heading">Ingredients</h3><ul class="recipes-ingredient-list">{% for line in analysis.lines %}<li><span>{{ line.name }}{% if line.source %}<small>From {{ line.source }}</small>{% endif %}{% if line.ingredient.preparation_note %}<small>{{ line.ingredient.preparation_note }}</small>{% endif %}<small class="recipes-stock-label recipes-stock-label--{{ line.status }}">{{ line.status|capfirst }}{% if line.reason %}: {{ line.reason }}{% endif %}</small></span><strong>{{ line.quantity|floatformat:-3 }} {{ line.unit }}</strong>{% if line.optional %}<em>Optional{% if not analysis.include_optional %} · excluded{% endif %}</em>{% endif %}</li>{% empty %}<li class="recipes-muted">No ingredients added yet.</li>{% endfor %}</ul></section>
<div class="recipes-content-stack"><section class="recipes-panel" aria-labelledby="recipe-instructions-heading"><h3 id="recipe-instructions-heading">Instructions</h3>{% if selected.instructions_markdown %}<div class="recipes-markdown-source">{{ selected.instructions_markdown|recipe_markdown }}</div>{% else %}<p class="recipes-muted">No instructions added yet.</p>{% endif %}</section>{% if selected.notes_markdown %}<section class="recipes-panel" aria-labelledby="recipe-notes-heading"><h3 id="recipe-notes-heading">Notes</h3><div class="recipes-markdown-source">{{ selected.notes_markdown|recipe_markdown }}</div></section>{% endif %}</div>
</div>
{% else %}
@@ -49,9 +51,11 @@
</section>
{% if selected %}<aside class="recipes-info" aria-label="Recipe information">
<section class="recipes-panel"><h3>At a glance</h3><dl class="recipes-facts"><div><dt>Servings</dt><dd>{{ selected.default_servings|floatformat:-2 }}</dd></div><div><dt>Preparation</dt><dd>{{ selected.preparation_minutes }} min</dd></div><div><dt>Cooking</dt><dd>{{ selected.cooking_minutes }} min</dd></div><div><dt>Status</dt><dd>{{ selected.get_status_display }}</dd></div></dl></section>
<section class="recipes-panel"><h3>At a glance</h3><dl class="recipes-facts"><div><dt>Selected servings</dt><dd>{{ analysis.servings|floatformat:-2 }}</dd></div><div><dt>Preparation</dt><dd>{{ selected.preparation_minutes }} min</dd></div><div><dt>Cooking</dt><dd>{{ selected.cooking_minutes }} min</dd></div><div><dt>Status</dt><dd>{{ selected.get_status_display }}</dd></div></dl></section>
<section class="recipes-panel"><h3>Nutrition</h3><p class="recipes-muted">For {{ analysis.servings|floatformat:-2 }} servings. Estimates use matched product data.</p><dl class="recipes-nutrition">{% for row in analysis.nutrition_rows %}<div><dt>{{ row.label }}</dt><dd>{% if row.total is not None %}{{ row.per_serving|floatformat:1 }} {{ row.unit }} / serving<small>{{ row.total|floatformat:1 }} {{ row.unit }} total{% if not row.complete %} · incomplete{% endif %}</small>{% else %}<span aria-label="No estimate">—</span><small>Data unavailable</small>{% endif %}</dd></div>{% endfor %}</dl><p class="recipes-muted">A partial estimate excludes missing nutrient values.</p></section>
<section class="recipes-panel"><h3>Inventory status</h3>{% for group in analysis.groups %}<div class="recipes-stock-group"><div><strong>{{ group.product.product_name }}</strong><span class="recipes-stock-label recipes-stock-label--{{ group.status }}">{{ group.status|capfirst }}</span></div><small>{% if group.plan %}{{ group.plan.total|floatformat:-3 }} / {{ group.stock_amount|floatformat:-3 }} {{ group.unit }} available{% else %}Unit conversion needed{% endif %}</small><div class="recipes-fill" role="progressbar" aria-label="{{ group.product.product_name }} available for recipe" aria-valuenow="{{ group.percent }}" aria-valuemin="0" aria-valuemax="100"><span style="width:{{ group.percent }}%"></span></div></div>{% empty %}<p class="recipes-muted">Match ingredients to products to check stock.</p>{% endfor %}<a class="recipes-outline-button recipes-preview-link" href="{% url 'recipes:stock-preview' selected.api_id %}?servings={{ analysis.servings }}{% if analysis.include_optional %}&optional=1{% endif %}">Review stock and deductions</a></section>
{% if selected.parent or selected.variations.all or selected.subrecipes.all %}<section class="recipes-panel"><h3>Related recipes</h3>{% if selected.parent %}<p>Variation of <a href="{% url 'recipes:detail' selected.parent.api_id %}">{{ selected.parent.title }}</a></p>{% endif %}{% for variation in selected.variations.all %}<p><a href="{% url 'recipes:detail' variation.api_id %}">{{ variation.title }}</a></p>{% endfor %}{% for item in selected.subrecipes.all %}<div class="recipes-related-component"><p>{{ item.quantity|floatformat:-3 }} {{ item.unit }} of <a href="{% url 'recipes:detail' item.component.api_id %}">{{ item.component.title }}</a></p>{% if item.component.instructions_markdown %}<details><summary>Show {{ item.component.title }} instructions</summary><div class="recipes-markdown-source">{{ item.component.instructions_markdown|recipe_markdown }}</div></details>{% endif %}</div>{% endfor %}</section>{% endif %}
<section class="recipes-panel"><h3>Actions</h3><a class="recipes-action" href="{% url 'recipes:edit' selected.api_id %}">Edit recipe</a><form method="post" action="{% url 'recipes:create-variation' selected.api_id %}" class="recipes-action-form">{% csrf_token %}<button type="submit" class="recipes-action">Create variation</button></form><a class="recipes-action recipes-action--danger" href="{% url 'recipes:delete' selected.api_id %}">Delete recipe</a></section>
<section class="recipes-panel"><h3>Actions</h3><a class="recipes-action" href="{% url 'recipes:edit' selected.api_id %}">Edit recipe</a><form method="post" action="{% url 'recipes:create-variation' selected.api_id %}" class="recipes-action-form">{% csrf_token %}<button type="submit" class="recipes-action">Create variation</button></form>{% if last_use %}<form method="post" action="{% url 'recipes:stock-undo' last_use.pk %}" class="recipes-action-form">{% csrf_token %}<button type="submit" class="recipes-action">Undo last inventory use</button></form>{% endif %}<a class="recipes-action recipes-action--danger" href="{% url 'recipes:delete' selected.api_id %}">Delete recipe</a></section>
</aside>{% endif %}
</div>
{% endblock %}
@@ -0,0 +1,12 @@
{% extends 'planner/base.html' %}{% load static %}
{% block title %}Review stock · {{ recipe.title }} · Tasknest{% endblock %}
{% block page_class %}recipes-page-content{% endblock %}
{% block content %}<link rel="stylesheet" href="{% static 'recipes/recipes.css' %}?v=4">
<div class="recipes-layout recipes-layout--form recipes-stock-preview">
<header class="recipes-form-header"><a href="{% url 'recipes:detail' recipe.api_id %}">← Back to {{ recipe.title }}</a><h1>Review inventory use</h1><p>Stock changes only after you confirm below.</p></header>
{% if error %}<p class="recipes-form-error" role="alert">{{ error }}</p>{% endif %}
<section class="recipes-panel"><h2>Recipe amounts</h2><form method="get" class="recipes-preview-options"><label>Servings<input type="number" name="servings" min="0.01" max="99999.99" step="0.01" value="{{ analysis.servings|floatformat:-2 }}"></label><label class="recipes-checkbox"><input type="checkbox" name="optional" value="1"{% if analysis.include_optional %} checked{% endif %}> Include optional ingredients</label><div class="recipes-preview-choices">{% for line in analysis.lines %}{% if line.substitutions %}<label>{{ line.name }} alternative<select name="sub_{{ line.ingredient.pk }}"><option value="">Original ingredient</option>{% for alternative in line.substitutions %}<option value="{{ alternative.pk }}"{% if line.selected_substitution == alternative.pk|stringformat:'s' %} selected{% endif %}>{{ alternative.name }} · {{ alternative.quantity|floatformat:-3 }} {{ alternative.unit }}</option>{% endfor %}</select></label>{% endif %}{% endfor %}</div><button type="submit" class="recipes-outline-button">Update preview</button></form></section>
<section class="recipes-panel"><h2>Ingredient checks</h2><ul class="recipes-ingredient-list">{% for line in analysis.lines %}<li><span>{{ line.name }}{% if line.source %}<small>From {{ line.source }}</small>{% endif %}<small class="recipes-stock-label recipes-stock-label--{{ line.status }}">{{ line.status|capfirst }}{% if line.reason %}: {{ line.reason }}{% endif %}</small>{% if line.ingredient.pk %}<small><a href="{% url 'recipes:substitution-add' line.ingredient.recipe.api_id line.ingredient.pk %}">Add a substitute</a></small>{% endif %}</span><strong>{{ line.quantity|floatformat:-3 }} {{ line.unit }}</strong></li>{% empty %}<li>No ingredients added yet.</li>{% endfor %}</ul><p><a href="{% url 'recipes:edit' recipe.api_id %}">Edit ingredient quantities and product matches</a></p></section>
<section class="recipes-panel"><h2>Package deductions</h2>{% if analysis.issues %}<ul class="recipes-preview-issues">{% for issue in analysis.issues %}<li>{{ issue }}</li>{% endfor %}</ul>{% endif %}{% for group in analysis.groups %}<div class="recipes-preview-group"><h3>{{ group.product.product_name }} <span class="recipes-stock-label recipes-stock-label--{{ group.status }}">{{ group.status|capfirst }}</span></h3><p>{{ group.stock_amount|floatformat:-3 }} {{ group.unit }} needed{% if group.plan %} · {{ group.plan.total|floatformat:-3 }} {{ group.unit }} available{% if group.plan.shortage %} · {{ group.plan.shortage|floatformat:-3 }} {{ group.unit }} missing{% endif %}{% endif %}</p>{% if group.plan %}{% for deduction in group.plan.deductions %}<div class="recipes-package"><div class="recipes-package__heading"><strong>Package {{ deduction.package.api_id|stringformat:'s'|slice:':8' }}</strong><span>{{ deduction.before|floatformat:-3 }} → {{ deduction.after|floatformat:-3 }} {{ deduction.unit }}</span></div><small>Use {{ deduction.amount|floatformat:-3 }} {{ deduction.unit }}{% if deduction.package.best_before %} · Best before {{ deduction.package.best_before }}{% endif %}</small><div class="recipes-fill" role="progressbar" aria-label="Package remaining after use" aria-valuenow="{{ deduction.after_percent }}" aria-valuemin="0" aria-valuemax="100"><span style="width:{{ deduction.after_percent }}%"></span></div></div>{% empty %}<p class="recipes-muted">No compatible packages.</p>{% endfor %}{% endif %}</div>{% empty %}<p class="recipes-muted">Match ingredients to inventory products to see a package plan.</p>{% endfor %}</section>
<section class="recipes-panel recipes-preview-confirm"><h2>Confirm inventory use</h2>{% if confirmation %}<p>This deducts the listed amounts from Kitchen Inventory. It does not log food in your diary.</p><form method="post" action="{% url 'recipes:stock-confirm' recipe.api_id %}">{% csrf_token %}<input type="hidden" name="confirmation" value="{{ confirmation }}"><button class="button" type="submit">Confirm and deduct stock</button></form>{% else %}<p>Resolve missing stock or unknown matches, then update the preview before confirming.</p>{% endif %}</section>
</div>{% endblock %}
@@ -0,0 +1,4 @@
{% extends 'planner/base.html' %}{% load static %}
{% block title %}Add substitute · {{ ingredient.name }} · Tasknest{% endblock %}
{% block page_class %}recipes-page-content{% endblock %}
{% block content %}<link rel="stylesheet" href="{% static 'recipes/recipes.css' %}?v=4"><div class="recipes-layout recipes-layout--form"><header class="recipes-form-header"><a href="{% url 'recipes:edit' recipe.api_id %}">← Back to recipe editor</a><h1>Substitutes for {{ ingredient.name }}</h1><p>Alternative quantities are measured for the recipe’s default servings.</p></header><form method="post" class="recipes-edit-card">{% csrf_token %}<section><h2>Add substitute</h2><div class="recipes-form-grid">{% for field in form %}<div class="recipes-field"><label for="{{ field.id_for_label }}">{{ field.label }}</label>{{ field }}{% if field.errors %}<div class="recipes-form-error" role="alert">{{ field.errors }}</div>{% endif %}</div>{% endfor %}</div></section><div class="recipes-form-actions"><button type="submit" class="button">Add substitute</button></div></form>{% if ingredient.substitutions.all %}<section class="recipes-panel recipes-substitution-list"><h2>Existing substitutes</h2>{% for item in ingredient.substitutions.all %}<div><span>{{ item.name }} · {{ item.quantity|floatformat:-3 }} {{ item.unit }}</span><form method="post" action="{% url 'recipes:substitution-delete' recipe.api_id ingredient.pk item.pk %}">{% csrf_token %}<button type="submit" class="recipes-outline-button">Remove</button></form></div>{% endfor %}</section>{% endif %}</div>{% endblock %}