mirror of
https://github.com/StefBuwalda/cal_counter.git
synced 2025-10-30 03:10:00 +00:00
Remove admin food item and barcode test routes and templates
Deleted the /food_items and /barcode_test routes from admin, along with their associated templates and the delete_food functionality. This streamlines the admin blueprint by removing unused or deprecated features.
This commit is contained in:
@@ -1,7 +1,5 @@
|
|||||||
from flask import Blueprint, render_template, abort, redirect, url_for
|
from flask import Blueprint, abort
|
||||||
from flask_login import current_user
|
from flask_login import current_user
|
||||||
from models import FoodItem
|
|
||||||
from application import db
|
|
||||||
|
|
||||||
admin_bp = Blueprint(
|
admin_bp = Blueprint(
|
||||||
"admin",
|
"admin",
|
||||||
@@ -15,24 +13,3 @@ admin_bp = Blueprint(
|
|||||||
def admin_required():
|
def admin_required():
|
||||||
if not current_user.is_admin:
|
if not current_user.is_admin:
|
||||||
abort(403)
|
abort(403)
|
||||||
|
|
||||||
|
|
||||||
@admin_bp.route("/food_items", methods=["GET"])
|
|
||||||
def food_items():
|
|
||||||
items = FoodItem.query.all()
|
|
||||||
return render_template("food_items.html", items=items)
|
|
||||||
|
|
||||||
|
|
||||||
@admin_bp.route("/barcode_test", methods=["GET"])
|
|
||||||
def barcode_test():
|
|
||||||
return render_template("barcode_test.html")
|
|
||||||
|
|
||||||
|
|
||||||
@admin_bp.route("/delete_food/<int:id>", methods=["POST"])
|
|
||||||
def delete_food(id):
|
|
||||||
item = FoodItem.query.get(id)
|
|
||||||
if item:
|
|
||||||
if item.owner_id == current_user.id:
|
|
||||||
db.session.delete(item)
|
|
||||||
db.session.commit()
|
|
||||||
return redirect(url_for("admin.food_items"))
|
|
||||||
|
|||||||
@@ -1,55 +0,0 @@
|
|||||||
{% extends "base.html" %}
|
|
||||||
{% block title %}
|
|
||||||
ZXing Barcode Scanner
|
|
||||||
{% endblock %}
|
|
||||||
|
|
||||||
{% block content %}
|
|
||||||
<div class="container text-center">
|
|
||||||
<h1 class="mb-4">📷 ZXing Barcode Scanner</h1>
|
|
||||||
|
|
||||||
<div class="mb-3">
|
|
||||||
<video id="video" class="border rounded shadow-sm" width="100%" style="max-width: 500px;"></video>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="mb-3">
|
|
||||||
<button id="startButton" class="btn btn-primary">Start Scanning</button>
|
|
||||||
<button id="stopButton" class="btn btn-danger ms-2">Stop</button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<h5>Result:</h5>
|
|
||||||
<p id="result" class="fw-bold text-success"></p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<script type="module">
|
|
||||||
import { BrowserMultiFormatReader } from 'https://cdn.jsdelivr.net/npm/@zxing/library@0.21.3/+esm';
|
|
||||||
|
|
||||||
const codeReader = new BrowserMultiFormatReader();
|
|
||||||
const videoElement = document.getElementById('video');
|
|
||||||
const resultElement = document.getElementById('result');
|
|
||||||
|
|
||||||
document.getElementById('startButton').addEventListener('click', async () => {
|
|
||||||
await navigator.mediaDevices.getUserMedia({ video: true });
|
|
||||||
console.log('[DEBUG] Start button clicked');
|
|
||||||
const devices = await codeReader.listVideoInputDevices();
|
|
||||||
console.log('[DEBUG] Cameras found:', devices);
|
|
||||||
const selectedDeviceId = devices[0]?.deviceId;
|
|
||||||
if (!selectedDeviceId) {
|
|
||||||
alert('No camera found!');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
codeReader.decodeFromVideoDevice(selectedDeviceId, videoElement, (result, err, controls) => {
|
|
||||||
if (result) {
|
|
||||||
resultElement.textContent = result.getText();
|
|
||||||
controls.stop();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
document.getElementById('stopButton').addEventListener('click', () => {
|
|
||||||
codeReader.reset();
|
|
||||||
resultElement.textContent = '';
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
{% endblock %}
|
|
||||||
@@ -1,47 +0,0 @@
|
|||||||
{% extends "base.html" %}
|
|
||||||
|
|
||||||
{% block title %}
|
|
||||||
Food Nutritional Info
|
|
||||||
{% endblock %}
|
|
||||||
|
|
||||||
{% block content %}
|
|
||||||
<div class="container mt-5">
|
|
||||||
<h1 class="mb-4">Food Nutritional Information (per 100g/100ml)</h1>
|
|
||||||
<div class="table-responsive">
|
|
||||||
<table class="table table-bordered table-hover align-middle">
|
|
||||||
<thead class="table-dark">
|
|
||||||
<tr>
|
|
||||||
<th>Name</th>
|
|
||||||
<th>Energy (kcal)</th>
|
|
||||||
<th>fat (g)</th>
|
|
||||||
<th>Saturated fat (g)</th>
|
|
||||||
<th>Sugars (g)</th>
|
|
||||||
<th>Carbs (g)</th>
|
|
||||||
<th>Protein (g)</th>
|
|
||||||
<th>Actions</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
{% for food in items %}
|
|
||||||
<tr>
|
|
||||||
<td class="bg-body-tertiary">{{ food.name }}</td>
|
|
||||||
<td class="bg-body-tertiary">{{ food.energy_100 }}</td>
|
|
||||||
<td class="bg-body-tertiary">{{ food.fat_100 }}</td>
|
|
||||||
<td class="bg-body-tertiary">{{ food.saturated_fat_100 }}</td>
|
|
||||||
<td class="bg-body-tertiary">{{ food.sugar_100 }}</td>
|
|
||||||
<td class="bg-body-tertiary">{{ food.carbs_100 }}</td>
|
|
||||||
<td class="bg-body-tertiary">{{ food.protein_100 }}</td>
|
|
||||||
<td class="bg-body-tertiary">
|
|
||||||
<form method="POST" action="{{ url_for('admin.delete_food', id=food.id) }}"
|
|
||||||
onsubmit="return confirm('Are you sure you want to delete this item?');">
|
|
||||||
<button type="submit" class="btn btn-danger btn-sm">Delete</button>
|
|
||||||
</form>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
{% endfor %}
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{% endblock%}
|
|
||||||
Reference in New Issue
Block a user