diff --git a/src/lib/server/db/schema.ts b/src/lib/server/db/schema.ts index 34042b4..47dc321 100644 --- a/src/lib/server/db/schema.ts +++ b/src/lib/server/db/schema.ts @@ -213,6 +213,8 @@ export const templateItems = pgTable( .notNull() .references(() => checklistTemplates.id, { onDelete: 'cascade' }), text: text('text').notNull(), + itemType: text('item_type').notNull().default('checkbox'), // 'checkbox' or 'input' + unit: text('unit'), // e.g. 'RPM', 'dB', '%' sortOrder: integer('sort_order').default(0).notNull() }, (table) => [index('template_items_template_idx').on(table.templateId)] @@ -241,7 +243,10 @@ export const checklistItems = pgTable( .notNull() .references(() => deviceChecklists.id, { onDelete: 'cascade' }), text: text('text').notNull(), + itemType: text('item_type').notNull().default('checkbox'), // 'checkbox' or 'input' + unit: text('unit'), // e.g. 'RPM', 'dB', '%' checked: boolean('checked').default(false).notNull(), + value: text('value'), // for input type items sortOrder: integer('sort_order').default(0).notNull(), createdAt: timestamp('created_at', { withTimezone: true }).defaultNow().notNull() }, diff --git a/src/routes/(app)/checklists/+page.server.ts b/src/routes/(app)/checklists/+page.server.ts index 1f2fed5..0842847 100644 --- a/src/routes/(app)/checklists/+page.server.ts +++ b/src/routes/(app)/checklists/+page.server.ts @@ -11,7 +11,7 @@ export const load: PageServerLoad = async () => { .orderBy(checklistTemplates.title); const templateIds = templates.map((t) => t.id); - let itemsByTemplate: Record> = {}; + let itemsByTemplate: Record> = {}; if (templateIds.length > 0) { const allItems = await db @@ -19,6 +19,8 @@ export const load: PageServerLoad = async () => { id: templateItems.id, templateId: templateItems.templateId, text: templateItems.text, + itemType: templateItems.itemType, + unit: templateItems.unit, sortOrder: templateItems.sortOrder }) .from(templateItems) @@ -65,6 +67,8 @@ export const actions: Actions = { const formData = await request.formData(); const templateId = formData.get('templateId') as string; const text = (formData.get('text') as string)?.trim(); + const itemType = (formData.get('itemType') as string) || 'checkbox'; + const unit = (formData.get('unit') as string)?.trim(); if (!text) return fail(400, { error: 'Item text is required' }); const existing = await db @@ -77,6 +81,8 @@ export const actions: Actions = { await db.insert(templateItems).values({ templateId, text, + itemType, + unit: unit || null, sortOrder: (existing[0]?.sortOrder ?? -1) + 1 }); diff --git a/src/routes/(app)/checklists/+page.svelte b/src/routes/(app)/checklists/+page.svelte index 7829124..4c3c6de 100644 --- a/src/routes/(app)/checklists/+page.svelte +++ b/src/routes/(app)/checklists/+page.svelte @@ -5,7 +5,9 @@ let showNewTemplate = $state(false); function resetForm(form: HTMLFormElement) { const input = form.querySelector('input[name="text"]') as HTMLInputElement; + const unit = form.querySelector('input[name="unit"]') as HTMLInputElement; if (input) input.value = ''; + if (unit) unit.value = ''; } @@ -85,6 +87,11 @@
{item.sortOrder + 1}. {item.text} + {#if item.itemType === 'input'} + + input{#if item.unit}: {item.unit}{/if} + + {/if}
+
+ + + + +
{/each} diff --git a/src/routes/(app)/devices/[id]/+page.server.ts b/src/routes/(app)/devices/[id]/+page.server.ts index 0d2bf2c..a9b1616 100644 --- a/src/routes/(app)/devices/[id]/+page.server.ts +++ b/src/routes/(app)/devices/[id]/+page.server.ts @@ -115,7 +115,7 @@ export const load: PageServerLoad = async ({ params }) => { const checklistIds = checklists.map((c) => c.id); let itemsByChecklist: Record = {}; - let allItems: Array<{ id: string; checklistId: string; text: string; checked: boolean; sortOrder: number; createdAt: Date }> = []; + let allItems: Array<{ id: string; checklistId: string; text: string; itemType: string; unit: string | null; checked: boolean; value: string | null; sortOrder: number; createdAt: Date }> = []; if (checklistIds.length > 0) { allItems = await db @@ -284,6 +284,8 @@ export const actions: Actions = { const formData = await request.formData(); const checklistId = formData.get('checklistId') as string; const text = (formData.get('text') as string)?.trim(); + const itemType = (formData.get('itemType') as string) || 'checkbox'; + const unit = (formData.get('unit') as string)?.trim(); if (!text) return fail(400, { error: 'Item text is required' }); // Get next sort order @@ -299,6 +301,8 @@ export const actions: Actions = { await db.insert(checklistItems).values({ checklistId, text, + itemType, + unit: unit || null, sortOrder: nextOrder }); @@ -318,6 +322,19 @@ export const actions: Actions = { return { itemToggled: true }; }, + saveChecklistValue: async ({ request }) => { + const formData = await request.formData(); + const itemId = formData.get('itemId') as string; + const value = formData.get('value') as string; + + await db + .update(checklistItems) + .set({ value: value || null }) + .where(eq(checklistItems.id, itemId)); + + return { valueSaved: true }; + }, + deleteChecklistItem: async ({ request }) => { const formData = await request.formData(); const itemId = formData.get('itemId') as string; @@ -359,6 +376,8 @@ export const actions: Actions = { items.map((item) => ({ checklistId: checklist.id, text: item.text, + itemType: item.itemType, + unit: item.unit, sortOrder: item.sortOrder })) ); diff --git a/src/routes/(app)/devices/[id]/+page.svelte b/src/routes/(app)/devices/[id]/+page.svelte index f2e25be..2b0c64f 100644 --- a/src/routes/(app)/devices/[id]/+page.svelte +++ b/src/routes/(app)/devices/[id]/+page.svelte @@ -13,7 +13,9 @@ let showImportChecklist = $state(false); function resetInput(formEl: HTMLFormElement) { const input = formEl.querySelector('input[name="text"]') as HTMLInputElement; + const unit = formEl.querySelector('input[name="unit"]') as HTMLInputElement; if (input) input.value = ''; + if (unit) unit.value = ''; } @@ -405,36 +407,62 @@ {/if} -
+
{#each checklist.items as item} -
-
- - - -
- - {item.text} - -
- - -
-
+ + +
+ + +
+
+ {:else} + +
+
+ + + +
+ + {item.text} + +
+ + +
+
+ {/if} {/each}
@@ -454,6 +482,13 @@ + +