Remove manual food item addition and barcode scanning

Deleted routes and templates related to manual food item entry and barcode scanning, including add_food_item, add_food_item_manual, food_item, log_food, and related session-based selection routes. Updated navigation in base.html to remove links to these features and added links to overview, daily log, and dashboard. Simplified daily_log.html to format log amounts, and removed unused imports and forms from routes.py.
This commit is contained in:
2025-08-07 17:09:47 +02:00
parent c552a4571e
commit b282f333fd
8 changed files with 11 additions and 395 deletions

View File

@@ -1,49 +0,0 @@
{% extends "base.html" %}
{% block content %}
<form method="POST">
{{ form.hidden_tag() }}
<div class="mb-3">
{{ form.barcode.label(class="form-label") }}
{{ form.barcode(class="form-control-plaintext", readonly=true) }}
</div>
<div class="mb-3">
{{ form.name.label(class="form-label") }}
{{ form.name(class="form-control") }}
</div>
<div class="mb-3">
{{ form.energy.label(class="form-label") }}
{{ form.energy(class="form-control") }}
</div>
<div class="mb-3">
{{ form.protein.label(class="form-label") }}
{{ form.protein(class="form-control") }}
</div>
<div class="mb-3">
{{ form.carbs.label(class="form-label") }}
{{ form.carbs(class="form-control") }}
</div>
<div class="mb-3">
{{ form.sugar.label(class="form-label") }}
{{ form.sugar(class="form-control") }}
</div>
<div class="mb-3">
{{ form.fat.label(class="form-label") }}
{{ form.fat(class="form-control") }}
</div>
<div class="mb-3">
{{ form.saturated_fat.label(class="form-label") }}
{{ form.saturated_fat(class="form-control") }}
</div>
{{ form.submit(class="btn btn-primary") }}
</form>
{% endblock%}

View File

@@ -1,49 +0,0 @@
{% extends "base.html" %}
{% block content %}
<form method="POST">
{{ form.hidden_tag() }}
<div class="mb-3">
{{ form.barcode.label(class="form-label") }}
{{ form.barcode(class="form-control") }}
</div>
<div class="mb-3">
{{ form.name.label(class="form-label") }}
{{ form.name(class="form-control") }}
</div>
<div class="mb-3">
{{ form.energy.label(class="form-label") }}
{{ form.energy(class="form-control") }}
</div>
<div class="mb-3">
{{ form.protein.label(class="form-label") }}
{{ form.protein(class="form-control") }}
</div>
<div class="mb-3">
{{ form.carbs.label(class="form-label") }}
{{ form.carbs(class="form-control") }}
</div>
<div class="mb-3">
{{ form.sugar.label(class="form-label") }}
{{ form.sugar(class="form-control") }}
</div>
<div class="mb-3">
{{ form.fat.label(class="form-label") }}
{{ form.fat(class="form-control") }}
</div>
<div class="mb-3">
{{ form.saturated_fat.label(class="form-label") }}
{{ form.saturated_fat(class="form-control") }}
</div>
{{ form.submit(class="btn btn-primary") }}
</form>
{% endblock%}

View File

@@ -29,7 +29,7 @@ Food Nutritional Info
</div>
<div>
{% for log in logs[0] %}
<p class="p-0 mb-0">{{log.food_item.name}} - {{log.amount}}</p>
<p class="p-0 mb-0">{{log.food_item.name}} - {{"{:g}".format(log.amount)}}</p>
{% endfor %}
</div>
</div>
@@ -41,7 +41,7 @@ Food Nutritional Info
</div>
<div>
{% for log in logs[1] %}
<p class="p-0 mb-0">{{log.food_item.name}} - {{log.amount}}</p>
<p class="p-0 mb-0">{{log.food_item.name}} - {{"{:g}".format(log.amount)}}</p>
{% endfor %}
</div>
</div>
@@ -52,7 +52,7 @@ Food Nutritional Info
</div>
<div>
{% for log in logs[2] %}
<p class="p-0 mb-0">{{log.food_item.name}} - {{log.amount}}</p>
<p class="p-0 mb-0">{{log.food_item.name}} - {{"{:g}".format(log.amount)}}</p>
{% endfor %}
</div>
</div>
@@ -63,7 +63,7 @@ Food Nutritional Info
</div>
<div>
{% for log in logs[3] %}
<p class="p-0 mb-0">{{log.food_item.name}} - {{log.amount}}</p>
<p class="p-0 mb-0">{{log.food_item.name}} - {{"{:g}".format(log.amount)}}</p>
{% endfor %}
</div>
</div>

View File

