Compare commits

..

107 Commits
0.2.11 ... main

Author SHA1 Message Date
8e0ec494cb
redis
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2025-01-17 23:10:39 +01:00
9d42a46b43
redis
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2025-01-17 23:05:38 +01:00
95fa775c61
redis
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2025-01-17 23:03:35 +01:00
f8b54f7bba
redis
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2025-01-17 23:01:14 +01:00
9d6555af82
disable oidc
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2025-01-17 14:34:05 +01:00
3d6c071233
disable oidc
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2025-01-17 14:27:56 +01:00
6ede84955c
disable oidc
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2025-01-17 14:25:52 +01:00
b9b7c6b48d
disable oidc
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2025-01-17 14:19:04 +01:00
d1280eea7b
disable oidc
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2025-01-17 14:10:03 +01:00
c403e4f253
disable oidc
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2025-01-17 14:06:47 +01:00
d3e624b9ce
new base image
All checks were successful
ci/woodpecker/manual/woodpecker Pipeline was successful
ci/woodpecker/push/woodpecker Pipeline was successful
2025-01-17 13:31:15 +01:00
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
11469a2865 removed xss
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2024-02-06 15:54:58 +01:00
9a4160e4e1 removed xss
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-02-06 15:51:14 +01:00
54c67cf5c2 no xss
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-02-06 15:46:53 +01:00
c7bf411f01
another trivy test, 11
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-02-06 13:20:03 +01:00
67c4981cbe
another trivy test, 10
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2024-02-06 13:17:34 +01:00
6211ea95a4
another trivy test, 9
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2024-02-06 12:52:09 +01:00
3cee043e28
another trivy test, 8
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2024-02-06 12:50:01 +01:00
6fe351e110
another trivy test, 7
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2024-02-06 12:47:42 +01:00
7429d4a4f0
another trivy test, 6
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2024-02-06 12:45:24 +01:00
515657b1fd
another trivy test, 5
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2024-02-06 12:38:55 +01:00
605ddc00d0
another trivy test, 4
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2024-02-06 12:36:49 +01:00
7e00994a37
another trivy test, 3
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2024-02-06 12:32:06 +01:00
fb1249d37b
another trivy test, 2
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-02-06 10:31:23 +01:00
d9195187f3
another trivy test
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2024-02-06 10:29:14 +01:00
161aea553c
test outaged alpine image
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-02-06 10:12:29 +01:00
7c3ae15c67
use Werkzeug 3.0.1 again
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-02-06 09:54:16 +01:00
d535fe3743
test trivy
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2024-02-06 09:49:55 +01:00
56ed58b6d4
password test
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-02-06 09:19:13 +01:00
863fcef491
add trivy into ci script and separate database for test instance
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-02-06 09:10:09 +01:00
807f1de774 test
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2024-02-01 17:41:56 +01:00
677874a0e1 left version
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-02-01 17:35:41 +01:00
81fc7ade5f test
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-02-01 17:34:28 +01:00
b941819b73 test
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-02-01 17:27:43 +01:00
dcc1336d62 test
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-02-01 17:22:08 +01:00
99bd1841cb try
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-02-01 17:21:30 +01:00
16f8c23c38 round
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-02-01 17:11:43 +01:00
cb84e3cdc0 table consistant
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-02-01 17:06:30 +01:00
ca734fda32 version left
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-02-01 17:03:29 +01:00
4f6d3de79c search
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-02-01 16:57:01 +01:00
bf245e215a fix
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-02-01 16:49:50 +01:00
443eb9ef00 fix
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-02-01 16:48:54 +01:00
ce38d6cf24 delete in db
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2024-02-01 16:43:31 +01:00
5c8f057843 button color
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-02-01 16:34:54 +01:00
85afd501ce version id, 2
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2024-02-01 09:55:40 +01:00
4dbc156439 version id
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-02-01 09:48:54 +01:00
fd3e8751fe order by name
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2024-02-01 09:28:26 +01:00
21ea1aa56f
Merge branch 'main' of gitea.hottis.de:moerp/elo-rezept-rechner
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-01-31 16:46:36 +01:00
eefc8d5b21
fix image tag 2024-01-31 16:46:31 +01:00
41010b8a7b small fix
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-01-31 16:27:17 +01:00
43583fb7f3 color
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-01-31 16:17:37 +01:00
1f5b4163e7 fix
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-01-31 16:11:17 +01:00
38d3381ecd
test instance
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-01-31 15:51:31 +01:00
db769ca053
postfix instead of prefix, 2
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-01-31 15:31:03 +01:00
536e933fef
postfix instead of prefix 2024-01-31 15:30:53 +01:00
d469a7cf2c
test deployment
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2024-01-31 15:27:22 +01:00
d308fd662a
logging, 4
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2024-01-31 15:05:58 +01:00
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
17 changed files with 465 additions and 138 deletions

