Files
ti/templates/tilbud.html
Henrik Jess Nielsen 65a99d2138 feat(offers): live Lübeck offer prices with pick-to-list and deal matching
Fetch CITTI Lübeck offers from the Tjek API (German dealer 3czmZx only —
never the Danish Flensburg booklet) and surface them in the app.

- New offers + offer_meta tables; defensive hotspots parser; upsert by
  offer id, prune per re-fetched catalog while preserving picked rows
- Daily in-process refresh scheduler (data.db lives on the app's own
  Nomad alloc disk, so a separate periodic job can't share it) plus a
  manual POST /api/offers/refresh and an "Opdater" button
- /tilbud page: browse all offers by catalog, search, EUR + DKK, and tick
  offers onto the shopping list; picks appear in a Lübeck-tilbud section
  on the main list and check off as bought via the existing /api/price
- Match the fixed catalog items against current offers and show a
  "på tilbud" badge with the matched offer name (conservative word-
  boundary token match, >=2 tokens for multi-word names)
- Dockerfile: add ca-certificates for urllib HTTPS to the Tjek API
2026-10-30 10:35:43 +01:00

162 lines
7.4 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!DOCTYPE html>
<html lang="da">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Citti Tilbud — Lübeck</title>
<link href="https://fonts.googleapis.com/css2?family=DM+Mono:wght@400;500&family=DM+Sans:wght@300;400;500;600&display=swap" rel="stylesheet">
<style>
:root {
--bg: #f5f2ed; --card: #ffffff; --border: #e2ddd6; --text: #1a1814;
--muted: #8a857c; --accent: #c84b2f; --green: #2d6a4f; --green-light: #e8f4ee;
--mono: 'DM Mono', monospace; --sans: 'DM Sans', sans-serif;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: var(--sans); background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.5; padding: 1.5rem 1rem 4rem; }
.page { max-width: 860px; margin: 0 auto; }
header { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; padding-bottom: 1.25rem; border-bottom: 2px solid var(--text); }
h1 { font-size: 1.75rem; font-weight: 600; letter-spacing: -0.03em; }
h1 span { color: var(--accent); }
.sub { font-size: 12px; color: var(--muted); margin-top: 4px; }
.btn { background: var(--card); color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 8px 14px; font-size: 13px; font-family: var(--sans); cursor: pointer; text-decoration: none; display: inline-block; font-weight: 500; }
.btn-back { background: var(--text); color: white; border: none; }
.btn-refresh { background: var(--green); color: white; border: none; }
.btn:active { opacity: 0.85; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 1.25rem; }
.search { flex: 1; min-width: 180px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; font-family: var(--sans); font-size: 14px; background: var(--card); }
.pick-count { font-size: 13px; color: var(--green); font-weight: 600; white-space: nowrap; }
.cat { margin-bottom: 1.5rem; }
.cat-title { background: var(--text); color: white; padding: 0.5rem 1rem; font-size: 12px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.05em; border-radius: 8px 8px 0 0; }
.cat-body { background: var(--card); border: 1px solid var(--border); border-top: none; border-radius: 0 0 8px 8px; overflow: hidden; }
.offer { display: grid; grid-template-columns: 34px 1fr auto; align-items: center; gap: 10px; padding: 0.55rem 1rem; border-bottom: 1px solid var(--border); }
.offer:last-child { border-bottom: none; }
.offer.picked { background: var(--green-light); }
.offer input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--green); cursor: pointer; }
.o-name { font-size: 14px; }
.o-meta { font-size: 11px; color: var(--muted); margin-top: 1px; }
.o-price { text-align: right; white-space: nowrap; }
.o-eur { font-family: var(--mono); font-weight: 600; font-size: 15px; }
.o-pre { font-family: var(--mono); font-size: 12px; color: var(--muted); text-decoration: line-through; margin-right: 4px; }
.o-dkk { font-family: var(--mono); font-size: 11px; color: var(--muted); }
.empty-state { padding: 2.5rem 2rem; text-align: center; color: var(--muted); font-size: 14px; background: var(--card); border: 1px solid var(--border); border-radius: 10px; }
.err { background: #fde8e3; color: var(--accent); font-size: 12px; padding: 8px 12px; border-radius: 8px; margin-bottom: 1rem; }
.cat.hidden, .offer.hidden { display: none; }
@media (max-width: 600px) {
.offer { grid-template-columns: 30px 1fr auto; }
}
</style>
</head>
<body>
<div class="page">
<header>
<div>
<h1>Citti <span>Tilbud</span></h1>
<div class="sub">
CITTI Lübeck · Herrenholz 14 · priser i EUR (≈ ×{{ "{:.2f}".format(eur_dkk).replace(".",",") }} kr.)<br>
{% if last_refresh %}Opdateret {{ last_refresh[:16].replace("T"," ") }} · {% endif %}{{ total }} tilbud
</div>
</div>
<div style="display:flex;flex-direction:column;gap:8px;align-items:flex-end">
<a href="/" class="btn btn-back">← Indkøbsseddel</a>
<button class="btn btn-refresh" id="refresh-btn" onclick="refreshOffers()">⟳ Opdater</button>
</div>
</header>
{% if last_error %}<div class="err">Sidste opdatering fejlede: {{ last_error }}</div>{% endif %}
<div class="toolbar">
<input class="search" id="search" type="search" placeholder="Søg i tilbud (tysk navn)…" oninput="filterOffers()">
<span class="pick-count" id="pick-count">{{ picked_count }} på seddel</span>
</div>
{% if total == 0 %}
<div class="empty-state">
Ingen tilbud hentet endnu. Tryk <strong>⟳ Opdater</strong> for at hente ugens tilbud fra CITTI Lübeck.
</div>
{% endif %}
{% for cat, offers in by_cat.items() %}
<div class="cat" data-cat>
<div class="cat-title">{{ cat }} ({{ offers|length }})</div>
<div class="cat-body">
{% for o in offers %}
<label class="offer{% if o.picked %} picked{% endif %}" data-name="{{ o.heading|lower }}">
<input type="checkbox" {% if o.picked %}checked{% endif %} onchange="togglePick(this, '{{ o.id }}')">
<div>
<div class="o-name">{{ o.heading }}</div>
<div class="o-meta">
{% if o.page %}s. {{ o.page }}{% endif %}
{% if o.unit and o.size_from %} · {{ o.size_from|int }}{% if o.size_to and o.size_to != o.size_from %}–{{ o.size_to|int }}{% endif %} {{ o.unit }}{% endif %}
{% if o.run_till %} · t.o.m. {{ o.run_till[:10] }}{% endif %}
</div>
</div>
<div class="o-price">
<div>
{% if o.pre_price_eur %}<span class="o-pre">{{ "{:.2f}".format(o.pre_price_eur).replace(".",",") }}</span>{% endif %}
<span class="o-eur">{{ "{:.2f}".format(o.price_eur).replace(".",",") }} €</span>
</div>
<div class="o-dkk">≈ {{ "{:.0f}".format(o.price_eur * eur_dkk) }} kr.</div>
</div>
</label>
{% endfor %}
</div>
</div>
{% endfor %}
</div>
<script>
let pickCount = {{ picked_count }};
async function togglePick(cb, id) {
const picked = cb.checked;
cb.closest('.offer').classList.toggle('picked', picked);
pickCount += picked ? 1 : -1;
document.getElementById('pick-count').textContent = pickCount + ' på seddel';
try {
await fetch('/api/offers/pick', {
method: 'POST',
headers: {'Content-Type':'application/json'},
body: JSON.stringify({id, picked})
});
} catch (e) {
cb.checked = !picked;
cb.closest('.offer').classList.toggle('picked', !picked);
pickCount += picked ? -1 : 1;
document.getElementById('pick-count').textContent = pickCount + ' på seddel';
}
}
function filterOffers() {
const q = document.getElementById('search').value.trim().toLowerCase();
document.querySelectorAll('[data-cat]').forEach(cat => {
let any = false;
cat.querySelectorAll('.offer').forEach(o => {
const match = !q || o.dataset.name.includes(q);
o.classList.toggle('hidden', !match);
if (match) any = true;
});
cat.classList.toggle('hidden', !any);
});
}
async function refreshOffers() {
const btn = document.getElementById('refresh-btn');
btn.textContent = '⟳ Henter…'; btn.disabled = true;
try {
const res = await fetch('/api/offers/refresh', {method: 'POST'});
const data = await res.json();
if (data.ok) { window.location.reload(); return; }
alert('Opdatering fejlede. Prøv igen om lidt.');
} catch (e) {
alert('Opdatering fejlede. Prøv igen om lidt.');
}
btn.textContent = '⟳ Opdater'; btn.disabled = false;
}
</script>
</body>
</html>