Recipes phase 2

This commit is contained in:
Joren de Graaf
2026-10-12 01:53:21 +02:00
parent 500f72382a
commit 13cd65622e
18 changed files with 618 additions and 45 deletions
+7 -5
View File
@@ -1,11 +1,13 @@
{% 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/recipes.css' %}">
{% block content %}<link rel="stylesheet" href="{% static 'recipes/vendor/toastui-editor.min.css' %}"><link rel="stylesheet" href="{% static 'recipes/recipes.css' %}?v=3">
<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>{% csrf_token %}
<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 %}
{% if form.non_field_errors %}<div class="recipes-form-error" role="alert">{{ form.non_field_errors }}</div>{% endif %}
<section><h2>Recipe details</h2><div class="recipes-form-grid">{% for field in form %}{% if field.name != 'remove_photo' %}<div class="recipes-field recipes-field--{{ field.name }}"><label for="{{ field.id_for_label }}">{{ field.label }}</label>{{ field }}{% if field.help_text %}<small>{{ field.help_text }}</small>{% endif %}{% if field.errors %}<div class="recipes-form-error" role="alert">{{ field.errors }}</div>{% endif %}</div>{% endif %}{% endfor %}{% if recipe.photo %}<div class="recipes-field recipes-field--remove_photo"><img src="{% url 'recipes:photo' recipe.api_id %}" alt="Current recipe photo" class="recipes-current-photo"><label class="recipes-checkbox">{{ form.remove_photo }} Remove current photo</label></div>{% endif %}</div></section>
<section><h2>Recipe details</h2><div class="recipes-form-grid">{% for field in form %}{% if field.name == 'markdown_revision' %}{{ field }}{% elif field.name != 'remove_photo' %}<div class="recipes-field recipes-field--{{ field.name }}"><label for="{{ field.id_for_label }}">{{ field.label }}</label>{{ field }}{% if field.name == 'instructions_markdown' or field.name == 'notes_markdown' %}<div class="recipes-markdown-editor" data-markdown-editor="{{ field.name }}" aria-label="{{ field.label }} editor"></div>{% endif %}{% if field.help_text %}<small>{{ field.help_text }}</small>{% endif %}{% if field.errors %}<div class="recipes-form-error" role="alert">{{ field.errors }}</div>{% endif %}</div>{% endif %}{% endfor %}{% if recipe.photo %}<div class="recipes-field recipes-field--remove_photo"><img src="{% url 'recipes:photo' recipe.api_id %}" alt="Current recipe photo" class="recipes-current-photo"><label class="recipes-checkbox">{{ form.remove_photo }} Remove current photo</label></div>{% endif %}</div></section>
<section><div class="recipes-section-heading"><div><h2>Ingredients</h2><p>Add measured ingredients now; product matching can be refined later.</p></div><button type="button" class="recipes-outline-button" data-add-ingredient>+ Add ingredient</button></div>{{ ingredients.management_form }}{% if ingredients.non_form_errors %}<div class="recipes-form-error" role="alert">{{ ingredients.non_form_errors }}</div>{% endif %}<div class="recipes-ingredient-forms" data-ingredient-forms>{% for ingredient in ingredients %}{% include 'recipes/ingredient_row.html' %}{% endfor %}</div><template id="recipe-empty-ingredient">{% with ingredient=ingredients.empty_form %}{% include 'recipes/ingredient_row.html' %}{% endwith %}</template></section>
<div class="recipes-form-actions"><button type="submit" class="button">Save recipe</button><a href="{% if creating %}{% url 'recipes:list' %}{% else %}{% url 'recipes:detail' recipe.api_id %}{% endif %}">Cancel</a></div>
</form></div><script defer src="{% static 'recipes/form.js' %}"></script>{% endblock %}
<section><div class="recipes-section-heading"><div><h2>Subrecipes</h2><p>Include an independently editable recipe as a component.</p></div><button type="button" class="recipes-outline-button" data-add-subrecipe>+ Add subrecipe</button></div>{{ subrecipes.management_form }}{% if subrecipes.non_form_errors %}<div class="recipes-form-error" role="alert">{{ subrecipes.non_form_errors }}</div>{% endif %}<div class="recipes-ingredient-forms" data-subrecipe-forms>{% for subrecipe in subrecipes %}{% include 'recipes/subrecipe_row.html' %}{% endfor %}</div><template id="recipe-empty-subrecipe">{% with subrecipe=subrecipes.empty_form %}{% include 'recipes/subrecipe_row.html' %}{% endwith %}</template></section>
<div class="recipes-form-actions"><button type="submit" class="button">Save recipe</button><a href="{% if creating %}{% url 'recipes:list' %}{% else %}{% url 'recipes:detail' recipe.api_id %}{% endif %}">Cancel</a><span class="recipes-save-status" data-save-status role="status" aria-live="polite">{% if creating %}Add a title to start autosave.{% else %}Saved{% endif %}</span></div>
</form></div><script defer src="{% static 'recipes/vendor/toastui-editor-all.min.js' %}"></script><script defer src="{% static 'recipes/editor-adapter.js' %}?v=4"></script><script defer src="{% static 'recipes/form.js' %}?v=5"></script>{% endblock %}
+5 -5
View File
@@ -1,8 +1,8 @@
{% extends 'planner/base.html' %}{% load static %}
{% extends 'planner/base.html' %}{% load static recipe_markdown %}
{% block title %}Recipes · Tasknest{% endblock %}
{% block page_class %}recipes-page-content{% endblock %}
{% block content %}
<link rel="stylesheet" href="{% static 'recipes/recipes.css' %}">
<link rel="stylesheet" href="{% static 'recipes/recipes.css' %}?v=3">
<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">
@@ -41,7 +41,7 @@
</div>
<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>
<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|linebreaksbr }}</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|linebreaksbr }}</div></section>{% endif %}</div>
<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 %}
<div class="recipes-empty-detail"><h2>Make room for something delicious.</h2><p>Save a recipe to see its ingredients and instructions here.</p><a class="button" href="{% url 'recipes:create' %}">Create your first recipe</a></div>
@@ -50,8 +50,8 @@
{% 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>
{% 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 %}<p>{{ item.quantity|floatformat:-3 }} {{ item.unit }} of <a href="{% url 'recipes:detail' item.component.api_id %}">{{ item.component.title }}</a></p>{% endfor %}</section>{% endif %}
<section class="recipes-panel"><h3>Actions</h3><a class="recipes-action" href="{% url 'recipes:edit' selected.api_id %}">Edit recipe</a><a class="recipes-action recipes-action--danger" href="{% url 'recipes:delete' selected.api_id %}">Delete recipe</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>
</aside>{% endif %}
</div>
{% endblock %}
@@ -0,0 +1 @@
<div class="recipes-ingredient-form"><div class="recipes-ingredient-form__main"><div class="recipes-field"><label for="{{ subrecipe.component.id_for_label }}">Component recipe</label>{{ subrecipe.component }}{{ subrecipe.id }}{% if subrecipe.component.errors %}<div class="recipes-form-error" role="alert">{{ subrecipe.component.errors }}</div>{% endif %}</div><div class="recipes-field"><label for="{{ subrecipe.quantity.id_for_label }}">Quantity</label>{{ subrecipe.quantity }}{% if subrecipe.quantity.errors %}<div class="recipes-form-error" role="alert">{{ subrecipe.quantity.errors }}</div>{% endif %}</div><div class="recipes-field"><label for="{{ subrecipe.unit.id_for_label }}">Unit</label>{{ subrecipe.unit }}{% if subrecipe.unit.errors %}<div class="recipes-form-error" role="alert">{{ subrecipe.unit.errors }}</div>{% endif %}</div></div><details class="recipes-ingredient-form__more"><summary>More options</summary><div class="recipes-form-grid"><div class="recipes-field"><label for="{{ subrecipe.note.id_for_label }}">Note</label>{{ subrecipe.note }}</div><div class="recipes-field"><label for="{{ subrecipe.display_order.id_for_label }}">Order</label>{{ subrecipe.display_order }}</div>{% if subrecipe.DELETE %}<div class="recipes-field"><label class="recipes-checkbox">{{ subrecipe.DELETE }} Remove component</label></div>{% endif %}</div></details>{% if subrecipe.non_field_errors %}<div class="recipes-form-error" role="alert">{{ subrecipe.non_field_errors }}</div>{% endif %}</div>