feat(trips): archive current list and start a fresh one
Add a "Arkivér & ny liste" button that snapshots the current trip (checked items, prices, quantities, extras and custom categories) into a new trips table, then clears the mutable state so the list resets to the fresh catalog. - New trips table in init_db() storing a self-contained JSON snapshot plus computed totals and item count - POST /api/archive with a no-op guard against archiving an empty list - /historik list view and /historik/<id> read-only detail view - Photo files are kept so archived trips can still show them
This commit is contained in:
@@ -172,9 +172,11 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="header-actions">
|
||||
<div style="display:flex;gap:8px">
|
||||
<div style="display:flex;gap:8px;flex-wrap:wrap">
|
||||
<button class="btn btn-cat" onclick="openCatModal()">+ Kategori</button>
|
||||
<a href="/analyse" class="btn">📊 Analyse</a>
|
||||
<a href="/historik" class="btn">🕑 Historik</a>
|
||||
<button class="btn" onclick="openArchiveModal()">🗂 Arkivér & ny liste</button>
|
||||
</div>
|
||||
<div class="savings-card">
|
||||
<div class="label">Estimeret besparelse</div>
|
||||
@@ -415,6 +417,22 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- ARKIVÉR MODAL -->
|
||||
<div class="modal-overlay" id="archive-modal" onclick="if(event.target===this)closeArchiveModal()">
|
||||
<div class="modal">
|
||||
<div class="modal-title">
|
||||
Arkivér & ny liste
|
||||
<button class="modal-close" onclick="closeArchiveModal()">×</button>
|
||||
</div>
|
||||
<p style="margin:0 0 1.25rem;color:var(--muted);line-height:1.5">
|
||||
Den nuværende tur gemmes i <strong>Historik</strong>, og listen nulstilles til en frisk
|
||||
udgave: afkrydsninger og priser fjernes, og dine tilføjede varer og egne kategorier ryddes.
|
||||
</p>
|
||||
<button class="btn-submit" id="archive-confirm" onclick="doArchive()">Arkivér & nulstil</button>
|
||||
<button class="btn-submit" style="background:transparent;color:var(--muted);margin-top:4px" onclick="closeArchiveModal()">Annullér</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
const SEC_IDS = ['koed','frost','mejeri','pasta','groent','konserves','indisk','mex','drikke','hus'];
|
||||
const DK_SAVINGS_RATIO = 0.35;
|
||||
@@ -621,6 +639,32 @@ async function deleteCategory(id) {
|
||||
document.getElementById(`csec-${id}`).remove();
|
||||
}
|
||||
|
||||
function openArchiveModal() {
|
||||
document.getElementById('archive-modal').classList.add('open');
|
||||
}
|
||||
function closeArchiveModal() {
|
||||
document.getElementById('archive-modal').classList.remove('open');
|
||||
}
|
||||
|
||||
async function doArchive() {
|
||||
const btn = document.getElementById('archive-confirm');
|
||||
btn.textContent = 'Arkiverer...'; btn.disabled = true;
|
||||
try {
|
||||
const res = await fetch('/api/archive', {method: 'POST'});
|
||||
const data = await res.json();
|
||||
if (data.ok) {
|
||||
window.location.reload();
|
||||
return;
|
||||
}
|
||||
if (data.empty) alert('Listen er allerede tom — intet at arkivere.');
|
||||
else alert('Kunne ikke arkivere. Prøv igen.');
|
||||
} catch (e) {
|
||||
alert('Kunne ikke arkivere. Prøv igen.');
|
||||
}
|
||||
btn.textContent = 'Arkivér & nulstil'; btn.disabled = false;
|
||||
closeArchiveModal();
|
||||
}
|
||||
|
||||
recalcAll();
|
||||
</script>
|
||||
</body>
|
||||
|
||||
Reference in New Issue
Block a user