code improvements
This commit is contained in:
parent
104cafbcec
commit
e2f011597d
|
|
@ -14,9 +14,6 @@
|
|||
|
||||
let { data, form } : PageProps = $props();
|
||||
|
||||
//$inspect(data);
|
||||
|
||||
const HEADERS: string[] = [ "Datum", "Wochentag", "Beginn", "Ende", "Dauer", "Anmerkung" ];
|
||||
|
||||
const status_ok = "ok";
|
||||
const status_missing = "missing";
|
||||
|
|
@ -42,6 +39,26 @@
|
|||
})
|
||||
|
||||
function setNewState() {
|
||||
if (form?.success != null) {
|
||||
new_state = {
|
||||
date: {
|
||||
valid: true,
|
||||
value: ""
|
||||
},
|
||||
start: {
|
||||
valid: true,
|
||||
value: ""
|
||||
},
|
||||
end: {
|
||||
valid: true,
|
||||
value: ""
|
||||
},
|
||||
comment: {
|
||||
value: ""
|
||||
}
|
||||
}
|
||||
return
|
||||
} else {
|
||||
new_state = {
|
||||
date: {
|
||||
valid: form?.new_entry?.date?.value !== "" || form?.new_entry?.date?.valid,
|
||||
|
|
@ -60,6 +77,7 @@
|
|||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function setEditing(entry: RecordEntry | null = null) {
|
||||
if (entry) {
|
||||
|
|
|
|||
|
|
@ -1,24 +1,21 @@
|
|||
<script lang="ts">
|
||||
import type { PageProps } from "./$types";
|
||||
|
||||
import { enhance } from "$app/forms";
|
||||
import type { FileProperties } from "$lib/server/docstore";
|
||||
|
||||
import { isoToLocalDate, padInt } from "$lib/util";
|
||||
|
||||
import Expander from "./expander.svelte";
|
||||
|
||||
let { data, form } : PageProps = $props();
|
||||
|
||||
$inspect(data);
|
||||
let { data } : PageProps = $props();
|
||||
|
||||
</script>
|
||||
|
||||
<div>
|
||||
<h1>Dokumente</h1>
|
||||
|
||||
<form id="form_download" method="GET" >
|
||||
<form id="form_download" method="GET" ></form>
|
||||
|
||||
{#snippet table(first_cell_name: string, rows)}
|
||||
{#snippet table(first_cell_name: string, rows: FileProperties[])}
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
|
|
@ -32,7 +29,7 @@
|
|||
{#each rows as file}
|
||||
<tr>
|
||||
<td>{file.identifier}</td>
|
||||
<td>{file.filename}</td>
|
||||
<td>{file.name}</td>
|
||||
<td>{isoToLocalDate(file.cdate.toISOString())}<br/>um {padInt(file.cdate.getHours(), 2)}:{padInt(file.cdate.getMinutes(), 2)}:{padInt(file.cdate.getSeconds(), 2)}</td>
|
||||
<td>
|
||||
<form method="GET" action={`dokumente/${file.path}`} target="_blank">
|
||||
|
|
@ -86,78 +83,6 @@
|
|||
</Expander>
|
||||
</div>
|
||||
|
||||
<div style:height="100px"></div>
|
||||
|
||||
|
||||
<!--<form method="POST" id="create_est" action="?/create_estimate" use:enhance></form>
|
||||
<form method="POST" id="create_rec" action="?/create_record" use:enhance></form>
|
||||
|
||||
<table>
|
||||
<caption>Dokument erstellen</caption>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>Stundenliste</td>
|
||||
<td>
|
||||
<input form="create_rec" style:width="2ch" name="month" /> -
|
||||
<input form="create_rec" style:width="4ch" name="year" placeholder="Jahr" value={new Date().getFullYear()} />
|
||||
</td>
|
||||
<td>
|
||||
<button form="create_rec" type="submit">Erstellen</button>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Stundenschätzung</td>
|
||||
<td>
|
||||
<input form="create_est" style:width="1ch" name="quarter" />. Quartal
|
||||
<input form="create_est" style:width="4ch" name="year" placeholder="Jahr" value={new Date().getFullYear()} />
|
||||
</td>
|
||||
<td>
|
||||
<button form="create_est" type="submit">Erstellen</button>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<div style:width="100%" style="text-align: center;">{!(form?.success) ? form?.message : "Dokument erstellt."}</div>
|
||||
|
||||
<div style:height="20px"></div>
|
||||
|
||||
<table>
|
||||
|
||||
<caption>Erstellte Dokumente</caption>
|
||||
|
||||
<thead>
|
||||
<tr>
|
||||
<th style:width="30ch">Dateiname</th>
|
||||
<th style:width="15ch">Erstellt</th>
|
||||
<th style:width="12ch">Aktion</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
{#each data.documents as doc}
|
||||
<tr>
|
||||
<td>{doc.name}</td>
|
||||
<td>{`${isoToLocalDate(doc.timestamp.toISOString())} um ${padInt(doc.timestamp.getHours(), 2)}:${padInt(doc.timestamp.getMinutes(), 2)}:${padInt(doc.timestamp.getSeconds(), 2)}`}</td>
|
||||
<td>
|
||||
<form method="GET" action={`dokumente/${doc.path}`}>
|
||||
<button type="submit">Download</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
{/each}
|
||||
<tr></tr>
|
||||
</tbody>
|
||||
|
||||
{#if data.documents.length === 0}
|
||||
<tfoot>
|
||||
<tr>
|
||||
<td class="td-no-elements" colspan="999">Noch keine Dokumente</td>
|
||||
</tr>
|
||||
</tfoot>
|
||||
{/if}
|
||||
</table> -->
|
||||
|
||||
</div>
|
||||
|
||||
<style>
|
||||
|
|
@ -187,10 +112,6 @@ tbody tr {
|
|||
border-bottom: 1px solid black;
|
||||
}
|
||||
|
||||
tbody tr th {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
tbody tr td {
|
||||
vertical-align: middle;
|
||||
text-align: center;
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
import type { Snippet } from "svelte";
|
||||
|
||||
let { id, label, children } : { label: string, children: Snippet } = $props();
|
||||
let { id, label, children } : { id: string, label: string, children: Snippet } = $props();
|
||||
|
||||
let _id = id + "_check";
|
||||
</script>
|
||||
|
|
|
|||
|
|
@ -497,11 +497,8 @@
|
|||
|
||||
</script>
|
||||
|
||||
<!--<tr>
|
||||
{#each { length: prepend_td }, n}
|
||||
<td></td>
|
||||
{/each}-->
|
||||
<td>
|
||||
<!-- svelte-ignore a11y_autofocus -->
|
||||
<input
|
||||
bind:this={dateInput}
|
||||
bind:value={states.date.value}
|
||||
|
|
@ -619,13 +616,8 @@
|
|||
{@render children?.()}
|
||||
</td>
|
||||
|
||||
<!--</tr>-->
|
||||
|
||||
<style>
|
||||
|
||||
/* * {
|
||||
border: 1px solid;
|
||||
}*/
|
||||
|
||||
td input {
|
||||
box-sizing: border-box;
|
||||
|
|
|
|||
|
|
@ -4,9 +4,7 @@
|
|||
import { enhance } from "$app/forms";
|
||||
import { MONTHS, toInt, toFloat, padInt } from "$lib/util";
|
||||
|
||||
let { form, data }: PageProps = $props();
|
||||
|
||||
$inspect(data);
|
||||
let { data }: PageProps = $props();
|
||||
|
||||
let next = $state((() => {
|
||||
if (data.estimates.size == 0) {
|
||||
|
|
@ -25,7 +23,6 @@
|
|||
estimate_2: { value: "" },
|
||||
editing: { value: "" }
|
||||
})
|
||||
$inspect(estimate_store);
|
||||
|
||||
function validate_year(event: InputEvent) {
|
||||
const input = event.target as HTMLInputElement;
|
||||
|
|
@ -55,20 +52,6 @@
|
|||
}
|
||||
}
|
||||
|
||||
/*const TODAY = new Date();
|
||||
const NEXT_QUART = (data?.estimates?.length > 0)
|
||||
? new Date(data.estimates[0].year + (data.estimates[0].quarter === 4 ? 1 : 0), 4 * (data.estimates[0].quarter - (data.estimates[0].quarter === 4 ? -4 : 0)))
|
||||
: TODAY;
|
||||
|
||||
const add_quart = quart_from_date(NEXT_QUART);
|
||||
|
||||
function quart_from_date(date: Date) {
|
||||
return Math.floor((date.getMonth()+1) / 4) + 1;
|
||||
}
|
||||
|
||||
function month_from_quart(quart: number, num: number) {
|
||||
return new Date(TODAY.getFullYear(), (quart - 1) * 4 + num);
|
||||
}*/
|
||||
</script>
|
||||
|
||||
<form id="form_add_quart" method="POST" action="?/add_quarter" use:enhance></form>
|
||||
|
|
@ -87,20 +70,20 @@
|
|||
|
||||
<tbody>
|
||||
<tr>
|
||||
<td rowspan="3">Neue Schätzung: <input form="form_add_quart" style:width="7ch" type="number" name="year" oninput={validate_year} value={next.year} tabindex="8"/> - <input form="form_add_quart" style:width="4ch" type="number" name="quarter" oninput={validate_quarter} value={new_quart} tabindex="9"/>. Quartal</td>
|
||||
<td rowspan="3">Neue Schätzung: <input form="form_add_quart" style:width="7ch" type="number" name="year" oninput={validate_year as any} value={next.year} tabindex="8"/> - <input form="form_add_quart" style:width="4ch" type="number" name="quarter" oninput={validate_quarter as any} value={new_quart} tabindex="9"/>. Quartal</td>
|
||||
|
||||
<td>{MONTHS[(new_quart - 1) * 3 + 0]}</td>
|
||||
<td><input form="form_add_quart" type="text" name="estimate_0" oninput={(e) => validate_estimate(e, estimate_store.estimate_0)} tabindex="10" /></td>
|
||||
<td><input form="form_add_quart" type="text" name="estimate_0" oninput={(e: any) => validate_estimate(e, estimate_store.estimate_0)} tabindex="10" /></td>
|
||||
|
||||
<td rowspan="3"><button form="form_add_quart" type="submit" tabindex="13">Erstellen</button></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{MONTHS[(new_quart - 1) * 3 + 1]}</td>
|
||||
<td><input form="form_add_quart" type="text" name="estimate_1" oninput={(e) => validate_estimate(e, estimate_store.estimate_1)} tabindex="11" /></td>
|
||||
<td><input form="form_add_quart" type="text" name="estimate_1" oninput={(e: any) => validate_estimate(e, estimate_store.estimate_1)} tabindex="11" /></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{MONTHS[(new_quart - 1) * 3 + 2]}</td>
|
||||
<td><input form="form_add_quart" type="text" name="estimate_2" oninput={(e) => validate_estimate(e, estimate_store.estimate_2)} tabindex="12" /></td>
|
||||
<td><input form="form_add_quart" type="text" name="estimate_2" oninput={(e: any) => validate_estimate(e, estimate_store.estimate_2)} tabindex="12" /></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
||||
|
|
@ -142,7 +125,7 @@
|
|||
|
||||
<td class="action" rowspan="3">
|
||||
{#if data.documents?.get(year)?.get(quarter)?.[0] != null}
|
||||
{@const document = data.documents.get(year).get(quarter)[0]}
|
||||
{@const document = data.documents!.get(year)!.get(quarter)![0]}
|
||||
<form method="GET" action={`/dokumente/${document.path}`}>
|
||||
<button type="submit">Download PDF</button>
|
||||
</form>
|
||||
|
|
@ -167,7 +150,7 @@
|
|||
{/each}
|
||||
</tbody>
|
||||
|
||||
{#if data.estimates === undefined || data.estimates.size === 0}
|
||||
{#if data.estimates.size === 0}
|
||||
<tfoot>
|
||||
<tr>
|
||||
<td class="td-no-elements" colspan="999">No records</td>
|
||||
|
|
@ -176,51 +159,6 @@
|
|||
{/if}
|
||||
</table>
|
||||
|
||||
|
||||
{"" /*<tr>
|
||||
<td rowspan="3">{add_quart}. Quartal {NEXT_QUART.getFullYear()}</td>
|
||||
|
||||
<td>{month_of(month_from_quart(add_quart, 0))}</td>
|
||||
<!-- svelte-ignore a11y_positive_tabindex -->
|
||||
<td><input form="form_add_quart" type="text" tabindex="1" name="estimate_0" value={form?.data?.estimate_0}/></td>
|
||||
|
||||
<td rowspan="3">
|
||||
<input form="form_add_quart" type="hidden" name="year" value={NEXT_QUART.getFullYear()}/>
|
||||
<input form="form_add_quart" type="hidden" name="quarter" value={add_quart}/>
|
||||
<button form="form_add_quart" type="submit">+</button>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{month_of(month_from_quart(add_quart, 1))}</td>
|
||||
<!-- svelte-ignore a11y_positive_tabindex -->
|
||||
<td><input form="form_add_quart" type="text" tabindex="2" name="estimate_1" value={form?.data?.estimate_1}/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{month_of(month_from_quart(add_quart, 2))}</td>
|
||||
<!-- svelte-ignore a11y_positive_tabindex -->
|
||||
<td><input form="form_add_quart" type="text" tabindex="3" name="estimate_2" value={form?.data?.estimate_2}/></td>
|
||||
</tr>*/}
|
||||
|
||||
{"" /*
|
||||
{#if months.length > 0}
|
||||
<tr>
|
||||
<td rowspan={rowspan}>
|
||||
{quarter.quarter}. Quartal {quarter.year}
|
||||
</td>
|
||||
|
||||
<td>{month_of(month_from_quart(quarter.quarter, months[0].i))}</td>
|
||||
<td>{months[0].estimate.toFixed(2)}</td>
|
||||
|
||||
<td rowspan={rowspan}>Edit</td>
|
||||
</tr>
|
||||
{#each months.slice(1) as month}
|
||||
<tr>
|
||||
<td>{month_of(month_from_quart(quarter.quarter, month.i))}</td>
|
||||
<td>{month.estimate.toFixed(2)}</td>
|
||||
</tr>
|
||||
{/each}
|
||||
{/if}*/}
|
||||
|
||||
<style>
|
||||
|
||||
form {
|
||||
|
|
|
|||
Loading…
Reference in New Issue