48 Commits
0.3.1 ... 0.5.0

Author SHA1 Message Date
86c8b76736 W
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2024-04-16 19:14:09 +02:00
c85b68b072 we
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-04-16 19:10:37 +02:00
c8648788d0 bett
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-04-16 19:07:08 +02:00
fe5ad6ba8d patzh
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-04-16 19:02:18 +02:00
512e89205c button
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-04-16 18:57:54 +02:00
dbb99ba47a elo
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-04-16 18:56:59 +02:00
9c42e0fc63 weig
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-04-16 18:50:08 +02:00
92508a23ae bigger
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-04-16 18:34:36 +02:00
8c3155434a bigger
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-04-16 18:30:59 +02:00
777ad92b22 bigger
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-04-16 18:26:02 +02:00
708ce6dd3d elosa
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-04-16 17:46:45 +02:00
75b66806a2 elkisa
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-04-16 17:42:29 +02:00
6b5c3c36ca elisa
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-04-16 17:38:38 +02:00
7f90ad4c05 back
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-04-11 16:45:20 +02:00
9dee350323 test
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-04-11 16:39:40 +02:00
c3c3b4f83d test
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-04-11 16:35:36 +02:00
727e2f60c4 input
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2024-04-09 20:27:57 +02:00
a411f59e00 runden
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-04-09 20:22:59 +02:00
be531a7ccf runden
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-04-09 20:17:35 +02:00
6e94925fda changes
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-04-09 20:10:04 +02:00
814c5b17e3 old nutri
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2024-04-08 23:09:45 +02:00
e66e54c424 sd
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2024-04-07 20:00:16 +02:00
0ad4c9e398 fee
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-04-07 19:53:41 +02:00
ce86d35b25 ter
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-04-07 19:49:12 +02:00
19552bf774
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-04-07 19:23:15 +02:00
b74f136f81 jetzt
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-04-07 19:16:12 +02:00
b52dbaec57 bug
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-04-07 19:10:34 +02:00
2769d0a33a bug
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-04-07 19:02:10 +02:00
5ac1a9f5a9 editable
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-04-07 18:52:37 +02:00
ab3378ec4d ls
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-04-04 16:52:05 +02:00
5e4ab261a7 change
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2024-04-04 13:41:43 +02:00
14227f0058 cahnge
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-04-04 13:37:36 +02:00
ed62772643 label
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-04-04 13:32:22 +02:00
43b74dc3c2 style
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-04-04 13:29:03 +02:00
1643aa65d4 change
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-04-04 13:24:33 +02:00
a44b0ecf58 bug
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-04-04 13:14:04 +02:00
0f3ff65605 local storage
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-04-04 13:09:13 +02:00
32df39efb8 bug
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-04-04 13:03:25 +02:00
b85b7957c6 change
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-04-04 12:53:05 +02:00
bee94df6e6 change table
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-04-04 12:46:24 +02:00
79cf147345 change table
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-04-04 12:41:41 +02:00
c9d50b6018 missing var
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-04-04 12:34:51 +02:00
8d853a8a43 protion option
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-04-04 12:30:18 +02:00
3e6d743fd4 back
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-04-04 12:25:51 +02:00
888f8717b5 revert
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-04-04 12:19:23 +02:00
eddd739c71 commented out
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-04-04 12:15:35 +02:00
7213cb4757 no scan
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-04-04 12:08:16 +02:00
204e2e4dd7 portion option
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2024-04-03 22:06:15 +02:00
10 changed files with 197 additions and 33 deletions

View File

@ -17,10 +17,10 @@ steps:
when:
- event: [push, tag]
scan_image:
image: aquasec/trivy
commands:
- trivy image $FORGE_NAME/$CI_REPO:$CI_COMMIT_SHA --quiet --exit-code 1
# scan_image:
# image: aquasec/trivy
# commands:
# - trivy image $FORGE_NAME/$CI_REPO:$CI_COMMIT_SHA --quiet --exit-code 1
deploytest:
image: portainer/kubectl-shell:latest

View File

