adding food logging, phase 2

This commit is contained in:
Joren de Graaf
2026-10-03 20:47:32 +02:00
parent 761cb180c5
commit fca2ef2acd
11 changed files with 294 additions and 12 deletions
+3
View File
@@ -0,0 +1,3 @@
{% extends 'planner/base.html' %}{% load static %}
{% block title %}Add food · Tasknest{% endblock %}
{% block content %}<link rel="stylesheet" href="{% static 'food/food.css' %}"><div id="food-workspace" class="food-form-page"><a href="{% url 'food:diary' %}?date={{ day|date:'Y-m-d' }}">← Back to diary</a><h1>Add food</h1>{% if product %}<section class="food-card">{% if product.image_url %}<img class="food-product-image" src="{{ product.image_url }}" alt="" loading="lazy">{% endif %}<h2>{{ product.product_name }}</h2>{% if product.brand %}<p>{{ product.brand }}</p>{% endif %}<p>Per 100 {{ product.base_unit }}: {% if product.energy_kcal_100 is not None %}{{ product.energy_kcal_100|floatformat:0 }} kcal{% else %}— kcal{% endif %}</p><details><summary>Nutrition information</summary><dl><dt>Carbohydrates</dt><dd>{{ product.carbohydrates_100|default_if_none:'—' }} g</dd><dt>Protein</dt><dd>{{ product.protein_100|default_if_none:'—' }} g</dd><dt>Fat</dt><dd>{{ product.fat_100|default_if_none:'—' }} g</dd><dt>Sugars</dt><dd>{{ product.sugars_100|default_if_none:'—' }} g</dd><dt>Fibre</dt><dd>{{ product.fibre_100|default_if_none:'—' }} g</dd><dt>Salt</dt><dd>{{ product.salt_100|default_if_none:'—' }} g</dd></dl></details></section><form method="post" class="food-card" hx-post="{% url 'food:add' %}" hx-target="#food-workspace" hx-push-url="{% url 'food:diary' %}?date={{ day|date:'Y-m-d' }}" hx-swap="outerHTML">{% csrf_token %}<input type="hidden" name="date" value="{{ day|date:'Y-m-d' }}"><input type="hidden" name="product" value="{{ product.pk }}">{% for field in form %}<div class="form-field">{{ field.label_tag }}{{ field }}{{ field.errors }}</div>{% endfor %}<button class="button" type="submit">Log food</button></form>{% else %}<form method="get" class="food-search"><input type="hidden" name="date" value="{{ day|date:'Y-m-d' }}"><input type="hidden" name="meal" value="{{ meal }}"><label for="food-query">Search your foods</label><input id="food-query" name="q" value="{{ query }}" type="search"><button class="button" type="submit">Search</button></form><ul class="food-product-list">{% for item in products %}<li><a href="{% url 'food:add' %}?date={{ day|date:'Y-m-d' }}&amp;meal={{ meal }}&amp;product={{ item.pk }}">{{ item.product_name }}{% if item.brand %} · {{ item.brand }}{% endif %}</a></li>{% empty %}<li>No local foods yet.</li>{% endfor %}</ul><a class="button" href="{% url 'food:manual' %}?date={{ day|date:'Y-m-d' }}&amp;meal={{ meal }}">Create a food manually</a>{% endif %}</div>{% endblock %}
+3 -9
View File
@@ -1,13 +1,7 @@
{% extends 'planner/base.html' %}
{% load static %}
{% block title %}Food · Tasknest{% endblock %}
{% block content %}
<section class="planner-hero" aria-labelledby="food-heading">
<div>
<p class="eyebrow">Food</p>
<h1 id="food-heading">Food diary</h1>
<p>Food logging is coming soon.</p>
</div>
</section>
<link rel="stylesheet" href="{% static 'food/food.css' %}">
{% include 'food/partials/diary_content.html' %}
{% endblock %}
+3
View File
@@ -0,0 +1,3 @@
{% extends 'planner/base.html' %}{% load static %}
{% block title %}Edit food log · Tasknest{% endblock %}
{% block content %}<link rel="stylesheet" href="{% static 'food/food.css' %}"><div id="food-workspace" class="food-form-page"><a href="{% url 'food:diary' %}?date={{ entry.date|date:'Y-m-d' }}">← Back to diary</a><h1>{{ entry.product_name_snapshot }}</h1>{% if entry.brand_snapshot %}<p>{{ entry.brand_snapshot }}</p>{% endif %}<div class="food-card"><p>{% if entry.calories_kcal is not None %}{{ entry.calories_kcal|floatformat:0 }} kcal{% else %}— kcal{% endif %} · {{ entry.carbohydrates_g|default_if_none:'—' }} g carbs · {{ entry.protein_g|default_if_none:'—' }} g protein · {{ entry.fat_g|default_if_none:'—' }} g fat</p><details><summary>Nutrition information</summary><dl><dt>Fibre</dt><dd>{{ entry.fibre_g|default_if_none:'—' }} g</dd><dt>Sugars</dt><dd>{{ entry.sugars_g|default_if_none:'—' }} g</dd><dt>Salt</dt><dd>{{ entry.salt_g|default_if_none:'—' }} g</dd></dl></details></div><form method="post" class="food-card" hx-post="{% url 'food:edit' entry.pk %}" hx-target="#food-workspace" hx-swap="outerHTML" hx-push-url="{% url 'food:diary' %}?date={{ entry.date|date:'Y-m-d' }}">{% csrf_token %}{% for field in form %}<div class="form-field">{{ field.label_tag }}{{ field }}{{ field.errors }}</div>{% endfor %}<button class="button" type="submit">Save changes</button></form><form method="post" action="{% url 'food:delete' entry.pk %}" onsubmit="return confirm('Delete this food entry?')" hx-post="{% url 'food:delete' entry.pk %}" hx-target="#food-workspace" hx-swap="outerHTML" hx-push-url="{% url 'food:diary' %}?date={{ entry.date|date:'Y-m-d' }}">{% csrf_token %}<button type="submit" class="button button--secondary">Delete entry</button></form></div>{% endblock %}
+3
View File
@@ -0,0 +1,3 @@
{% extends 'planner/base.html' %}{% load static %}
{% block title %}Create food · Tasknest{% endblock %}
{% block content %}<link rel="stylesheet" href="{% static 'food/food.css' %}"><div class="food-form-page"><a href="{% url 'food:add' %}?date={{ day|date:'Y-m-d' }}&amp;meal={{ meal }}">← Back to foods</a><h1>Create a food</h1><p>Enter nutrition per 100 g or 100 ml. Missing optional values stay unknown.</p><form method="post" class="food-card">{% csrf_token %}<input type="hidden" name="date" value="{{ day|date:'Y-m-d' }}"><input type="hidden" name="meal" value="{{ meal }}">{% for field in form %}<div class="form-field">{{ field.label_tag }}{{ field }}{{ field.errors }}</div>{% endfor %}<button class="button" type="submit">Save food</button></form></div>{% endblock %}
@@ -0,0 +1,19 @@
<div id="food-workspace" class="food-page"><div id="food-diary">
<header class="food-heading"><div><p class="eyebrow">Food diary</p><h1>{{ day|date:"l j F Y" }}</h1></div><nav aria-label="Diary dates"><a href="{% url 'food:diary' %}?date={{ previous_day|date:'Y-m-d' }}" aria-label="Previous day">←</a><a href="{% url 'food:diary' %}">Today</a><a href="{% url 'food:diary' %}?date={{ next_day|date:'Y-m-d' }}" aria-label="Next day">→</a></nav></header>
<div class="food-layout">
<div class="food-meals">
{% for meal in meals %}
<section class="food-meal" id="meal-{{ meal.key }}" aria-labelledby="meal-title-{{ meal.key }}">
<div class="food-meal-heading"><div><h2 id="meal-title-{{ meal.key }}">{{ meal.label }}</h2><p>{{ meal.calories|floatformat:0 }} kcal</p></div><a class="food-add-meal" href="{% url 'food:add' %}?date={{ day|date:'Y-m-d' }}&amp;meal={{ meal.key }}" aria-label="Add food to {{ meal.label }}">+</a></div>
{% if meal.entries %}<ul class="food-entry-list">{% for entry in meal.entries %}<li class="food-entry"><div class="food-entry-main">{% if entry.product and entry.product.image_url %}<img src="{{ entry.product.image_url }}" alt="" loading="lazy">{% endif %}<div><strong>{{ entry.product_name_snapshot }}</strong>{% if entry.brand_snapshot %}<span>{{ entry.brand_snapshot }}</span>{% endif %}<small>{% if entry.calories_kcal is not None %}{{ entry.calories_kcal|floatformat:0 }} kcal{% else %}— kcal{% endif %} · {% if entry.portion_label_snapshot %}{{ entry.portion_label_snapshot }} {% endif %}({{ entry.amount|floatformat:-3 }} {{ entry.unit }})</small></div></div><a href="{% url 'food:edit' entry.pk %}" aria-label="Edit {{ entry.product_name_snapshot }}">Edit</a></li>{% endfor %}</ul>{% else %}<p class="food-empty">Nothing logged yet.</p>{% endif %}
</section>
{% endfor %}
<a class="button" href="{% url 'food:add' %}?date={{ day|date:'Y-m-d' }}">Add food</a>
</div>
<aside class="food-sidebar" aria-label="Daily nutrition summary">
<section class="food-card" id="food-summary"><h2>Calories</h2>{% if calorie_goal is not None %}<p class="food-remaining">{% if calorie_remaining < 0 %}{{ calorie_remaining|floatformat:0|cut:'-' }} kcal over goal{% else %}{{ calorie_remaining|floatformat:0 }} kcal remaining{% endif %}</p><div class="food-progress" role="progressbar" aria-label="Calories eaten" aria-valuenow="{{ totals.calories_kcal|floatformat:0 }}" aria-valuemin="0" aria-valuemax="{{ calorie_goal }}"><span style="width:{{ calorie_percent }}%"></span></div><p>{{ totals.calories_kcal|floatformat:0 }} kcal eaten · Goal: {{ calorie_goal }} kcal</p>{% else %}<p class="food-remaining">{{ totals.calories_kcal|floatformat:0 }} kcal eaten</p><p>No calorie goal. <a href="{% url 'planner:user-settings' %}">Set one in Settings</a>.</p>{% endif %}</section>
<section class="food-macros" id="food-macro-summary" aria-label="Macronutrients">{% for macro in macros %}<article class="food-card food-macro food-macro--{{ macro.color }}"><div class="food-ring" {% if macro.percent is not None %}style="--progress:{{ macro.percent }}%"{% endif %}><span>{% if macro.percent is not None %}{{ macro.percent }}%{% else %}—{% endif %}</span></div><div><h3>{{ macro.label }}</h3><p>{{ macro.eaten|floatformat:1 }} g eaten</p>{% if macro.goal is not None %}<p>{% if macro.remaining < 0 %}{{ macro.remaining|floatformat:1|cut:'-' }} g over target{% else %}{{ macro.remaining|floatformat:1 }} g remaining{% endif %}</p>{% else %}<p>No target</p>{% endif %}</div></article>{% endfor %}</section>
</aside>
</div>
</div>
</div>