Live refresh inventory scan review counts

This commit is contained in:
Joren de Graaf
2026-10-26 20:21:53 +01:00
parent 7d9beb915f
commit 129ceec408
6 changed files with 137 additions and 9 deletions
@@ -1,8 +1,8 @@
{% extends 'planner/base.html' %}{% load static %}
{% block title %}Kitchen Inventory · Tasknest{% endblock %}
{% block content %}<link rel="stylesheet" href="{% static 'food/food.css' %}?v=20261026-review-1">
{% block content %}<link rel="stylesheet" href="{% static 'food/food.css' %}?v=20261026-review-2">
<div class="food-page inventory-page"><header class="food-heading"><div><h1>Kitchen Inventory</h1><p>What you have and where it lives.</p></div><div class="inventory-heading-actions"><a class="button" href="{% url 'food:inventory-add' %}">+ Add item</a><a class="button button--secondary" href="{% url 'food:scanner' %}?mode=inventory">Scan barcode</a></div></header>
<section class="food-card inventory-staging" id="inventory-review" aria-labelledby="inventory-staging-title"><div class="inventory-staging-top"><div><p class="inventory-kicker">Bulk scanner</p><h2 id="inventory-staging-title">Staged scan items</h2><p>Track background enrichment and finish products that need your input.</p></div><a class="button" href="{% url 'food:inventory-review' %}">Open review</a></div><div class="inventory-staging-counts"><a href="{% url 'food:inventory-review' %}?state=processing"><strong>{{ processing_count }}</strong><span>Processing</span></a><a href="{% url 'food:inventory-review' %}"><strong>{{ needs_review_count }}</strong><span>Needs Review</span></a></div><form method="post" action="{% url 'food:inventory-review' %}" class="inventory-review-mode">{% csrf_token %}<input type="hidden" name="action" value="mode"><span>Review mode</span><button name="mode" value="individual" aria-pressed="{% if review_mode == 'individual' %}true{% else %}false{% endif %}" class="{% if review_mode == 'individual' %}is-selected{% endif %}">Individual</button><button name="mode" value="bulk" aria-pressed="{% if review_mode == 'bulk' %}true{% else %}false{% endif %}" class="{% if review_mode == 'bulk' %}is-selected{% endif %}">Bulk review</button></form></section>
<section class="food-card inventory-staging" id="inventory-review" aria-labelledby="inventory-staging-title"><div class="inventory-staging-top"><div><p class="inventory-kicker">Bulk scanner</p><h2 id="inventory-staging-title">Staged scan items</h2><p>Track background enrichment and finish products that need your input.</p></div><a class="button" href="{% url 'food:inventory-review' %}">Open review</a></div>{% include 'food/partials/inventory_staging_counts.html' %}<form method="post" action="{% url 'food:inventory-review' %}" class="inventory-review-mode">{% csrf_token %}<input type="hidden" name="action" value="mode"><span>Review mode</span><button name="mode" value="individual" aria-pressed="{% if review_mode == 'individual' %}true{% else %}false{% endif %}" class="{% if review_mode == 'individual' %}is-selected{% endif %}">Individual</button><button name="mode" value="bulk" aria-pressed="{% if review_mode == 'bulk' %}true{% else %}false{% endif %}" class="{% if review_mode == 'bulk' %}is-selected{% endif %}">Bulk review</button></form></section>
<form method="get" class="food-card inventory-filters" role="search" aria-label="Search kitchen inventory">
<div class="inventory-filter-search"><label for="inventory-search">Search inventory</label><div><input id="inventory-search" type="search" name="q" value="{{ query }}"><button class="button" type="submit">Search</button></div></div>
<details class="inventory-filter-details" data-responsive-filters open><summary>More filters{% if selected_location or selected_category or opened or use_soon == '1' or sort != 'location' %} · Applied{% endif %}</summary><div class="inventory-filter-options"><label>Location<select name="location"><option value="">All locations</option>{% for location in locations %}<option value="{{ location.pk }}" {% if selected_location == location.pk|stringformat:'s' %}selected{% endif %}>{{ location.name }}</option>{% endfor %}</select></label><label>Category<select name="category"><option value="">All categories</option>{% for category in categories %}<option value="{{ category.pk }}" {% if selected_category == category.pk|stringformat:'s' %}selected{% endif %}>{{ category.name }}</option>{% endfor %}</select></label><label>Opened<select name="opened"><option value="">All</option><option value="yes" {% if opened == 'yes' %}selected{% endif %}>Opened</option><option value="no" {% if opened == 'no' %}selected{% endif %}>Unopened</option></select></label><label>Sort<select name="sort"><option value="location" {% if sort == 'location' %}selected{% endif %}>Location</option><option value="category" {% if sort == 'category' %}selected{% endif %}>Category</option><option value="name" {% if sort == 'name' %}selected{% endif %}>Product name</option><option value="recent" {% if sort == 'recent' %}selected{% endif %}>Recently added</option><option value="best_before" {% if sort == 'best_before' %}selected{% endif %}>Best before</option></select></label><label class="inventory-check"><input type="checkbox" name="use_soon" value="1" {% if use_soon == '1' %}checked{% endif %}> Use soon</label><button class="button" type="submit">Apply filters</button></div></details>
@@ -0,0 +1,7 @@
<div class="inventory-staging-counts" id="inventory-staging-counts"
hx-get="{% url 'food:inventory-staging-counts' %}"
hx-trigger="load, every 5s" hx-swap="outerHTML"
aria-live="polite" aria-atomic="true">
<a href="{% url 'food:inventory-review' %}?state=processing"><strong>{{ processing_count }}</strong><span>Processing</span></a>
<a href="{% url 'food:inventory-review' %}"><strong>{{ needs_review_count }}</strong><span>Needs Review</span></a>
</div>