View File

@ -2,7 +2,7 @@ steps:
build: build:
image: plugins/kaniko image: plugins/kaniko
settings: settings:
repo: gitea.hottis.de/moerp/elo-rezept-rechner repo: ${FORGE_NAME}/${CI_REPO}
registry: registry:
from_secret: container_registry from_secret: container_registry
tags: latest,${CI_COMMIT_SHA},${CI_COMMIT_TAG} tags: latest,${CI_COMMIT_SHA},${CI_COMMIT_TAG}
@ -10,10 +10,34 @@ steps:
from_secret: container_registry_username from_secret: container_registry_username
password: password:
from_secret: container_registry_password from_secret: container_registry_password
build_args:
- VERSION_ID1=${CI_COMMIT_SHA}
- VERSION_ID2=${CI_COMMIT_TAG}
dockerfile: Dockerfile dockerfile: Dockerfile
when: when:
- event: [push, tag] - event: [push, tag]
# 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
secrets:
- source: kube_config
target: KUBE_CONFIG_CONTENT
- source: encryption_key
target: ENCRYPTION_KEY
- source: secrets_checksum
target: MD5_CHECKSUM
commands:
- printf "$KUBE_CONFIG_CONTENT" > /tmp/kubeconfig
- export KUBECONFIG=/tmp/kubeconfig
- ./deployment/deploy.sh test
when:
- event: [push, tag]
deploy: deploy:
image: portainer/kubectl-shell:latest image: portainer/kubectl-shell:latest
secrets: secrets:

View File

@ -1,6 +1,8 @@
FROM python:3.12-alpine3.19 FROM python:3.12-alpine3.21
ARG APP_DIR="/opt/app" ARG APP_DIR="/opt/app"
ARG VERSION_ID1="x"
ARG VERSION_ID2="alpha"
COPY ./src/ ${APP_DIR}/ COPY ./src/ ${APP_DIR}/
COPY start.sh ${APP_DIR}/ COPY start.sh ${APP_DIR}/
@ -8,8 +10,12 @@ COPY start.sh ${APP_DIR}/
WORKDIR ${APP_DIR} WORKDIR ${APP_DIR}
RUN \ RUN \
apk add --no-cache build-base libpq-dev && \ apk add --no-cache build-base libpq-dev npm && \
pip install -r requirements.txt pip install --upgrade pip && \
pip install -r requirements.txt && \
if [ "${VERSION_ID2}" != "" ]; then VERSION_ID=${VERSION_ID2}; else VERSION_ID=${VERSION_ID1}; fi && \
sed -i -e 's/VERSION_ID/'$VERSION_ID'/' ${APP_DIR}/templates/index.html && \
sed -i -e 's/VERSION_ID/'"$VERSION_ID"'/' ${APP_DIR}/templates/nutrition.html
EXPOSE 8080 EXPOSE 8080

View File

@ -1,5 +1,7 @@
#!/bin/bash #!/bin/bash
if [ "$ENCRYPTION_KEY" = "" ]; then if [ "$ENCRYPTION_KEY" = "" ]; then
echo "ENCRYPTION_KEY not set" echo "ENCRYPTION_KEY not set"
exit 1 exit 1
@ -10,6 +12,7 @@ if [ "$MD5_CHECKSUM" = "" ]; then
exit 1 exit 1
fi fi
SECRETS_CIPHERTEXT_FILE=secrets.enc SECRETS_CIPHERTEXT_FILE=secrets.enc
SECRETS_PLAINTEXT_FILE=/tmp/secrets SECRETS_PLAINTEXT_FILE=/tmp/secrets
TMP_FILE=`mktemp` TMP_FILE=`mktemp`

View File

@ -46,10 +46,10 @@ metadata:
spec: spec:
tls: tls:
- hosts: - hosts:
- nutri.hottis.de - nutri%POSTFIX%.hottis.de
secretName: nutri-cert secretName: nutri-cert
rules: rules:
- host: nutri.hottis.de - host: nutri%POSTFIX%.hottis.de
http: http:
paths: paths:
- path: / - path: /

View File

