Spaces:
Sleeping
Sleeping
Pascal Claude Opus 4.6 commited on
Commit ·
4f6a052
1
Parent(s): 179772a
Sparrezepte v6: Dark Mode, PWA, Datenqualität, HF Spaces Deployment
Browse files- Dark Mode mit System-Erkennung und Toggle
- PWA: Service Worker, Manifest, Offline-Support
- Favoriten-System mit vollem Rezeptdaten-Speicher
- Pantry-Chips mit Autocomplete und Presets
- Skeleton-Loader statt Spinner
- Rezept-Export (Kopieren, Teilen via Web Share API)
- Einkaufsliste: persistente Checkboxen, Teilen, Drucken
- Datenqualität: Platzhalter-Filter, Zukunfts-Filter, Deduplizierung
- Netto-API-Key korrigiert (netto-marken-discount)
- Accessibility: ARIA-Attribute, Skip-Link, Fokus-Management
- Dockerfile + Gunicorn für Hugging Face Spaces
- 97 Tests (Routes, Marktguru-Client, Recipe-Engine)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- .dockerignore +9 -0
- Dockerfile +21 -0
- README.md +39 -0
- app.py +3 -1
- config.py +3 -3
- requirements.txt +0 -1
- services/marktguru.py +23 -2
- services/recipe_engine.py +2 -0
- static/icon.svg +5 -0
- static/manifest.json +18 -0
- static/style.css +421 -18
- static/sw.js +74 -0
- templates/base.html +348 -8
- templates/index.html +165 -13
- templates/partials/recipe_detail.html +67 -1
- templates/partials/recipes.html +55 -14
- templates/partials/shopping_list.html +98 -2
- tests/test_marktguru.py +254 -0
- tests/test_routes.py +313 -0
.dockerignore
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
__pycache__
|
| 2 |
+
*.pyc
|
| 3 |
+
.git
|
| 4 |
+
.gitignore
|
| 5 |
+
cache.db
|
| 6 |
+
tests/
|
| 7 |
+
*.md
|
| 8 |
+
.env
|
| 9 |
+
.pytest_cache
|
Dockerfile
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.11-slim
|
| 2 |
+
|
| 3 |
+
# HF Spaces erwartet User mit UID 1000
|
| 4 |
+
RUN useradd -m -u 1000 user
|
| 5 |
+
WORKDIR /app
|
| 6 |
+
|
| 7 |
+
# Dependencies installieren
|
| 8 |
+
COPY requirements.txt .
|
| 9 |
+
RUN pip install --no-cache-dir -r requirements.txt gunicorn
|
| 10 |
+
|
| 11 |
+
# App-Code kopieren
|
| 12 |
+
COPY . .
|
| 13 |
+
|
| 14 |
+
# Cache-Verzeichnis mit Schreibrechten
|
| 15 |
+
RUN mkdir -p /app/cache && chown -R user:user /app
|
| 16 |
+
|
| 17 |
+
USER user
|
| 18 |
+
|
| 19 |
+
EXPOSE 7860
|
| 20 |
+
|
| 21 |
+
CMD ["gunicorn", "app:app", "--bind", "0.0.0.0:7860", "--workers", "2", "--timeout", "120"]
|
README.md
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: Sparrezepte
|
| 3 |
+
emoji: "\U0001F6D2"
|
| 4 |
+
colorFrom: green
|
| 5 |
+
colorTo: yellow
|
| 6 |
+
sdk: docker
|
| 7 |
+
app_port: 7860
|
| 8 |
+
pinned: false
|
| 9 |
+
license: mit
|
| 10 |
+
short_description: Kochen mit Supermarkt-Angeboten
|
| 11 |
+
---
|
| 12 |
+
|
| 13 |
+
# Sparrezepte
|
| 14 |
+
|
| 15 |
+
Kochen mit Supermarkt-Angeboten: Aktuelle Angebote laden, Sparrezepte generieren, Einkaufsliste erstellen.
|
| 16 |
+
|
| 17 |
+
## Features
|
| 18 |
+
|
| 19 |
+
- **Echtzeit-Angebote** von Aldi, Lidl, Penny, Netto, Edeka, REWE, Kaufland
|
| 20 |
+
- **Rezeptgenerierung** basierend auf aktuellen Angeboten
|
| 21 |
+
- **Wochenplan** mit optimierter Einkaufsliste
|
| 22 |
+
- **Preisvergleich** zwischen Stores
|
| 23 |
+
- **Favoriten** lokal speichern
|
| 24 |
+
- **Dark Mode**, PWA-Support, Offline-fähig
|
| 25 |
+
|
| 26 |
+
## Technologie
|
| 27 |
+
|
| 28 |
+
- **Backend**: Python Flask + Gunicorn
|
| 29 |
+
- **Frontend**: HTMX, Vanilla JS, CSS Custom Properties
|
| 30 |
+
- **API**: Marktguru.de (inoffizielle API)
|
| 31 |
+
- **Caching**: SQLite
|
| 32 |
+
|
| 33 |
+
## Lokal starten
|
| 34 |
+
|
| 35 |
+
```bash
|
| 36 |
+
pip install -r requirements.txt
|
| 37 |
+
python app.py
|
| 38 |
+
# -> http://localhost:5000
|
| 39 |
+
```
|
app.py
CHANGED
|
@@ -3,6 +3,7 @@
|
|
| 3 |
from dotenv import load_dotenv
|
| 4 |
load_dotenv()
|
| 5 |
|
|
|
|
| 6 |
from flask import Flask, render_template, request, jsonify, session
|
| 7 |
|
| 8 |
import config
|
|
@@ -228,4 +229,5 @@ def health():
|
|
| 228 |
|
| 229 |
|
| 230 |
if __name__ == "__main__":
|
| 231 |
-
|
|
|
|
|
|
| 3 |
from dotenv import load_dotenv
|
| 4 |
load_dotenv()
|
| 5 |
|
| 6 |
+
import os
|
| 7 |
from flask import Flask, render_template, request, jsonify, session
|
| 8 |
|
| 9 |
import config
|
|
|
|
| 229 |
|
| 230 |
|
| 231 |
if __name__ == "__main__":
|
| 232 |
+
port = int(os.environ.get("PORT", 5000))
|
| 233 |
+
app.run(debug=True, port=port)
|
config.py
CHANGED
|
@@ -3,7 +3,7 @@
|
|
| 3 |
import os
|
| 4 |
|
| 5 |
# Flask
|
| 6 |
-
SECRET_KEY = os.environ.get("SECRET_KEY",
|
| 7 |
|
| 8 |
# Standard-PLZ
|
| 9 |
DEFAULT_ZIP_CODE = os.environ.get("DEFAULT_ZIP_CODE", "69250")
|
|
@@ -33,7 +33,7 @@ ALL_RETAILERS = {
|
|
| 33 |
"aldi-nord": "Aldi Nord",
|
| 34 |
"lidl": "Lidl",
|
| 35 |
"penny": "Penny",
|
| 36 |
-
"netto": "Netto",
|
| 37 |
"edeka": "Edeka",
|
| 38 |
"rewe": "REWE",
|
| 39 |
"kaufland": "Kaufland",
|
|
@@ -46,7 +46,7 @@ DEFAULT_STORES = {"aldi-sued", "lidl", "penny"}
|
|
| 46 |
|
| 47 |
# Cache
|
| 48 |
CACHE_TTL_HOURS = int(os.environ.get("CACHE_TTL_HOURS", "12"))
|
| 49 |
-
CACHE_DB_PATH = os.path.join(os.path.dirname(__file__), "cache.db")
|
| 50 |
|
| 51 |
# Ernährungsfilter
|
| 52 |
DIETARY_FILTERS = {
|
|
|
|
| 3 |
import os
|
| 4 |
|
| 5 |
# Flask
|
| 6 |
+
SECRET_KEY = os.environ.get("SECRET_KEY", os.urandom(24).hex())
|
| 7 |
|
| 8 |
# Standard-PLZ
|
| 9 |
DEFAULT_ZIP_CODE = os.environ.get("DEFAULT_ZIP_CODE", "69250")
|
|
|
|
| 33 |
"aldi-nord": "Aldi Nord",
|
| 34 |
"lidl": "Lidl",
|
| 35 |
"penny": "Penny",
|
| 36 |
+
"netto-marken-discount": "Netto",
|
| 37 |
"edeka": "Edeka",
|
| 38 |
"rewe": "REWE",
|
| 39 |
"kaufland": "Kaufland",
|
|
|
|
| 46 |
|
| 47 |
# Cache
|
| 48 |
CACHE_TTL_HOURS = int(os.environ.get("CACHE_TTL_HOURS", "12"))
|
| 49 |
+
CACHE_DB_PATH = os.environ.get("CACHE_DB_PATH", os.path.join(os.path.dirname(__file__), "cache.db"))
|
| 50 |
|
| 51 |
# Ernährungsfilter
|
| 52 |
DIETARY_FILTERS = {
|
requirements.txt
CHANGED
|
@@ -2,4 +2,3 @@ flask>=3.0
|
|
| 2 |
requests>=2.31
|
| 3 |
thefuzz[speedup]>=0.22
|
| 4 |
python-dotenv>=1.0
|
| 5 |
-
pytest>=8.0
|
|
|
|
| 2 |
requests>=2.31
|
| 3 |
thefuzz[speedup]>=0.22
|
| 4 |
python-dotenv>=1.0
|
|
|
services/marktguru.py
CHANGED
|
@@ -168,6 +168,18 @@ class MarktguruClient:
|
|
| 168 |
product_name = product.get("name", "") if product else ""
|
| 169 |
name = description or product_name or "Unbekannt"
|
| 170 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 171 |
offer_id = raw.get("id")
|
| 172 |
image_url = None
|
| 173 |
if offer_id:
|
|
@@ -245,13 +257,22 @@ class MarktguruClient:
|
|
| 245 |
except Exception:
|
| 246 |
pass
|
| 247 |
|
| 248 |
-
# Abgelaufene filtern
|
| 249 |
today_date = datetime.now().date().isoformat()
|
| 250 |
all_offers = [
|
| 251 |
o for o in all_offers
|
| 252 |
-
if not o["valid_until"] or o["valid_until"] >= today_date
|
|
|
|
| 253 |
]
|
| 254 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 255 |
self._save_cache(cache_key, all_offers)
|
| 256 |
|
| 257 |
return [o for o in all_offers if o["retailer"] in stores]
|
|
|
|
| 168 |
product_name = product.get("name", "") if product else ""
|
| 169 |
name = description or product_name or "Unbekannt"
|
| 170 |
|
| 171 |
+
# Platzhalter-Angebote ohne echten Produktnamen filtern
|
| 172 |
+
_placeholder_patterns = [
|
| 173 |
+
"details im prospekt", "details im markt",
|
| 174 |
+
"verschiedene sorten", "diverse artikel",
|
| 175 |
+
]
|
| 176 |
+
name_lower = name.lower().strip()
|
| 177 |
+
if any(name_lower.startswith(p) for p in _placeholder_patterns):
|
| 178 |
+
return None
|
| 179 |
+
# Zu kurze Namen (z.B. nur "500g") sind keine echten Produkte
|
| 180 |
+
if len(name.strip()) < 3:
|
| 181 |
+
return None
|
| 182 |
+
|
| 183 |
offer_id = raw.get("id")
|
| 184 |
image_url = None
|
| 185 |
if offer_id:
|
|
|
|
| 257 |
except Exception:
|
| 258 |
pass
|
| 259 |
|
| 260 |
+
# Abgelaufene und zukünftige Angebote filtern
|
| 261 |
today_date = datetime.now().date().isoformat()
|
| 262 |
all_offers = [
|
| 263 |
o for o in all_offers
|
| 264 |
+
if (not o["valid_until"] or o["valid_until"] >= today_date)
|
| 265 |
+
and (not o["valid_from"] or o["valid_from"] <= today_date)
|
| 266 |
]
|
| 267 |
|
| 268 |
+
# Duplikate deduplizieren: gleicher Name+Retailer -> günstigsten behalten
|
| 269 |
+
dedup = {}
|
| 270 |
+
for o in all_offers:
|
| 271 |
+
key = (o["name"].lower().strip(), o["retailer"])
|
| 272 |
+
if key not in dedup or o["price"] < dedup[key]["price"]:
|
| 273 |
+
dedup[key] = o
|
| 274 |
+
all_offers = list(dedup.values())
|
| 275 |
+
|
| 276 |
self._save_cache(cache_key, all_offers)
|
| 277 |
|
| 278 |
return [o for o in all_offers if o["retailer"] in stores]
|
services/recipe_engine.py
CHANGED
|
@@ -127,6 +127,7 @@ def find_cheapest_across_stores(template, deals_by_store):
|
|
| 127 |
"offer_name": best_match.get("product_name") or best_match["name"],
|
| 128 |
"price": best_match["price"],
|
| 129 |
"old_price": best_match.get("old_price"),
|
|
|
|
| 130 |
"savings": round(savings, 2),
|
| 131 |
"match_score": best_match["match_score"],
|
| 132 |
"essential": ing.get("essential", False),
|
|
@@ -338,6 +339,7 @@ def enrich_recipe(template, best_store, match_result, servings):
|
|
| 338 |
"amount": ing.get("amount", ""),
|
| 339 |
"is_on_sale": m is not None,
|
| 340 |
"offer_name": m["offer_name"] if m else "",
|
|
|
|
| 341 |
"store": m.get("store", best_store) if m else "",
|
| 342 |
"sale_price": m["price"] if m else None,
|
| 343 |
"old_price": m.get("old_price") if m else None,
|
|
|
|
| 127 |
"offer_name": best_match.get("product_name") or best_match["name"],
|
| 128 |
"price": best_match["price"],
|
| 129 |
"old_price": best_match.get("old_price"),
|
| 130 |
+
"quantity": best_match.get("quantity", ""),
|
| 131 |
"savings": round(savings, 2),
|
| 132 |
"match_score": best_match["match_score"],
|
| 133 |
"essential": ing.get("essential", False),
|
|
|
|
| 339 |
"amount": ing.get("amount", ""),
|
| 340 |
"is_on_sale": m is not None,
|
| 341 |
"offer_name": m["offer_name"] if m else "",
|
| 342 |
+
"quantity": m.get("quantity", "") if m else "",
|
| 343 |
"store": m.get("store", best_store) if m else "",
|
| 344 |
"sale_price": m["price"] if m else None,
|
| 345 |
"old_price": m.get("old_price") if m else None,
|
static/icon.svg
ADDED
|
|
static/manifest.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "Sparrezepte",
|
| 3 |
+
"short_name": "Sparrezepte",
|
| 4 |
+
"description": "Kochen mit Supermarkt-Angeboten — Geld sparen beim Einkaufen",
|
| 5 |
+
"start_url": "/",
|
| 6 |
+
"display": "standalone",
|
| 7 |
+
"background_color": "#f5f5f0",
|
| 8 |
+
"theme_color": "#2d6a4f",
|
| 9 |
+
"lang": "de",
|
| 10 |
+
"icons": [
|
| 11 |
+
{
|
| 12 |
+
"src": "/static/icon.svg",
|
| 13 |
+
"sizes": "any",
|
| 14 |
+
"type": "image/svg+xml",
|
| 15 |
+
"purpose": "any maskable"
|
| 16 |
+
}
|
| 17 |
+
]
|
| 18 |
+
}
|
static/style.css
CHANGED
|
@@ -20,6 +20,24 @@
|
|
| 20 |
--radius: 10px;
|
| 21 |
--sale-color: #e63946;
|
| 22 |
--save-color: #2d6a4f;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
}
|
| 24 |
|
| 25 |
body {
|
|
@@ -30,6 +48,37 @@ body {
|
|
| 30 |
min-height: 100vh;
|
| 31 |
}
|
| 32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
/* === Header === */
|
| 34 |
header {
|
| 35 |
background: var(--accent);
|
|
@@ -43,6 +92,13 @@ header {
|
|
| 43 |
margin: 0 auto;
|
| 44 |
}
|
| 45 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
header h1 {
|
| 47 |
font-size: 1.8rem;
|
| 48 |
font-weight: 700;
|
|
@@ -55,6 +111,98 @@ header h1 {
|
|
| 55 |
margin-top: 0.2rem;
|
| 56 |
}
|
| 57 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
/* === Main === */
|
| 59 |
main {
|
| 60 |
max-width: 1200px;
|
|
@@ -267,7 +415,7 @@ select:focus {
|
|
| 267 |
justify-content: space-between;
|
| 268 |
align-items: center;
|
| 269 |
padding: 0.5rem 0.75rem;
|
| 270 |
-
background:
|
| 271 |
border-radius: 6px;
|
| 272 |
gap: 0.75rem;
|
| 273 |
}
|
|
@@ -356,7 +504,7 @@ select:focus {
|
|
| 356 |
display: flex;
|
| 357 |
align-items: center;
|
| 358 |
padding: 0.6rem 0.75rem;
|
| 359 |
-
background:
|
| 360 |
border-radius: 6px;
|
| 361 |
gap: 1rem;
|
| 362 |
}
|
|
@@ -407,6 +555,55 @@ select:focus {
|
|
| 407 |
display: block;
|
| 408 |
}
|
| 409 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 410 |
.loading-section {
|
| 411 |
text-align: center;
|
| 412 |
padding: 3rem;
|
|
@@ -483,7 +680,7 @@ select:focus {
|
|
| 483 |
.top-deal-hot {
|
| 484 |
border-left-color: var(--sale-color);
|
| 485 |
border-left-width: 4px;
|
| 486 |
-
background:
|
| 487 |
}
|
| 488 |
|
| 489 |
.top-deal-info {
|
|
@@ -598,7 +795,7 @@ select:focus {
|
|
| 598 |
|
| 599 |
.deal-list li {
|
| 600 |
padding: 0.3rem 0;
|
| 601 |
-
border-bottom: 1px solid
|
| 602 |
font-size: 0.85rem;
|
| 603 |
display: flex;
|
| 604 |
justify-content: space-between;
|
|
@@ -874,28 +1071,28 @@ select:focus {
|
|
| 874 |
}
|
| 875 |
|
| 876 |
.tag-time {
|
| 877 |
-
background:
|
| 878 |
color: #1971c2;
|
| 879 |
}
|
| 880 |
|
| 881 |
.tag-cal {
|
| 882 |
-
background:
|
| 883 |
color: #e65100;
|
| 884 |
}
|
| 885 |
|
| 886 |
.tag-protein {
|
| 887 |
-
background:
|
| 888 |
color: #c62828;
|
| 889 |
}
|
| 890 |
|
| 891 |
.tag-match {
|
| 892 |
-
background:
|
| 893 |
color: var(--save-color);
|
| 894 |
}
|
| 895 |
|
| 896 |
.recipe-footer {
|
| 897 |
padding: 0.6rem 1.25rem;
|
| 898 |
-
background:
|
| 899 |
display: flex;
|
| 900 |
justify-content: space-between;
|
| 901 |
align-items: center;
|
|
@@ -1043,12 +1240,12 @@ select:focus {
|
|
| 1043 |
|
| 1044 |
.ingredients-table td {
|
| 1045 |
padding: 0.45rem 0.5rem;
|
| 1046 |
-
border-bottom: 1px solid
|
| 1047 |
font-size: 0.9rem;
|
| 1048 |
}
|
| 1049 |
|
| 1050 |
.ingredients-table tr.on-sale td {
|
| 1051 |
-
background:
|
| 1052 |
}
|
| 1053 |
|
| 1054 |
.sale-indicator {
|
|
@@ -1083,7 +1280,7 @@ select:focus {
|
|
| 1083 |
align-items: center;
|
| 1084 |
margin: 0.5rem 0;
|
| 1085 |
padding: 0.5rem 0.75rem;
|
| 1086 |
-
background:
|
| 1087 |
border-radius: 6px;
|
| 1088 |
}
|
| 1089 |
|
|
@@ -1098,7 +1295,7 @@ select:focus {
|
|
| 1098 |
counter-increment: step;
|
| 1099 |
padding: 0.5rem 0 0.5rem 2.5rem;
|
| 1100 |
position: relative;
|
| 1101 |
-
border-bottom: 1px solid
|
| 1102 |
font-size: 0.9rem;
|
| 1103 |
}
|
| 1104 |
|
|
@@ -1130,7 +1327,7 @@ select:focus {
|
|
| 1130 |
.nutrition-item {
|
| 1131 |
text-align: center;
|
| 1132 |
padding: 0.75rem;
|
| 1133 |
-
background:
|
| 1134 |
border-radius: 8px;
|
| 1135 |
}
|
| 1136 |
|
|
@@ -1153,6 +1350,14 @@ select:focus {
|
|
| 1153 |
font-size: 0.9rem;
|
| 1154 |
}
|
| 1155 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1156 |
/* === Shopping List === */
|
| 1157 |
.shopping-section {
|
| 1158 |
margin-top: 1rem;
|
|
@@ -1173,6 +1378,16 @@ select:focus {
|
|
| 1173 |
flex-wrap: wrap;
|
| 1174 |
}
|
| 1175 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1176 |
.shopping-actions {
|
| 1177 |
display: flex;
|
| 1178 |
gap: 0.5rem;
|
|
@@ -1265,7 +1480,7 @@ select:focus {
|
|
| 1265 |
|
| 1266 |
.shopping-items li {
|
| 1267 |
padding: 0.3rem 0;
|
| 1268 |
-
border-bottom: 1px solid
|
| 1269 |
}
|
| 1270 |
|
| 1271 |
.shopping-item {
|
|
@@ -1351,9 +1566,9 @@ select:focus {
|
|
| 1351 |
|
| 1352 |
/* === Error === */
|
| 1353 |
.error-msg {
|
| 1354 |
-
background:
|
| 1355 |
-
border: 1px solid
|
| 1356 |
-
color:
|
| 1357 |
padding: 1rem;
|
| 1358 |
border-radius: var(--radius);
|
| 1359 |
margin: 1rem 0;
|
|
@@ -1363,6 +1578,9 @@ select:focus {
|
|
| 1363 |
@media (max-width: 768px) {
|
| 1364 |
header { padding: 1rem; }
|
| 1365 |
header h1 { font-size: 1.4rem; }
|
|
|
|
|
|
|
|
|
|
| 1366 |
main { padding: 1rem; }
|
| 1367 |
.settings-bar { flex-direction: column; }
|
| 1368 |
.recipes-grid { grid-template-columns: 1fr; }
|
|
@@ -1379,3 +1597,188 @@ select:focus {
|
|
| 1379 |
.cost-breakdown { flex-direction: column; gap: 0.5rem; }
|
| 1380 |
.cost-item { border-right: none; padding: 0; }
|
| 1381 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
--radius: 10px;
|
| 21 |
--sale-color: #e63946;
|
| 22 |
--save-color: #2d6a4f;
|
| 23 |
+
--surface-alt: #fafaf8;
|
| 24 |
+
--surface-hover: rgba(0, 0, 0, 0.12);
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
[data-theme="dark"] {
|
| 28 |
+
--bg: #121212;
|
| 29 |
+
--surface: #1e1e1e;
|
| 30 |
+
--text: #e0e0e0;
|
| 31 |
+
--text-muted: #999;
|
| 32 |
+
--accent: #52b788;
|
| 33 |
+
--accent-light: #74c69d;
|
| 34 |
+
--accent-bg: rgba(82, 183, 136, 0.15);
|
| 35 |
+
--border: #333;
|
| 36 |
+
--shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
|
| 37 |
+
--sale-color: #ff6b6b;
|
| 38 |
+
--save-color: #52b788;
|
| 39 |
+
--surface-alt: #252525;
|
| 40 |
+
--surface-hover: rgba(255, 255, 255, 0.12);
|
| 41 |
}
|
| 42 |
|
| 43 |
body {
|
|
|
|
| 48 |
min-height: 100vh;
|
| 49 |
}
|
| 50 |
|
| 51 |
+
/* === Skip Link === */
|
| 52 |
+
.skip-link {
|
| 53 |
+
position: absolute;
|
| 54 |
+
top: -100%;
|
| 55 |
+
left: 1rem;
|
| 56 |
+
background: var(--accent);
|
| 57 |
+
color: white;
|
| 58 |
+
padding: 0.5rem 1rem;
|
| 59 |
+
border-radius: 0 0 6px 6px;
|
| 60 |
+
font-weight: 600;
|
| 61 |
+
z-index: 9999;
|
| 62 |
+
text-decoration: none;
|
| 63 |
+
transition: top 0.2s;
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
.skip-link:focus {
|
| 67 |
+
top: 0;
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
/* === Focus Visible === */
|
| 71 |
+
:focus-visible {
|
| 72 |
+
outline: 2.5px solid var(--accent);
|
| 73 |
+
outline-offset: 2px;
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
button:focus:not(:focus-visible),
|
| 77 |
+
input:focus:not(:focus-visible),
|
| 78 |
+
select:focus:not(:focus-visible) {
|
| 79 |
+
outline: none;
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
/* === Header === */
|
| 83 |
header {
|
| 84 |
background: var(--accent);
|
|
|
|
| 92 |
margin: 0 auto;
|
| 93 |
}
|
| 94 |
|
| 95 |
+
.header-row {
|
| 96 |
+
display: flex;
|
| 97 |
+
justify-content: space-between;
|
| 98 |
+
align-items: center;
|
| 99 |
+
gap: 1rem;
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
header h1 {
|
| 103 |
font-size: 1.8rem;
|
| 104 |
font-weight: 700;
|
|
|
|
| 111 |
margin-top: 0.2rem;
|
| 112 |
}
|
| 113 |
|
| 114 |
+
.btn-fav-toggle {
|
| 115 |
+
display: flex;
|
| 116 |
+
align-items: center;
|
| 117 |
+
gap: 0.4rem;
|
| 118 |
+
padding: 0.5rem 1rem;
|
| 119 |
+
background: rgba(255, 255, 255, 0.15);
|
| 120 |
+
color: white;
|
| 121 |
+
border: 1.5px solid rgba(255, 255, 255, 0.3);
|
| 122 |
+
border-radius: 8px;
|
| 123 |
+
font-size: 0.9rem;
|
| 124 |
+
font-weight: 600;
|
| 125 |
+
cursor: pointer;
|
| 126 |
+
transition: all 0.2s;
|
| 127 |
+
white-space: nowrap;
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
.btn-fav-toggle:hover {
|
| 131 |
+
background: rgba(255, 255, 255, 0.25);
|
| 132 |
+
border-color: rgba(255, 255, 255, 0.5);
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
+
.header-actions {
|
| 136 |
+
display: flex;
|
| 137 |
+
align-items: center;
|
| 138 |
+
gap: 0.5rem;
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
.fav-toggle-icon {
|
| 142 |
+
color: #ff6b6b;
|
| 143 |
+
font-size: 1.1rem;
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
.fav-count-badge {
|
| 147 |
+
background: #ff6b6b;
|
| 148 |
+
color: white;
|
| 149 |
+
font-size: 0.7rem;
|
| 150 |
+
font-weight: 700;
|
| 151 |
+
min-width: 18px;
|
| 152 |
+
height: 18px;
|
| 153 |
+
border-radius: 9px;
|
| 154 |
+
display: inline-flex;
|
| 155 |
+
align-items: center;
|
| 156 |
+
justify-content: center;
|
| 157 |
+
padding: 0 4px;
|
| 158 |
+
}
|
| 159 |
+
|
| 160 |
+
/* === Favorites Panel === */
|
| 161 |
+
.favorites-panel {
|
| 162 |
+
max-width: 1200px;
|
| 163 |
+
margin: 0 auto;
|
| 164 |
+
padding: 1.5rem;
|
| 165 |
+
background: var(--surface);
|
| 166 |
+
border-bottom: 2px solid var(--border);
|
| 167 |
+
animation: panel-slide 0.2s ease;
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
.favorites-panel.hidden {
|
| 171 |
+
display: none;
|
| 172 |
+
}
|
| 173 |
+
|
| 174 |
+
@keyframes panel-slide {
|
| 175 |
+
from { opacity: 0; transform: translateY(-10px); }
|
| 176 |
+
to { opacity: 1; transform: translateY(0); }
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
.favorites-panel-header {
|
| 180 |
+
display: flex;
|
| 181 |
+
justify-content: space-between;
|
| 182 |
+
align-items: center;
|
| 183 |
+
margin-bottom: 1rem;
|
| 184 |
+
}
|
| 185 |
+
|
| 186 |
+
.favorites-panel-header h2 {
|
| 187 |
+
font-size: 1.2rem;
|
| 188 |
+
color: var(--text);
|
| 189 |
+
}
|
| 190 |
+
|
| 191 |
+
.favorites-list .recipes-grid {
|
| 192 |
+
grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
|
| 193 |
+
}
|
| 194 |
+
|
| 195 |
+
.fav-empty {
|
| 196 |
+
color: var(--text-muted);
|
| 197 |
+
font-style: italic;
|
| 198 |
+
padding: 2rem 0;
|
| 199 |
+
text-align: center;
|
| 200 |
+
}
|
| 201 |
+
|
| 202 |
+
.fav-card .recipe-header {
|
| 203 |
+
cursor: default;
|
| 204 |
+
}
|
| 205 |
+
|
| 206 |
/* === Main === */
|
| 207 |
main {
|
| 208 |
max-width: 1200px;
|
|
|
|
| 415 |
justify-content: space-between;
|
| 416 |
align-items: center;
|
| 417 |
padding: 0.5rem 0.75rem;
|
| 418 |
+
background: var(--surface-alt);
|
| 419 |
border-radius: 6px;
|
| 420 |
gap: 0.75rem;
|
| 421 |
}
|
|
|
|
| 504 |
display: flex;
|
| 505 |
align-items: center;
|
| 506 |
padding: 0.6rem 0.75rem;
|
| 507 |
+
background: var(--surface-alt);
|
| 508 |
border-radius: 6px;
|
| 509 |
gap: 1rem;
|
| 510 |
}
|
|
|
|
| 555 |
display: block;
|
| 556 |
}
|
| 557 |
|
| 558 |
+
/* === Skeleton Loader === */
|
| 559 |
+
.skeleton-section {
|
| 560 |
+
padding: 1.5rem 0;
|
| 561 |
+
}
|
| 562 |
+
|
| 563 |
+
.skeleton-grid {
|
| 564 |
+
display: grid;
|
| 565 |
+
grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
|
| 566 |
+
gap: 1rem;
|
| 567 |
+
}
|
| 568 |
+
|
| 569 |
+
.skeleton-card {
|
| 570 |
+
background: var(--surface);
|
| 571 |
+
border-radius: var(--radius);
|
| 572 |
+
padding: 1.25rem;
|
| 573 |
+
box-shadow: var(--shadow);
|
| 574 |
+
display: flex;
|
| 575 |
+
flex-direction: column;
|
| 576 |
+
gap: 0.75rem;
|
| 577 |
+
}
|
| 578 |
+
|
| 579 |
+
.skeleton-card-tall {
|
| 580 |
+
min-height: 160px;
|
| 581 |
+
}
|
| 582 |
+
|
| 583 |
+
.skeleton-bar {
|
| 584 |
+
height: 14px;
|
| 585 |
+
background: linear-gradient(90deg, var(--border) 25%, transparent 50%, var(--border) 75%);
|
| 586 |
+
background-size: 200% 100%;
|
| 587 |
+
border-radius: 6px;
|
| 588 |
+
animation: skeleton-pulse 1.5s ease-in-out infinite;
|
| 589 |
+
}
|
| 590 |
+
|
| 591 |
+
.skeleton-bar.short {
|
| 592 |
+
width: 60%;
|
| 593 |
+
}
|
| 594 |
+
|
| 595 |
+
.skeleton-bar.skeleton-title {
|
| 596 |
+
height: 22px;
|
| 597 |
+
width: 200px;
|
| 598 |
+
margin-bottom: 0.75rem;
|
| 599 |
+
}
|
| 600 |
+
|
| 601 |
+
@keyframes skeleton-pulse {
|
| 602 |
+
0% { background-position: 200% 0; }
|
| 603 |
+
100% { background-position: -200% 0; }
|
| 604 |
+
}
|
| 605 |
+
|
| 606 |
+
/* Keep old spinner for potential reuse */
|
| 607 |
.loading-section {
|
| 608 |
text-align: center;
|
| 609 |
padding: 3rem;
|
|
|
|
| 680 |
.top-deal-hot {
|
| 681 |
border-left-color: var(--sale-color);
|
| 682 |
border-left-width: 4px;
|
| 683 |
+
background: rgba(230, 57, 70, 0.06);
|
| 684 |
}
|
| 685 |
|
| 686 |
.top-deal-info {
|
|
|
|
| 795 |
|
| 796 |
.deal-list li {
|
| 797 |
padding: 0.3rem 0;
|
| 798 |
+
border-bottom: 1px solid var(--border);
|
| 799 |
font-size: 0.85rem;
|
| 800 |
display: flex;
|
| 801 |
justify-content: space-between;
|
|
|
|
| 1071 |
}
|
| 1072 |
|
| 1073 |
.tag-time {
|
| 1074 |
+
background: rgba(25, 113, 194, 0.12);
|
| 1075 |
color: #1971c2;
|
| 1076 |
}
|
| 1077 |
|
| 1078 |
.tag-cal {
|
| 1079 |
+
background: rgba(230, 81, 0, 0.12);
|
| 1080 |
color: #e65100;
|
| 1081 |
}
|
| 1082 |
|
| 1083 |
.tag-protein {
|
| 1084 |
+
background: rgba(198, 40, 40, 0.12);
|
| 1085 |
color: #c62828;
|
| 1086 |
}
|
| 1087 |
|
| 1088 |
.tag-match {
|
| 1089 |
+
background: rgba(45, 106, 79, 0.12);
|
| 1090 |
color: var(--save-color);
|
| 1091 |
}
|
| 1092 |
|
| 1093 |
.recipe-footer {
|
| 1094 |
padding: 0.6rem 1.25rem;
|
| 1095 |
+
background: var(--surface-alt);
|
| 1096 |
display: flex;
|
| 1097 |
justify-content: space-between;
|
| 1098 |
align-items: center;
|
|
|
|
| 1240 |
|
| 1241 |
.ingredients-table td {
|
| 1242 |
padding: 0.45rem 0.5rem;
|
| 1243 |
+
border-bottom: 1px solid var(--border);
|
| 1244 |
font-size: 0.9rem;
|
| 1245 |
}
|
| 1246 |
|
| 1247 |
.ingredients-table tr.on-sale td {
|
| 1248 |
+
background: rgba(45, 106, 79, 0.08);
|
| 1249 |
}
|
| 1250 |
|
| 1251 |
.sale-indicator {
|
|
|
|
| 1280 |
align-items: center;
|
| 1281 |
margin: 0.5rem 0;
|
| 1282 |
padding: 0.5rem 0.75rem;
|
| 1283 |
+
background: var(--surface-alt);
|
| 1284 |
border-radius: 6px;
|
| 1285 |
}
|
| 1286 |
|
|
|
|
| 1295 |
counter-increment: step;
|
| 1296 |
padding: 0.5rem 0 0.5rem 2.5rem;
|
| 1297 |
position: relative;
|
| 1298 |
+
border-bottom: 1px solid var(--border);
|
| 1299 |
font-size: 0.9rem;
|
| 1300 |
}
|
| 1301 |
|
|
|
|
| 1327 |
.nutrition-item {
|
| 1328 |
text-align: center;
|
| 1329 |
padding: 0.75rem;
|
| 1330 |
+
background: var(--surface-alt);
|
| 1331 |
border-radius: 8px;
|
| 1332 |
}
|
| 1333 |
|
|
|
|
| 1350 |
font-size: 0.9rem;
|
| 1351 |
}
|
| 1352 |
|
| 1353 |
+
.recipe-export-actions {
|
| 1354 |
+
display: flex;
|
| 1355 |
+
gap: 0.5rem;
|
| 1356 |
+
margin-top: 1.5rem;
|
| 1357 |
+
padding-top: 1rem;
|
| 1358 |
+
border-top: 1px solid var(--border);
|
| 1359 |
+
}
|
| 1360 |
+
|
| 1361 |
/* === Shopping List === */
|
| 1362 |
.shopping-section {
|
| 1363 |
margin-top: 1rem;
|
|
|
|
| 1378 |
flex-wrap: wrap;
|
| 1379 |
}
|
| 1380 |
|
| 1381 |
+
.checked-counter {
|
| 1382 |
+
font-size: 0.8rem;
|
| 1383 |
+
font-weight: 600;
|
| 1384 |
+
color: var(--accent);
|
| 1385 |
+
background: var(--accent-bg);
|
| 1386 |
+
padding: 0.15rem 0.6rem;
|
| 1387 |
+
border-radius: 10px;
|
| 1388 |
+
margin-left: 0.5rem;
|
| 1389 |
+
}
|
| 1390 |
+
|
| 1391 |
.shopping-actions {
|
| 1392 |
display: flex;
|
| 1393 |
gap: 0.5rem;
|
|
|
|
| 1480 |
|
| 1481 |
.shopping-items li {
|
| 1482 |
padding: 0.3rem 0;
|
| 1483 |
+
border-bottom: 1px solid var(--border);
|
| 1484 |
}
|
| 1485 |
|
| 1486 |
.shopping-item {
|
|
|
|
| 1566 |
|
| 1567 |
/* === Error === */
|
| 1568 |
.error-msg {
|
| 1569 |
+
background: rgba(230, 57, 70, 0.08);
|
| 1570 |
+
border: 1px solid var(--sale-color);
|
| 1571 |
+
color: var(--sale-color);
|
| 1572 |
padding: 1rem;
|
| 1573 |
border-radius: var(--radius);
|
| 1574 |
margin: 1rem 0;
|
|
|
|
| 1578 |
@media (max-width: 768px) {
|
| 1579 |
header { padding: 1rem; }
|
| 1580 |
header h1 { font-size: 1.4rem; }
|
| 1581 |
+
.header-row { flex-direction: column; align-items: flex-start; gap: 0.5rem; }
|
| 1582 |
+
.header-actions { align-self: flex-end; }
|
| 1583 |
+
.btn-fav-toggle { font-size: 0.8rem; padding: 0.35rem 0.75rem; }
|
| 1584 |
main { padding: 1rem; }
|
| 1585 |
.settings-bar { flex-direction: column; }
|
| 1586 |
.recipes-grid { grid-template-columns: 1fr; }
|
|
|
|
| 1597 |
.cost-breakdown { flex-direction: column; gap: 0.5rem; }
|
| 1598 |
.cost-item { border-right: none; padding: 0; }
|
| 1599 |
}
|
| 1600 |
+
|
| 1601 |
+
/* === Pantry Chips === */
|
| 1602 |
+
.pantry-container {
|
| 1603 |
+
position: relative;
|
| 1604 |
+
width: 100%;
|
| 1605 |
+
}
|
| 1606 |
+
|
| 1607 |
+
.pantry-chips {
|
| 1608 |
+
display: flex;
|
| 1609 |
+
flex-wrap: wrap;
|
| 1610 |
+
gap: 0.35rem;
|
| 1611 |
+
margin-bottom: 0.4rem;
|
| 1612 |
+
min-height: 1.6rem;
|
| 1613 |
+
}
|
| 1614 |
+
|
| 1615 |
+
.pantry-chip {
|
| 1616 |
+
display: inline-flex;
|
| 1617 |
+
align-items: center;
|
| 1618 |
+
gap: 0.25rem;
|
| 1619 |
+
padding: 0.25rem 0.55rem;
|
| 1620 |
+
background: var(--accent-bg);
|
| 1621 |
+
color: var(--accent);
|
| 1622 |
+
border: 1.5px solid var(--accent);
|
| 1623 |
+
border-radius: 20px;
|
| 1624 |
+
font-size: 0.82rem;
|
| 1625 |
+
font-weight: 600;
|
| 1626 |
+
white-space: nowrap;
|
| 1627 |
+
animation: chip-in 0.15s ease;
|
| 1628 |
+
}
|
| 1629 |
+
|
| 1630 |
+
@keyframes chip-in {
|
| 1631 |
+
from { transform: scale(0.8); opacity: 0; }
|
| 1632 |
+
to { transform: scale(1); opacity: 1; }
|
| 1633 |
+
}
|
| 1634 |
+
|
| 1635 |
+
.pantry-chip-remove {
|
| 1636 |
+
background: none;
|
| 1637 |
+
border: none;
|
| 1638 |
+
color: var(--accent);
|
| 1639 |
+
cursor: pointer;
|
| 1640 |
+
font-size: 1rem;
|
| 1641 |
+
line-height: 1;
|
| 1642 |
+
padding: 0 0.1rem;
|
| 1643 |
+
opacity: 0.6;
|
| 1644 |
+
transition: opacity 0.15s;
|
| 1645 |
+
}
|
| 1646 |
+
|
| 1647 |
+
.pantry-chip-remove:hover {
|
| 1648 |
+
opacity: 1;
|
| 1649 |
+
color: var(--sale-color);
|
| 1650 |
+
}
|
| 1651 |
+
|
| 1652 |
+
.pantry-input-field {
|
| 1653 |
+
width: 100%;
|
| 1654 |
+
padding: 0.5rem 0.75rem;
|
| 1655 |
+
border: 1.5px solid var(--border);
|
| 1656 |
+
border-radius: 6px;
|
| 1657 |
+
font-size: 0.95rem;
|
| 1658 |
+
transition: border-color 0.2s;
|
| 1659 |
+
}
|
| 1660 |
+
|
| 1661 |
+
.pantry-input-field:focus {
|
| 1662 |
+
border-color: var(--accent);
|
| 1663 |
+
outline: none;
|
| 1664 |
+
}
|
| 1665 |
+
|
| 1666 |
+
.pantry-suggestions {
|
| 1667 |
+
display: none;
|
| 1668 |
+
position: absolute;
|
| 1669 |
+
top: 100%;
|
| 1670 |
+
left: 0;
|
| 1671 |
+
right: 0;
|
| 1672 |
+
background: var(--surface);
|
| 1673 |
+
border: 1.5px solid var(--border);
|
| 1674 |
+
border-radius: 6px;
|
| 1675 |
+
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
|
| 1676 |
+
z-index: 50;
|
| 1677 |
+
max-height: 180px;
|
| 1678 |
+
overflow-y: auto;
|
| 1679 |
+
}
|
| 1680 |
+
|
| 1681 |
+
.pantry-suggestion-item {
|
| 1682 |
+
padding: 0.5rem 0.75rem;
|
| 1683 |
+
cursor: pointer;
|
| 1684 |
+
font-size: 0.9rem;
|
| 1685 |
+
transition: background 0.1s;
|
| 1686 |
+
}
|
| 1687 |
+
|
| 1688 |
+
.pantry-suggestion-item:hover {
|
| 1689 |
+
background: var(--accent-bg);
|
| 1690 |
+
color: var(--accent);
|
| 1691 |
+
}
|
| 1692 |
+
|
| 1693 |
+
.pantry-presets {
|
| 1694 |
+
display: flex;
|
| 1695 |
+
flex-wrap: wrap;
|
| 1696 |
+
gap: 0.3rem;
|
| 1697 |
+
align-items: center;
|
| 1698 |
+
margin-top: 0.35rem;
|
| 1699 |
+
}
|
| 1700 |
+
|
| 1701 |
+
.pantry-presets .setting-hint {
|
| 1702 |
+
margin-right: 0.25rem;
|
| 1703 |
+
}
|
| 1704 |
+
|
| 1705 |
+
.pantry-preset-btn {
|
| 1706 |
+
padding: 0.2rem 0.5rem;
|
| 1707 |
+
border: 1px solid var(--border);
|
| 1708 |
+
border-radius: 12px;
|
| 1709 |
+
background: var(--surface);
|
| 1710 |
+
color: var(--text-muted);
|
| 1711 |
+
font-size: 0.75rem;
|
| 1712 |
+
cursor: pointer;
|
| 1713 |
+
transition: all 0.15s;
|
| 1714 |
+
}
|
| 1715 |
+
|
| 1716 |
+
.pantry-preset-btn:hover:not(:disabled) {
|
| 1717 |
+
border-color: var(--accent);
|
| 1718 |
+
color: var(--accent);
|
| 1719 |
+
background: var(--accent-bg);
|
| 1720 |
+
}
|
| 1721 |
+
|
| 1722 |
+
.pantry-preset-btn:disabled,
|
| 1723 |
+
.pantry-preset-active {
|
| 1724 |
+
opacity: 0.4;
|
| 1725 |
+
cursor: default;
|
| 1726 |
+
border-color: var(--accent);
|
| 1727 |
+
background: var(--accent-bg);
|
| 1728 |
+
color: var(--accent);
|
| 1729 |
+
}
|
| 1730 |
+
|
| 1731 |
+
/* === Theme Toggle === */
|
| 1732 |
+
.theme-toggle {
|
| 1733 |
+
background: rgba(255, 255, 255, 0.15);
|
| 1734 |
+
border: 1.5px solid rgba(255, 255, 255, 0.3);
|
| 1735 |
+
color: white;
|
| 1736 |
+
width: 36px;
|
| 1737 |
+
height: 36px;
|
| 1738 |
+
border-radius: 8px;
|
| 1739 |
+
cursor: pointer;
|
| 1740 |
+
display: flex;
|
| 1741 |
+
align-items: center;
|
| 1742 |
+
justify-content: center;
|
| 1743 |
+
font-size: 1.1rem;
|
| 1744 |
+
transition: all 0.2s;
|
| 1745 |
+
flex-shrink: 0;
|
| 1746 |
+
}
|
| 1747 |
+
|
| 1748 |
+
.theme-toggle:hover {
|
| 1749 |
+
background: rgba(255, 255, 255, 0.25);
|
| 1750 |
+
border-color: rgba(255, 255, 255, 0.5);
|
| 1751 |
+
}
|
| 1752 |
+
|
| 1753 |
+
/* Dark mode overrides */
|
| 1754 |
+
[data-theme="dark"] header {
|
| 1755 |
+
background: #1a3a2a;
|
| 1756 |
+
}
|
| 1757 |
+
|
| 1758 |
+
[data-theme="dark"] .modal-content {
|
| 1759 |
+
background: var(--surface);
|
| 1760 |
+
}
|
| 1761 |
+
|
| 1762 |
+
[data-theme="dark"] input[type="text"],
|
| 1763 |
+
[data-theme="dark"] select {
|
| 1764 |
+
background: var(--surface-alt);
|
| 1765 |
+
color: var(--text);
|
| 1766 |
+
}
|
| 1767 |
+
|
| 1768 |
+
[data-theme="dark"] .fav-btn {
|
| 1769 |
+
background: rgba(30, 30, 30, 0.85);
|
| 1770 |
+
}
|
| 1771 |
+
|
| 1772 |
+
[data-theme="dark"] .recipe-checkbox input {
|
| 1773 |
+
accent-color: var(--accent);
|
| 1774 |
+
}
|
| 1775 |
+
|
| 1776 |
+
[data-theme="dark"] .pantry-input-field {
|
| 1777 |
+
background: var(--surface-alt);
|
| 1778 |
+
color: var(--text);
|
| 1779 |
+
}
|
| 1780 |
+
|
| 1781 |
+
[data-theme="dark"] .favorites-panel {
|
| 1782 |
+
background: var(--surface);
|
| 1783 |
+
border-color: var(--border);
|
| 1784 |
+
}
|
static/sw.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
var CACHE_NAME = 'sparrezepte-v1';
|
| 2 |
+
var STATIC_ASSETS = [
|
| 3 |
+
'/',
|
| 4 |
+
'/static/style.css',
|
| 5 |
+
'/static/htmx.min.js',
|
| 6 |
+
'/static/manifest.json',
|
| 7 |
+
];
|
| 8 |
+
|
| 9 |
+
// Install: cache static assets
|
| 10 |
+
self.addEventListener('install', function(e) {
|
| 11 |
+
e.waitUntil(
|
| 12 |
+
caches.open(CACHE_NAME).then(function(cache) {
|
| 13 |
+
return cache.addAll(STATIC_ASSETS);
|
| 14 |
+
})
|
| 15 |
+
);
|
| 16 |
+
self.skipWaiting();
|
| 17 |
+
});
|
| 18 |
+
|
| 19 |
+
// Activate: clean old caches
|
| 20 |
+
self.addEventListener('activate', function(e) {
|
| 21 |
+
e.waitUntil(
|
| 22 |
+
caches.keys().then(function(names) {
|
| 23 |
+
return Promise.all(
|
| 24 |
+
names.filter(function(n) { return n !== CACHE_NAME; })
|
| 25 |
+
.map(function(n) { return caches.delete(n); })
|
| 26 |
+
);
|
| 27 |
+
})
|
| 28 |
+
);
|
| 29 |
+
self.clients.claim();
|
| 30 |
+
});
|
| 31 |
+
|
| 32 |
+
// Fetch: network-first for API, cache-first for static
|
| 33 |
+
self.addEventListener('fetch', function(e) {
|
| 34 |
+
var url = new URL(e.request.url);
|
| 35 |
+
|
| 36 |
+
// API-Requests: immer Netzwerk, kein Cache
|
| 37 |
+
if (url.pathname.startsWith('/api/')) {
|
| 38 |
+
e.respondWith(
|
| 39 |
+
fetch(e.request).catch(function() {
|
| 40 |
+
return new Response(
|
| 41 |
+
'<div class="error-msg">Offline — bitte Internetverbindung prüfen.</div>',
|
| 42 |
+
{ headers: { 'Content-Type': 'text/html; charset=utf-8' } }
|
| 43 |
+
);
|
| 44 |
+
})
|
| 45 |
+
);
|
| 46 |
+
return;
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
// Statische Dateien: Cache-first, Network-Fallback
|
| 50 |
+
e.respondWith(
|
| 51 |
+
caches.match(e.request).then(function(cached) {
|
| 52 |
+
if (cached) return cached;
|
| 53 |
+
return fetch(e.request).then(function(response) {
|
| 54 |
+
// Nur GET-Responses cachen
|
| 55 |
+
if (e.request.method === 'GET' && response.status === 200) {
|
| 56 |
+
var clone = response.clone();
|
| 57 |
+
caches.open(CACHE_NAME).then(function(cache) {
|
| 58 |
+
cache.put(e.request, clone);
|
| 59 |
+
});
|
| 60 |
+
}
|
| 61 |
+
return response;
|
| 62 |
+
});
|
| 63 |
+
}).catch(function() {
|
| 64 |
+
// Offline-Fallback fuer HTML
|
| 65 |
+
if (e.request.headers.get('accept').indexOf('text/html') !== -1) {
|
| 66 |
+
return new Response(
|
| 67 |
+
'<!DOCTYPE html><html><body style="font-family:sans-serif;text-align:center;padding:3rem">' +
|
| 68 |
+
'<h1>Sparrezepte</h1><p>Du bist offline. Bitte verbinde dich mit dem Internet.</p></body></html>',
|
| 69 |
+
{ headers: { 'Content-Type': 'text/html; charset=utf-8' } }
|
| 70 |
+
);
|
| 71 |
+
}
|
| 72 |
+
})
|
| 73 |
+
);
|
| 74 |
+
});
|
templates/base.html
CHANGED
|
@@ -3,35 +3,112 @@
|
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
<title>Sparrezepte</title>
|
| 7 |
<link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
|
| 8 |
<script src="{{ url_for('static', filename='htmx.min.js') }}"></script>
|
| 9 |
</head>
|
| 10 |
<body>
|
| 11 |
-
<
|
|
|
|
| 12 |
<div class="header-content">
|
| 13 |
-
<
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
</div>
|
| 16 |
</header>
|
| 17 |
-
<main>
|
| 18 |
{% block content %}{% endblock %}
|
| 19 |
</main>
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
<!-- Rezept-Detail Modal -->
|
| 22 |
-
<div id="recipe-modal" class="modal hidden" onclick="if(event.target===this)closeModal()"
|
|
|
|
| 23 |
<div class="modal-content">
|
| 24 |
-
<button class="modal-close" onclick="closeModal()">×</button>
|
| 25 |
<div id="modal-body"></div>
|
| 26 |
</div>
|
| 27 |
</div>
|
| 28 |
|
| 29 |
<script>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
function closeModal() {
|
| 31 |
document.getElementById('recipe-modal').classList.add('hidden');
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
}
|
| 33 |
function openModal() {
|
| 34 |
-
document.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
}
|
| 36 |
document.addEventListener('keydown', function(e) {
|
| 37 |
if (e.key === 'Escape') closeModal();
|
|
@@ -43,6 +120,216 @@
|
|
| 43 |
}
|
| 44 |
});
|
| 45 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
// === localStorage Settings ===
|
| 47 |
function saveSettings() {
|
| 48 |
var settings = {
|
|
@@ -95,7 +382,7 @@
|
|
| 95 |
document.addEventListener('DOMContentLoaded', function() {
|
| 96 |
var hadSettings = loadSettings();
|
| 97 |
// Settings bei Änderungen speichern
|
| 98 |
-
document.querySelectorAll('[name="stores"], [name="dietary_filters"], #servings-input, #zip-input
|
| 99 |
el.addEventListener('change', saveSettings);
|
| 100 |
});
|
| 101 |
// Auto-Load wenn Settings vorhanden
|
|
@@ -105,6 +392,59 @@
|
|
| 105 |
}, 200);
|
| 106 |
}
|
| 107 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
</script>
|
| 109 |
</body>
|
| 110 |
</html>
|
|
|
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<meta name="theme-color" content="#2d6a4f">
|
| 7 |
+
<meta name="apple-mobile-web-app-capable" content="yes">
|
| 8 |
+
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
|
| 9 |
+
<link rel="manifest" href="{{ url_for('static', filename='manifest.json') }}">
|
| 10 |
+
<link rel="icon" href="{{ url_for('static', filename='icon.svg') }}" type="image/svg+xml">
|
| 11 |
+
<link rel="apple-touch-icon" href="{{ url_for('static', filename='icon.svg') }}">
|
| 12 |
<title>Sparrezepte</title>
|
| 13 |
<link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
|
| 14 |
<script src="{{ url_for('static', filename='htmx.min.js') }}"></script>
|
| 15 |
</head>
|
| 16 |
<body>
|
| 17 |
+
<a href="#main-content" class="skip-link">Zum Inhalt springen</a>
|
| 18 |
+
<header role="banner">
|
| 19 |
<div class="header-content">
|
| 20 |
+
<div class="header-row">
|
| 21 |
+
<div>
|
| 22 |
+
<h1>Sparrezepte</h1>
|
| 23 |
+
<p class="subtitle">Kochen mit Supermarkt-Angeboten</p>
|
| 24 |
+
</div>
|
| 25 |
+
<div class="header-actions">
|
| 26 |
+
<button class="btn-fav-toggle" id="fav-toggle-btn" onclick="toggleFavoritesPanel()"
|
| 27 |
+
aria-label="Favoriten anzeigen" aria-expanded="false" aria-controls="favorites-panel">
|
| 28 |
+
<span class="fav-toggle-icon" aria-hidden="true">♥</span> Favoriten
|
| 29 |
+
<span class="fav-count-badge" id="fav-count-badge" style="display:none" aria-live="polite">0</span>
|
| 30 |
+
</button>
|
| 31 |
+
<button class="theme-toggle" id="theme-toggle" onclick="toggleTheme()"
|
| 32 |
+
aria-label="Farbmodus wechseln" title="Dark/Light Mode">
|
| 33 |
+
<span id="theme-icon" aria-hidden="true">☾</span>
|
| 34 |
+
</button>
|
| 35 |
+
</div>
|
| 36 |
+
</div>
|
| 37 |
</div>
|
| 38 |
</header>
|
| 39 |
+
<main id="main-content" role="main">
|
| 40 |
{% block content %}{% endblock %}
|
| 41 |
</main>
|
| 42 |
|
| 43 |
+
<!-- Favoriten-Panel -->
|
| 44 |
+
<div id="favorites-panel" class="favorites-panel hidden" role="region" aria-label="Gespeicherte Rezepte">
|
| 45 |
+
<div class="favorites-panel-header">
|
| 46 |
+
<h2>♥ Gespeicherte Rezepte</h2>
|
| 47 |
+
<button class="btn btn-small" onclick="toggleFavoritesPanel()" aria-label="Favoriten schliessen">Schliessen</button>
|
| 48 |
+
</div>
|
| 49 |
+
<div id="favorites-list" class="favorites-list" aria-live="polite"></div>
|
| 50 |
+
</div>
|
| 51 |
+
|
| 52 |
<!-- Rezept-Detail Modal -->
|
| 53 |
+
<div id="recipe-modal" class="modal hidden" onclick="if(event.target===this)closeModal()"
|
| 54 |
+
role="dialog" aria-modal="true" aria-label="Rezeptdetails">>
|
| 55 |
<div class="modal-content">
|
| 56 |
+
<button class="modal-close" onclick="closeModal()" aria-label="Modal schliessen">×</button>
|
| 57 |
<div id="modal-body"></div>
|
| 58 |
</div>
|
| 59 |
</div>
|
| 60 |
|
| 61 |
<script>
|
| 62 |
+
// === Theme (sofort laden um Flash zu vermeiden) ===
|
| 63 |
+
(function() {
|
| 64 |
+
var saved = localStorage.getItem('sparrezepte_theme');
|
| 65 |
+
var theme;
|
| 66 |
+
if (saved) {
|
| 67 |
+
theme = saved;
|
| 68 |
+
} else if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
|
| 69 |
+
theme = 'dark';
|
| 70 |
+
} else {
|
| 71 |
+
theme = 'light';
|
| 72 |
+
}
|
| 73 |
+
if (theme === 'dark') {
|
| 74 |
+
document.documentElement.setAttribute('data-theme', 'dark');
|
| 75 |
+
}
|
| 76 |
+
})();
|
| 77 |
+
|
| 78 |
+
function toggleTheme() {
|
| 79 |
+
var isDark = document.documentElement.getAttribute('data-theme') === 'dark';
|
| 80 |
+
if (isDark) {
|
| 81 |
+
document.documentElement.removeAttribute('data-theme');
|
| 82 |
+
localStorage.setItem('sparrezepte_theme', 'light');
|
| 83 |
+
document.getElementById('theme-icon').innerHTML = '☾';
|
| 84 |
+
} else {
|
| 85 |
+
document.documentElement.setAttribute('data-theme', 'dark');
|
| 86 |
+
localStorage.setItem('sparrezepte_theme', 'dark');
|
| 87 |
+
document.getElementById('theme-icon').innerHTML = '☼';
|
| 88 |
+
}
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
// Icon beim Laden setzen
|
| 92 |
+
document.addEventListener('DOMContentLoaded', function() {
|
| 93 |
+
var isDark = document.documentElement.getAttribute('data-theme') === 'dark';
|
| 94 |
+
document.getElementById('theme-icon').innerHTML = isDark ? '☼' : '☾';
|
| 95 |
+
});
|
| 96 |
+
|
| 97 |
+
var _lastFocusedElement = null;
|
| 98 |
+
|
| 99 |
function closeModal() {
|
| 100 |
document.getElementById('recipe-modal').classList.add('hidden');
|
| 101 |
+
if (_lastFocusedElement) {
|
| 102 |
+
_lastFocusedElement.focus();
|
| 103 |
+
_lastFocusedElement = null;
|
| 104 |
+
}
|
| 105 |
}
|
| 106 |
function openModal() {
|
| 107 |
+
_lastFocusedElement = document.activeElement;
|
| 108 |
+
var modal = document.getElementById('recipe-modal');
|
| 109 |
+
modal.classList.remove('hidden');
|
| 110 |
+
var closeBtn = modal.querySelector('.modal-close');
|
| 111 |
+
if (closeBtn) closeBtn.focus();
|
| 112 |
}
|
| 113 |
document.addEventListener('keydown', function(e) {
|
| 114 |
if (e.key === 'Escape') closeModal();
|
|
|
|
| 120 |
}
|
| 121 |
});
|
| 122 |
|
| 123 |
+
// === Favoriten-Panel ===
|
| 124 |
+
function toggleFavoritesPanel() {
|
| 125 |
+
var panel = document.getElementById('favorites-panel');
|
| 126 |
+
var btn = document.getElementById('fav-toggle-btn');
|
| 127 |
+
panel.classList.toggle('hidden');
|
| 128 |
+
var isOpen = !panel.classList.contains('hidden');
|
| 129 |
+
btn.setAttribute('aria-expanded', isOpen);
|
| 130 |
+
if (isOpen) {
|
| 131 |
+
renderFavoritesList();
|
| 132 |
+
}
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
+
function getFavStoreGlobal() {
|
| 136 |
+
try { return JSON.parse(localStorage.getItem('sparrezepte_fav_recipes') || '{}'); }
|
| 137 |
+
catch(e) { return {}; }
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
function removeFavoriteFromPanel(id) {
|
| 141 |
+
var store = getFavStoreGlobal();
|
| 142 |
+
delete store[id];
|
| 143 |
+
localStorage.setItem('sparrezepte_fav_recipes', JSON.stringify(store));
|
| 144 |
+
renderFavoritesList();
|
| 145 |
+
// Button in Hauptliste aktualisieren
|
| 146 |
+
var card = document.getElementById('recipe-card-' + id);
|
| 147 |
+
if (card) {
|
| 148 |
+
var btn = card.querySelector('.fav-btn');
|
| 149 |
+
if (btn) {
|
| 150 |
+
btn.classList.remove('fav-active');
|
| 151 |
+
btn.querySelector('.fav-icon').innerHTML = '♡';
|
| 152 |
+
}
|
| 153 |
+
}
|
| 154 |
+
updateFavCountGlobal();
|
| 155 |
+
}
|
| 156 |
+
|
| 157 |
+
function updateFavCountGlobal() {
|
| 158 |
+
var badge = document.getElementById('fav-count-badge');
|
| 159 |
+
if (!badge) return;
|
| 160 |
+
var count = Object.keys(getFavStoreGlobal()).length;
|
| 161 |
+
badge.textContent = count;
|
| 162 |
+
badge.style.display = count > 0 ? 'inline-flex' : 'none';
|
| 163 |
+
}
|
| 164 |
+
|
| 165 |
+
function renderFavoritesList() {
|
| 166 |
+
var container = document.getElementById('favorites-list');
|
| 167 |
+
var store = getFavStoreGlobal();
|
| 168 |
+
var ids = Object.keys(store);
|
| 169 |
+
|
| 170 |
+
if (ids.length === 0) {
|
| 171 |
+
container.innerHTML = '<p class="fav-empty">Noch keine Favoriten gespeichert. Klicke auf das Herz bei einem Rezept!</p>';
|
| 172 |
+
return;
|
| 173 |
+
}
|
| 174 |
+
|
| 175 |
+
var html = '<div class="recipes-grid">';
|
| 176 |
+
ids.forEach(function(id) {
|
| 177 |
+
var r = store[id];
|
| 178 |
+
var cost = r.estimated_total || 0;
|
| 179 |
+
var tags = (r.tags || []).join(' ');
|
| 180 |
+
var escapedId = id.replace(/'/g, "\\'");
|
| 181 |
+
html += '<div class="recipe-card fav-card" data-tags="' + tags + '">';
|
| 182 |
+
html += '<div class="recipe-select">';
|
| 183 |
+
html += '<button class="fav-btn fav-active" onclick="event.stopPropagation(); removeFavoriteFromPanel(\'' + escapedId + '\')" title="Entfernen">';
|
| 184 |
+
html += '<span class="fav-icon">♥</span></button>';
|
| 185 |
+
html += '</div>';
|
| 186 |
+
html += '<div class="recipe-clickable" onclick="showFavRecipeDetail(\'' + escapedId + '\')">';
|
| 187 |
+
html += '<div class="recipe-header">';
|
| 188 |
+
html += '<h3>' + escapeHtml(r.name || 'Rezept') + '</h3>';
|
| 189 |
+
html += '<p class="recipe-desc">' + escapeHtml(r.description || '') + '</p>';
|
| 190 |
+
html += '</div>';
|
| 191 |
+
html += '<div class="recipe-meta">';
|
| 192 |
+
(r.stores_needed || []).forEach(function(s) {
|
| 193 |
+
html += '<span class="meta-tag tag-store">' + escapeHtml(s) + '</span>';
|
| 194 |
+
});
|
| 195 |
+
if (r.prep_time_minutes) {
|
| 196 |
+
html += '<span class="meta-tag tag-time">' + r.prep_time_minutes + ' Min</span>';
|
| 197 |
+
}
|
| 198 |
+
if (r.nutrition_per_serving && r.nutrition_per_serving.calories) {
|
| 199 |
+
html += '<span class="meta-tag tag-cal">' + r.nutrition_per_serving.calories + ' kcal</span>';
|
| 200 |
+
}
|
| 201 |
+
html += '</div>';
|
| 202 |
+
html += '<div class="recipe-footer">';
|
| 203 |
+
if (cost > 0) {
|
| 204 |
+
html += '<span class="recipe-cost">~' + cost.toFixed(2) + ' €</span>';
|
| 205 |
+
}
|
| 206 |
+
if (r.total_savings > 0) {
|
| 207 |
+
html += '<span class="recipe-savings">-' + r.total_savings.toFixed(2) + ' €</span>';
|
| 208 |
+
}
|
| 209 |
+
html += '<span class="recipe-match">' + escapeHtml(r.match_label || '') + '</span>';
|
| 210 |
+
html += '</div></div></div>';
|
| 211 |
+
});
|
| 212 |
+
html += '</div>';
|
| 213 |
+
container.innerHTML = html;
|
| 214 |
+
updateFavCountGlobal();
|
| 215 |
+
}
|
| 216 |
+
|
| 217 |
+
function escapeHtml(text) {
|
| 218 |
+
var div = document.createElement('div');
|
| 219 |
+
div.textContent = text;
|
| 220 |
+
return div.innerHTML;
|
| 221 |
+
}
|
| 222 |
+
|
| 223 |
+
function showFavRecipeDetail(id) {
|
| 224 |
+
var store = getFavStoreGlobal();
|
| 225 |
+
var r = store[id];
|
| 226 |
+
if (!r) return;
|
| 227 |
+
|
| 228 |
+
var html = '<h2>' + escapeHtml(r.name || '') + '</h2>';
|
| 229 |
+
html += '<p class="recipe-desc">' + escapeHtml(r.description || '') + '</p>';
|
| 230 |
+
|
| 231 |
+
// Meta-Tags
|
| 232 |
+
html += '<div class="recipe-meta" style="margin: 1rem 0">';
|
| 233 |
+
(r.stores_needed || []).forEach(function(s) {
|
| 234 |
+
html += '<span class="meta-tag tag-store">' + escapeHtml(s) + '</span>';
|
| 235 |
+
});
|
| 236 |
+
if (r.prep_time_minutes) html += '<span class="meta-tag tag-time">' + r.prep_time_minutes + ' Min</span>';
|
| 237 |
+
if (r.servings) html += '<span class="meta-tag tag-cal">' + r.servings + ' Portionen</span>';
|
| 238 |
+
html += '</div>';
|
| 239 |
+
|
| 240 |
+
// Zutaten-Tabelle
|
| 241 |
+
if (r.ingredients && r.ingredients.length > 0) {
|
| 242 |
+
html += '<h3>Zutaten</h3>';
|
| 243 |
+
html += '<table class="ingredients-table"><thead><tr>';
|
| 244 |
+
html += '<th></th><th>Zutat</th><th>Menge</th><th>Store</th><th>Preis</th>';
|
| 245 |
+
html += '</tr></thead><tbody>';
|
| 246 |
+
r.ingredients.forEach(function(ing) {
|
| 247 |
+
var onSale = ing.is_on_sale ? ' on-sale' : '';
|
| 248 |
+
html += '<tr class="' + onSale + '">';
|
| 249 |
+
html += '<td><span class="sale-indicator ' + (ing.is_on_sale ? 'sale-yes' : 'sale-no') + '"></span></td>';
|
| 250 |
+
html += '<td>' + escapeHtml(ing.name || '');
|
| 251 |
+
if (ing.is_on_sale && ing.offer_name) {
|
| 252 |
+
html += '<span class="offer-match-name">' + escapeHtml(ing.offer_name) + '</span>';
|
| 253 |
+
}
|
| 254 |
+
html += '</td>';
|
| 255 |
+
html += '<td>' + escapeHtml(ing.amount || '') + '</td>';
|
| 256 |
+
html += '<td>';
|
| 257 |
+
if (ing.is_on_sale && ing.store) {
|
| 258 |
+
html += '<span class="store-tag-small">' + escapeHtml(ing.store) + '</span>';
|
| 259 |
+
} else {
|
| 260 |
+
html += '—';
|
| 261 |
+
}
|
| 262 |
+
html += '</td><td>';
|
| 263 |
+
if (ing.is_on_sale && ing.sale_price) {
|
| 264 |
+
html += '<strong class="deal-price">' + ing.sale_price.toFixed(2) + ' €</strong>';
|
| 265 |
+
if (ing.old_price) {
|
| 266 |
+
html += ' <span class="deal-old-price">' + ing.old_price.toFixed(2) + ' €</span>';
|
| 267 |
+
}
|
| 268 |
+
} else {
|
| 269 |
+
html += '—';
|
| 270 |
+
}
|
| 271 |
+
html += '</td></tr>';
|
| 272 |
+
});
|
| 273 |
+
html += '</tbody></table>';
|
| 274 |
+
}
|
| 275 |
+
|
| 276 |
+
// Preis-Zusammenfassung
|
| 277 |
+
if (r.estimated_total > 0) {
|
| 278 |
+
html += '<div class="recipe-price-summary">';
|
| 279 |
+
html += '<span>Geschaetzte Gesamtkosten: <strong>~' + r.estimated_total.toFixed(2) + ' €</strong>';
|
| 280 |
+
if (r.total_deal_price > 0) {
|
| 281 |
+
html += ' (davon ' + r.total_deal_price.toFixed(2) + ' € im Angebot)';
|
| 282 |
+
}
|
| 283 |
+
html += '</span>';
|
| 284 |
+
if (r.total_savings > 0) {
|
| 285 |
+
html += '<span class="recipe-savings">Gespart: <strong>' + r.total_savings.toFixed(2) + ' €</strong></span>';
|
| 286 |
+
}
|
| 287 |
+
html += '</div>';
|
| 288 |
+
}
|
| 289 |
+
|
| 290 |
+
// Zubereitung
|
| 291 |
+
if (r.instructions && r.instructions.length > 0) {
|
| 292 |
+
html += '<h3 style="margin-top: 1.5rem">Zubereitung</h3>';
|
| 293 |
+
html += '<ol class="instructions-list">';
|
| 294 |
+
r.instructions.forEach(function(step) {
|
| 295 |
+
html += '<li>' + escapeHtml(step) + '</li>';
|
| 296 |
+
});
|
| 297 |
+
html += '</ol>';
|
| 298 |
+
}
|
| 299 |
+
|
| 300 |
+
// Nährwerte
|
| 301 |
+
var n = r.nutrition_per_serving;
|
| 302 |
+
if (n && (n.calories || n.protein_g)) {
|
| 303 |
+
html += '<h3 style="margin-top: 1.5rem">Naehrwerte pro Portion</h3>';
|
| 304 |
+
html += '<div class="nutrition-grid">';
|
| 305 |
+
html += '<div class="nutrition-item"><div class="nutrition-value">' + (n.calories || 0) + '</div><div class="nutrition-label">Kalorien</div></div>';
|
| 306 |
+
html += '<div class="nutrition-item"><div class="nutrition-value">' + (n.protein_g || 0) + 'g</div><div class="nutrition-label">Protein</div></div>';
|
| 307 |
+
html += '<div class="nutrition-item"><div class="nutrition-value">' + (n.carbs_g || 0) + 'g</div><div class="nutrition-label">Kohlenhydrate</div></div>';
|
| 308 |
+
html += '<div class="nutrition-item"><div class="nutrition-value">' + (n.fat_g || 0) + 'g</div><div class="nutrition-label">Fett</div></div>';
|
| 309 |
+
html += '</div>';
|
| 310 |
+
}
|
| 311 |
+
|
| 312 |
+
// Gespeichert-Hinweis
|
| 313 |
+
if (r.saved_at) {
|
| 314 |
+
var d = new Date(r.saved_at);
|
| 315 |
+
html += '<p style="margin-top: 1rem; font-size: 0.8rem; color: var(--text-muted)">Gespeichert am ' + d.toLocaleDateString('de-DE') + '</p>';
|
| 316 |
+
}
|
| 317 |
+
|
| 318 |
+
// Export-Buttons
|
| 319 |
+
html += '<div class="recipe-export-actions">';
|
| 320 |
+
html += '<button class="btn btn-small btn-primary" onclick="copyRecipeFromModal()">Rezept kopieren</button>';
|
| 321 |
+
html += '<button class="btn btn-small" onclick="shareRecipeFromModal()">Teilen</button>';
|
| 322 |
+
html += '</div>';
|
| 323 |
+
|
| 324 |
+
document.getElementById('modal-body').innerHTML = html;
|
| 325 |
+
openModal();
|
| 326 |
+
}
|
| 327 |
+
|
| 328 |
+
// Badge beim Start aktualisieren
|
| 329 |
+
document.addEventListener('DOMContentLoaded', function() {
|
| 330 |
+
updateFavCountGlobal();
|
| 331 |
+
});
|
| 332 |
+
|
| 333 |
// === localStorage Settings ===
|
| 334 |
function saveSettings() {
|
| 335 |
var settings = {
|
|
|
|
| 382 |
document.addEventListener('DOMContentLoaded', function() {
|
| 383 |
var hadSettings = loadSettings();
|
| 384 |
// Settings bei Änderungen speichern
|
| 385 |
+
document.querySelectorAll('[name="stores"], [name="dietary_filters"], #servings-input, #zip-input').forEach(function(el) {
|
| 386 |
el.addEventListener('change', saveSettings);
|
| 387 |
});
|
| 388 |
// Auto-Load wenn Settings vorhanden
|
|
|
|
| 392 |
}, 200);
|
| 393 |
}
|
| 394 |
});
|
| 395 |
+
|
| 396 |
+
// === Service Worker ===
|
| 397 |
+
if ('serviceWorker' in navigator) {
|
| 398 |
+
navigator.serviceWorker.register('/static/sw.js').catch(function() {});
|
| 399 |
+
}
|
| 400 |
+
|
| 401 |
+
// === Rezept-Export (global fuer Modal) ===
|
| 402 |
+
function getRecipeTextFromModal() {
|
| 403 |
+
var modal = document.getElementById('modal-body');
|
| 404 |
+
var name = modal.querySelector('h2') ? modal.querySelector('h2').textContent.trim() : '';
|
| 405 |
+
var desc = modal.querySelector('.recipe-desc') ? modal.querySelector('.recipe-desc').textContent.trim() : '';
|
| 406 |
+
var lines = [name, desc, ''];
|
| 407 |
+
lines.push('Zutaten:');
|
| 408 |
+
modal.querySelectorAll('.ingredients-table tbody tr').forEach(function(row) {
|
| 409 |
+
var cells = row.querySelectorAll('td');
|
| 410 |
+
if (cells.length >= 3) {
|
| 411 |
+
var ingredient = cells[1].childNodes[0].textContent.trim();
|
| 412 |
+
var amount = cells[2].textContent.trim();
|
| 413 |
+
lines.push(' - ' + ingredient + (amount ? ' (' + amount + ')' : ''));
|
| 414 |
+
}
|
| 415 |
+
});
|
| 416 |
+
lines.push('');
|
| 417 |
+
lines.push('Zubereitung:');
|
| 418 |
+
modal.querySelectorAll('.instructions-list li').forEach(function(li, i) {
|
| 419 |
+
lines.push(' ' + (i + 1) + '. ' + li.textContent.trim());
|
| 420 |
+
});
|
| 421 |
+
lines.push('');
|
| 422 |
+
var nutrition = modal.querySelectorAll('.nutrition-item');
|
| 423 |
+
if (nutrition.length > 0) {
|
| 424 |
+
lines.push('Naehrwerte pro Portion:');
|
| 425 |
+
nutrition.forEach(function(n) {
|
| 426 |
+
var val = n.querySelector('.nutrition-value').textContent.trim();
|
| 427 |
+
var label = n.querySelector('.nutrition-label').textContent.trim();
|
| 428 |
+
lines.push(' ' + label + ': ' + val);
|
| 429 |
+
});
|
| 430 |
+
}
|
| 431 |
+
return lines.join('\n');
|
| 432 |
+
}
|
| 433 |
+
function copyRecipeFromModal() {
|
| 434 |
+
var text = getRecipeTextFromModal();
|
| 435 |
+
navigator.clipboard.writeText(text).then(function() {
|
| 436 |
+
var btn = document.querySelector('.recipe-export-actions .btn-primary');
|
| 437 |
+
if (btn) { var o = btn.textContent; btn.textContent = 'Kopiert!'; setTimeout(function() { btn.textContent = o; }, 2000); }
|
| 438 |
+
});
|
| 439 |
+
}
|
| 440 |
+
function shareRecipeFromModal() {
|
| 441 |
+
var text = getRecipeTextFromModal();
|
| 442 |
+
if (navigator.share) {
|
| 443 |
+
navigator.share({ title: 'Rezept', text: text }).catch(function() {});
|
| 444 |
+
} else {
|
| 445 |
+
window.open('https://wa.me/?text=' + encodeURIComponent(text), '_blank');
|
| 446 |
+
}
|
| 447 |
+
}
|
| 448 |
</script>
|
| 449 |
</body>
|
| 450 |
</html>
|
templates/index.html
CHANGED
|
@@ -2,7 +2,7 @@
|
|
| 2 |
|
| 3 |
{% block content %}
|
| 4 |
<!-- Einstellungen -->
|
| 5 |
-
<section class="settings-bar">
|
| 6 |
<div class="setting-group">
|
| 7 |
<label for="zip-input">PLZ</label>
|
| 8 |
<input type="text" id="zip-input" name="zip_code" value="{{ default_zip }}" maxlength="5" pattern="\d{5}">
|
|
@@ -44,11 +44,31 @@
|
|
| 44 |
</div>
|
| 45 |
|
| 46 |
<div class="setting-group setting-wide">
|
| 47 |
-
<label
|
| 48 |
-
<
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
</div>
|
| 53 |
|
| 54 |
<div class="setting-group setting-actions">
|
|
@@ -56,7 +76,8 @@
|
|
| 56 |
hx-get="/api/deals"
|
| 57 |
hx-target="#deals-container"
|
| 58 |
hx-include="[name='zip_code'], [name='stores']"
|
| 59 |
-
hx-indicator="#deals-loading"
|
|
|
|
| 60 |
Angebote laden
|
| 61 |
</button>
|
| 62 |
</div>
|
|
@@ -81,9 +102,15 @@
|
|
| 81 |
</section>
|
| 82 |
|
| 83 |
<!-- Deals Loading -->
|
| 84 |
-
<div id="deals-loading" class="htmx-indicator
|
| 85 |
-
<div class="
|
| 86 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
</div>
|
| 88 |
|
| 89 |
<!-- Deals Container (HTMX-Target) -->
|
|
@@ -152,9 +179,16 @@
|
|
| 152 |
</section>
|
| 153 |
|
| 154 |
<!-- Recipes Loading -->
|
| 155 |
-
<div id="recipes-loading" class="htmx-indicator
|
| 156 |
-
<div class="
|
| 157 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 158 |
</div>
|
| 159 |
|
| 160 |
<!-- Recipes Container -->
|
|
@@ -189,5 +223,123 @@ document.getElementById('deal-search-input').addEventListener('keydown', functio
|
|
| 189 |
e.preventDefault();
|
| 190 |
}
|
| 191 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 192 |
</script>
|
| 193 |
{% endblock %}
|
|
|
|
| 2 |
|
| 3 |
{% block content %}
|
| 4 |
<!-- Einstellungen -->
|
| 5 |
+
<section class="settings-bar" role="search" aria-label="Einstellungen und Filter">
|
| 6 |
<div class="setting-group">
|
| 7 |
<label for="zip-input">PLZ</label>
|
| 8 |
<input type="text" id="zip-input" name="zip_code" value="{{ default_zip }}" maxlength="5" pattern="\d{5}">
|
|
|
|
| 44 |
</div>
|
| 45 |
|
| 46 |
<div class="setting-group setting-wide">
|
| 47 |
+
<label>Vorrat (vorhandene Zutaten)</label>
|
| 48 |
+
<div class="pantry-container">
|
| 49 |
+
<div class="pantry-chips" id="pantry-chips"></div>
|
| 50 |
+
<input type="text" id="pantry-add-input"
|
| 51 |
+
placeholder="Zutat eingeben..."
|
| 52 |
+
class="pantry-input-field"
|
| 53 |
+
autocomplete="off">
|
| 54 |
+
<div class="pantry-suggestions" id="pantry-suggestions"></div>
|
| 55 |
+
</div>
|
| 56 |
+
<input type="hidden" id="pantry-input" name="pantry">
|
| 57 |
+
<div class="pantry-presets">
|
| 58 |
+
<span class="setting-hint">Schnell hinzufuegen:</span>
|
| 59 |
+
<button type="button" class="pantry-preset-btn" onclick="addPantryItem('Salz')">Salz</button>
|
| 60 |
+
<button type="button" class="pantry-preset-btn" onclick="addPantryItem('Pfeffer')">Pfeffer</button>
|
| 61 |
+
<button type="button" class="pantry-preset-btn" onclick="addPantryItem('Olivenöl')">Olivenoel</button>
|
| 62 |
+
<button type="button" class="pantry-preset-btn" onclick="addPantryItem('Butter')">Butter</button>
|
| 63 |
+
<button type="button" class="pantry-preset-btn" onclick="addPantryItem('Mehl')">Mehl</button>
|
| 64 |
+
<button type="button" class="pantry-preset-btn" onclick="addPantryItem('Zucker')">Zucker</button>
|
| 65 |
+
<button type="button" class="pantry-preset-btn" onclick="addPantryItem('Reis')">Reis</button>
|
| 66 |
+
<button type="button" class="pantry-preset-btn" onclick="addPantryItem('Nudeln')">Nudeln</button>
|
| 67 |
+
<button type="button" class="pantry-preset-btn" onclick="addPantryItem('Knoblauch')">Knoblauch</button>
|
| 68 |
+
<button type="button" class="pantry-preset-btn" onclick="addPantryItem('Zwiebeln')">Zwiebeln</button>
|
| 69 |
+
<button type="button" class="pantry-preset-btn" onclick="addPantryItem('Eier')">Eier</button>
|
| 70 |
+
<button type="button" class="pantry-preset-btn" onclick="addPantryItem('Milch')">Milch</button>
|
| 71 |
+
</div>
|
| 72 |
</div>
|
| 73 |
|
| 74 |
<div class="setting-group setting-actions">
|
|
|
|
| 76 |
hx-get="/api/deals"
|
| 77 |
hx-target="#deals-container"
|
| 78 |
hx-include="[name='zip_code'], [name='stores']"
|
| 79 |
+
hx-indicator="#deals-loading"
|
| 80 |
+
aria-label="Aktuelle Angebote laden">
|
| 81 |
Angebote laden
|
| 82 |
</button>
|
| 83 |
</div>
|
|
|
|
| 102 |
</section>
|
| 103 |
|
| 104 |
<!-- Deals Loading -->
|
| 105 |
+
<div id="deals-loading" class="htmx-indicator">
|
| 106 |
+
<div class="skeleton-section">
|
| 107 |
+
<div class="skeleton-bar skeleton-title"></div>
|
| 108 |
+
<div class="skeleton-grid">
|
| 109 |
+
<div class="skeleton-card"><div class="skeleton-bar"></div><div class="skeleton-bar short"></div><div class="skeleton-bar short"></div></div>
|
| 110 |
+
<div class="skeleton-card"><div class="skeleton-bar"></div><div class="skeleton-bar short"></div><div class="skeleton-bar short"></div></div>
|
| 111 |
+
<div class="skeleton-card"><div class="skeleton-bar"></div><div class="skeleton-bar short"></div><div class="skeleton-bar short"></div></div>
|
| 112 |
+
</div>
|
| 113 |
+
</div>
|
| 114 |
</div>
|
| 115 |
|
| 116 |
<!-- Deals Container (HTMX-Target) -->
|
|
|
|
| 179 |
</section>
|
| 180 |
|
| 181 |
<!-- Recipes Loading -->
|
| 182 |
+
<div id="recipes-loading" class="htmx-indicator">
|
| 183 |
+
<div class="skeleton-section">
|
| 184 |
+
<div class="skeleton-bar skeleton-title"></div>
|
| 185 |
+
<div class="skeleton-grid">
|
| 186 |
+
<div class="skeleton-card skeleton-card-tall"><div class="skeleton-bar"></div><div class="skeleton-bar short"></div><div class="skeleton-bar"></div><div class="skeleton-bar short"></div></div>
|
| 187 |
+
<div class="skeleton-card skeleton-card-tall"><div class="skeleton-bar"></div><div class="skeleton-bar short"></div><div class="skeleton-bar"></div><div class="skeleton-bar short"></div></div>
|
| 188 |
+
<div class="skeleton-card skeleton-card-tall"><div class="skeleton-bar"></div><div class="skeleton-bar short"></div><div class="skeleton-bar"></div><div class="skeleton-bar short"></div></div>
|
| 189 |
+
<div class="skeleton-card skeleton-card-tall"><div class="skeleton-bar"></div><div class="skeleton-bar short"></div><div class="skeleton-bar"></div><div class="skeleton-bar short"></div></div>
|
| 190 |
+
</div>
|
| 191 |
+
</div>
|
| 192 |
</div>
|
| 193 |
|
| 194 |
<!-- Recipes Container -->
|
|
|
|
| 223 |
e.preventDefault();
|
| 224 |
}
|
| 225 |
});
|
| 226 |
+
|
| 227 |
+
// === Pantry Chips ===
|
| 228 |
+
var pantryItems = [];
|
| 229 |
+
var PANTRY_SUGGESTIONS = [
|
| 230 |
+
'Salz', 'Pfeffer', 'Olivenöl', 'Sonnenblumenöl', 'Butter', 'Mehl',
|
| 231 |
+
'Zucker', 'Reis', 'Nudeln', 'Knoblauch', 'Zwiebeln', 'Eier', 'Milch',
|
| 232 |
+
'Essig', 'Senf', 'Sojasauce', 'Tomatenmark', 'Haferflocken',
|
| 233 |
+
'Paprikapulver', 'Oregano', 'Basilikum', 'Thymian', 'Kreuzkümmel',
|
| 234 |
+
'Zimt', 'Muskatnuss', 'Honig', 'Kartoffeln', 'Sahne', 'Parmesan',
|
| 235 |
+
'Petersilie', 'Backpulver', 'Vanillezucker', 'Brühe', 'Ketchup',
|
| 236 |
+
'Mayonnaise', 'Speisestärke',
|
| 237 |
+
];
|
| 238 |
+
|
| 239 |
+
function renderPantryChips() {
|
| 240 |
+
var container = document.getElementById('pantry-chips');
|
| 241 |
+
container.innerHTML = '';
|
| 242 |
+
pantryItems.forEach(function(item) {
|
| 243 |
+
var chip = document.createElement('span');
|
| 244 |
+
chip.className = 'pantry-chip';
|
| 245 |
+
chip.innerHTML = item + '<button type="button" class="pantry-chip-remove" onclick="removePantryItem(\'' + item.replace(/'/g, "\\'") + '\')">×</button>';
|
| 246 |
+
container.appendChild(chip);
|
| 247 |
+
});
|
| 248 |
+
syncPantryHidden();
|
| 249 |
+
updatePresetButtons();
|
| 250 |
+
}
|
| 251 |
+
|
| 252 |
+
function syncPantryHidden() {
|
| 253 |
+
document.getElementById('pantry-input').value = pantryItems.join(', ');
|
| 254 |
+
if (typeof saveSettings === 'function') saveSettings();
|
| 255 |
+
}
|
| 256 |
+
|
| 257 |
+
function addPantryItem(item) {
|
| 258 |
+
item = item.trim();
|
| 259 |
+
if (!item) return;
|
| 260 |
+
var lower = item.toLowerCase();
|
| 261 |
+
if (pantryItems.some(function(p) { return p.toLowerCase() === lower; })) return;
|
| 262 |
+
pantryItems.push(item);
|
| 263 |
+
renderPantryChips();
|
| 264 |
+
document.getElementById('pantry-add-input').value = '';
|
| 265 |
+
hideSuggestions();
|
| 266 |
+
}
|
| 267 |
+
|
| 268 |
+
function removePantryItem(item) {
|
| 269 |
+
var lower = item.toLowerCase();
|
| 270 |
+
pantryItems = pantryItems.filter(function(p) { return p.toLowerCase() !== lower; });
|
| 271 |
+
renderPantryChips();
|
| 272 |
+
}
|
| 273 |
+
|
| 274 |
+
function updatePresetButtons() {
|
| 275 |
+
var lowerItems = pantryItems.map(function(p) { return p.toLowerCase(); });
|
| 276 |
+
document.querySelectorAll('.pantry-preset-btn').forEach(function(btn) {
|
| 277 |
+
var val = btn.textContent.trim().toLowerCase();
|
| 278 |
+
// Match against the onclick argument instead
|
| 279 |
+
var match = btn.getAttribute('onclick').match(/addPantryItem\('(.+?)'\)/);
|
| 280 |
+
if (match) val = match[1].toLowerCase();
|
| 281 |
+
if (lowerItems.indexOf(val) > -1) {
|
| 282 |
+
btn.classList.add('pantry-preset-active');
|
| 283 |
+
btn.disabled = true;
|
| 284 |
+
} else {
|
| 285 |
+
btn.classList.remove('pantry-preset-active');
|
| 286 |
+
btn.disabled = false;
|
| 287 |
+
}
|
| 288 |
+
});
|
| 289 |
+
}
|
| 290 |
+
|
| 291 |
+
function showSuggestions(query) {
|
| 292 |
+
var container = document.getElementById('pantry-suggestions');
|
| 293 |
+
if (!query) { hideSuggestions(); return; }
|
| 294 |
+
var q = query.toLowerCase();
|
| 295 |
+
var lowerItems = pantryItems.map(function(p) { return p.toLowerCase(); });
|
| 296 |
+
var matches = PANTRY_SUGGESTIONS.filter(function(s) {
|
| 297 |
+
return s.toLowerCase().indexOf(q) > -1 && lowerItems.indexOf(s.toLowerCase()) === -1;
|
| 298 |
+
}).slice(0, 5);
|
| 299 |
+
|
| 300 |
+
if (matches.length === 0) { hideSuggestions(); return; }
|
| 301 |
+
|
| 302 |
+
container.innerHTML = '';
|
| 303 |
+
matches.forEach(function(m) {
|
| 304 |
+
var div = document.createElement('div');
|
| 305 |
+
div.className = 'pantry-suggestion-item';
|
| 306 |
+
div.textContent = m;
|
| 307 |
+
div.onclick = function() { addPantryItem(m); };
|
| 308 |
+
container.appendChild(div);
|
| 309 |
+
});
|
| 310 |
+
container.style.display = 'block';
|
| 311 |
+
}
|
| 312 |
+
|
| 313 |
+
function hideSuggestions() {
|
| 314 |
+
document.getElementById('pantry-suggestions').style.display = 'none';
|
| 315 |
+
}
|
| 316 |
+
|
| 317 |
+
// Input-Events
|
| 318 |
+
document.getElementById('pantry-add-input').addEventListener('keydown', function(e) {
|
| 319 |
+
if (e.key === 'Enter') {
|
| 320 |
+
e.preventDefault();
|
| 321 |
+
addPantryItem(this.value);
|
| 322 |
+
}
|
| 323 |
+
if (e.key === 'Backspace' && !this.value && pantryItems.length > 0) {
|
| 324 |
+
removePantryItem(pantryItems[pantryItems.length - 1]);
|
| 325 |
+
}
|
| 326 |
+
});
|
| 327 |
+
document.getElementById('pantry-add-input').addEventListener('input', function() {
|
| 328 |
+
showSuggestions(this.value);
|
| 329 |
+
});
|
| 330 |
+
document.addEventListener('click', function(e) {
|
| 331 |
+
if (!e.target.closest('.pantry-container')) hideSuggestions();
|
| 332 |
+
});
|
| 333 |
+
|
| 334 |
+
// Pantry aus localStorage laden (Kompatibilität mit altem Format)
|
| 335 |
+
function loadPantryFromSettings() {
|
| 336 |
+
var raw = document.getElementById('pantry-input').value;
|
| 337 |
+
if (raw) {
|
| 338 |
+
pantryItems = raw.split(',').map(function(s) { return s.trim(); }).filter(Boolean);
|
| 339 |
+
}
|
| 340 |
+
renderPantryChips();
|
| 341 |
+
}
|
| 342 |
+
// Wird nach loadSettings() in base.html aufgerufen
|
| 343 |
+
setTimeout(loadPantryFromSettings, 50);
|
| 344 |
</script>
|
| 345 |
{% endblock %}
|
templates/partials/recipe_detail.html
CHANGED
|
@@ -28,7 +28,7 @@
|
|
| 28 |
<td>
|
| 29 |
{{ ing.name }}
|
| 30 |
{% if ing.is_on_sale and ing.offer_name %}
|
| 31 |
-
<span class="offer-match-name">{{ ing.offer_name }}</span>
|
| 32 |
{% endif %}
|
| 33 |
</td>
|
| 34 |
<td>{{ ing.amount }}</td>
|
|
@@ -97,3 +97,69 @@
|
|
| 97 |
Nicht im Angebot: {{ recipe.unmatched|join(', ') }}
|
| 98 |
</div>
|
| 99 |
{% endif %}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
<td>
|
| 29 |
{{ ing.name }}
|
| 30 |
{% if ing.is_on_sale and ing.offer_name %}
|
| 31 |
+
<span class="offer-match-name">{{ ing.offer_name }}{% if ing.quantity %} ({{ ing.quantity }}){% endif %}</span>
|
| 32 |
{% endif %}
|
| 33 |
</td>
|
| 34 |
<td>{{ ing.amount }}</td>
|
|
|
|
| 97 |
Nicht im Angebot: {{ recipe.unmatched|join(', ') }}
|
| 98 |
</div>
|
| 99 |
{% endif %}
|
| 100 |
+
|
| 101 |
+
<div class="recipe-export-actions">
|
| 102 |
+
<button class="btn btn-small btn-primary" onclick="copyRecipeFromModal()">Rezept kopieren</button>
|
| 103 |
+
<button class="btn btn-small" onclick="shareRecipeFromModal()">Teilen</button>
|
| 104 |
+
</div>
|
| 105 |
+
|
| 106 |
+
<script>
|
| 107 |
+
function getRecipeTextFromModal() {
|
| 108 |
+
var modal = document.getElementById('modal-body');
|
| 109 |
+
var name = modal.querySelector('h2') ? modal.querySelector('h2').textContent.trim() : '';
|
| 110 |
+
var desc = modal.querySelector('.recipe-desc') ? modal.querySelector('.recipe-desc').textContent.trim() : '';
|
| 111 |
+
var lines = [name, desc, ''];
|
| 112 |
+
|
| 113 |
+
// Zutaten
|
| 114 |
+
lines.push('Zutaten:');
|
| 115 |
+
modal.querySelectorAll('.ingredients-table tbody tr').forEach(function(row) {
|
| 116 |
+
var cells = row.querySelectorAll('td');
|
| 117 |
+
if (cells.length >= 3) {
|
| 118 |
+
var ingredient = cells[1].childNodes[0].textContent.trim();
|
| 119 |
+
var amount = cells[2].textContent.trim();
|
| 120 |
+
lines.push(' - ' + ingredient + (amount ? ' (' + amount + ')' : ''));
|
| 121 |
+
}
|
| 122 |
+
});
|
| 123 |
+
lines.push('');
|
| 124 |
+
|
| 125 |
+
// Zubereitung
|
| 126 |
+
lines.push('Zubereitung:');
|
| 127 |
+
modal.querySelectorAll('.instructions-list li').forEach(function(li, i) {
|
| 128 |
+
lines.push(' ' + (i + 1) + '. ' + li.textContent.trim());
|
| 129 |
+
});
|
| 130 |
+
lines.push('');
|
| 131 |
+
|
| 132 |
+
// Nährwerte
|
| 133 |
+
var nutrition = modal.querySelectorAll('.nutrition-item');
|
| 134 |
+
if (nutrition.length > 0) {
|
| 135 |
+
lines.push('Naehrwerte pro Portion:');
|
| 136 |
+
nutrition.forEach(function(n) {
|
| 137 |
+
var val = n.querySelector('.nutrition-value').textContent.trim();
|
| 138 |
+
var label = n.querySelector('.nutrition-label').textContent.trim();
|
| 139 |
+
lines.push(' ' + label + ': ' + val);
|
| 140 |
+
});
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
return lines.join('\n');
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
function copyRecipeFromModal() {
|
| 147 |
+
var text = getRecipeTextFromModal();
|
| 148 |
+
navigator.clipboard.writeText(text).then(function() {
|
| 149 |
+
var btn = document.querySelector('.recipe-export-actions .btn-primary');
|
| 150 |
+
var orig = btn.textContent;
|
| 151 |
+
btn.textContent = 'Kopiert!';
|
| 152 |
+
setTimeout(function() { btn.textContent = orig; }, 2000);
|
| 153 |
+
});
|
| 154 |
+
}
|
| 155 |
+
|
| 156 |
+
function shareRecipeFromModal() {
|
| 157 |
+
var text = getRecipeTextFromModal();
|
| 158 |
+
if (navigator.share) {
|
| 159 |
+
navigator.share({ title: 'Rezept', text: text }).catch(function() {});
|
| 160 |
+
} else {
|
| 161 |
+
var encoded = encodeURIComponent(text);
|
| 162 |
+
window.open('https://wa.me/?text=' + encoded, '_blank');
|
| 163 |
+
}
|
| 164 |
+
}
|
| 165 |
+
</script>
|
templates/partials/recipes.html
CHANGED
|
@@ -12,7 +12,8 @@
|
|
| 12 |
</div>
|
| 13 |
<div class="recipes-grid">
|
| 14 |
{% for recipe in recipes %}
|
| 15 |
-
<div class="recipe-card" id="recipe-card-{{ recipe.id }}" data-tags="{{ recipe.tags|join(' ') }}"
|
|
|
|
| 16 |
<div class="recipe-select">
|
| 17 |
<button class="fav-btn" onclick="toggleFavorite('{{ recipe.id }}', this)" title="Favorit">
|
| 18 |
<span class="fav-icon">♡</span>
|
|
@@ -65,27 +66,65 @@
|
|
| 65 |
</section>
|
| 66 |
|
| 67 |
<script>
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
|
|
|
| 71 |
}
|
| 72 |
-
function
|
| 73 |
-
localStorage.setItem('
|
|
|
|
| 74 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
function toggleFavorite(id, btn) {
|
| 76 |
event.stopPropagation();
|
| 77 |
-
var
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
favs.splice(idx, 1);
|
| 81 |
btn.classList.remove('fav-active');
|
| 82 |
btn.querySelector('.fav-icon').innerHTML = '♡';
|
| 83 |
} else {
|
| 84 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
btn.classList.add('fav-active');
|
| 86 |
btn.querySelector('.fav-icon').innerHTML = '♥';
|
| 87 |
}
|
| 88 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
}
|
| 90 |
|
| 91 |
function filterByTag(tag, btn) {
|
|
@@ -102,10 +141,11 @@ function filterByTag(tag, btn) {
|
|
| 102 |
}
|
| 103 |
});
|
| 104 |
}
|
|
|
|
| 105 |
// Favoriten nach dem Laden markieren
|
| 106 |
(function() {
|
| 107 |
-
var
|
| 108 |
-
|
| 109 |
var card = document.getElementById('recipe-card-' + id);
|
| 110 |
if (card) {
|
| 111 |
var btn = card.querySelector('.fav-btn');
|
|
@@ -115,6 +155,7 @@ function filterByTag(tag, btn) {
|
|
| 115 |
}
|
| 116 |
}
|
| 117 |
});
|
|
|
|
| 118 |
})();
|
| 119 |
</script>
|
| 120 |
{% else %}
|
|
|
|
| 12 |
</div>
|
| 13 |
<div class="recipes-grid">
|
| 14 |
{% for recipe in recipes %}
|
| 15 |
+
<div class="recipe-card" id="recipe-card-{{ recipe.id }}" data-tags="{{ recipe.tags|join(' ') }}"
|
| 16 |
+
data-recipe='{{ recipe | tojson }}'>
|
| 17 |
<div class="recipe-select">
|
| 18 |
<button class="fav-btn" onclick="toggleFavorite('{{ recipe.id }}', this)" title="Favorit">
|
| 19 |
<span class="fav-icon">♡</span>
|
|
|
|
| 66 |
</section>
|
| 67 |
|
| 68 |
<script>
|
| 69 |
+
// === Favoriten mit Rezeptdaten ===
|
| 70 |
+
function getFavStore() {
|
| 71 |
+
try { return JSON.parse(localStorage.getItem('sparrezepte_fav_recipes') || '{}'); }
|
| 72 |
+
catch(e) { return {}; }
|
| 73 |
}
|
| 74 |
+
function saveFavStore(store) {
|
| 75 |
+
localStorage.setItem('sparrezepte_fav_recipes', JSON.stringify(store));
|
| 76 |
+
updateFavCount();
|
| 77 |
}
|
| 78 |
+
function isFavorite(id) {
|
| 79 |
+
return id in getFavStore();
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
function toggleFavorite(id, btn) {
|
| 83 |
event.stopPropagation();
|
| 84 |
+
var store = getFavStore();
|
| 85 |
+
if (id in store) {
|
| 86 |
+
delete store[id];
|
|
|
|
| 87 |
btn.classList.remove('fav-active');
|
| 88 |
btn.querySelector('.fav-icon').innerHTML = '♡';
|
| 89 |
} else {
|
| 90 |
+
// Rezeptdaten aus data-Attribut lesen
|
| 91 |
+
var card = document.getElementById('recipe-card-' + id);
|
| 92 |
+
if (card && card.dataset.recipe) {
|
| 93 |
+
try {
|
| 94 |
+
var recipe = JSON.parse(card.dataset.recipe);
|
| 95 |
+
store[id] = {
|
| 96 |
+
id: recipe.id,
|
| 97 |
+
name: recipe.name,
|
| 98 |
+
description: recipe.description,
|
| 99 |
+
prep_time_minutes: recipe.prep_time_minutes,
|
| 100 |
+
tags: recipe.tags || [],
|
| 101 |
+
stores_needed: recipe.stores_needed || [],
|
| 102 |
+
nutrition_per_serving: recipe.nutrition_per_serving || {},
|
| 103 |
+
estimated_total: recipe.estimated_total || 0,
|
| 104 |
+
total_savings: recipe.total_savings || 0,
|
| 105 |
+
match_ratio: recipe.match_ratio || 0,
|
| 106 |
+
match_label: recipe.match_label || '',
|
| 107 |
+
ingredients: recipe.ingredients || [],
|
| 108 |
+
instructions: recipe.instructions || [],
|
| 109 |
+
servings: recipe.servings || 2,
|
| 110 |
+
saved_at: new Date().toISOString(),
|
| 111 |
+
};
|
| 112 |
+
} catch(e) {
|
| 113 |
+
store[id] = { id: id, name: 'Rezept', saved_at: new Date().toISOString() };
|
| 114 |
+
}
|
| 115 |
+
}
|
| 116 |
btn.classList.add('fav-active');
|
| 117 |
btn.querySelector('.fav-icon').innerHTML = '♥';
|
| 118 |
}
|
| 119 |
+
saveFavStore(store);
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
function updateFavCount() {
|
| 123 |
+
var badge = document.getElementById('fav-count-badge');
|
| 124 |
+
if (!badge) return;
|
| 125 |
+
var count = Object.keys(getFavStore()).length;
|
| 126 |
+
badge.textContent = count;
|
| 127 |
+
badge.style.display = count > 0 ? 'inline-flex' : 'none';
|
| 128 |
}
|
| 129 |
|
| 130 |
function filterByTag(tag, btn) {
|
|
|
|
| 141 |
}
|
| 142 |
});
|
| 143 |
}
|
| 144 |
+
|
| 145 |
// Favoriten nach dem Laden markieren
|
| 146 |
(function() {
|
| 147 |
+
var store = getFavStore();
|
| 148 |
+
Object.keys(store).forEach(function(id) {
|
| 149 |
var card = document.getElementById('recipe-card-' + id);
|
| 150 |
if (card) {
|
| 151 |
var btn = card.querySelector('.fav-btn');
|
|
|
|
| 155 |
}
|
| 156 |
}
|
| 157 |
});
|
| 158 |
+
updateFavCount();
|
| 159 |
})();
|
| 160 |
</script>
|
| 161 |
{% else %}
|
templates/partials/shopping_list.html
CHANGED
|
@@ -5,10 +5,13 @@
|
|
| 5 |
{% if total_savings > 0 %}
|
| 6 |
<span class="savings-badge-large">Sparst ~{{ "%.2f"|format(total_savings) }} €</span>
|
| 7 |
{% endif %}
|
|
|
|
| 8 |
</h2>
|
| 9 |
<div class="shopping-actions">
|
| 10 |
<button class="btn btn-small btn-primary" onclick="copyShoppingList()">Kopieren</button>
|
|
|
|
| 11 |
<button class="btn btn-small btn-secondary" onclick="printShoppingList()">Drucken</button>
|
|
|
|
| 12 |
</div>
|
| 13 |
</div>
|
| 14 |
|
|
@@ -54,7 +57,7 @@
|
|
| 54 |
{% for item in items %}
|
| 55 |
<li>
|
| 56 |
<label class="shopping-item">
|
| 57 |
-
<input type="checkbox">
|
| 58 |
<span class="item-name">
|
| 59 |
{{ item.name }}
|
| 60 |
{% if item.offer_name and item.offer_name != item.name %}
|
|
@@ -87,7 +90,7 @@
|
|
| 87 |
{% for item in no_deal %}
|
| 88 |
<li>
|
| 89 |
<label class="shopping-item">
|
| 90 |
-
<input type="checkbox">
|
| 91 |
<span class="item-name">
|
| 92 |
{{ item.name }}
|
| 93 |
<span class="item-amount">{{ item.amount }}</span>
|
|
@@ -169,6 +172,99 @@ function printShoppingList() {
|
|
| 169 |
win.document.close();
|
| 170 |
win.print();
|
| 171 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 172 |
</script>
|
| 173 |
{% else %}
|
| 174 |
<div class="error-msg">Bitte zuerst Rezepte generieren.</div>
|
|
|
|
| 5 |
{% if total_savings > 0 %}
|
| 6 |
<span class="savings-badge-large">Sparst ~{{ "%.2f"|format(total_savings) }} €</span>
|
| 7 |
{% endif %}
|
| 8 |
+
<span id="checked-counter" class="checked-counter" style="display:none"></span>
|
| 9 |
</h2>
|
| 10 |
<div class="shopping-actions">
|
| 11 |
<button class="btn btn-small btn-primary" onclick="copyShoppingList()">Kopieren</button>
|
| 12 |
+
<button class="btn btn-small" onclick="shareShoppingList()">Teilen</button>
|
| 13 |
<button class="btn btn-small btn-secondary" onclick="printShoppingList()">Drucken</button>
|
| 14 |
+
<button class="btn btn-small" onclick="resetChecked()" title="Alle Haekchen entfernen">Zuruecksetzen</button>
|
| 15 |
</div>
|
| 16 |
</div>
|
| 17 |
|
|
|
|
| 57 |
{% for item in items %}
|
| 58 |
<li>
|
| 59 |
<label class="shopping-item">
|
| 60 |
+
<input type="checkbox" data-shop-item="{{ store }}::{{ item.name }}">
|
| 61 |
<span class="item-name">
|
| 62 |
{{ item.name }}
|
| 63 |
{% if item.offer_name and item.offer_name != item.name %}
|
|
|
|
| 90 |
{% for item in no_deal %}
|
| 91 |
<li>
|
| 92 |
<label class="shopping-item">
|
| 93 |
+
<input type="checkbox" data-shop-item="nodeal::{{ item.name }}">
|
| 94 |
<span class="item-name">
|
| 95 |
{{ item.name }}
|
| 96 |
<span class="item-amount">{{ item.amount }}</span>
|
|
|
|
| 172 |
win.document.close();
|
| 173 |
win.print();
|
| 174 |
}
|
| 175 |
+
|
| 176 |
+
function getShoppingListText() {
|
| 177 |
+
var lines = ['Einkaufsliste (Sparrezepte)', ''];
|
| 178 |
+
var section = document.querySelector('.shopping-section');
|
| 179 |
+
section.querySelectorAll('.shopping-store:not(.shopping-store-pantry)').forEach(function(store) {
|
| 180 |
+
var storeName = store.querySelector('h3').textContent.trim().replace(/\s+\d+$/, '');
|
| 181 |
+
lines.push(storeName);
|
| 182 |
+
store.querySelectorAll('.shopping-item').forEach(function(item) {
|
| 183 |
+
var name = item.querySelector('.item-name').childNodes[0].textContent.trim();
|
| 184 |
+
var amount = item.querySelector('.item-amount');
|
| 185 |
+
var price = item.querySelector('.item-price');
|
| 186 |
+
var line = ' - ' + name;
|
| 187 |
+
if (amount) line += ' ' + amount.textContent.trim();
|
| 188 |
+
if (price) line += ' (' + price.textContent.trim() + ')';
|
| 189 |
+
lines.push(line);
|
| 190 |
+
});
|
| 191 |
+
var total = store.querySelector('.store-total');
|
| 192 |
+
if (total) lines.push(' ' + total.textContent.trim());
|
| 193 |
+
lines.push('');
|
| 194 |
+
});
|
| 195 |
+
return lines.join('\n');
|
| 196 |
+
}
|
| 197 |
+
|
| 198 |
+
function shareShoppingList() {
|
| 199 |
+
var text = getShoppingListText();
|
| 200 |
+
|
| 201 |
+
if (navigator.share) {
|
| 202 |
+
navigator.share({
|
| 203 |
+
title: 'Einkaufsliste',
|
| 204 |
+
text: text,
|
| 205 |
+
}).catch(function() {});
|
| 206 |
+
} else {
|
| 207 |
+
// Fallback: WhatsApp Web
|
| 208 |
+
var encoded = encodeURIComponent(text);
|
| 209 |
+
window.open('https://wa.me/?text=' + encoded, '_blank');
|
| 210 |
+
}
|
| 211 |
+
}
|
| 212 |
+
|
| 213 |
+
// === Persistent Checkboxen ===
|
| 214 |
+
function getCheckedItems() {
|
| 215 |
+
try { return JSON.parse(localStorage.getItem('sparrezepte_checked') || '[]'); }
|
| 216 |
+
catch(e) { return []; }
|
| 217 |
+
}
|
| 218 |
+
|
| 219 |
+
function saveCheckedItems() {
|
| 220 |
+
var checked = [];
|
| 221 |
+
document.querySelectorAll('[data-shop-item]').forEach(function(cb) {
|
| 222 |
+
if (cb.checked) checked.push(cb.getAttribute('data-shop-item'));
|
| 223 |
+
});
|
| 224 |
+
localStorage.setItem('sparrezepte_checked', JSON.stringify(checked));
|
| 225 |
+
updateCheckedCount();
|
| 226 |
+
}
|
| 227 |
+
|
| 228 |
+
function loadCheckedItems() {
|
| 229 |
+
var checked = getCheckedItems();
|
| 230 |
+
if (checked.length === 0) return;
|
| 231 |
+
document.querySelectorAll('[data-shop-item]').forEach(function(cb) {
|
| 232 |
+
if (checked.indexOf(cb.getAttribute('data-shop-item')) > -1) {
|
| 233 |
+
cb.checked = true;
|
| 234 |
+
}
|
| 235 |
+
});
|
| 236 |
+
updateCheckedCount();
|
| 237 |
+
}
|
| 238 |
+
|
| 239 |
+
function resetChecked() {
|
| 240 |
+
document.querySelectorAll('[data-shop-item]').forEach(function(cb) {
|
| 241 |
+
cb.checked = false;
|
| 242 |
+
});
|
| 243 |
+
localStorage.removeItem('sparrezepte_checked');
|
| 244 |
+
updateCheckedCount();
|
| 245 |
+
}
|
| 246 |
+
|
| 247 |
+
function updateCheckedCount() {
|
| 248 |
+
var total = document.querySelectorAll('[data-shop-item]').length;
|
| 249 |
+
var checked = document.querySelectorAll('[data-shop-item]:checked').length;
|
| 250 |
+
var counter = document.getElementById('checked-counter');
|
| 251 |
+
if (counter) {
|
| 252 |
+
if (checked > 0) {
|
| 253 |
+
counter.textContent = checked + '/' + total + ' erledigt';
|
| 254 |
+
counter.style.display = '';
|
| 255 |
+
} else {
|
| 256 |
+
counter.style.display = 'none';
|
| 257 |
+
}
|
| 258 |
+
}
|
| 259 |
+
}
|
| 260 |
+
|
| 261 |
+
// Event-Listener fuer Checkboxen
|
| 262 |
+
document.querySelectorAll('[data-shop-item]').forEach(function(cb) {
|
| 263 |
+
cb.addEventListener('change', saveCheckedItems);
|
| 264 |
+
});
|
| 265 |
+
|
| 266 |
+
// Beim Laden wiederherstellen
|
| 267 |
+
loadCheckedItems();
|
| 268 |
</script>
|
| 269 |
{% else %}
|
| 270 |
<div class="error-msg">Bitte zuerst Rezepte generieren.</div>
|
tests/test_marktguru.py
ADDED
|
@@ -0,0 +1,254 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Tests für services/marktguru.py"""
|
| 2 |
+
|
| 3 |
+
import json
|
| 4 |
+
from datetime import datetime, timedelta
|
| 5 |
+
from unittest.mock import patch, MagicMock
|
| 6 |
+
|
| 7 |
+
import pytest
|
| 8 |
+
|
| 9 |
+
from services.marktguru import MarktguruClient, group_by_store
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
# --- group_by_store ---
|
| 13 |
+
|
| 14 |
+
def test_group_by_store_basic():
|
| 15 |
+
offers = [
|
| 16 |
+
{"retailer_name": "Lidl", "name": "Hack"},
|
| 17 |
+
{"retailer_name": "Lidl", "name": "Nudeln"},
|
| 18 |
+
{"retailer_name": "Aldi Süd", "name": "Paprika"},
|
| 19 |
+
]
|
| 20 |
+
result = group_by_store(offers)
|
| 21 |
+
assert len(result) == 2
|
| 22 |
+
assert len(result["Lidl"]) == 2
|
| 23 |
+
assert len(result["Aldi Süd"]) == 1
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def test_group_by_store_empty():
|
| 27 |
+
assert group_by_store([]) == {}
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
# --- _normalize_offer ---
|
| 31 |
+
|
| 32 |
+
@pytest.fixture
|
| 33 |
+
def client_instance(tmp_path):
|
| 34 |
+
return MarktguruClient(db_path=str(tmp_path / "test_cache.db"))
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
def test_normalize_offer_complete(client_instance):
|
| 38 |
+
raw = {
|
| 39 |
+
"id": 123,
|
| 40 |
+
"description": "Hackfleisch gemischt 500g",
|
| 41 |
+
"product": {"name": "Hackfleisch"},
|
| 42 |
+
"brand": {"name": "Metzgerfrisch"},
|
| 43 |
+
"price": 3.49,
|
| 44 |
+
"oldPrice": 4.99,
|
| 45 |
+
"advertisers": [{"uniqueName": "lidl", "name": "Lidl"}],
|
| 46 |
+
"categories": [{"name": "Fleisch"}],
|
| 47 |
+
"validityDates": [
|
| 48 |
+
{"from": "2026-03-20T00:00:00Z", "to": "2026-03-27T23:59:59Z"}
|
| 49 |
+
],
|
| 50 |
+
"requiresLoyalityMembership": False,
|
| 51 |
+
"unit": {"name": "500g"},
|
| 52 |
+
}
|
| 53 |
+
offer = client_instance._normalize_offer(raw)
|
| 54 |
+
assert offer is not None
|
| 55 |
+
assert offer["id"] == 123
|
| 56 |
+
assert offer["name"] == "Hackfleisch gemischt 500g"
|
| 57 |
+
assert offer["product_name"] == "Hackfleisch"
|
| 58 |
+
assert offer["brand"] == "Metzgerfrisch"
|
| 59 |
+
assert offer["price"] == 3.49
|
| 60 |
+
assert offer["old_price"] == 4.99
|
| 61 |
+
assert offer["retailer"] == "lidl"
|
| 62 |
+
assert offer["retailer_name"] == "Lidl"
|
| 63 |
+
assert offer["category"] == "Fleisch"
|
| 64 |
+
assert offer["valid_from"] == "2026-03-20"
|
| 65 |
+
assert offer["valid_until"] == "2026-03-27"
|
| 66 |
+
assert offer["requires_loyalty"] is False
|
| 67 |
+
assert offer["quantity"] == "500g"
|
| 68 |
+
assert "medium.jpg" in offer["image_url"]
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
def test_normalize_offer_no_advertisers(client_instance):
|
| 72 |
+
raw = {"id": 1, "price": 2.99, "advertisers": [], "description": "Test"}
|
| 73 |
+
assert client_instance._normalize_offer(raw) is None
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
def test_normalize_offer_no_price(client_instance):
|
| 77 |
+
raw = {"id": 1, "price": None, "advertisers": [{"uniqueName": "lidl", "name": "Lidl"}]}
|
| 78 |
+
assert client_instance._normalize_offer(raw) is None
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
def test_normalize_offer_no_old_price(client_instance):
|
| 82 |
+
raw = {
|
| 83 |
+
"id": 2, "description": "Tomate", "product": {"name": "Tomate"},
|
| 84 |
+
"price": 1.29, "advertisers": [{"uniqueName": "lidl", "name": "Lidl"}],
|
| 85 |
+
"categories": [], "validityDates": [], "unit": {"name": "1kg"},
|
| 86 |
+
}
|
| 87 |
+
offer = client_instance._normalize_offer(raw)
|
| 88 |
+
assert offer is not None
|
| 89 |
+
assert offer["old_price"] is None
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
def test_normalize_offer_missing_fields(client_instance):
|
| 93 |
+
raw = {
|
| 94 |
+
"id": 3, "price": 0.99,
|
| 95 |
+
"advertisers": [{"uniqueName": "penny", "name": "Penny"}],
|
| 96 |
+
}
|
| 97 |
+
offer = client_instance._normalize_offer(raw)
|
| 98 |
+
assert offer is not None
|
| 99 |
+
assert offer["name"] == "Unbekannt"
|
| 100 |
+
assert offer["brand"] == ""
|
| 101 |
+
assert offer["category"] == ""
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
# --- _extract_category ---
|
| 105 |
+
|
| 106 |
+
def test_extract_category_with_categories(client_instance):
|
| 107 |
+
raw = {"categories": [{"name": "Fleisch"}, {"name": "Frisch"}]}
|
| 108 |
+
assert client_instance._extract_category(raw) == "Fleisch"
|
| 109 |
+
|
| 110 |
+
|
| 111 |
+
def test_extract_category_empty(client_instance):
|
| 112 |
+
assert client_instance._extract_category({"categories": []}) == ""
|
| 113 |
+
assert client_instance._extract_category({}) == ""
|
| 114 |
+
|
| 115 |
+
|
| 116 |
+
# --- Cache ---
|
| 117 |
+
|
| 118 |
+
def test_cache_roundtrip(client_instance):
|
| 119 |
+
offers = [{"id": 1, "name": "Test", "retailer_name": "Lidl"}]
|
| 120 |
+
client_instance._save_cache("test:key", offers)
|
| 121 |
+
loaded = client_instance._load_cache("test:key")
|
| 122 |
+
assert loaded is not None
|
| 123 |
+
assert len(loaded) == 1
|
| 124 |
+
assert loaded[0]["name"] == "Test"
|
| 125 |
+
|
| 126 |
+
|
| 127 |
+
def test_cache_miss(client_instance):
|
| 128 |
+
assert client_instance._load_cache("nonexistent:key") is None
|
| 129 |
+
|
| 130 |
+
|
| 131 |
+
def test_cache_expired(client_instance):
|
| 132 |
+
"""Expired cache should return None."""
|
| 133 |
+
import sqlite3
|
| 134 |
+
conn = client_instance._get_db()
|
| 135 |
+
old_time = (datetime.now() - timedelta(hours=24)).isoformat()
|
| 136 |
+
conn.execute(
|
| 137 |
+
"INSERT OR REPLACE INTO offer_cache (cache_key, offers_json, fetched_at) VALUES (?, ?, ?)",
|
| 138 |
+
("expired:key", json.dumps([{"id": 1}]), old_time),
|
| 139 |
+
)
|
| 140 |
+
conn.commit()
|
| 141 |
+
conn.close()
|
| 142 |
+
assert client_instance._load_cache("expired:key") is None
|
| 143 |
+
|
| 144 |
+
|
| 145 |
+
# --- fetch_deals (mocked) ---
|
| 146 |
+
|
| 147 |
+
def test_fetch_deals_uses_cache(client_instance):
|
| 148 |
+
"""If cache is fresh, no API call should be made."""
|
| 149 |
+
today = datetime.now().strftime("%Y-%m-%d")
|
| 150 |
+
cache_key = f"69250:{today}"
|
| 151 |
+
offers = [
|
| 152 |
+
{"id": 1, "name": "Cached Offer", "retailer": "lidl", "retailer_name": "Lidl",
|
| 153 |
+
"valid_until": "2099-12-31"},
|
| 154 |
+
]
|
| 155 |
+
client_instance._save_cache(cache_key, offers)
|
| 156 |
+
|
| 157 |
+
with patch.object(client_instance, "_search_offers") as mock_search:
|
| 158 |
+
result = client_instance.fetch_deals("69250", ["lidl"])
|
| 159 |
+
mock_search.assert_not_called()
|
| 160 |
+
|
| 161 |
+
assert len(result) == 1
|
| 162 |
+
assert result[0]["name"] == "Cached Offer"
|
| 163 |
+
|
| 164 |
+
|
| 165 |
+
def test_fetch_deals_filters_by_store(client_instance):
|
| 166 |
+
today = datetime.now().strftime("%Y-%m-%d")
|
| 167 |
+
cache_key = f"69250:{today}"
|
| 168 |
+
offers = [
|
| 169 |
+
{"id": 1, "name": "Lidl Offer", "retailer": "lidl", "retailer_name": "Lidl",
|
| 170 |
+
"valid_until": "2099-12-31"},
|
| 171 |
+
{"id": 2, "name": "Penny Offer", "retailer": "penny", "retailer_name": "Penny",
|
| 172 |
+
"valid_until": "2099-12-31"},
|
| 173 |
+
]
|
| 174 |
+
client_instance._save_cache(cache_key, offers)
|
| 175 |
+
|
| 176 |
+
result = client_instance.fetch_deals("69250", ["lidl"])
|
| 177 |
+
assert len(result) == 1
|
| 178 |
+
assert result[0]["retailer"] == "lidl"
|
| 179 |
+
|
| 180 |
+
|
| 181 |
+
def test_fetch_deals_calls_api_on_cache_miss(client_instance):
|
| 182 |
+
"""Without cache, should call the API."""
|
| 183 |
+
raw_response = [
|
| 184 |
+
{
|
| 185 |
+
"id": 99, "description": "Fresh API Offer", "product": {"name": "Test"},
|
| 186 |
+
"price": 1.99, "advertisers": [{"uniqueName": "lidl", "name": "Lidl"}],
|
| 187 |
+
"categories": [], "validityDates": [
|
| 188 |
+
{"from": "2026-03-20T00:00:00Z", "to": "2099-12-31T23:59:59Z"}
|
| 189 |
+
],
|
| 190 |
+
"unit": {"name": "1kg"},
|
| 191 |
+
},
|
| 192 |
+
]
|
| 193 |
+
|
| 194 |
+
with patch.object(client_instance, "_search_offers", return_value=raw_response):
|
| 195 |
+
with patch.object(client_instance, "_get_headers"):
|
| 196 |
+
result = client_instance.fetch_deals("99999", ["lidl"])
|
| 197 |
+
|
| 198 |
+
assert len(result) == 1
|
| 199 |
+
assert result[0]["price"] == 1.99
|
| 200 |
+
|
| 201 |
+
|
| 202 |
+
# --- _fetch_api_keys (mocked) ---
|
| 203 |
+
|
| 204 |
+
def test_fetch_api_keys_success(client_instance):
|
| 205 |
+
html = '''
|
| 206 |
+
<html><head>
|
| 207 |
+
<script type="application/json">
|
| 208 |
+
{"config": {"apiKey": "test-api-key", "clientKey": "test-client-key"}}
|
| 209 |
+
</script>
|
| 210 |
+
</head></html>
|
| 211 |
+
'''
|
| 212 |
+
mock_resp = MagicMock()
|
| 213 |
+
mock_resp.text = html
|
| 214 |
+
mock_resp.raise_for_status = MagicMock()
|
| 215 |
+
|
| 216 |
+
with patch("services.marktguru.requests.get", return_value=mock_resp):
|
| 217 |
+
client_instance._fetch_api_keys()
|
| 218 |
+
|
| 219 |
+
assert client_instance._api_key == "test-api-key"
|
| 220 |
+
assert client_instance._client_key == "test-client-key"
|
| 221 |
+
|
| 222 |
+
|
| 223 |
+
def test_fetch_api_keys_failure(client_instance):
|
| 224 |
+
html = '<html><body>No keys here</body></html>'
|
| 225 |
+
mock_resp = MagicMock()
|
| 226 |
+
mock_resp.text = html
|
| 227 |
+
mock_resp.raise_for_status = MagicMock()
|
| 228 |
+
|
| 229 |
+
with patch("services.marktguru.requests.get", return_value=mock_resp):
|
| 230 |
+
with pytest.raises(RuntimeError, match="API-Keys"):
|
| 231 |
+
client_instance._fetch_api_keys()
|
| 232 |
+
|
| 233 |
+
|
| 234 |
+
# --- _extract_keys ---
|
| 235 |
+
|
| 236 |
+
def test_extract_keys_nested(client_instance):
|
| 237 |
+
data = {"foo": {"bar": {"apiKey": "ak", "clientKey": "ck"}}}
|
| 238 |
+
assert client_instance._extract_keys(data) == ("ak", "ck")
|
| 239 |
+
|
| 240 |
+
|
| 241 |
+
def test_extract_keys_in_config(client_instance):
|
| 242 |
+
data = {"config": {"apiKey": "ak2", "clientKey": "ck2"}}
|
| 243 |
+
assert client_instance._extract_keys(data) == ("ak2", "ck2")
|
| 244 |
+
|
| 245 |
+
|
| 246 |
+
def test_extract_keys_in_list(client_instance):
|
| 247 |
+
data = [{"apiKey": "ak3", "clientKey": "ck3"}]
|
| 248 |
+
assert client_instance._extract_keys(data) == ("ak3", "ck3")
|
| 249 |
+
|
| 250 |
+
|
| 251 |
+
def test_extract_keys_not_found(client_instance):
|
| 252 |
+
assert client_instance._extract_keys({"foo": "bar"}) is None
|
| 253 |
+
assert client_instance._extract_keys("string") is None
|
| 254 |
+
assert client_instance._extract_keys(42) is None
|
tests/test_routes.py
ADDED
|
@@ -0,0 +1,313 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Tests für Flask-Routen in app.py"""
|
| 2 |
+
|
| 3 |
+
from unittest.mock import patch, MagicMock
|
| 4 |
+
|
| 5 |
+
import pytest
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
# --- Fixtures ---
|
| 9 |
+
|
| 10 |
+
@pytest.fixture
|
| 11 |
+
def mock_offers(sample_offers):
|
| 12 |
+
"""Patch MarktguruClient.fetch_deals to return sample_offers."""
|
| 13 |
+
with patch("app.client") as mock_client:
|
| 14 |
+
mock_client.fetch_deals.return_value = sample_offers
|
| 15 |
+
yield mock_client
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
# --- GET / ---
|
| 19 |
+
|
| 20 |
+
def test_index_returns_200(client):
|
| 21 |
+
resp = client.get("/")
|
| 22 |
+
assert resp.status_code == 200
|
| 23 |
+
assert "Sparrezepte" in resp.data.decode()
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def test_index_contains_settings(client):
|
| 27 |
+
data = resp = client.get("/").data.decode()
|
| 28 |
+
assert "zip-input" in data
|
| 29 |
+
assert "stores" in data
|
| 30 |
+
assert "pantry-input" in data
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
# --- GET /api/health ---
|
| 34 |
+
|
| 35 |
+
def test_health(client):
|
| 36 |
+
resp = client.get("/api/health")
|
| 37 |
+
assert resp.status_code == 200
|
| 38 |
+
assert resp.json == {"status": "ok"}
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
# --- GET /api/deals ---
|
| 42 |
+
|
| 43 |
+
def test_get_deals_success(client, mock_offers):
|
| 44 |
+
resp = client.get("/api/deals?zip_code=69250&stores=lidl&stores=aldi-sued")
|
| 45 |
+
assert resp.status_code == 200
|
| 46 |
+
data = resp.data.decode()
|
| 47 |
+
assert "Lidl" in data or "Aldi" in data
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
def test_get_deals_default_params(client, mock_offers):
|
| 51 |
+
resp = client.get("/api/deals")
|
| 52 |
+
assert resp.status_code == 200
|
| 53 |
+
mock_offers.fetch_deals.assert_called_once()
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
def test_get_deals_error(client):
|
| 57 |
+
with patch("app.client") as mc:
|
| 58 |
+
mc.fetch_deals.side_effect = RuntimeError("API down")
|
| 59 |
+
resp = client.get("/api/deals")
|
| 60 |
+
assert resp.status_code == 500
|
| 61 |
+
assert "Fehler" in resp.data.decode()
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
# --- POST /api/recipes ---
|
| 65 |
+
|
| 66 |
+
def test_get_recipes_success(client, mock_offers):
|
| 67 |
+
resp = client.post("/api/recipes", data={
|
| 68 |
+
"zip_code": "69250",
|
| 69 |
+
"stores": ["lidl", "aldi-sued"],
|
| 70 |
+
"servings": "2",
|
| 71 |
+
"num_recipes": "3",
|
| 72 |
+
"sort_by": "score",
|
| 73 |
+
})
|
| 74 |
+
assert resp.status_code == 200
|
| 75 |
+
data = resp.data.decode()
|
| 76 |
+
assert "recipe-card" in data or "Keine passenden" in data
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
def test_get_recipes_with_dietary_filters(client, mock_offers):
|
| 80 |
+
resp = client.post("/api/recipes", data={
|
| 81 |
+
"zip_code": "69250",
|
| 82 |
+
"stores": ["lidl"],
|
| 83 |
+
"dietary_filters": ["vegetarian"],
|
| 84 |
+
"servings": "2",
|
| 85 |
+
"num_recipes": "4",
|
| 86 |
+
})
|
| 87 |
+
assert resp.status_code == 200
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
def test_get_recipes_only_deals(client, mock_offers):
|
| 91 |
+
resp = client.post("/api/recipes", data={
|
| 92 |
+
"zip_code": "69250",
|
| 93 |
+
"stores": ["lidl"],
|
| 94 |
+
"servings": "2",
|
| 95 |
+
"num_recipes": "4",
|
| 96 |
+
"only_deals": "on",
|
| 97 |
+
})
|
| 98 |
+
assert resp.status_code == 200
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
def test_get_recipes_sort_options(client, mock_offers):
|
| 102 |
+
for sort_by in ["savings", "price", "time", "match", "score"]:
|
| 103 |
+
resp = client.post("/api/recipes", data={
|
| 104 |
+
"zip_code": "69250",
|
| 105 |
+
"stores": ["lidl", "aldi-sued"],
|
| 106 |
+
"servings": "2",
|
| 107 |
+
"num_recipes": "3",
|
| 108 |
+
"sort_by": sort_by,
|
| 109 |
+
})
|
| 110 |
+
assert resp.status_code == 200, f"Sort '{sort_by}' failed"
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
def test_get_recipes_no_offers(client):
|
| 114 |
+
with patch("app.client") as mc:
|
| 115 |
+
mc.fetch_deals.return_value = []
|
| 116 |
+
resp = client.post("/api/recipes", data={
|
| 117 |
+
"zip_code": "00000",
|
| 118 |
+
"stores": ["lidl"],
|
| 119 |
+
"servings": "2",
|
| 120 |
+
"num_recipes": "3",
|
| 121 |
+
})
|
| 122 |
+
assert resp.status_code == 404
|
| 123 |
+
assert "Keine Angebote" in resp.data.decode()
|
| 124 |
+
|
| 125 |
+
|
| 126 |
+
def test_get_recipes_error(client):
|
| 127 |
+
with patch("app.client") as mc:
|
| 128 |
+
mc.fetch_deals.side_effect = RuntimeError("Boom")
|
| 129 |
+
resp = client.post("/api/recipes", data={
|
| 130 |
+
"zip_code": "69250",
|
| 131 |
+
"stores": ["lidl"],
|
| 132 |
+
"servings": "2",
|
| 133 |
+
"num_recipes": "3",
|
| 134 |
+
})
|
| 135 |
+
assert resp.status_code == 500
|
| 136 |
+
assert "Fehler" in resp.data.decode()
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
# --- GET /api/recipe/<recipe_id> ---
|
| 140 |
+
|
| 141 |
+
def test_get_recipe_detail(client, mock_offers):
|
| 142 |
+
# First generate recipes to populate session
|
| 143 |
+
with client.session_transaction() as sess:
|
| 144 |
+
sess["last_recipes"] = [
|
| 145 |
+
{"id": "test-rezept-1", "name": "Test Rezept",
|
| 146 |
+
"ingredients": [], "instructions": [], "stores_needed": [],
|
| 147 |
+
"nutrition_per_serving": {"calories": 400, "protein_g": 20,
|
| 148 |
+
"carbs_g": 50, "fat_g": 15},
|
| 149 |
+
"match_ratio": 0.5, "match_label": "3/6", "best_store": "Lidl",
|
| 150 |
+
"total_deal_price": 5.99, "total_savings": 1.50,
|
| 151 |
+
"estimated_total": 8.00, "servings": 2,
|
| 152 |
+
"description": "Ein Testrezept", "tags": [],
|
| 153 |
+
"prep_time_minutes": 20, "matched": [], "unmatched": []},
|
| 154 |
+
]
|
| 155 |
+
|
| 156 |
+
resp = client.get("/api/recipe/test-rezept-1")
|
| 157 |
+
assert resp.status_code == 200
|
| 158 |
+
|
| 159 |
+
|
| 160 |
+
def test_get_recipe_detail_not_found(client):
|
| 161 |
+
with client.session_transaction() as sess:
|
| 162 |
+
sess["last_recipes"] = []
|
| 163 |
+
|
| 164 |
+
resp = client.get("/api/recipe/nonexistent")
|
| 165 |
+
assert resp.status_code == 404
|
| 166 |
+
assert "nicht gefunden" in resp.data.decode()
|
| 167 |
+
|
| 168 |
+
|
| 169 |
+
# --- POST /api/shopping-list ---
|
| 170 |
+
|
| 171 |
+
def test_get_shopping_list(client):
|
| 172 |
+
with client.session_transaction() as sess:
|
| 173 |
+
sess["last_recipes"] = [
|
| 174 |
+
{
|
| 175 |
+
"name": "Test Rezept",
|
| 176 |
+
"servings": 2,
|
| 177 |
+
"estimated_total": 8.00,
|
| 178 |
+
"ingredients": [
|
| 179 |
+
{"name": "Hackfleisch", "amount": "400g", "is_on_sale": True,
|
| 180 |
+
"store": "Lidl", "sale_price": 3.49, "old_price": 4.99,
|
| 181 |
+
"offer_name": "Hackfleisch 500g", "savings": 1.50},
|
| 182 |
+
{"name": "Zwiebeln", "amount": "2 Stück", "is_on_sale": False},
|
| 183 |
+
],
|
| 184 |
+
},
|
| 185 |
+
]
|
| 186 |
+
|
| 187 |
+
resp = client.post("/api/shopping-list")
|
| 188 |
+
assert resp.status_code == 200
|
| 189 |
+
data = resp.data.decode()
|
| 190 |
+
assert "Hackfleisch" in data
|
| 191 |
+
|
| 192 |
+
|
| 193 |
+
def test_get_shopping_list_with_pantry(client):
|
| 194 |
+
with client.session_transaction() as sess:
|
| 195 |
+
sess["last_recipes"] = [
|
| 196 |
+
{
|
| 197 |
+
"name": "Test Rezept",
|
| 198 |
+
"servings": 2,
|
| 199 |
+
"estimated_total": 5.00,
|
| 200 |
+
"ingredients": [
|
| 201 |
+
{"name": "Hackfleisch", "amount": "400g", "is_on_sale": True,
|
| 202 |
+
"store": "Lidl", "sale_price": 3.49, "offer_name": "Hack",
|
| 203 |
+
"savings": 0},
|
| 204 |
+
{"name": "Olivenöl", "amount": "2 EL", "is_on_sale": False},
|
| 205 |
+
],
|
| 206 |
+
},
|
| 207 |
+
]
|
| 208 |
+
|
| 209 |
+
resp = client.post("/api/shopping-list", data={"pantry": "Olivenöl, Salz"})
|
| 210 |
+
assert resp.status_code == 200
|
| 211 |
+
data = resp.data.decode()
|
| 212 |
+
assert "Vorrat" in data
|
| 213 |
+
|
| 214 |
+
|
| 215 |
+
def test_get_shopping_list_no_recipes(client):
|
| 216 |
+
with client.session_transaction() as sess:
|
| 217 |
+
sess["last_recipes"] = []
|
| 218 |
+
|
| 219 |
+
resp = client.post("/api/shopping-list")
|
| 220 |
+
assert resp.status_code == 404
|
| 221 |
+
assert "zuerst Rezepte" in resp.data.decode()
|
| 222 |
+
|
| 223 |
+
|
| 224 |
+
def test_get_shopping_list_selected_ids(client):
|
| 225 |
+
with client.session_transaction() as sess:
|
| 226 |
+
sess["last_recipes"] = [
|
| 227 |
+
{"id": "r1", "name": "Rezept A", "servings": 2, "estimated_total": 5,
|
| 228 |
+
"ingredients": [{"name": "Tomate", "amount": "3", "is_on_sale": False}]},
|
| 229 |
+
{"id": "r2", "name": "Rezept B", "servings": 2, "estimated_total": 5,
|
| 230 |
+
"ingredients": [{"name": "Gurke", "amount": "1", "is_on_sale": False}]},
|
| 231 |
+
]
|
| 232 |
+
|
| 233 |
+
resp = client.post("/api/shopping-list", data={"recipe_ids": ["r1"]})
|
| 234 |
+
assert resp.status_code == 200
|
| 235 |
+
|
| 236 |
+
|
| 237 |
+
# --- POST /api/meal-plan ---
|
| 238 |
+
|
| 239 |
+
def test_get_meal_plan_success(client, mock_offers):
|
| 240 |
+
resp = client.post("/api/meal-plan", data={
|
| 241 |
+
"zip_code": "69250",
|
| 242 |
+
"stores": ["lidl", "aldi-sued"],
|
| 243 |
+
"servings": "2",
|
| 244 |
+
"days": "3",
|
| 245 |
+
})
|
| 246 |
+
assert resp.status_code == 200
|
| 247 |
+
|
| 248 |
+
|
| 249 |
+
def test_get_meal_plan_no_offers(client):
|
| 250 |
+
with patch("app.client") as mc:
|
| 251 |
+
mc.fetch_deals.return_value = []
|
| 252 |
+
resp = client.post("/api/meal-plan", data={
|
| 253 |
+
"zip_code": "00000",
|
| 254 |
+
"stores": ["lidl"],
|
| 255 |
+
"servings": "2",
|
| 256 |
+
"days": "3",
|
| 257 |
+
})
|
| 258 |
+
assert resp.status_code == 404
|
| 259 |
+
assert "Keine Angebote" in resp.data.decode()
|
| 260 |
+
|
| 261 |
+
|
| 262 |
+
def test_get_meal_plan_error(client):
|
| 263 |
+
with patch("app.client") as mc:
|
| 264 |
+
mc.fetch_deals.side_effect = RuntimeError("API kaputt")
|
| 265 |
+
resp = client.post("/api/meal-plan", data={
|
| 266 |
+
"zip_code": "69250",
|
| 267 |
+
"stores": ["lidl"],
|
| 268 |
+
"servings": "2",
|
| 269 |
+
"days": "3",
|
| 270 |
+
})
|
| 271 |
+
assert resp.status_code == 500
|
| 272 |
+
|
| 273 |
+
|
| 274 |
+
# --- GET /api/search-deals ---
|
| 275 |
+
|
| 276 |
+
def test_search_deals_success(client, mock_offers):
|
| 277 |
+
resp = client.get("/api/search-deals?q=Hackfleisch&zip_code=69250&stores=lidl")
|
| 278 |
+
assert resp.status_code == 200
|
| 279 |
+
data = resp.data.decode()
|
| 280 |
+
assert "Hackfleisch" in data or "search-result" in data
|
| 281 |
+
|
| 282 |
+
|
| 283 |
+
def test_search_deals_empty_query(client):
|
| 284 |
+
resp = client.get("/api/search-deals?q=")
|
| 285 |
+
assert resp.status_code == 200
|
| 286 |
+
assert "Suchbegriff" in resp.data.decode()
|
| 287 |
+
|
| 288 |
+
|
| 289 |
+
def test_search_deals_error(client):
|
| 290 |
+
with patch("app.client") as mc:
|
| 291 |
+
mc.fetch_deals.side_effect = RuntimeError("Nope")
|
| 292 |
+
resp = client.get("/api/search-deals?q=Test&zip_code=69250")
|
| 293 |
+
assert resp.status_code == 500
|
| 294 |
+
|
| 295 |
+
|
| 296 |
+
# --- GET /api/compare ---
|
| 297 |
+
|
| 298 |
+
def test_compare_prices_success(client, mock_offers):
|
| 299 |
+
resp = client.get("/api/compare?q=Hackfleisch&zip_code=69250&stores=lidl&stores=aldi-sued")
|
| 300 |
+
assert resp.status_code == 200
|
| 301 |
+
|
| 302 |
+
|
| 303 |
+
def test_compare_prices_empty_query(client):
|
| 304 |
+
resp = client.get("/api/compare?q=")
|
| 305 |
+
assert resp.status_code == 200
|
| 306 |
+
assert "Suchbegriff" in resp.data.decode()
|
| 307 |
+
|
| 308 |
+
|
| 309 |
+
def test_compare_prices_error(client):
|
| 310 |
+
with patch("app.client") as mc:
|
| 311 |
+
mc.fetch_deals.side_effect = RuntimeError("Fehler")
|
| 312 |
+
resp = client.get("/api/compare?q=Milch&zip_code=69250")
|
| 313 |
+
assert resp.status_code == 500
|