fixed some bugs and maybe prod ready

This commit is contained in:
Patrick 2025-04-12 22:49:53 +02:00
parent 88041b8133
commit d63f096aaa
11 changed files with 62 additions and 21 deletions

BIN
bun.lockb

Binary file not shown.

View File

@ -4,14 +4,14 @@
"devDependencies": {
"@sveltejs/adapter-auto": "^3.3.1",
"@sveltejs/adapter-node": "^5.2.12",
"@sveltejs/kit": "^2.16.1",
"@sveltejs/kit": "^2.20.4",
"@sveltejs/vite-plugin-svelte": "^5.0.3",
"@types/sqlite3": "^3.1.11",
"svelte": "^5.19.6",
"svelte": "^5.25.6",
"svelte-adapter-bun": "^0.5.2",
"svelte-check": "^4.1.4",
"typescript": "^5.7.3",
"vite": "^6.0.11"
"svelte-check": "^4.1.5",
"typescript": "^5.8.2",
"vite": "^6.2.5"
},
"private": true,
"scripts": {
@ -21,5 +21,11 @@
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch"
},
"type": "module"
"type": "module",
"dependencies": {
"clsx": "^2.1.1",
"cookie": "^1.0.2",
"devalue": "^5.1.1",
"set-cookie-parser": "^2.7.1"
}
}

View File

@ -84,6 +84,8 @@ export async function generateEstimatePDF(user: User, year: number, quarter: num
const estimates = user.get_estimate(year, quarter);
console.log(estimates);
let exitCode = 0;
({ exitCode: exitCode } = await b.$`mkdir -p ${dir}`.nothrow().quiet());

View File

@ -203,7 +203,7 @@ async function _genLatexRec(user: User, file_pref: string, year: number, month:
}
const records = user.get_entries_by_month(year, month);
const estimate = user.get_estimate_by_month(year, month);
const estimate = user.get_estimate_by_month(year, month-1);
const hr_sum = (() => { let s = 0; records.forEach((r) => { s += calculateDuration(r.start, r.end) }); return s; })()
if (estimate == null || isNaN(estimate)) {
@ -213,6 +213,10 @@ async function _genLatexRec(user: User, file_pref: string, year: number, month:
// TODO: escape semicolon in comment
const csvfile = Bun.file(`${dir}/${file_pref}.csv`)
if (await csvfile.exists()) {
await csvfile.delete();
}
const csvfilewriter = csvfile.writer()
csvfilewriter.write(`${user.name};${MONTHS[month - 1]} ${year};${hr_sum.toFixed(2)};${estimate.toFixed(2)};${padInt(hr_sum - estimate, 2, 2, ' ')}\n`)
@ -252,7 +256,12 @@ async function _genLatexEst(user: User, file_pref: string, year: number, quarter
}
const csvfile = Bun.file(`${dir}/estimate.csv`)
const csvfilewriter = csvfile.writer()
if (await csvfile.exists()) {
await csvfile.delete();
}
const csvfilewriter = csvfile.writer();
csvfilewriter.write(`${SALUTATION[user.gender]} ${user.name};${user.address};Arbeitnehmer${GENDER_END[user.gender]};Teilzeitmitarbeiter${GENDER_END[user.gender]};${isoToLocalDate(new Date().toISOString())}\n`)

View File

@ -49,8 +49,6 @@ export const load: PageServerLoad = async ({ locals }) => {
map.set(key, m);
})
console.log(documents_grouped)
return {
records: records_grouped,
estimates: estimates_grouped,

View File

@ -143,7 +143,7 @@
<tr style:border="none">
<td style:border="none"></td>
<td style:border="none"></td>
<RecordInputRow targetForm="form_new_entry" bind:states={new_state} enabled={editing == null}>
<RecordInputRow targetForm="form_new_entry" bind:states={new_state} enabled={editing == null} autofocus={true}>
<button
type="submit"
form="form_new_entry"
@ -156,7 +156,7 @@
{#each data.estimates as estimates_pair}
{@const year = estimates_pair[0] }
{@const mmonths = estimates_pair[1] }
{@const yentries = data.records.get(year)}
{@const yentries = data.records.get(year) ?? new Map()}
{#each mmonths as month_pair, mindex}
{@const month = month_pair[0] }
@ -221,7 +221,7 @@
</RecordInputRow>
{/if}
{#if eindex == 0}
{@const document = data?.documents?.get(year)?.get(month)}
{@const document = data?.documents?.get(year)?.get(month + 1)}
<td rowspan={entries.length < 4 ? 4 : entries.length} class="stats">
<table>
@ -251,7 +251,7 @@
<button type="submit">Stundenliste erstellen</button>
</form>
{:else}
<form id="form_download" method="GET" action={`/dokumente/${document.path}`}>
<form id="form_download" method="GET" action={`/dokumente/${document.path}`} target="_blank">
<input type="hidden" name="month" value={month + 1} />
<input type="hidden" name="year" value={year} />
<button type="submit">Download</button>

View File

@ -14,10 +14,11 @@
interface Props {
targetForm: string,
enabled: boolean,
autofocus: boolean,
states: RowState,
children: Snippet
}
let { targetForm, enabled, states = $bindable(), children }: Props = $props();
let { targetForm, enabled, autofocus = false, states = $bindable(), children }: Props = $props();
const TODAY: Date = new Date();
const CENTURY_PREF: number = Math.floor(TODAY.getFullYear() / 100);
@ -520,7 +521,16 @@
states.date.value = dateInput.value;
}
}
onkeydown={
(event) => {
if (event.key == "Enter") {
states.date.valid = validateDate(dateInput);
states.date.value = dateInput.value;
}
}
}
disabled={!enabled}
{autofocus}
required>
</td>
@ -548,6 +558,14 @@
states.start.value = startInput.value;
}
}
onkeydown={
(event) => {
if (event.key == "Enter") {
states.start.valid = validateTime(startInput);
states.start.value = startInput.value;
}
}
}
disabled={!enabled}
required>
</td>
@ -572,6 +590,14 @@
states.end.value = endInput.value;
}
}
onkeydown={
(event) => {
if (event.key == "Enter") {
states.end.valid = validateTime(endInput);
states.end.value = endInput.value;
}
}
}
disabled={!enabled}
required>
</td>

