9 Commits

Author SHA1 Message Date
a9a8a36cb9 logging, 3
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2024-01-31 14:53:04 +01:00
845e4ec673 logging, 2
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2024-01-31 14:46:18 +01:00
d82770158c logging
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2024-01-31 13:49:14 +01:00
3852d78725 table adjusted
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2024-01-31 13:43:21 +01:00
fd057e3415 token stuff, 4
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2024-01-31 13:15:03 +01:00
e4fe5b9831 token stuff, 3
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2024-01-31 13:09:26 +01:00
6a9b938ab9 token stuff, 2
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2024-01-31 13:03:04 +01:00
367e76f9f1 token stuff
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2024-01-31 12:47:35 +01:00
e59b184da5 style
All checks were successful
ci/woodpecker/tag/woodpecker Pipeline was successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-01-30 23:11:29 +01:00
6 changed files with 69 additions and 16 deletions

View File

@ -5,6 +5,7 @@ from werkzeug.middleware.proxy_fix import ProxyFix
import os import os
import json import json
import psycopg2 import psycopg2
import logging
app = Flask(__name__) app = Flask(__name__)
app.config.update({ app.config.update({
@ -20,7 +21,6 @@ app.config.update({
oidc = OpenIDConnect(app) oidc = OpenIDConnect(app)
def calculate_nutrition(food, weight): def calculate_nutrition(food, weight):
try: try:
conn = psycopg2.connect() conn = psycopg2.connect()
@ -105,8 +105,10 @@ def convert_decimal(value):
@app.route('/add_nutrition', methods=['POST']) @app.route('/add_nutrition', methods=['POST'])
@oidc.accept_token(True) @oidc.accept_token(['openid'])
def add_nutrition(): def add_nutrition():
app.logger.info("add_nutrition")
food = request.form.get('food') food = request.form.get('food')
kcal = convert_decimal(request.form.get('kcal')) kcal = convert_decimal(request.form.get('kcal'))
ew = convert_decimal(request.form.get('ew')) ew = convert_decimal(request.form.get('ew'))
@ -121,9 +123,12 @@ def add_nutrition():
with conn.cursor() as cursor: 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)", 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()
return redirect(url_for('nutrition')) return redirect(url_for('nutrition'))
except Exception as e:
app.logger.warn(f"error in add_nutrition: {e}")
return jsonify({"error": str(e)}), 500
finally: finally:
if conn: if conn:
conn.close() conn.close()
@ -141,13 +146,14 @@ def get_token():
@app.route('/get_database_entries') @app.route('/get_database_entries')
@oidc.require_login
def get_database_entries(): def get_database_entries():
try: try:
# Ersetzen Sie diese Werte mit Ihren Datenbank-Verbindungsinformationen # Ersetzen Sie diese Werte mit Ihren Datenbank-Verbindungsinformationen
conn = psycopg2.connect() conn = psycopg2.connect()
cursor = conn.cursor() cursor = conn.cursor()
with conn.cursor() as cursor: with conn.cursor() as cursor:
cursor.execute("SELECT name, kcal, ew, fett, kh, bst, ca FROM nutrition_table") cursor.execute("SELECT name, kcal, ew, fett, kh, bst, ca FROM nutrition_table ORDER BY name")
entries = cursor.fetchall() entries = cursor.fetchall()
# Umwandeln der Daten in ein JSON-freundliches Format # Umwandeln der Daten in ein JSON-freundliches Format
@ -169,7 +175,7 @@ def get_database_entries():
if conn: if conn:
conn.close() conn.close()
app = ProxyFix(app, x_for=1, x_host=1) exposed_app = ProxyFix(app, x_for=1, x_host=1)

View File

@ -13,13 +13,16 @@ cursor = conn.cursor()
# Erstellen der Tabelle (falls noch nicht vorhanden) # Erstellen der Tabelle (falls noch nicht vorhanden)
cursor.execute(''' cursor.execute('''
CREATE TABLE IF NOT EXISTS nutrition_table ( CREATE TABLE IF NOT EXISTS nutrition_table (
name TEXT, id serial not null,
name TEXT not null,
kcal REAL, kcal REAL,
EW REAL, EW REAL,
Fett REAL, Fett REAL,
KH REAL, KH REAL,
BST REAL, BST REAL,
Ca REAL Ca REAL,
constraint nutrition_table_pk primary key (id),
constraint nutrition_table_name_uk unique (name)
) )
''') ''')

View File

@ -6,7 +6,6 @@ Hühnerei,137,11.9,9.3,1.5,0.0,51
Pflanzenmargarine,722,0.2,80.0,0.4,0.0,8 Pflanzenmargarine,722,0.2,80.0,0.4,0.0,8
Sahne 30%,309,2.4,31.7,3.4,0.0,80 Sahne 30%,309,2.4,31.7,3.4,0.0,80
Maisstärke,353,0.4,0.1,85.9,1.0,0 Maisstärke,353,0.4,0.1,85.9,1.0,0
Paniermehl,368,10.1,2.1,73.5,5.3,50
Weizengrieß,335,9.6,0.8,69.0,7.1,17 Weizengrieß,335,9.6,0.8,69.0,7.1,17
Mehl405,343,9.8,1.0,71.8,4.0,15 Mehl405,343,9.8,1.0,71.8,4.0,15
Rapsöl,884,0,100.0,0,0,0 Rapsöl,884,0,100.0,0,0,0
@ -43,13 +42,11 @@ Knoblauch,145,6.1,0.1,28.4,1.8,38
Senf,88,6.0,4.0,6.0,1.0,124 Senf,88,6.0,4.0,6.0,1.0,124
Blattspinat roh,21,2.7,0.3,0.6,2.6,117 Blattspinat roh,21,2.7,0.3,0.6,2.6,117
Buttermilch,37,3.5,0.5,4.0,0.0,109 Buttermilch,37,3.5,0.5,4.0,0.0,109
Himbeere,37,1.3,0.3,4.8,4.7,40
Salz dill gurken,9,0.4,0.1,1.3,0.5,18 Salz dill gurken,9,0.4,0.1,1.3,0.5,18
Schmand 20%,205,2.8,20.0,3.6,0.0,100 Schmand 20%,205,2.8,20.0,3.6,0.0,100
Aspikpulver,338,84.2,0.1,0.0,0.0,11 Aspikpulver,338,84.2,0.1,0.0,0.0,11
Lachs atlantischer,210,20.4,13.4,0.3,0.0,4 Lachs atlantischer,210,20.4,13.4,0.3,0.0,4
Pinienkerne,589,24.0,50.7,7.3,7.2,26 Pinienkerne,589,24.0,50.7,7.3,7.2,26
Zwieback,385,9.9,4.3,73.1,5.2,42
Speisequark,72,13.5,0.3,3.2,0.0,92 Speisequark,72,13.5,0.3,3.2,0.0,92
Basilikum,47,3.1,0.8,5.1,3.1,369 Basilikum,47,3.1,0.8,5.1,3.1,369
Mayonaise 50%,490,0.5,52.0,5.0,0.0,10 Mayonaise 50%,490,0.5,52.0,5.0,0.0,10
@ -83,7 +80,6 @@ Naturreis,349,7.2,2.2,74.1,2.2,16
Mehl Type 405,343,9.8,1.0,71.8,4.0,15 Mehl Type 405,343,9.8,1.0,71.8,4.0,15
Mehl Type 550,346,9.8,1.1,72.0,4.3,17 Mehl Type 550,346,9.8,1.1,72.0,4.3,17
Milchreis,316,6.4,0.8,80.2,1.1,6 Milchreis,316,6.4,0.8,80.2,1.1,6
Kartoffelstärke,341,0.6,0.1,83.1,0.1,35
Hmilch fettarm 1.5%,47,3.4,1.5,4.9,0.0,123 Hmilch fettarm 1.5%,47,3.4,1.5,4.9,0.0,123
Edamer 30%,254,26.4,16.2,0,0.0,800 Edamer 30%,254,26.4,16.2,0,0.0,800
Gouda alt 48%,414,24.6,33.7,0.1,0.0,871 Gouda alt 48%,414,24.6,33.7,0.1,0.0,871
@ -98,7 +94,6 @@ Butterkeks,441,8.2,11.0,74.7,3.3,47
Zwieback,385,9.9,4.3,73.1,5.2,42 Zwieback,385,9.9,4.3,73.1,5.2,42
Schokolade 75% Kakaomasse,598,7.8,42.6,35.0,10.9,73 Schokolade 75% Kakaomasse,598,7.8,42.6,35.0,10.9,73
Paniermehl,368,10.1,0.1,73.5,5.3,50 Paniermehl,368,10.1,0.1,73.5,5.3,50
Senf,88,6.0,4.0,6.0,1.0,124
Schinken geräuchert,152,20.7,7.7,0.0,0.0,2 Schinken geräuchert,152,20.7,7.7,0.0,0.0,2
Rinderkeule,148,20.0,7.6,0.0,0.0,6 Rinderkeule,148,20.0,7.6,0.0,0.0,6
Kirsche süß,62,0.9,0.3,13.3,1.3,17 Kirsche süß,62,0.9,0.3,13.3,1.3,17
@ -107,7 +102,6 @@ Eisbergsalat,16,1.0,0.2,2.0,1.1,19
Endivie,18,1.8,0.2,1.2,1.9,54 Endivie,18,1.8,0.2,1.2,1.9,54
Feldsalat,18,1.8,0.4,0.8,1.5,32 Feldsalat,18,1.8,0.4,0.8,1.5,32
Gurke,14,0.6,0.2,1.8,0.9,15 Gurke,14,0.6,0.2,1.8,0.9,15
Kopfsalat,14,1.2,0.2,1.1,1.4,20
Schalotte,25,1.5,0.2,3.3,1.5,37 Schalotte,25,1.5,0.2,3.3,1.5,37
Gemüsebrühe verz,7,1.6,0,0,0,12 Gemüsebrühe verz,7,1.6,0,0,0,12
Fleischbrühe,4,0.2,0,1,0,5 Fleischbrühe,4,0.2,0,1,0,5
@ -122,8 +116,7 @@ Paprika rot,43,1.3,0.5,6.4,3.6,10
Knollensellerie,27,1.6,0.3,2.3,4.2,50 Knollensellerie,27,1.6,0.3,2.3,4.2,50
Erdbeeren tiefgefroren,38,0.9,0.4,5.8,2.1,24 Erdbeeren tiefgefroren,38,0.9,0.4,5.8,2.1,24
Himbeeren tiefgefroren,45,1.4,0.3,5.0,4.8,42 Himbeeren tiefgefroren,45,1.4,0.3,5.0,4.8,42
Dill,65,3.7,0.8,8.0,5.3,230
Kerbel,58,4.1,0.6,6.2,5.3,400 Kerbel,58,4.1,0.6,6.2,5.3,400
Majoran,52,2.1,1.1,6.9,2.9,322 Majoran,52,2.1,1.1,6.9,2.9,322
Oregano,72,2.2,2.0,9.7,2.5,310 Oregano,72,2.2,2.0,9.7,2.5,310
Thymian,52,1.5,1.2,7.4,3.0,307 Thymian,52,1.5,1.2,7.4,3.0,307

1 name kcal EW Fett KH BST Ca
6 Pflanzenmargarine 722 0.2 80.0 0.4 0.0 8
7 Sahne 30% 309 2.4 31.7 3.4 0.0 80
8 Maisstärke 353 0.4 0.1 85.9 1.0 0
Paniermehl 368 10.1 2.1 73.5 5.3 50
9 Weizengrieß 335 9.6 0.8 69.0 7.1 17
10 Mehl405 343 9.8 1.0 71.8 4.0 15
11 Rapsöl 884 0 100.0 0 0 0
42 Senf 88 6.0 4.0 6.0 1.0 124
43 Blattspinat roh 21 2.7 0.3 0.6 2.6 117
44 Buttermilch 37 3.5 0.5 4.0 0.0 109
Himbeere 37 1.3 0.3 4.8 4.7 40
45 Salz dill gurken 9 0.4 0.1 1.3 0.5 18
46 Schmand 20% 205 2.8 20.0 3.6 0.0 100
47 Aspikpulver 338 84.2 0.1 0.0 0.0 11
48 Lachs atlantischer 210 20.4 13.4 0.3 0.0 4
49 Pinienkerne 589 24.0 50.7 7.3 7.2 26
Zwieback 385 9.9 4.3 73.1 5.2 42
50 Speisequark 72 13.5 0.3 3.2 0.0 92
51 Basilikum 47 3.1 0.8 5.1 3.1 369
52 Mayonaise 50% 490 0.5 52.0 5.0 0.0 10
80 Mehl Type 405 343 9.8 1.0 71.8 4.0 15
81 Mehl Type 550 346 9.8 1.1 72.0 4.3 17
82 Milchreis 316 6.4 0.8 80.2 1.1 6
Kartoffelstärke 341 0.6 0.1 83.1 0.1 35
83 Hmilch fettarm 1.5% 47 3.4 1.5 4.9 0.0 123
84 Edamer 30% 254 26.4 16.2 0 0.0 800
85 Gouda alt 48% 414 24.6 33.7 0.1 0.0 871
94 Zwieback 385 9.9 4.3 73.1 5.2 42
95 Schokolade 75% Kakaomasse 598 7.8 42.6 35.0 10.9 73
96 Paniermehl 368 10.1 0.1 73.5 5.3 50
Senf 88 6.0 4.0 6.0 1.0 124
97 Schinken geräuchert 152 20.7 7.7 0.0 0.0 2
98 Rinderkeule 148 20.0 7.6 0.0 0.0 6
99 Kirsche süß 62 0.9 0.3 13.3 1.3 17
102 Endivie 18 1.8 0.2 1.2 1.9 54
103 Feldsalat 18 1.8 0.4 0.8 1.5 32
104 Gurke 14 0.6 0.2 1.8 0.9 15
Kopfsalat 14 1.2 0.2 1.1 1.4 20
105 Schalotte 25 1.5 0.2 3.3 1.5 37
106 Gemüsebrühe verz 7 1.6 0 0 0 12
107 Fleischbrühe 4 0.2 0 1 0 5
116 Knollensellerie 27 1.6 0.3 2.3 4.2 50
117 Erdbeeren tiefgefroren 38 0.9 0.4 5.8 2.1 24
118 Himbeeren tiefgefroren 45 1.4 0.3 5.0 4.8 42
Dill 65 3.7 0.8 8.0 5.3 230
119 Kerbel 58 4.1 0.6 6.2 5.3 400
120 Majoran 52 2.1 1.1 6.9 2.9 322
121 Oregano 72 2.2 2.0 9.7 2.5 310
122 Thymian 52 1.5 1.2 7.4 3.0 307

View File

@ -174,3 +174,43 @@ tr:hover:not(.selected) {
#database-nutrition-table tr.selected { #database-nutrition-table tr.selected {
background-color: #f0e68c; 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 */
}

View File

@ -61,8 +61,10 @@
table.addEventListener('click', function(e) { table.addEventListener('click', function(e) {
if (e.target.tagName === 'TD') { if (e.target.tagName === 'TD') {
e.target.parentNode.classList.toggle('selected'); e.target.parentNode.classList.toggle('selected');
updateDeleteButtonState();
} }
}); });
updateDeleteButtonState();
}); });
function deleteSelectedRows() { function deleteSelectedRows() {
@ -95,6 +97,15 @@
} }
} }
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() { function loadDatabaseEntries() {
fetch('/get_database_entries') // Pfad zur entsprechenden Flask-Route fetch('/get_database_entries') // Pfad zur entsprechenden Flask-Route

View File

@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
gunicorn 'Run:app' --bind 0.0.0.0:8080 --log-level=info --workers=4 gunicorn 'Run:exposed_app' --bind 0.0.0.0:8080 --log-level=debug --workers=4