Compare commits
14 Commits
Author | SHA1 | Date | |
---|---|---|---|
f39c902ace | |||
ff26644f06 | |||
5f63092a67 | |||
1fc9dd70df | |||
794b50e041 | |||
5583bc2b60 | |||
5f34449601
|
|||
8bc3857482
|
|||
5c7fe128c8
|
|||
3a17338358 | |||
4761910092 | |||
2c499b363b
|
|||
39e2f2634d | |||
ffa6944e7b
|
29
src/Run.py
29
src/Run.py
@ -20,6 +20,7 @@ app.config.update({
|
||||
oidc = OpenIDConnect(app)
|
||||
|
||||
|
||||
|
||||
def calculate_nutrition(food, weight):
|
||||
try:
|
||||
conn = psycopg2.connect()
|
||||
@ -66,7 +67,6 @@ def get_products():
|
||||
with conn.cursor() as cursor:
|
||||
cursor.execute('SELECT name FROM nutrition_table')
|
||||
products = cursor.fetchall()
|
||||
print("ter")
|
||||
return {'products': [product[0] for product in products]}
|
||||
finally:
|
||||
if conn:
|
||||
@ -97,19 +97,24 @@ def add_lm():
|
||||
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'])
|
||||
@oidc.accept_token(require_token=True, scopes_required=['openid'])
|
||||
@oidc.accept_token(True)
|
||||
def add_nutrition():
|
||||
food = request.form.get('food')
|
||||
kcal = float(request.form.get('kcal'))
|
||||
ew = float(request.form.get('ew'))
|
||||
fett = float(request.form.get('fett'))
|
||||
kh = float(request.form.get('kh'))
|
||||
bst = float(request.form.get('bst'))
|
||||
ca = float(request.form.get('ca'))
|
||||
kcal = convert_decimal(request.form.get('kcal'))
|
||||
ew = convert_decimal(request.form.get('ew'))
|
||||
fett = convert_decimal(request.form.get('fett'))
|
||||
kh = convert_decimal(request.form.get('kh'))
|
||||
bst = convert_decimal(request.form.get('bst'))
|
||||
ca = convert_decimal(request.form.get('ca'))
|
||||
|
||||
print("test")
|
||||
# Verbindung zur Datenbank herstellen und Daten einfügen
|
||||
try:
|
||||
conn = psycopg2.connect()
|
||||
@ -129,6 +134,12 @@ def add_nutrition():
|
||||
def nutrition():
|
||||
return render_template('nutrition.html')
|
||||
|
||||
@app.route('/get_token')
|
||||
@oidc.require_login
|
||||
def get_token():
|
||||
return jsonify(token=oidc.get_access_token())
|
||||
|
||||
|
||||
|
||||
|
||||
app = ProxyFix(app, x_for=1, x_host=1)
|
||||
|
@ -34,7 +34,7 @@ button:not(:disabled):hover {
|
||||
}
|
||||
|
||||
button#remove-button {
|
||||
background-color: #f443366f; /* Helles Rot */
|
||||
background-color: #640000; /* Helles Rot */
|
||||
}
|
||||
|
||||
button#remove-button:disabled {
|
||||
@ -43,7 +43,7 @@ button#remove-button:disabled {
|
||||
}
|
||||
|
||||
button#remove-button:not(:disabled):hover {
|
||||
background-color: #d32f2f3d; /* Dunkleres Rot */
|
||||
background-color: #490000; /* Dunkleres Rot */
|
||||
}
|
||||
|
||||
|
||||
@ -72,7 +72,7 @@ tr:nth-child(even) {
|
||||
}
|
||||
|
||||
.selected, tr.selected {
|
||||
background-color: #ffdd99; /* Hervorhebung der Auswahl */
|
||||
background-color: #e5b5b5; /* Hervorhebung der Auswahl */
|
||||
}
|
||||
|
||||
tr:hover:not(.selected) {
|
||||
|
@ -7,8 +7,6 @@
|
||||
<link rel="shortcut icon" href="../static/images/favicon.ico">
|
||||
|
||||
<script>
|
||||
|
||||
// JavaScript-Funktion, um die Produkte beim Laden der Seite zu holen
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
cleanUpLocalStorage();
|
||||
restoreTableFromLocalStorage();
|
||||
@ -156,12 +154,12 @@ function updateTotalNutrition() {
|
||||
|
||||
// Durchlaufen aller Zeilen in der Haupttabelle und Addition der Werte
|
||||
Array.from(document.getElementById('nutrition-table').rows).slice(1).forEach(row => {
|
||||
totalKcal += parseFloat(row.cells[2].innerText);
|
||||
totalEw += parseFloat(row.cells[3].innerText);
|
||||
totalFett += parseFloat(row.cells[4].innerText);
|
||||
totalKh += parseFloat(row.cells[5].innerText);
|
||||
totalBst += parseFloat(row.cells[6].innerText);
|
||||
totalCa += parseFloat(row.cells[7].innerText);
|
||||
totalKcal += parseFloat(row.cells[4].innerText);
|
||||
totalEw += parseFloat(row.cells[4].innerText);
|
||||
totalFett += parseFloat(row.cells[5].innerText);
|
||||
totalKh += parseFloat(row.cells[6].innerText);
|
||||
totalBst += parseFloat(row.cells[7].innerText);
|
||||
totalCa += parseFloat(row.cells[8].innerText);
|
||||
});
|
||||
|
||||
// Rundung und Aktualisierung der Gesamtwerte
|
||||
@ -177,7 +175,7 @@ function updateTotalNutrition() {
|
||||
</head>
|
||||
<body>
|
||||
<nav id="navbar">
|
||||
<h1>Elos Rezept Rechner</h1>
|
||||
<h1>Elo's Rezept Rechner</h1>
|
||||
<ul>
|
||||
<li><a href="/" class="active">Rechner</a></li>
|
||||
<li><a href="/nutrition">Neue Lebensmittel</a></li>
|
||||
@ -212,6 +210,8 @@ function updateTotalNutrition() {
|
||||
<button id="remove-button" onclick="removeSelectedRow()" disabled>Entfernen</button>
|
||||
<table id="total-nutrition-table">
|
||||
<tr>
|
||||
<th>Lebensmittel</th>
|
||||
<th>Gewicht (g)</th>
|
||||
<th>kcal</th>
|
||||
<th>EW</th>
|
||||
<th>Fett</th>
|
||||
@ -220,6 +220,8 @@ function updateTotalNutrition() {
|
||||
<th>CA</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Gesamtwerte</td>
|
||||
<td>-</td>
|
||||
<td id="total-kcal">0</td>
|
||||
<td id="total-ew">0</td>
|
||||
<td id="total-fett">0</td>
|
||||
|
@ -13,13 +13,27 @@
|
||||
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 formData = new FormData(form);
|
||||
|
||||
fetch('/add_nutrition', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Authorization': 'Bearer ' + token
|
||||
},
|
||||
body: formData
|
||||
}).then(response => {
|
||||
// Behandlung der Serverantwort
|
||||
@ -38,13 +52,14 @@
|
||||
|
||||
// Deaktiviere den "Hinzufügen"-Button wieder
|
||||
document.getElementById('submit-button').disabled = true;
|
||||
});
|
||||
}
|
||||
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<nav id="navbar">
|
||||
<h1>Elos Rezept Rechner</h1>
|
||||
<h1>Elo's Rezept Rechner</h1>
|
||||
<ul>
|
||||
<li><a href="/">Rechner</a></li>
|
||||
<li><a href="/nutrition" class="active">Neue Lebensmittel</a></li>
|
||||
@ -65,12 +80,12 @@
|
||||
</tr>
|
||||
<tr>
|
||||
<td><input type="text" name="food" placeholder="Lebensmittel" 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})?" placeholder="g" 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})?" placeholder="g" 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})?" placeholder="mg" 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})?" placeholder="g" 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})?" placeholder="g" 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})?" placeholder="mg" oninput="updateSubmitButtonState()"></td>
|
||||
</tr>
|
||||
</table>
|
||||
<button type="submit" id="submit-button" disabled>Hinzufügen</button>
|
||||
|
Reference in New Issue
Block a user