@ -1,13 +1,19 @@
#!/bin/bash #!/bin/bash
if [ "$1" == "test" ]; then
POSTFIX="-test"
IMAGE_TAG=${CI_COMMIT_SHA}
else
POSTFIX=""
fi
if [ "$IMAGE_TAG" == "" ]; then if [ "$IMAGE_TAG" == "" ]; then
echo "Make sure IMAGE_TAG is set" echo "Make sure IMAGE_TAG is set"
exit 1 exit 1
fi fi
IMAGE_NAME=gitea.hottis.de/moerp/elo-rezept-rechner IMAGE_NAME=gitea.hottis.de/moerp/elo-rezept-rechner
NAMESPACE=moerp NAMESPACE=moerp${POSTFIX}
DEPLOYMENT_DIR=$PWD/deployment DEPLOYMENT_DIR=$PWD/deployment
pushd $DEPLOYMENT_DIR > /dev/null pushd $DEPLOYMENT_DIR > /dev/null
@ -15,7 +21,7 @@ pushd $DEPLOYMENT_DIR > /dev/null
. /tmp/secrets . /tmp/secrets
rm /tmp/secrets rm /tmp/secrets
CLIENT_SECRETS=`cat oidc-config.json | sed -e's!%CLIENT_SECRET%!'$CLIENT_SECRET'!'` CLIENT_SECRETS=`cat oidc-config${POSTFIX}.json | sed -e's!%CLIENT_SECRET%!'$CLIENT_SECRET'!'`
kubectl create namespace $NAMESPACE \ kubectl create namespace $NAMESPACE \
--dry-run=client \ --dry-run=client \
@ -30,13 +36,14 @@ kubectl create secret generic nutri-secrets \
--from-literal=CLIENT_SECRETS="$CLIENT_SECRETS" \ --from-literal=CLIENT_SECRETS="$CLIENT_SECRETS" \
--from-literal=PGUSER="$PGUSER" \ --from-literal=PGUSER="$PGUSER" \
--from-literal=PGPASSWORD="$PGPASSWORD" \ --from-literal=PGPASSWORD="$PGPASSWORD" \
--from-literal=PGDATABASE="$PGDATABASE" \ --from-literal=PGDATABASE="$PGDATABASE$POSTFIX" \
--from-literal=PGHOST="timescaledb.database.svc.cluster.local" \ --from-literal=PGHOST="timescaledb.database.svc.cluster.local" \
--from-literal=PGSSLMODE="require" | \ --from-literal=PGSSLMODE="require" | \
kubectl apply -f - -n $NAMESPACE kubectl apply -f - -n $NAMESPACE
cat $DEPLOYMENT_DIR/deploy-yml.tmpl | \ cat $DEPLOYMENT_DIR/deploy-yml.tmpl | \
sed -e 's,%IMAGE%,'$IMAGE_NAME':'$IMAGE_TAG','g | \ sed -e 's,%IMAGE%,'$IMAGE_NAME':'$IMAGE_TAG','g | \
sed -e 's,%POSTFIX%,'$POSTFIX','g | \
kubectl apply -f - -n $NAMESPACE kubectl apply -f - -n $NAMESPACE
popd > /dev/null popd > /dev/null

View File

@ -0,0 +1,13 @@
{
"web": {
"issuer": "https://auth2.hottis.de/realms/hottis",
"auth_uri": "https://auth2.hottis.de/ealms/hottis/protocol/openid-connect/auth",
"client_id": "nutri",
"client_secret": "%CLIENT_SECRET%",
"redirect_uris": [
"https://nutri-test.hottis.de/*"
],
"userinfo_uri": "https://auth2.hottis.de/realms/hottis/protocol/openid-connect/userinfo",
"token_uri": "https://auth2.hottis.de/realms/hottis/protocol/openid-connect/token"
}
}

View File

