Compare commits
49 Commits
Author | SHA1 | Date | |
---|---|---|---|
6a9b938ab9
|
|||
367e76f9f1
|
|||
e59b184da5 | |||
c318cd21e0 | |||
224e6a9147 | |||
8f15a05a4e | |||
f0fcbc3c56
|
|||
1e8ae0105a | |||
f39c902ace | |||
ff26644f06 | |||
5f63092a67 | |||
1fc9dd70df | |||
794b50e041 | |||
5583bc2b60 | |||
5f34449601
|
|||
8bc3857482
|
|||
5c7fe128c8
|
|||
3a17338358 | |||
4761910092 | |||
2c499b363b
|
|||
39e2f2634d | |||
ffa6944e7b
|
|||
449dba1d7e
|
|||
b6d1367019
|
|||
2ff8757b74 | |||
7f06e900bb
|
|||
4c2338c34a
|
|||
5f8d49f054
|
|||
5cfba1c068 | |||
09a670727f | |||
f4a4597223
|
|||
70815f0172
|
|||
e4e8e19466 | |||
2228f0cfb5 | |||
24fb1c2941
|
|||
cc3a6381d5
|
|||
938562b9d8
|
|||
103d60764b
|
|||
8a446b8a8d
|
|||
5948cf3840
|
|||
63dbfcc89f
|
|||
439f6085e7
|
|||
21479212f8
|
|||
5d8997d45e
|
|||
6e6effb1bc
|
|||
00d48b4de1
|
|||
fc9cd70776
|
|||
8b9654370c
|
|||
4471c140c1 |
@ -7,7 +7,9 @@ COPY start.sh ${APP_DIR}/
|
|||||||
|
|
||||||
WORKDIR ${APP_DIR}
|
WORKDIR ${APP_DIR}
|
||||||
|
|
||||||
RUN pip install -r requirements.txt
|
RUN \
|
||||||
|
apk add --no-cache build-base libpq-dev && \
|
||||||
|
pip install -r requirements.txt
|
||||||
|
|
||||||
EXPOSE 8080
|
EXPOSE 8080
|
||||||
|
|
||||||
|
138
src/Run.py
138
src/Run.py
@ -4,6 +4,7 @@ from flask_oidc import OpenIDConnect
|
|||||||
from werkzeug.middleware.proxy_fix import ProxyFix
|
from werkzeug.middleware.proxy_fix import ProxyFix
|
||||||
import os
|
import os
|
||||||
import json
|
import json
|
||||||
|
import psycopg2
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
app.config.update({
|
app.config.update({
|
||||||
@ -19,61 +20,16 @@ app.config.update({
|
|||||||
oidc = OpenIDConnect(app)
|
oidc = OpenIDConnect(app)
|
||||||
|
|
||||||
|
|
||||||
# Datenbankverbindung konfigurieren
|
|
||||||
def get_db_connection():
|
|
||||||
conn = sqlite3.connect('nutrition.db') # 'nutrition.db' ist der Name der Datenbankdatei
|
|
||||||
conn.row_factory = sqlite3.Row # Ermöglicht den Zugriff auf Daten durch Spaltennamen
|
|
||||||
return conn
|
|
||||||
|
|
||||||
|
|
||||||
#def init_db():
|
|
||||||
# conn = get_db_connection()
|
|
||||||
# cursor = conn.cursor()
|
|
||||||
#
|
|
||||||
# # Erstellen der Tabelle
|
|
||||||
# cursor.execute('''
|
|
||||||
# CREATE TABLE IF NOT EXISTS nutrition_table (
|
|
||||||
# id INTEGER PRIMARY KEY,
|
|
||||||
# name TEXT NOT NULL,
|
|
||||||
# kcal REAL,
|
|
||||||
# EW REAL,
|
|
||||||
# Fett REAL,
|
|
||||||
# KH REAL,
|
|
||||||
# BST REAL,
|
|
||||||
# CA REAL
|
|
||||||
# )
|
|
||||||
# ''')
|
|
||||||
#
|
|
||||||
# # Testdaten einfügen
|
|
||||||
# test_data = [
|
|
||||||
# ('Apfel', 52, 0.3, 0.2, 14, 0.2, 6),
|
|
||||||
# ('Banane', 89, 1.1, 0.3, 23, 0.3, 5),
|
|
||||||
# ('Karotte', 41, 0.9, 0.2, 10, 0.2, 3),
|
|
||||||
# ('Tomate', 18, 0.9, 0.2, 3.9, 0.2, 4),
|
|
||||||
# ('Brokkoli', 34, 2.8, 0.4, 6.6, 0.4, 2),
|
|
||||||
# ('Spinat', 23, 2.9, 0.4, 3.6, 0.4, 99),
|
|
||||||
# ('Kartoffel', 77, 2, 0.1, 17, 0.1, 12),
|
|
||||||
# ('Huhn', 239, 27, 14, 0, 0, 2),
|
|
||||||
# ('Lachs', 208, 20, 13, 0, 0, 1),
|
|
||||||
# ('Ei', 155, 13, 11, 1.1, 1, 1)
|
|
||||||
# ]
|
|
||||||
#
|
|
||||||
# cursor.executemany('INSERT INTO nutrition_table (name, kcal, EW, Fett, KH, BST, CA) VALUES (?, ?, ?, ?, ?, ?, ?)', test_data)
|
|
||||||
#
|
|
||||||
# conn.commit()
|
|
||||||
# conn.close()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def calculate_nutrition(food, weight):
|
def calculate_nutrition(food, weight):
|
||||||
conn = get_db_connection()
|
try:
|
||||||
cursor = conn.cursor()
|
conn = psycopg2.connect()
|
||||||
|
|
||||||
|
with conn.cursor() as cursor:
|
||||||
# Abfrage der Nährwertdaten aus der Datenbank
|
# Abfrage der Nährwertdaten aus der Datenbank
|
||||||
cursor.execute('SELECT kcal, EW, Fett, KH, BST, CA FROM nutrition_table WHERE name = ?', (food,))
|
cursor.execute('SELECT kcal, EW, Fett, KH, BST, CA FROM nutrition_table WHERE name = %s', (food,))
|
||||||
|
|
||||||
result = cursor.fetchone()
|
result = cursor.fetchone()
|
||||||
conn.close()
|
|
||||||
|
|
||||||
if result:
|
if result:
|
||||||
# Runden und Berechnen der Nährwerte basierend auf dem Gewicht
|
# Runden und Berechnen der Nährwerte basierend auf dem Gewicht
|
||||||
@ -89,6 +45,10 @@ def calculate_nutrition(food, weight):
|
|||||||
return nutrition_values
|
return nutrition_values
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
finally:
|
||||||
|
if conn:
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Index-Route
|
# Index-Route
|
||||||
@ -102,16 +62,15 @@ def index():
|
|||||||
@app.route('/get_products')
|
@app.route('/get_products')
|
||||||
@oidc.require_login
|
@oidc.require_login
|
||||||
def get_products():
|
def get_products():
|
||||||
conn = get_db_connection()
|
try:
|
||||||
cursor = conn.cursor()
|
conn = psycopg2.connect()
|
||||||
|
with conn.cursor() as cursor:
|
||||||
cursor.execute('SELECT name FROM nutrition_table')
|
cursor.execute('SELECT name FROM nutrition_table')
|
||||||
products = cursor.fetchall()
|
products = cursor.fetchall()
|
||||||
conn.close()
|
|
||||||
print("ter")
|
|
||||||
return {'products': [product[0] for product in products]}
|
return {'products': [product[0] for product in products]}
|
||||||
|
finally:
|
||||||
|
if conn:
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
|
||||||
# Route zum Hinzufügen und Berechnen von Lebensmitteln
|
# Route zum Hinzufügen und Berechnen von Lebensmitteln
|
||||||
@ -138,28 +97,36 @@ def add_lm():
|
|||||||
return "Lebensmittel nicht gefunden.", 404
|
return "Lebensmittel nicht gefunden.", 404
|
||||||
|
|
||||||
|
|
||||||
|
def convert_decimal(value):
|
||||||
|
try:
|
||||||
|
return float(value.replace(',', '.'))
|
||||||
|
except (ValueError, TypeError):
|
||||||
|
return 0.0 # Rückgabe eines Standardwertes im Fehlerfall
|
||||||
|
|
||||||
|
|
||||||
@app.route('/add_nutrition', methods=['POST'])
|
@app.route('/add_nutrition', methods=['POST'])
|
||||||
@oidc.accept_token(require_token=True, scopes_required=['openid'])
|
@oidc.accept_token(['openid'])
|
||||||
def add_nutrition():
|
def add_nutrition():
|
||||||
food = request.form.get('food')
|
food = request.form.get('food')
|
||||||
kcal = float(request.form.get('kcal'))
|
kcal = convert_decimal(request.form.get('kcal'))
|
||||||
ew = float(request.form.get('ew'))
|
ew = convert_decimal(request.form.get('ew'))
|
||||||
fett = float(request.form.get('fett'))
|
fett = convert_decimal(request.form.get('fett'))
|
||||||
kh = float(request.form.get('kh'))
|
kh = convert_decimal(request.form.get('kh'))
|
||||||
bst = float(request.form.get('bst'))
|
bst = convert_decimal(request.form.get('bst'))
|
||||||
ca = float(request.form.get('ca'))
|
ca = convert_decimal(request.form.get('ca'))
|
||||||
|
|
||||||
print("test")
|
|
||||||
# Verbindung zur Datenbank herstellen und Daten einfügen
|
# Verbindung zur Datenbank herstellen und Daten einfügen
|
||||||
conn = get_db_connection()
|
try:
|
||||||
cursor = conn.cursor()
|
conn = psycopg2.connect()
|
||||||
cursor.execute("INSERT INTO nutrition_table (name, kcal, ew, fett, kh, bst, ca) VALUES (?, ?, ?, ?, ?, ?, ?)",
|
with conn.cursor() as cursor:
|
||||||
|
cursor.execute("INSERT INTO nutrition_table (name, kcal, ew, fett, kh, bst, ca) VALUES (%s, %s, %s, %s, %s, %s, %s)",
|
||||||
(food, kcal, ew, fett, kh, bst, ca))
|
(food, kcal, ew, fett, kh, bst, ca))
|
||||||
conn.commit()
|
|
||||||
conn.close()
|
|
||||||
|
|
||||||
return redirect(url_for('nutrition'))
|
return redirect(url_for('nutrition'))
|
||||||
|
finally:
|
||||||
|
if conn:
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
|
||||||
@app.route('/nutrition')
|
@app.route('/nutrition')
|
||||||
@ -167,8 +134,41 @@ def add_nutrition():
|
|||||||
def nutrition():
|
def nutrition():
|
||||||
return render_template('nutrition.html')
|
return render_template('nutrition.html')
|
||||||
|
|
||||||
|
@app.route('/get_token')
|
||||||
|
@oidc.require_login
|
||||||
|
def get_token():
|
||||||
|
return jsonify(token=oidc.get_access_token())
|
||||||
|
|
||||||
|
|
||||||
|
@app.route('/get_database_entries')
|
||||||
|
def get_database_entries():
|
||||||
|
try:
|
||||||
|
# Ersetzen Sie diese Werte mit Ihren Datenbank-Verbindungsinformationen
|
||||||
|
conn = psycopg2.connect()
|
||||||
|
cursor = conn.cursor()
|
||||||
|
with conn.cursor() as cursor:
|
||||||
|
cursor.execute("SELECT name, kcal, ew, fett, kh, bst, ca FROM nutrition_table")
|
||||||
|
entries = cursor.fetchall()
|
||||||
|
|
||||||
|
# Umwandeln der Daten in ein JSON-freundliches Format
|
||||||
|
entries_list = []
|
||||||
|
for entry in entries:
|
||||||
|
entries_list.append({
|
||||||
|
"food": entry[0],
|
||||||
|
"kcal": entry[1],
|
||||||
|
"ew": entry[2],
|
||||||
|
"fett": entry[3],
|
||||||
|
"kh": entry[4],
|
||||||
|
"bst": entry[5],
|
||||||
|
"ca": entry[6]
|
||||||
|
})
|
||||||
|
return jsonify(entries_list)
|
||||||
|
except Exception as e:
|
||||||
|
return jsonify({"error": str(e)}), 500
|
||||||
|
finally:
|
||||||
|
if conn:
|
||||||
|
conn.close()
|
||||||
|
|
||||||
app = ProxyFix(app, x_for=1, x_host=1)
|
app = ProxyFix(app, x_for=1, x_host=1)
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,14 +1,13 @@
|
|||||||
import csv
|
import csv
|
||||||
import sqlite3
|
import psycopg2
|
||||||
|
|
||||||
# Pfad zur Ihrer CSV-Datei
|
# Pfad zur Ihrer CSV-Datei
|
||||||
csv_file_path = 'nu.csv'
|
csv_file_path = 'nu.csv'
|
||||||
|
|
||||||
# Pfad zur Ihrer SQLite-Datenbank
|
# Pfad zur Ihrer SQLite-Datenbank
|
||||||
sqlite_db_path = 'nutrition.db'
|
|
||||||
|
|
||||||
# Verbindung zur SQLite-Datenbank herstellen
|
# Verbindung zur SQLite-Datenbank herstellen
|
||||||
conn = sqlite3.connect(sqlite_db_path)
|
conn = psycopg2.connect()
|
||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
|
|
||||||
# Erstellen der Tabelle (falls noch nicht vorhanden)
|
# Erstellen der Tabelle (falls noch nicht vorhanden)
|
||||||
@ -29,8 +28,9 @@ with open(csv_file_path, newline='', encoding='utf-8') as csvfile:
|
|||||||
reader = csv.reader(csvfile)
|
reader = csv.reader(csvfile)
|
||||||
next(reader, None) # Überspringen der Kopfzeile
|
next(reader, None) # Überspringen der Kopfzeile
|
||||||
for row in reader:
|
for row in reader:
|
||||||
cursor.execute('INSERT INTO nutrition_table (name, kcal, EW, Fett, KH, BST, Ca) VALUES (?, ?, ?, ?, ?, ?, ?)', row)
|
cursor.execute('INSERT INTO nutrition_table (name, kcal, EW, Fett, KH, BST, Ca) VALUES (%s, %s, %s, %s, %s, %s, %s)', row)
|
||||||
|
|
||||||
# Änderungen speichern und Verbindung schließen
|
# Änderungen speichern und Verbindung schließen
|
||||||
conn.commit()
|
conn.commit()
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
|
@ -13,6 +13,8 @@ itsdangerous==2.1.2
|
|||||||
Jinja2==3.1.3
|
Jinja2==3.1.3
|
||||||
MarkupSafe==2.1.4
|
MarkupSafe==2.1.4
|
||||||
packaging==23.2
|
packaging==23.2
|
||||||
|
psycopg==3.1.17
|
||||||
|
psycopg2==2.9.9
|
||||||
pycparser==2.21
|
pycparser==2.21
|
||||||
requests==2.31.0
|
requests==2.31.0
|
||||||
typing_extensions==4.9.0
|
typing_extensions==4.9.0
|
||||||
|
BIN
src/static/images/favicon.ico
Normal file
BIN
src/static/images/favicon.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 13 KiB |
@ -34,13 +34,20 @@ button:not(:disabled):hover {
|
|||||||
}
|
}
|
||||||
|
|
||||||
button#remove-button {
|
button#remove-button {
|
||||||
background-color: #f443366f; /* Helles Rot */
|
background-color: #640000; /* Helles Rot */
|
||||||
|
}
|
||||||
|
|
||||||
|
button#remove-button:disabled {
|
||||||
|
background-color: #cccccc;
|
||||||
|
color: #666666;
|
||||||
}
|
}
|
||||||
|
|
||||||
button#remove-button:not(:disabled):hover {
|
button#remove-button:not(:disabled):hover {
|
||||||
background-color: #d32f2f3d; /* Dunkleres Rot */
|
background-color: #490000; /* Dunkleres Rot */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
table {
|
table {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
border-collapse: collapse;
|
border-collapse: collapse;
|
||||||
@ -65,7 +72,7 @@ tr:nth-child(even) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.selected, tr.selected {
|
.selected, tr.selected {
|
||||||
background-color: #ffdd99; /* Hervorhebung der Auswahl */
|
background-color: #e5b5b5; /* Hervorhebung der Auswahl */
|
||||||
}
|
}
|
||||||
|
|
||||||
tr:hover:not(.selected) {
|
tr:hover:not(.selected) {
|
||||||
@ -121,3 +128,89 @@ tr:hover:not(.selected) {
|
|||||||
padding: 20px;
|
padding: 20px;
|
||||||
margin: 20px 0;
|
margin: 20px 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#nutrition-input-table {
|
||||||
|
width: 100%; /* Tabelle nimmt die volle Breite ein */
|
||||||
|
border-collapse: collapse; /* Entfernt doppelte Ränder */
|
||||||
|
}
|
||||||
|
|
||||||
|
#nutrition-input-table th, #nutrition-input-table td {
|
||||||
|
border: 1px solid #ddd; /* Fügt Ränder hinzu */
|
||||||
|
padding: 8px; /* Fügt Innenabstand hinzu */
|
||||||
|
text-align: left; /* Ausrichtung des Textes */
|
||||||
|
}
|
||||||
|
|
||||||
|
#nutrition-input-table input {
|
||||||
|
width: 100%; /* Eingabefelder nehmen die volle Breite der Zelle ein */
|
||||||
|
box-sizing: border-box; /* Box-Modell für die Breitenberechnung */
|
||||||
|
}
|
||||||
|
|
||||||
|
@media screen and (max-width: 600px) {
|
||||||
|
#nutrition-input-table {
|
||||||
|
display: block;
|
||||||
|
overflow-x: auto; /* Ermöglicht horizontales Scrollen auf kleinen Bildschirmen */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#table-container {
|
||||||
|
overflow-y: auto;
|
||||||
|
max-height: 400px; /* Passen Sie die Höhe nach Bedarf an */
|
||||||
|
border-radius: 10px;
|
||||||
|
margin-top: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#database-nutrition-table {
|
||||||
|
width: 100%;
|
||||||
|
border-collapse: collapse;
|
||||||
|
}
|
||||||
|
|
||||||
|
#database-nutrition-table th, #database-nutrition-table td {
|
||||||
|
border: 1px solid #ddd;
|
||||||
|
padding: 8px;
|
||||||
|
text-align: left;
|
||||||
|
}
|
||||||
|
|
||||||
|
#database-nutrition-table tr.selected {
|
||||||
|
background-color: #f0e68c;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#password-prompt {
|
||||||
|
margin-top: 10px;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
#password-prompt input[type="password"] {
|
||||||
|
padding: 8px;
|
||||||
|
margin-right: 10px;
|
||||||
|
border: 1px solid #ddd;
|
||||||
|
border-radius: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#password-prompt button {
|
||||||
|
padding: 8px 15px;
|
||||||
|
margin-right: 10px;
|
||||||
|
border: none;
|
||||||
|
border-radius: 4px;
|
||||||
|
cursor: pointer;
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
#password-prompt button[type="submit"] {
|
||||||
|
background-color: #008C50; /* Helles Grün */
|
||||||
|
}
|
||||||
|
|
||||||
|
#password-prompt button[type="submit"]:hover {
|
||||||
|
background-color: #007344; /* Dunkleres Grün */
|
||||||
|
}
|
||||||
|
|
||||||
|
#password-prompt button[type="button"] {
|
||||||
|
background-color: #640000; /* Helles Rot */
|
||||||
|
}
|
||||||
|
|
||||||
|
#password-prompt button[type="button"]:hover {
|
||||||
|
background-color: #490000; /* Dunkleres Rot */
|
||||||
|
}
|
||||||
|
@ -4,10 +4,9 @@
|
|||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<title>Nährwertberechnungs-App</title>
|
<title>Nährwertberechnungs-App</title>
|
||||||
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='style.css') }}">
|
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='style.css') }}">
|
||||||
|
<link rel="shortcut icon" href="../static/images/favicon.ico">
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
|
||||||
// JavaScript-Funktion, um die Produkte beim Laden der Seite zu holen
|
|
||||||
document.addEventListener('DOMContentLoaded', function() {
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
cleanUpLocalStorage();
|
cleanUpLocalStorage();
|
||||||
restoreTableFromLocalStorage();
|
restoreTableFromLocalStorage();
|
||||||
@ -172,20 +171,11 @@ function updateTotalNutrition() {
|
|||||||
document.getElementById('total-ca').innerText = Math.round(totalCa);
|
document.getElementById('total-ca').innerText = Math.round(totalCa);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rufen Sie diese Funktion auf, wenn sich die Haupttabelle ändert
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Diese Funktion sollte aufgerufen werden, wenn ein Produkt hinzugefügt oder entfernt wird
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<nav id="navbar">
|
<nav id="navbar">
|
||||||
<h1>Elos Rezept Rechner</h1>
|
<h1>Elo's Rezept Rechner</h1>
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="/" class="active">Rechner</a></li>
|
<li><a href="/" class="active">Rechner</a></li>
|
||||||
<li><a href="/nutrition">Neue Lebensmittel</a></li>
|
<li><a href="/nutrition">Neue Lebensmittel</a></li>
|
||||||
@ -196,7 +186,7 @@ function updateTotalNutrition() {
|
|||||||
<div class="content">
|
<div class="content">
|
||||||
<form onsubmit="event.preventDefault(); addProduct();" id="product-form">
|
<form onsubmit="event.preventDefault(); addProduct();" id="product-form">
|
||||||
<label for="my_combobox">Wählen Sie ein Lebensmittel</label>
|
<label for="my_combobox">Wählen Sie ein Lebensmittel</label>
|
||||||
<input list="products" name="my_combobox" id="my_combobox" oninput="updateButtonState()" autocomplete="off">
|
<input list="products" name="my_combobox" id="my_combobox" placeholder="Lebensmittel" oninput="updateButtonState()" autocomplete="off">
|
||||||
<datalist id="products">
|
<datalist id="products">
|
||||||
<!-- Produkte werden hier dynamisch eingefügt -->
|
<!-- Produkte werden hier dynamisch eingefügt -->
|
||||||
</datalist>
|
</datalist>
|
||||||
@ -220,6 +210,8 @@ function updateTotalNutrition() {
|
|||||||
<button id="remove-button" onclick="removeSelectedRow()" disabled>Entfernen</button>
|
<button id="remove-button" onclick="removeSelectedRow()" disabled>Entfernen</button>
|
||||||
<table id="total-nutrition-table">
|
<table id="total-nutrition-table">
|
||||||
<tr>
|
<tr>
|
||||||
|
<th>Lebensmittel</th>
|
||||||
|
<th>Gewicht (g)</th>
|
||||||
<th>kcal</th>
|
<th>kcal</th>
|
||||||
<th>EW</th>
|
<th>EW</th>
|
||||||
<th>Fett</th>
|
<th>Fett</th>
|
||||||
@ -228,6 +220,8 @@ function updateTotalNutrition() {
|
|||||||
<th>CA</th>
|
<th>CA</th>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
|
<td>Gesamtwerte</td>
|
||||||
|
<td>-</td>
|
||||||
<td id="total-kcal">0</td>
|
<td id="total-kcal">0</td>
|
||||||
<td id="total-ew">0</td>
|
<td id="total-ew">0</td>
|
||||||
<td id="total-fett">0</td>
|
<td id="total-fett">0</td>
|
||||||
|
@ -4,6 +4,8 @@
|
|||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<title>Neue Lebensmittel hinzufügen</title>
|
<title>Neue Lebensmittel hinzufügen</title>
|
||||||
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='style.css') }}">
|
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='style.css') }}">
|
||||||
|
<link rel="shortcut icon" href="../static/images/favicon.ico">
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
function updateSubmitButtonState() {
|
function updateSubmitButtonState() {
|
||||||
const inputs = document.querySelectorAll('#nutrition-form input');
|
const inputs = document.querySelectorAll('#nutrition-form input');
|
||||||
@ -11,13 +13,27 @@
|
|||||||
document.getElementById('submit-button').disabled = !allFilled;
|
document.getElementById('submit-button').disabled = !allFilled;
|
||||||
}
|
}
|
||||||
|
|
||||||
function addNutritionEntry() {
|
function getBearerToken(callback) {
|
||||||
|
fetch('/get_token')
|
||||||
|
.then(response => response.json())
|
||||||
|
.then(data => {
|
||||||
|
callback(data.token);
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.error('Fehler beim Abrufen des Tokens:', error);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function addNutritionEntry() {
|
||||||
|
getBearerToken(token => {
|
||||||
const form = document.getElementById('nutrition-form');
|
const form = document.getElementById('nutrition-form');
|
||||||
const formData = new FormData(form);
|
const formData = new FormData(form);
|
||||||
|
|
||||||
fetch('/add_nutrition', {
|
fetch('/add_nutrition', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Authorization': 'Bearer ' + token
|
||||||
|
},
|
||||||
body: formData
|
body: formData
|
||||||
}).then(response => {
|
}).then(response => {
|
||||||
// Behandlung der Serverantwort
|
// Behandlung der Serverantwort
|
||||||
@ -36,13 +52,90 @@
|
|||||||
|
|
||||||
// Deaktiviere den "Hinzufügen"-Button wieder
|
// Deaktiviere den "Hinzufügen"-Button wieder
|
||||||
document.getElementById('submit-button').disabled = true;
|
document.getElementById('submit-button').disabled = true;
|
||||||
}
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
|
const table = document.getElementById('database-nutrition-table');
|
||||||
|
table.addEventListener('click', function(e) {
|
||||||
|
if (e.target.tagName === 'TD') {
|
||||||
|
e.target.parentNode.classList.toggle('selected');
|
||||||
|
updateDeleteButtonState();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
updateDeleteButtonState();
|
||||||
|
});
|
||||||
|
|
||||||
|
function deleteSelectedRows() {
|
||||||
|
const table = document.getElementById('database-nutrition-table');
|
||||||
|
Array.from(table.rows).forEach(row => {
|
||||||
|
if (row.classList.contains('selected')) {
|
||||||
|
// Logik zum Löschen der Zeile aus der Datenbank
|
||||||
|
table.deleteRow(row.rowIndex);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function showPasswordPrompt() {
|
||||||
|
document.getElementById('delete-row-button').style.display = 'none';
|
||||||
|
document.getElementById('password-prompt').style.display = 'block';
|
||||||
|
}
|
||||||
|
|
||||||
|
function hidePasswordPrompt() {
|
||||||
|
document.getElementById('delete-row-button').style.display = 'block';
|
||||||
|
document.getElementById('password-prompt').style.display = 'none';
|
||||||
|
}
|
||||||
|
|
||||||
|
function deleteRowsIfPasswordCorrect() {
|
||||||
|
const password = document.getElementById('password-input').value;
|
||||||
|
if (password === 'wowmuchsecurity') {
|
||||||
|
deleteSelectedRows(); // Funktion, die die ausgewählten Zeilen löscht
|
||||||
|
hidePasswordPrompt();
|
||||||
|
} else {
|
||||||
|
alert('Falsches Passwort!');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateDeleteButtonState() {
|
||||||
|
const selectedRows = document.querySelectorAll('#nutrition-table .selected').length;
|
||||||
|
const deleteButton = document.getElementById('delete-row-button');
|
||||||
|
deleteButton.disabled = selectedRows === 0;
|
||||||
|
if (selectedRows === 0) {
|
||||||
|
hidePasswordPrompt(); // Versteckt die Passwort-Eingabe, falls keine Zeile ausgewählt ist
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function loadDatabaseEntries() {
|
||||||
|
fetch('/get_database_entries') // Pfad zur entsprechenden Flask-Route
|
||||||
|
.then(response => response.json())
|
||||||
|
.then(data => {
|
||||||
|
const tableBody = document.getElementById('database-nutrition-table').getElementsByTagName('tbody')[0];
|
||||||
|
data.forEach(entry => {
|
||||||
|
const row = tableBody.insertRow();
|
||||||
|
row.insertCell(0).innerHTML = entry.food;
|
||||||
|
row.insertCell(1).innerHTML = entry.kcal;
|
||||||
|
row.insertCell(2).innerHTML = entry.ew;
|
||||||
|
row.insertCell(3).innerHTML = entry.fett;
|
||||||
|
row.insertCell(4).innerHTML = entry.kh;
|
||||||
|
row.insertCell(5).innerHTML = entry.bst;
|
||||||
|
row.insertCell(6).innerHTML = entry.ca;
|
||||||
|
|
||||||
|
// ... Fügen Sie weitere Zellen für die anderen Werte hinzu ...
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.catch(error => console.error('Fehler:', error));
|
||||||
|
}
|
||||||
|
|
||||||
|
document.addEventListener('DOMContentLoaded', loadDatabaseEntries);
|
||||||
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<nav id="navbar">
|
<nav id="navbar">
|
||||||
<h1>Elos Rezept Rechner</h1>
|
<h1>Elo's Rezept Rechner</h1>
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="/">Rechner</a></li>
|
<li><a href="/">Rechner</a></li>
|
||||||
<li><a href="/nutrition" class="active">Neue Lebensmittel</a></li>
|
<li><a href="/nutrition" class="active">Neue Lebensmittel</a></li>
|
||||||
@ -62,17 +155,45 @@
|
|||||||
<th>CA</th>
|
<th>CA</th>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td><input type="text" name="food" oninput="updateSubmitButtonState()"></td>
|
<td><input type="text" name="food" placeholder="Lebensmittel" oninput="updateSubmitButtonState()"></td>
|
||||||
<td><input <input type="text" name="kcal" pattern="\d+(\.\d{1,2})?" oninput="updateSubmitButtonState()"></td>
|
<td><input <input type="text" name="kcal" pattern="\d+([.,]\d{1,2})?" placeholder="g" oninput="updateSubmitButtonState()"></td>
|
||||||
<td><input <input type="text" name="ew" pattern="\d+(\.\d{1,2})?" oninput="updateSubmitButtonState()"></td>
|
<td><input <input type="text" name="ew" pattern="\d+([.,]\d{1,2})?" placeholder="g" oninput="updateSubmitButtonState()"></td>
|
||||||
<td><input <input type="text" name="fett" pattern="\d+(\.\d{1,2})?" oninput="updateSubmitButtonState()"></td>
|
<td><input <input type="text" name="fett" pattern="\d+([.,]\d{1,2})?" placeholder="g" oninput="updateSubmitButtonState()"></td>
|
||||||
<td><input <input type="text" name="kh" pattern="\d+(\.\d{1,2})?" oninput="updateSubmitButtonState()"></td>
|
<td><input <input type="text" name="kh" pattern="\d+([.,]\d{1,2})?" placeholder="g" oninput="updateSubmitButtonState()"></td>
|
||||||
<td><input <input type="text" name="bst" pattern="\d+(\.\d{1,2})?" oninput="updateSubmitButtonState()"></td>
|
<td><input <input type="text" name="bst" pattern="\d+([.,]\d{1,2})?" placeholder="g" oninput="updateSubmitButtonState()"></td>
|
||||||
<td><input <input type="text" name="ca" pattern="\d+(\.\d{1,2})?" oninput="updateSubmitButtonState()"></td>
|
<td><input <input type="text" name="ca" pattern="\d+([.,]\d{1,2})?" placeholder="mg" oninput="updateSubmitButtonState()"></td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
<button type="submit" id="submit-button" disabled>Hinzufügen</button>
|
<button type="submit" id="submit-button" disabled>Hinzufügen</button>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
<div id="table-container">
|
||||||
|
<table id="database-nutrition-table">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Lebensmittel</th>
|
||||||
|
<th>kcal</th>
|
||||||
|
<th>EW</th>
|
||||||
|
<th>Fett</th>
|
||||||
|
<th>KH</th>
|
||||||
|
<th>BST</th>
|
||||||
|
<th>CA</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<!-- Die Zeilen werden dynamisch aus der Datenbank geladen -->
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
<button id="delete-row-button" onclick="showPasswordPrompt()">Zeilen löschen</button>
|
||||||
|
|
||||||
|
<div id="password-prompt" style="display: none;">
|
||||||
|
<input type="password" id="password-input" placeholder="Passwort">
|
||||||
|
<button onclick="deleteRowsIfPasswordCorrect()">OK</button>
|
||||||
|
<button onclick="hidePasswordPrompt()">Abbrechen</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
Reference in New Issue
Block a user