View File

@ -50,6 +50,8 @@ export const actions = {
const estimate_1 = data.get("estimate_1");
const estimate_2 = data.get("estimate_2");
console.log(data);
if (year == null || quart == null || estimate_0 == null || estimate_1 == null || estimate_2 == null) {
return fail(400, { year: year, quarter: quart, estimate_0: estimate_0, estimate_1: estimate_1, estimate_2: estimate_2 });
}
@ -68,8 +70,6 @@ export const actions = {
return fail(409, { reason: "Estimate already exists" } );
}
return { success: true };
const res = locals.user.insert_estimate(y, q, est_0, est_1, est_2)
if (!res) {

View File

@ -157,11 +157,11 @@
</tr>
<tr>
<td>{months[1].month}</td>
<td class="estimate">{months[1].estimate != null ? padInt(months[0].estimate, 3, 2, "\u2007", false, false) : fill_str}</td>
<td class="estimate">{months[1].estimate != null ? padInt(months[1].estimate, 3, 2, "\u2007", false, false) : fill_str}</td>
</tr>
<tr>
<td>{months[2].month}</td>
<td class="estimate">{months[2].estimate != null ? padInt(months[0].estimate, 3, 2, "\u2007", false, false) : fill_str}</td>
<td class="estimate">{months[2].estimate != null ? padInt(months[2].estimate, 3, 2, "\u2007", false, false) : fill_str}</td>
</tr>
{/each}
{/each}

View File

@ -1,4 +1,4 @@
import adapter from '@sveltejs/adapter-node';
import adapter from 'svelte-adapter-bun';
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
/** @type {import('@sveltejs/kit').Config} */