@@ -1,44 +0,0 @@
{% extends "base.html" %}
{% block content %}
<div class="card mb-4" style="max-width: 600px;">
<div class="card-header">
<h5 class="card-title mb-0">{{ item.name }}</h5>
<small class="text-muted">Barcode: {{ item.barcode }}</small>
</div>
<div class="card-body">
<dl class="row">
<dt class="col-sm-5">Energy per 100g</dt>
<dd class="col-sm-7">{{ item.energy_100 }} kcal</dd>
<dt class="col-sm-5">Protein per 100g</dt>
<dd class="col-sm-7">{{ "%.1f"|format(item.protein_100) }} g</dd>
<dt class="col-sm-5">Carbohydrates per 100g</dt>
<dd class="col-sm-7">{{ "%.1f"|format(item.carbs_100) }} g</dd>
<dt class="col-sm-5">Sugar per 100g</dt>
<dd class="col-sm-7">
{% if item.sugar_100 is not none %}
{{ "%.1f"|format(item.sugar_100) }} g
{% else %}
<span class="text-muted">N/A</span>
{% endif %}
</dd>
<dt class="col-sm-5">fat per 100g</dt>
<dd class="col-sm-7">{{ "%.1f"|format(item.fat_100) }} g</dd>
<dt class="col-sm-5">Saturated fat per 100g</dt>
<dd class="col-sm-7">
{% if item.saturated_fat_100 is not none %}
{{ "%.1f"|format(item.saturated_fat_100) }} g
{% else %}
<span class="text-muted">N/A</span>
{% endif %}
</dd>
</dl>
</div>
</div>
{% endblock%}

View File

@@ -1,76 +0,0 @@
{% extends "base.html" %}
{% block content %}
<div class="container py-5">
<div class="text-center mb-4">
<h1 class="fw-bold">Barcode Scanner</h1>
<p class="text-muted">Use your camera to scan barcodes</p>
</div>
<div class="d-flex justify-content-center mb-4">
<video id="video" class="border rounded shadow-sm" style="width: 100%; max-width: 500px;" autoplay
muted></video>
</div>
<div class="d-flex justify-content-center">
<button id="startButton" class="btn btn-primary px-4">Start Scanning</button>
<button id="stopButton" class="btn btn-danger px-4 ms-3">Stop</button>
</div>
</div>
<script type="module">
import { BrowserMultiFormatReader } from 'https://cdn.jsdelivr.net/npm/@zxing/library@0.21.3/+esm';
// constants
const codeReader = new BrowserMultiFormatReader();
const videoElement = document.getElementById('video');
// Start scanning for barcode
document.getElementById('startButton').addEventListener('click', async () => {
console.log('[DEBUG] Start button clicked')
try {
await navigator.mediaDevices.getUserMedia({ video: true });
} catch (err) {
alert("No camera found or no camera permission");
console.error("Could not access the camera:", err);
return;
}
console.log('[DEBUG] Permission given and at least one device present');
const devices = await codeReader.listVideoInputDevices();
console.log('[DEBUG] Cameras found:', devices);
const rearCamera = devices.find(device => device.label.toLowerCase().includes('back'))
|| devices.find(device => device.label.toLowerCase().includes('rear'))
|| devices[0]; // fallback
const selectedDeviceId = rearCamera?.deviceId;
await codeReader.decodeFromVideoDevice(selectedDeviceId, videoElement, async (result, err) => {
if (result) {
// Result found, this should post the barcode
const codeText = result.getText();
const baseURL = "{{url_for('user.foodId_from_barcode', barcode='!')}}"
fetch(baseURL.replace("!", encodeURIComponent(codeText)))
.then(response => {
if (!response.ok) {
throw new Error('Network response was not OK');
}
return response.json();
})
.then(data => {
const baseURL2 = "{{url_for('user.select_item', item_id='0')}}"
window.location.href = baseURL2.replace("0", encodeURIComponent(data["item_id"]))
})
.catch(error => {
console.error('Fetch error:', error);
});
}
});
});
document.getElementById('stopButton').addEventListener('click', () => {
codeReader.reset();
});
</script>
{% endblock %}

View File

@@ -1,20 +0,0 @@
{% extends "base.html" %}
{% block content %}
<form method="POST">
{{ form.hidden_tag() }}
<div class="mb-3">
<div class="form-control-plaintext">
{{item_id}}
</div>
</div>
<div class="mb-3">
{{ form.amount.label(class="form-label") }}
{{ form.amount(class="form-control") }}
</div>
{{ form.submit(class="btn btn-primary") }}
</form>
{% endblock%}