@ -1,4 +1,6 @@
from flask import Flask, request, render_template, jsonify, redirect, url_for, g from flask import Flask, request, render_template, jsonify, redirect, url_for, g
from flask_session import Session
import redis
import sqlite3 import sqlite3
from flask_oidc import OpenIDConnect from flask_oidc import OpenIDConnect
from werkzeug.middleware.proxy_fix import ProxyFix from werkzeug.middleware.proxy_fix import ProxyFix
@ -6,20 +8,29 @@ import os
import json import json
import psycopg2 import psycopg2
import logging import logging
from math import ceil, floor
app = Flask(__name__) app = Flask(__name__)
app.config.update({ app.config.update({
'SECRET_KEY': os.environ['SECRET'], 'SECRET_KEY': os.environ['SECRET'],
'DEBUG': False, 'DEBUG': True,
'OIDC_CLIENT_SECRETS': json.loads(os.environ['CLIENT_SECRETS']), 'OIDC_CLIENT_SECRETS': json.loads(os.environ['CLIENT_SECRETS']),
'OIDC_ID_TOKEN_COOKIE_SECURE': False, 'OIDC_ID_TOKEN_COOKIE_SECURE': True,
'OIDC_USER_INFO_ENABLED': True, 'OIDC_USER_INFO_ENABLED': True,
'OIDC_OPENID_REALM': 'hottis', 'OIDC_OPENID_REALM': 'hottis',
'OIDC_SCOPES': ['openid', 'email', 'profile'] 'OIDC_SCOPES': ['openid', 'email'],
'SESSION_TYPE': 'redis',
'SESSION_PERMANENT': False,
'SESSION_USE_SIGNER': True,
'SESSION_KEY_PREFIX': 'nutri',
'SESSION_REDIS': redis.StrictRedis(host='redis-master.redis.svc.cluster.local', port=6379, db=4)
}) })
oidc = OpenIDConnect(app) oidc = OpenIDConnect(app)
logging.basicConfig(level=logging.DEBUG)
app.logger.handlers = logging.getLogger('gunicorn.error').handlers
datapw = 'dasrtwegdffgtewrt4335wferg'
def calculate_nutrition(food, weight): def calculate_nutrition(food, weight):
try: try:
@ -35,12 +46,12 @@ def calculate_nutrition(food, weight):
# Runden und Berechnen der Nährwerte basierend auf dem Gewicht # Runden und Berechnen der Nährwerte basierend auf dem Gewicht
kcal, ew, fett, kh, bst, ca = result kcal, ew, fett, kh, bst, ca = result
nutrition_values = [ nutrition_values = [
round(kcal * weight / 100), # kcal gerundet auf ganze Zahl schulrunden(kcal * weight / 100, ist_kcal=True), # kcal gerundet auf ganze Zahl
round(ew * weight / 100, 1), # EW gerundet auf eine Dezimalstelle schulrunden(ew * weight / 100, 1), # EW gerundet auf eine Dezimalstelle
round(fett * weight / 100, 1), # Fett gerundet auf eine Dezimalstelle schulrunden(fett * weight / 100, 1), # Fett gerundet auf eine Dezimalstelle
round(kh * weight / 100, 1), # KH gerundet auf eine Dezimalstelle schulrunden(kh * weight / 100, 1), # KH gerundet auf eine Dezimalstelle
round(bst * weight / 100, 1), # BST gerundet auf eine Dezimalstelle schulrunden(bst * weight / 100, 1), # BST gerundet auf eine Dezimalstelle
round(ca * weight / 100) # CA gerundet auf ganze Zahl schulrunden(ca * weight / 100) # CA gerundet auf ganze Zahl
] ]
return nutrition_values return nutrition_values
else: else:
@ -51,21 +62,38 @@ 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 # Index-Route
@app.route('/') @app.route('/')
@oidc.require_login # @oidc.require_login
def index(): def index():
return render_template('index.html') return render_template('index.html')
# ... # ...
@app.route('/get_products') @app.route('/get_products')
@oidc.require_login # @oidc.require_login
def get_products(): def get_products():
try: try:
conn = psycopg2.connect() conn = psycopg2.connect()
with conn.cursor() as cursor: with conn.cursor() as cursor:
cursor.execute('SELECT name FROM nutrition_table') cursor.execute('SELECT name FROM nutrition_table ORDER BY name')
products = cursor.fetchall() products = cursor.fetchall()
return {'products': [product[0] for product in products]} return {'products': [product[0] for product in products]}
finally: finally:
@ -75,7 +103,7 @@ def get_products():
# Route zum Hinzufügen und Berechnen von Lebensmitteln # Route zum Hinzufügen und Berechnen von Lebensmitteln
@app.route('/add_lm', methods=['GET']) @app.route('/add_lm', methods=['GET'])
@oidc.require_login # @oidc.require_login
def add_lm(): def add_lm():
food = request.args.get('food') food = request.args.get('food')
weight = float(request.args.get('weight')) weight = float(request.args.get('weight'))
@ -105,8 +133,10 @@ def convert_decimal(value):
@app.route('/add_nutrition', methods=['POST']) @app.route('/add_nutrition', methods=['POST'])
@oidc.accept_token(['openid']) # @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'))
@ -133,18 +163,18 @@ def add_nutrition():
@app.route('/nutrition') @app.route('/nutrition')
@oidc.require_login # @oidc.require_login
def nutrition(): def nutrition():
return render_template('nutrition.html') return render_template('nutrition.html')
@app.route('/get_token') @app.route('/get_token')
@oidc.require_login # @oidc.require_login
def get_token(): def get_token():
return jsonify(token=oidc.get_access_token()) return jsonify(token=oidc.get_access_token())
@app.route('/get_database_entries') @app.route('/get_database_entries')
@oidc.require_login # @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
@ -173,8 +203,37 @@ def get_database_entries():
if conn: if conn:
conn.close() conn.close()
app = ProxyFix(app, x_for=1, x_host=1)
@app.route('/delete_nutrition', methods=['POST'])
# @oidc.accept_token(['openid'])
def delete_nutrition():
data = request.get_json()
foodNames = data['foodNames']
if not foodNames:
return jsonify({'error': 'Keine Lebensmittel zum Löschen angegeben'}), 400
try:
conn = psycopg2.connect()
with conn.cursor() as cursor:
query = "DELETE FROM nutrition_table WHERE name = ANY(%s)"
cursor.execute(query, (foodNames,))
conn.commit()
return jsonify({'message': 'Erfolgreich gelöscht'}), 200
except Exception as e:
return jsonify({'error': str(e)}), 500
finally:
if conn:
conn.close()
@app.route('/random')
@oidc.require_login
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)
#