@ -6,6 +6,7 @@ import os
import json
import psycopg2
import logging
from math import ceil, floor
app = Flask(__name__)
app.config.update({
@ -37,12 +38,12 @@ def calculate_nutrition(food, weight):
# Runden und Berechnen der Nährwerte basierend auf dem Gewicht
kcal, ew, fett, kh, bst, ca = result
nutrition_values = [
round(kcal * weight / 100), # kcal gerundet auf ganze Zahl
round(ew * weight / 100, 1), # EW gerundet auf eine Dezimalstelle
round(fett * weight / 100, 1), # Fett gerundet auf eine Dezimalstelle
round(kh * weight / 100, 1), # KH gerundet auf eine Dezimalstelle
round(bst * weight / 100, 1), # BST gerundet auf eine Dezimalstelle
round(ca * weight / 100) # CA gerundet auf ganze Zahl
schulrunden(kcal * weight / 100, ist_kcal=True), # kcal gerundet auf ganze Zahl
schulrunden(ew * weight / 100, 1), # EW gerundet auf eine Dezimalstelle
schulrunden(fett * weight / 100, 1), # Fett gerundet auf eine Dezimalstelle
schulrunden(kh * weight / 100, 1), # KH gerundet auf eine Dezimalstelle
schulrunden(bst * weight / 100, 1), # BST gerundet auf eine Dezimalstelle
schulrunden(ca * weight / 100) # CA gerundet auf ganze Zahl
]
return nutrition_values
else:
@ -53,6 +54,23 @@ def calculate_nutrition(food, weight):
def schulrunden(zahl, stellen=0, ist_kcal=False):
# Wenn es sich um kcal handelt und der Wert vor der Rundung zwischen 0 und 1 liegt
if ist_kcal and 0 < zahl < 1:
return 1
faktor = 10 ** stellen
zahl = zahl * faktor
basis = floor(zahl)
if zahl - basis >= 0.5:
gerundet = basis + 1
else:
gerundet = basis
return gerundet / faktor
# Index-Route
@app.route('/')
@oidc.require_login
@ -201,6 +219,12 @@ def delete_nutrition():
conn.close()
@app.route('/random')
def random_page():
# Diese Route gibt die HTML-Seite 'random.html' zurück
return render_template('random.html')
exposed_app = ProxyFix(app, x_for=1, x_host=1)

BIN
src/static/images/elisa.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB

BIN
src/static/images/elo.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 256 KiB

BIN
src/static/images/marie.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 56 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 167 KiB

View File

@ -231,4 +231,37 @@ button#cancel-button:disabled {
button#cancel-button:not(:disabled):hover {
background-color: #490000; /* Dunkleres Rot */
}
}
.form-layout {
display: flex;
flex-direction: column;
}
.form-row {
margin-bottom: 10px;
}
button#submit-button {
background-image: url('images/elisa.jpg'); /* Pfad zum Bild */
background-size: contain; /* Passt das Bild innerhalb des Buttons an, ohne es zu strecken */
background-repeat: no-repeat; /* Verhindert das Wiederholen des Bildes */
background-position: center; /* Zentriert das Bild im Button */
color: transparent; /* Macht den Text unsichtbar, damit nur das Bild sichtbar ist */
width: 62px; /* Setzt die Breite automatisch entsprechend des Inhalts */
height: 85px; /* Passt die Höhe an, um das Bild vollständig anzuzeigen */
padding: 10px 20px; /* Hinzufügen von etwas Platz um das Bild */
}
button#remove-button {
background-image: url('images/marie2.jpg'); /* Pfad zum Bild */
background-size: contain; /* Passt das Bild innerhalb des Buttons an, ohne es zu strecken */
background-repeat: no-repeat; /* Verhindert das Wiederholen des Bildes */
background-position: center; /* Zentriert das Bild im Button */
color: transparent; /* Macht den Text unsichtbar, damit nur das Bild sichtbar ist */
width: 78px; /* Setzt die Breite automatisch entsprechend des Inhalts */
height: 85px; /* Passt die Höhe an, um das Bild vollständig anzuzeigen */
padding: 10px 20px; /* Hinzufügen von etwas Platz um das Bild */
}

View File

