50 lines
4.9 KiB
HTML
50 lines
4.9 KiB
HTML
{% load static %}
|
|
<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 %}
|
|
<div class="food-detail-title"><h2>{{ product.product_name }}</h2>{% include "food/partials/favourite_button.html" with is_favourite=product.is_favourite %}</div>
|
|
{% 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>
|
|
{% if product.source == 'openfoodfacts' %}<p class="food-attribution">Product data from <a href="https://world.openfoodfacts.org/product/{{ product.barcode }}" rel="noopener noreferrer">Open Food Facts</a>.</p>{% endif %}
|
|
</section>
|
|
<form method="post" class="food-card" hx-post="{% url 'food:add' %}" hx-target="#food-workspace" hx-swap="outerHTML">
|
|
{% csrf_token %}<input type="hidden" name="date" value="{{ day|date:'Y-m-d' }}"><input type="hidden" name="product" value="{{ product.pk }}">
|
|
{% include 'food/partials/portion_fields.html' %}
|
|
<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 }}"><input type="hidden" name="tab" value="{{ tab }}">
|
|
<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>
|
|
<nav class="food-tabs" aria-label="Local food lists">
|
|
<a {% if tab == 'overview' %}aria-current="page"{% endif %} href="{% url 'food:add' %}?date={{ day|date:'Y-m-d' }}&meal={{ meal }}&tab=overview">For you</a>
|
|
<a {% if tab == 'recent' %}aria-current="page"{% endif %} href="{% url 'food:add' %}?date={{ day|date:'Y-m-d' }}&meal={{ meal }}&tab=recent&q={{ query|urlencode }}">Recent</a>
|
|
<a {% if tab == 'favourites' %}aria-current="page"{% endif %} href="{% url 'food:add' %}?date={{ day|date:'Y-m-d' }}&meal={{ meal }}&tab=favourites&q={{ query|urlencode }}">Favourites</a>
|
|
<a {% if tab == 'mine' %}aria-current="page"{% endif %} href="{% url 'food:add' %}?date={{ day|date:'Y-m-d' }}&meal={{ meal }}&tab=mine&q={{ query|urlencode }}">My foods</a>
|
|
</nav>
|
|
{% if tab == 'overview' and not query %}
|
|
<div id="food-favourites-list"><h2>Favourites</h2>{% include 'food/partials/product_list.html' with products=favourites %}</div>
|
|
<div id="food-recents-list"><h2>Recent</h2>{% include 'food/partials/product_list.html' with products=recents %}</div>
|
|
{% else %}{% include 'food/partials/product_list.html' with products=products %}{% endif %}
|
|
<div class="food-actions"><a class="button" href="{% url 'food:manual' %}?date={{ day|date:'Y-m-d' }}&meal={{ meal }}">Create a food manually</a>
|
|
<a class="button" href="{% url 'food:scanner' %}?date={{ day|date:'Y-m-d' }}&meal={{ meal }}">Scan barcode</a>
|
|
<a class="button button--secondary" href="{% url 'food:external-search' %}?date={{ day|date:'Y-m-d' }}&meal={{ meal }}&q={{ query|urlencode }}">Search Open Food Facts</a></div>
|
|
<form method="post" action="{% url 'food:import-product' %}" class="food-barcode-form">{% csrf_token %}<input type="hidden" name="date" value="{{ day|date:'Y-m-d' }}"><input type="hidden" name="meal" value="{{ meal }}"><label for="food-barcode">Barcode</label><input id="food-barcode" name="barcode" inputmode="numeric" pattern="[0-9]+" required><button class="button button--secondary" type="submit">Look up barcode</button></form>
|
|
<p class="food-attribution">External product data from <a href="https://world.openfoodfacts.org/" rel="noopener noreferrer">Open Food Facts</a>.</p>
|
|
{% endif %}
|
|
</div>
|
|
{% if product %}<script src="{% static 'food/portions.js' %}" defer></script>{% endif %}
|
|
{% if not product %}<nav class="food-mobile-switch" aria-label="Add food method"><span aria-current="page">Search</span><a href="{% url 'food:scanner' %}?date={{ day|date:'Y-m-d' }}&meal={{ meal }}">Barcode</a></nav>{% endif %}
|