View File

@ -20,3 +20,6 @@ requests==2.31.0
typing_extensions==4.9.0 typing_extensions==4.9.0
urllib3==2.1.0 urllib3==2.1.0
Werkzeug==3.0.1 Werkzeug==3.0.1
Flask-Session
redis

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

@ -46,13 +46,30 @@ button#remove-button:not(:disabled):hover {
background-color: #490000; /* Dunkleres Rot */ background-color: #490000; /* Dunkleres Rot */
} }
table { table {
width: 100%; width: 100%;
border-collapse: collapse; border-collapse: separate; /* Erlaubt die Anwendung von border-radius */
border-spacing: 0;
border-radius: 10px;
} }
table th:first-child {
border-top-left-radius: 10px;
}
table th:last-child {
border-top-right-radius: 10px;
}
table tr:last-child td:first-child {
border-bottom-left-radius: 10px;
}
table tr:last-child td:last-child {
border-bottom-right-radius: 10px;
}
table, th, td { table, th, td {
border: 1px solid #ddd; border: 1px solid #ddd;
} }
@ -72,7 +89,7 @@ tr:nth-child(even) {
} }
.selected, tr.selected { .selected, tr.selected {
background-color: #e5b5b5; /* Hervorhebung der Auswahl */ background-color: #efcccc; /* Hervorhebung der Auswahl */
} }
tr:hover:not(.selected) { tr:hover:not(.selected) {
@ -89,9 +106,20 @@ tr:hover:not(.selected) {
border-radius: 10px; border-radius: 10px;
} }
#navbar .navbar-header {
display: flex;
align-items: center;
}
#navbar h1 { #navbar h1 {
margin: 0; margin: 0;
font-size: 24px; font-size: 24px;
display: inline-block;
}
#navbar .versionid {
margin-left: 20px;
display: inline-block;
} }
#navbar ul { #navbar ul {
@ -113,13 +141,10 @@ tr:hover:not(.selected) {
transition: background-color 0.3s; transition: background-color 0.3s;
} }
#navbar a:hover { #navbar a:hover, #navbar a.active {
background-color: #007344; /* Etwas helleres Grün */ background-color: #007344; /* Etwas helleres Grün */
} }
#navbar a.active {
background-color: #008C50; /* Mittleres Grün */
}
.content { .content {
@ -130,10 +155,8 @@ tr:hover:not(.selected) {
} }
#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 { #nutrition-input-table th, #nutrition-input-table td {
border: 1px solid #ddd; /* Fügt Ränder hinzu */ border: 1px solid #ddd; /* Fügt Ränder hinzu */
@ -153,16 +176,17 @@ tr:hover:not(.selected) {
} }
} }
#table-container { .table-container {
overflow-y: auto; overflow-y: auto;
max-height: 400px; /* Passen Sie die Höhe nach Bedarf an */ max-height: 500px; /* Passen Sie die Höhe nach Bedarf an */
border-radius: 10px; border-radius: 10px;
margin-top: 20px; margin-top: 20px;
} }
#database-nutrition-table { #database-nutrition-table {
width: 100%; width: 100%;
border-collapse: collapse; border-collapse: separate; /* Erlaubt die Anwendung von border-radius */
border-spacing: 0;
} }
#database-nutrition-table th, #database-nutrition-table td { #database-nutrition-table th, #database-nutrition-table td {
@ -172,7 +196,7 @@ tr:hover:not(.selected) {
} }
#database-nutrition-table tr.selected { #database-nutrition-table tr.selected {
background-color: #f0e68c; background-color: #efcccc;
} }
@ -183,34 +207,61 @@ tr:hover:not(.selected) {
justify-content: center; justify-content: center;
} }
#password-prompt input[type="password"] { button#delete-row-button {
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 */ background-color: #640000; /* Helles Rot */
} }
#password-prompt button[type="button"]:hover { button#delete-row-button:disabled {
background-color: #cccccc;
color: #666666;
}
button#delete-row-button:not(:disabled):hover {
background-color: #490000; /* Dunkleres Rot */ background-color: #490000; /* Dunkleres Rot */
} }
button#cancel-button {
background-color: #640000; /* Helles Rot */
}
button#cancel-button:disabled {
background-color: #cccccc;
color: #666666;
}
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

