implemented year select for export csv

This commit is contained in:
Djeeberjr 2025-10-23 16:33:15 +02:00
parent 4bf89626b9
commit c3eaff03d9

View File

@ -1,32 +1,81 @@
<script lang="ts"> <script lang="ts">
import Modal from "./Modal.svelte"; import Modal from "./Modal.svelte";
let { onSubmitted }: { onSubmitted?: (from: Date, to: Date) => void } = $props(); let { onSubmitted }: { onSubmitted?: (from: Date, to: Date) => void } =
$props();
let modal: Modal; let modal: Modal;
let fromDate: string | undefined = $state(); let fromDate: string | undefined = $state();
let toDate: string | undefined = $state(); let toDate: string | undefined = $state();
let selectedYear: number = $state(new Date().getFullYear());
let selectedTab = $state(0);
export function open() { export function open() {
modal.open(); modal.open();
} }
function generateYears() {
const currentYear = new Date().getFullYear();
const startingYear = 2020;
return Array.from(
new Array(currentYear + 1 - startingYear),
(_, i) => i + startingYear,
);
}
function onsubmit(e: SubmitEvent) { function onsubmit(e: SubmitEvent) {
let from: Date;
let to: Date;
switch (selectedTab) {
case 0:
if (!fromDate || !toDate) { if (!fromDate || !toDate) {
e.preventDefault(); e.preventDefault();
return; return;
} }
let from = new Date(fromDate); from = new Date(fromDate);
let to = new Date(toDate); to = new Date(toDate);
break;
case 1:
from = new Date(selectedYear, 0);
to = new Date(selectedYear + 1, 0);
break;
default:
console.error("Invalid tab");
return;
}
onSubmitted?.(from, to); onSubmitted?.(from, to);
} }
</script> </script>
<Modal bind:this={modal}> <Modal bind:this={modal}>
<div class="flex">
<button
onclick={() => {
selectedTab = 0;
}}
class="tab {selectedTab === 0 ? 'tab-active' : ''}"
>
Datum
</button>
<button
onclick={() => {
selectedTab = 1;
}}
class="tab {selectedTab === 1 ? 'tab-active' : ''}"
>
Jahr
</button>
</div>
<form method="dialog" {onsubmit} class="flex flex-col"> <form method="dialog" {onsubmit} class="flex flex-col">
{#if selectedTab === 0}
<div>
<label class="form-row"> <label class="form-row">
<span>Von:</span> <span>Von:</span>
<input type="date" class="form-input" bind:value={fromDate} /> <input type="date" class="form-input" bind:value={fromDate} />
@ -36,6 +85,21 @@
<span>Bis:</span> <span>Bis:</span>
<input type="date" class="form-input" bind:value={toDate} /> <input type="date" class="form-input" bind:value={toDate} />
</label> </label>
</div>
{/if}
{#if selectedTab === 1}
<div>
<label class="form-row">
<span>Kalendar Jahr:</span>
<select class="form-input" bind:value={selectedYear}>
{#each generateYears() as year}
<option value={year}>{year}</option>
{/each}
</select>
</label>
</div>
{/if}
<div class="flex justify-end mt-3"> <div class="flex justify-end mt-3">
<button <button
@ -60,11 +124,19 @@
<style scoped> <style scoped>
@reference "../app.css"; @reference "../app.css";
.tab {
@apply px-4 py-2 rounded-t-lg bg-indigo-600 hover:bg-indigo-700 font-medium border-b-2 border-transparent cursor-pointer transition-colors duration-200;
}
.tab-active {
@apply px-4 py-2 bg-indigo-500 font-semibold border-b-2 border-blue-600 shadow-sm cursor-pointer;
}
.form-row { .form-row {
@apply flex justify-between; @apply flex justify-between my-1;
} }
.form-input { .form-input {
@apply ml-10; @apply ml-20;
} }
</style> </style>