@ -9,7 +9,9 @@
<script>
document.addEventListener('DOMContentLoaded', function() {
cleanUpLocalStorage();
restorePortions()
restoreTableFromLocalStorage();
updateTotalNutrition();
fetch('/get_products')
.then(response => response.json())
@ -32,6 +34,65 @@
});
});
document.getElementById('portions').addEventListener('input', function() {
const portions = this.value;
localStorage.setItem('savedPortions', portions); // Speichern der Portionen im localStorage
recalculateTableBasedOnPortions(); // Bestehende Funktion, um die Tabelle zu aktualisieren
});
function restorePortions() {
const savedPortions = localStorage.getItem('savedPortions');
if (savedPortions) {
document.getElementById('portions').value = savedPortions;
recalculateTableBasedOnPortions(); // Falls notwendig, um die Tabelle direkt zu aktualisieren
}
}
function recalculateTableBasedOnPortions() {
const portions = parseInt(document.getElementById('portions').value, 10) || 1;
let entries = JSON.parse(localStorage.getItem('nutritionEntries')) || [];
entries.forEach((entry, index) => {
const newWeight = Math.ceil(entry.weight / portions);
// Da die Server-Anfrage möglicherweise nicht sofort antwortet, passen wir den Index an, um die korrekte Zeile zu aktualisieren.
fetchUpdatedNutrition(entry.food, newWeight, index + 1); // +1, um den Kopfzeilenindex zu überspringen
});
}
function fetchUpdatedNutrition(food, weight, rowIndex) {
fetch(`/add_lm?food=${encodeURIComponent(food)}&weight=${encodeURIComponent(weight)}`)
.then(response => response.json())
.then(data => {
// Direktes Aktualisieren der Zeile mit den neuen Daten
const table = document.getElementById('nutrition-table');
if (table.rows[rowIndex]) {
updateRowWithNewData(table.rows[rowIndex], weight, data);
}
updateTotalNutrition(); // Aktualisiert die Gesamtnährwerte
})
.catch(error => {
console.error('Fehler:', error);
// Behandlung spezifischer Fehler, z.B. Zurücksetzen der Werte oder Anzeigen einer Fehlermeldung
});
}
function updateRowWithNewData(row, weight, nutritionData) {
if (nutritionData && row.cells.length > 7) {
row.cells[1].innerText = weight; // Aktualisiere Gewicht
row.cells[2].innerText = nutritionData.kcal;
row.cells[3].innerText = nutritionData.ew;
row.cells[4].innerText = nutritionData.fett;
row.cells[5].innerText = nutritionData.kh;
row.cells[6].innerText = nutritionData.bst;
row.cells[7].innerText = nutritionData.ca;
} else {
// Fehlerbehandlung, falls die Datenstruktur nicht wie erwartet ist
console.error('Unvollständige Daten erhalten: ', nutritionData);
}
}
function restoreTableFromLocalStorage() {
let entries = JSON.parse(localStorage.getItem('nutritionEntries')) || [];
let oneHourAgo = new Date().getTime() - (60 * 60 * 1000);
@ -94,10 +155,14 @@
}
function removeEntryFromLocalStorage(rowData) {
let entries = JSON.parse(localStorage.getItem('nutritionEntries')) || [];
entries = entries.filter(entry => entry.food !== rowData.food || entry.weight !== rowData.weight);
localStorage.setItem('nutritionEntries', JSON.stringify(entries));
}
let entries = JSON.parse(localStorage.getItem('nutritionEntries')) || [];
// Konvertieren von rowData.weight in eine Zahl, um eine korrekte Vergleichsbasis zu schaffen
const weightToCompare = parseFloat(rowData.weight);
// Verwendung einer strikten Gleichheitsprüfung für beide Werte
entries = entries.filter(entry => entry.food !== rowData.food || parseFloat(entry.weight) !== weightToCompare);
localStorage.setItem('nutritionEntries', JSON.stringify(entries));
}
function updateRemoveButtonState() {
const selectedRows = document.querySelectorAll('#nutrition-table .selected').length;
@ -111,11 +176,29 @@
document.getElementById('submit-button').disabled = !(food && weight);
}
function schulrunden(zahl) {
// Multipliziere die Zahl mit 10, um die relevante Dezimalstelle vor das Komma zu bekommen
zahl = zahl * 10;
// Wende Math.ceil an, um auf die nächste ganze Zahl aufzurunden,
// aber nur, wenn der Dezimalteil >= 0.5 ist. Andernfalls verwende Math.floor.
zahl = (zahl - Math.floor(zahl) >= 0.5) ? Math.ceil(zahl) : Math.floor(zahl);
// Teile durch 10, um die ursprüngliche Skalierung wiederherzustellen,
// aber mit der erforderlichen Rundung
return zahl / 10;
}
function addProduct() {
const foodInput = document.getElementById('my_combobox');
const weightInput = document.getElementById('weight');
const portionsInput = document.getElementById('portions');
const food = foodInput.value;
const weight = weightInput.value;
let weight = parseFloat(weightInput.value);
const portions = portionsInput.value ? parseInt(portionsInput.value, 10) : 1;
// Teilen des Gewichts durch die Anzahl der Portionen und Aufrunden
weight = schulrunden(weight / portions);
fetch(`/add_lm?food=${encodeURIComponent(food)}&weight=${encodeURIComponent(weight)}`)
@ -187,15 +270,23 @@ function updateTotalNutrition() {
<div class="content">
<form onsubmit="event.preventDefault(); addProduct();" id="product-form">
<label for="my_combobox">Wählen Sie ein Lebensmittel</label>
<input list="products" name="my_combobox" id="my_combobox" placeholder="Lebensmittel" oninput="updateButtonState()" autocomplete="off">
<datalist id="products">
<!-- Produkte werden hier dynamisch eingefügt -->
</datalist>
<input type="number" id="weight" name="weight" placeholder="Gramm" oninput="updateButtonState()">
<button type="submit" id="submit-button" disabled>Hinzufügen</button>
<form onsubmit="event.preventDefault(); addProduct();" id="product-form" class="form-layout">
<div class="form-row">
<label for="portions">Wählen Sie die Anzahl an Portionen</label>
<input type="number" id="portions" name="portions" placeholder="Portionen" min="1" value="1" oninput="recalculateTableBasedOnPortions()">
</div>
<div class="form-row">
<label for="my_combobox">Wählen Sie ein Lebensmittel</label>
<input list="products" name="my_combobox" id="my_combobox" placeholder="Lebensmittel" oninput="updateButtonState()" autocomplete="off">
<datalist id="products">
<!-- Produkte werden hier dynamisch eingefügt -->
</datalist>
<input type="number" id="weight" name="weight" placeholder="Gramm" step="0.1" min="0" oninput="updateButtonState()">
<button type="submit" id="submit-button" disabled>Hinzufügen</button>
</div>
</form>
<table id="nutrition-table">
<tr>
@ -210,7 +301,7 @@ function updateTotalNutrition() {
</tr>
<!-- Zeilen werden hier dynamisch hinzugefügt -->
</table>
<button id="remove-button" onclick="removeSelectedRow()" disabled>Entfernen</button>
<button id="remove-button" onclick="removeSelectedRow()" disabled></button>
<table id="total-nutrition-table">
<tr>
<th>Lebensmittel</th>

View File

@ -137,13 +137,13 @@
tableBody.innerHTML = '';
data.forEach(entry => {
const row = tableBody.insertRow();
row.insertCell(0).innerText = entry.food;
row.insertCell(1).innerText = entry.kcal;
row.insertCell(2).innerText = entry.ew;
row.insertCell(3).innerText = entry.fett;
row.insertCell(4).innerText = entry.kh;
row.insertCell(5).innerText = entry.bst;
row.insertCell(6).innerText = entry.ca;
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 ...
});
@ -172,7 +172,9 @@
}
}
function openImagePage() {
window.open('random', '_blank'); // Öffnet die neue Seite in einem neuen Tab
}
</script>
</head>
<body>
@ -215,6 +217,10 @@
<div class="search-container">
<input type="text" id="search-input" placeholder="Lebensmittel suchen..." oninput="filterTable()">
<button onclick="openImagePage()" style="background-image: url('../static/images/marie.jpg'); border: none; cursor: pointer; background-size: cover; width: 62px; height: 85px; vertical-align: middle;">
<!-- Der Text wird durch den transparenten Text ersetzt, falls nötig -->
<span style="opacity: 0;">Öffnen</span>
</button>
</div>

10
src/templates/random.html Normal file
View File

@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Bildansicht</title>
</head>
<body style="margin: 0; padding: 0; display: flex; justify-content: center; align-items: center; height: 100vh;">
<img src="../static/images/elo.jpg" alt="Elo Bild" style="max-width: 100%; max-height: 100%;">
</body>
</html>