@ -2,14 +2,16 @@
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>Nährwertberechnungs-App</title> <title>Elo's Rezept Rechner</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"> <link rel="shortcut icon" href="../static/images/favicon.ico">
<script> <script>
document.addEventListener('DOMContentLoaded', function() { document.addEventListener('DOMContentLoaded', function() {
cleanUpLocalStorage(); cleanUpLocalStorage();
restorePortions()
restoreTableFromLocalStorage(); restoreTableFromLocalStorage();
updateTotalNutrition(); updateTotalNutrition();
fetch('/get_products') fetch('/get_products')
.then(response => response.json()) .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() { function restoreTableFromLocalStorage() {
let entries = JSON.parse(localStorage.getItem('nutritionEntries')) || []; let entries = JSON.parse(localStorage.getItem('nutritionEntries')) || [];
let oneHourAgo = new Date().getTime() - (60 * 60 * 1000); let oneHourAgo = new Date().getTime() - (60 * 60 * 1000);
@ -49,14 +110,14 @@
const table = document.getElementById('nutrition-table'); const table = document.getElementById('nutrition-table');
const row = table.insertRow(); const row = table.insertRow();
row.insertCell(0).innerHTML = food; row.insertCell(0).innerText = food;
row.insertCell(1).innerHTML = weight; row.insertCell(1).innerText = weight;
row.insertCell(2).innerHTML = nutritionData.kcal; row.insertCell(2).innerText = nutritionData.kcal;
row.insertCell(3).innerHTML = nutritionData.ew; row.insertCell(3).innerText = nutritionData.ew;
row.insertCell(4).innerHTML = nutritionData.fett; row.insertCell(4).innerText = nutritionData.fett;
row.insertCell(5).innerHTML = nutritionData.kh; row.insertCell(5).innerText = nutritionData.kh;
row.insertCell(6).innerHTML = nutritionData.bst; row.insertCell(6).innerText = nutritionData.bst;
row.insertCell(7).innerHTML = nutritionData.ca; row.insertCell(7).innerText = nutritionData.ca;
} }
@ -94,10 +155,14 @@
} }
function removeEntryFromLocalStorage(rowData) { function removeEntryFromLocalStorage(rowData) {
let entries = JSON.parse(localStorage.getItem('nutritionEntries')) || []; let entries = JSON.parse(localStorage.getItem('nutritionEntries')) || [];
entries = entries.filter(entry => entry.food !== rowData.food || entry.weight !== rowData.weight); // Konvertieren von rowData.weight in eine Zahl, um eine korrekte Vergleichsbasis zu schaffen
localStorage.setItem('nutritionEntries', JSON.stringify(entries)); 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() { function updateRemoveButtonState() {
const selectedRows = document.querySelectorAll('#nutrition-table .selected').length; const selectedRows = document.querySelectorAll('#nutrition-table .selected').length;
@ -111,11 +176,29 @@
document.getElementById('submit-button').disabled = !(food && weight); 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() { function addProduct() {
const foodInput = document.getElementById('my_combobox'); const foodInput = document.getElementById('my_combobox');
const weightInput = document.getElementById('weight'); const weightInput = document.getElementById('weight');
const portionsInput = document.getElementById('portions');
const food = foodInput.value; 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)}`) fetch(`/add_lm?food=${encodeURIComponent(food)}&weight=${encodeURIComponent(weight)}`)
@ -124,14 +207,14 @@
const table = document.getElementById('nutrition-table'); const table = document.getElementById('nutrition-table');
const row = table.insertRow(); const row = table.insertRow();
// Fügt die einzelnen Nährwerte zur neuen Zeile hinzu // Fügt die einzelnen Nährwerte zur neuen Zeile hinzu
row.insertCell(0).innerHTML = food; row.insertCell(0).innerText = food;
row.insertCell(1).innerHTML = weight; row.insertCell(1).innerText = weight;
row.insertCell(2).innerHTML = data.kcal; row.insertCell(2).innerText = data.kcal;
row.insertCell(3).innerHTML = data.ew; row.insertCell(3).innerText = data.ew;
row.insertCell(4).innerHTML = data.fett; row.insertCell(4).innerText = data.fett;
row.insertCell(5).innerHTML = data.kh; row.insertCell(5).innerText = data.kh;
row.insertCell(6).innerHTML = data.bst; row.insertCell(6).innerText = data.bst;
row.insertCell(7).innerHTML = data.ca; row.insertCell(7).innerText = data.ca;
foodInput.value = ''; // Zurücksetzen des Lebensmittel-Eingabefeldes foodInput.value = ''; // Zurücksetzen des Lebensmittel-Eingabefeldes
weightInput.value = ''; // Zurücksetzen des Gewicht-Eingabefeldes weightInput.value = ''; // Zurücksetzen des Gewicht-Eingabefeldes
@ -175,7 +258,10 @@ function updateTotalNutrition() {
</head> </head>
<body> <body>
<nav id="navbar"> <nav id="navbar">
<h1>Elo's Rezept Rechner</h1> <div class="navbar-header">
<h1>Elo's Rezept Rechner</h1>
<li class="versionid">VERSION_ID</li>
</div>
<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>
@ -184,15 +270,23 @@ function updateTotalNutrition() {
<div class="content"> <div class="content">
<form onsubmit="event.preventDefault(); addProduct();" id="product-form"> <form onsubmit="event.preventDefault(); addProduct();" id="product-form" class="form-layout">
<label for="my_combobox">Wählen Sie ein Lebensmittel</label> <div class="form-row">
<input list="products" name="my_combobox" id="my_combobox" placeholder="Lebensmittel" oninput="updateButtonState()" autocomplete="off"> <label for="portions">Wählen Sie die Anzahl an Portionen</label>
<datalist id="products"> <input type="number" id="portions" name="portions" placeholder="Portionen" min="1" value="1" oninput="recalculateTableBasedOnPortions()">
<!-- Produkte werden hier dynamisch eingefügt --> </div>
</datalist> <div class="form-row">
<input type="number" id="weight" name="weight" placeholder="Gramm" oninput="updateButtonState()"> <label for="my_combobox">Wählen Sie ein Lebensmittel</label>
<button type="submit" id="submit-button" disabled>Hinzufügen</button> <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> </form>
<table id="nutrition-table"> <table id="nutrition-table">
<tr> <tr>
@ -207,7 +301,7 @@ function updateTotalNutrition() {
</tr> </tr>
<!-- Zeilen werden hier dynamisch hinzugefügt --> <!-- Zeilen werden hier dynamisch hinzugefügt -->
</table> </table>
<button id="remove-button" onclick="removeSelectedRow()" disabled>Entfernen</button> <button id="remove-button" onclick="removeSelectedRow()" disabled></button>
<table id="total-nutrition-table"> <table id="total-nutrition-table">
<tr> <tr>
<th>Lebensmittel</th> <th>Lebensmittel</th>
@ -232,4 +326,4 @@ function updateTotalNutrition() {
</table> </table>
</div> </div>
</body> </body>
</html> </html>

View File

@ -2,7 +2,7 @@
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>Neue Lebensmittel hinzufügen</title> <title>Elo's Rezept Rechner</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"> <link rel="shortcut icon" href="../static/images/favicon.ico">
@ -40,6 +40,7 @@
// Beispielsweise das Formular zurücksetzen // Beispielsweise das Formular zurücksetzen
form.reset(); form.reset();
updateSubmitButtonState(); updateSubmitButtonState();
loadDatabaseEntries();
}).catch(error => { }).catch(error => {
console.error('Fehler:', error); console.error('Fehler:', error);
}); });
@ -69,14 +70,34 @@
function deleteSelectedRows() { function deleteSelectedRows() {
const table = document.getElementById('database-nutrition-table'); const table = document.getElementById('database-nutrition-table');
Array.from(table.rows).forEach(row => { const selectedRows = Array.from(table.querySelectorAll('tr.selected'));
if (row.classList.contains('selected')) { const foodNames = selectedRows.map(row => row.cells[0].innerText); // Annahme, der Name des Lebensmittels befindet sich in der ersten Zelle
// Logik zum Löschen der Zeile aus der Datenbank
table.deleteRow(row.rowIndex); if (foodNames.length > 0) {
} // Holen des Tokens und Senden einer Anfrage an das Backend, um die Einträge zu löschen
}); getBearerToken(token => {
fetch('/delete_nutrition', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + token
},
body: JSON.stringify({foodNames: foodNames})
}).then(response => {
if (response.ok) {
// Erfolgreich gelöscht, entferne Zeilen aus der Tabelle
selectedRows.forEach(row => {
table.deleteRow(row.rowIndex);
});
} else {
console.error('Fehler beim Löschen der Datenbank-Einträge');
}
}).catch(error => console.error('Fehler:', error));
});
}
} }
function showPasswordPrompt() { function showPasswordPrompt() {
document.getElementById('delete-row-button').style.display = 'none'; document.getElementById('delete-row-button').style.display = 'none';
document.getElementById('password-prompt').style.display = 'block'; document.getElementById('password-prompt').style.display = 'block';
@ -89,7 +110,7 @@
function deleteRowsIfPasswordCorrect() { function deleteRowsIfPasswordCorrect() {
const password = document.getElementById('password-input').value; const password = document.getElementById('password-input').value;
if (password === 'wowmuchsecurity') { if (password === 'geheim') {
deleteSelectedRows(); // Funktion, die die ausgewählten Zeilen löscht deleteSelectedRows(); // Funktion, die die ausgewählten Zeilen löscht
hidePasswordPrompt(); hidePasswordPrompt();
} else { } else {
@ -98,7 +119,7 @@
} }
function updateDeleteButtonState() { function updateDeleteButtonState() {
const selectedRows = document.querySelectorAll('#nutrition-table .selected').length; const selectedRows = document.querySelectorAll('#database-nutrition-table .selected').length;
const deleteButton = document.getElementById('delete-row-button'); const deleteButton = document.getElementById('delete-row-button');
deleteButton.disabled = selectedRows === 0; deleteButton.disabled = selectedRows === 0;
if (selectedRows === 0) { if (selectedRows === 0) {
@ -107,11 +128,13 @@
} }
function loadDatabaseEntries() { function loadDatabaseEntries() {
fetch('/get_database_entries') // Pfad zur entsprechenden Flask-Route fetch('/get_database_entries') // Pfad zur entsprechenden Flask-Route
.then(response => response.json()) .then(response => response.json())
.then(data => { .then(data => {
const tableBody = document.getElementById('database-nutrition-table').getElementsByTagName('tbody')[0]; const tableBody = document.getElementById('database-nutrition-table').getElementsByTagName('tbody')[0];
tableBody.innerHTML = '';
data.forEach(entry => { data.forEach(entry => {
const row = tableBody.insertRow(); const row = tableBody.insertRow();
row.insertCell(0).innerHTML = entry.food; row.insertCell(0).innerHTML = entry.food;
@ -128,46 +151,80 @@
.catch(error => console.error('Fehler:', error)); .catch(error => console.error('Fehler:', error));
} }
document.addEventListener('DOMContentLoaded', loadDatabaseEntries); document.addEventListener('DOMContentLoaded', loadDatabaseEntries);
function filterTable() {
const searchInput = document.getElementById('search-input');
const filterText = searchInput.value.toUpperCase();
const table = document.getElementById('database-nutrition-table');
const rows = table.getElementsByTagName('tr');
for (let i = 1; i < rows.length; i++) { // Beginnen bei 1, um die Kopfzeile auszulassen
const cell = rows[i].getElementsByTagName('td')[0]; // Angenommen, der zu suchende Text befindet sich in der ersten Spalte
if (cell) {
const textValue = cell.textContent || cell.innerText;
if (textValue.toUpperCase().indexOf(filterText) > -1) {
rows[i].style.display = ""; // Zeile anzeigen
} else {
rows[i].style.display = "none"; // Zeile verstecken
}
}
}
}
function openImagePage() {
window.open('random', '_blank'); // Öffnet die neue Seite in einem neuen Tab
}
</script> </script>
</head> </head>
<body> <body>
<nav id="navbar"> <nav id="navbar">
<h1>Elo's Rezept Rechner</h1> <div class="navbar-header">
<h1>Elo's Rezept Rechner</h1>
<li class="versionid">VERSION_ID</li>
</div>
<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>
</ul> </ul>
</nav> </nav>
<div class="content"> <div class="content">
<form onsubmit="event.preventDefault(); addNutritionEntry();" method="POST" id="nutrition-form"> <form onsubmit="event.preventDefault(); addNutritionEntry();" method="POST" id="nutrition-form">
<table id="nutrition-input-table"> <table id="nutrition-input-table">
<tr> <tr>
<th>Lebensmittel</th> <th>Lebensmittel</th>
<th>kcal</th> <th>kcal</th>
<th>EW</th> <th>EW</th>
<th>Fett</th> <th>Fett</th>
<th>KH</th> <th>KH</th>
<th>BST</th> <th>BST</th>
<th>CA</th> <th>CA</th>
</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"> <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>
<div class="table-container">
<table id="database-nutrition-table"> <table id="database-nutrition-table">
<thead> <thead>
<tr> <tr>
@ -189,8 +246,8 @@ document.addEventListener('DOMContentLoaded', loadDatabaseEntries);
<div id="password-prompt" style="display: none;"> <div id="password-prompt" style="display: none;">
<input type="password" id="password-input" placeholder="Passwort"> <input type="password" id="password-input" placeholder="Passwort">
<button onclick="deleteRowsIfPasswordCorrect()">OK</button> <button id="ok-button" onclick="deleteRowsIfPasswordCorrect()">OK</button>
<button onclick="hidePasswordPrompt()">Abbrechen</button> <button id="cancel-button" onclick="hidePasswordPrompt()">Abbrechen</button>
</div> </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>

View File

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