Compare commits
27 Commits
Author | SHA1 | Date | |
---|---|---|---|
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
|
@ -15,4 +15,3 @@ EXPOSE 8080
|
|||||||
|
|
||||||
CMD "./start.sh"
|
CMD "./start.sh"
|
||||||
|
|
||||||
|
|
||||||
|
55
src/Run.py
55
src/Run.py
@ -21,7 +21,6 @@ oidc = OpenIDConnect(app)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def calculate_nutrition(food, weight):
|
def calculate_nutrition(food, weight):
|
||||||
try:
|
try:
|
||||||
conn = psycopg2.connect()
|
conn = psycopg2.connect()
|
||||||
@ -51,6 +50,7 @@ def calculate_nutrition(food, weight):
|
|||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Index-Route
|
# Index-Route
|
||||||
@app.route('/')
|
@app.route('/')
|
||||||
@oidc.require_login
|
@oidc.require_login
|
||||||
@ -67,7 +67,6 @@ def get_products():
|
|||||||
with conn.cursor() as cursor:
|
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()
|
||||||
print("ter")
|
|
||||||
return {'products': [product[0] for product in products]}
|
return {'products': [product[0] for product in products]}
|
||||||
finally:
|
finally:
|
||||||
if conn:
|
if conn:
|
||||||
@ -98,19 +97,24 @@ 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(require_token=True, scopes_required=['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
|
||||||
try:
|
try:
|
||||||
conn = psycopg2.connect()
|
conn = psycopg2.connect()
|
||||||
@ -130,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)
|
||||||
|
|
||||||
|
|
||||||
|
@ -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) {
|
||||||
@ -145,3 +152,65 @@ tr:hover:not(.selected) {
|
|||||||
overflow-x: auto; /* Ermöglicht horizontales Scrollen auf kleinen Bildschirmen */
|
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 */
|
||||||
|
}
|
||||||
|
@ -7,8 +7,6 @@
|
|||||||
<link rel="shortcut icon" href="../static/images/favicon.ico">
|
<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();
|
||||||
@ -177,7 +175,7 @@ function updateTotalNutrition() {
|
|||||||
</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>
|
||||||
@ -212,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>
|
||||||
@ -220,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>
|
||||||
|
@ -13,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
|
||||||
@ -38,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>
|
||||||
@ -65,16 +156,44 @@
|
|||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td><input type="text" name="food" placeholder="Lebensmittel" 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})?" placeholder="g" 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="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="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="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="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="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