From 0113803378115902cd4e2f96236baa8b1a74fae5 Mon Sep 17 00:00:00 2001
From: grabowski
In storage at {#if data.parentLocationName}{data.parentLocationName} › {/if}{c.locationName}
+In storage at {#if data.parentLocationName}{data.parentLocationName} › {/if}{c.locationName}
{:else}In storage (no location set)
{/if} diff --git a/src/routes/(app)/devices/[id]/+page.svelte b/src/routes/(app)/devices/[id]/+page.svelte index bce58da..466987b 100644 --- a/src/routes/(app)/devices/[id]/+page.svelte +++ b/src/routes/(app)/devices/[id]/+page.svelte @@ -545,7 +545,9 @@{loc.description}
diff --git a/src/routes/(app)/locations/[id]/+page.server.ts b/src/routes/(app)/locations/[id]/+page.server.ts new file mode 100644 index 0000000..6fdf81e --- /dev/null +++ b/src/routes/(app)/locations/[id]/+page.server.ts @@ -0,0 +1,59 @@ +import type { PageServerLoad } from './$types'; +import { db } from '$lib/server/db/index.js'; +import { locations, devices, components } from '$lib/server/db/schema.js'; +import { eq, and, isNull } from 'drizzle-orm'; +import { error } from '@sveltejs/kit'; + +export const load: PageServerLoad = async ({ params }) => { + const [location] = await db + .select() + .from(locations) + .where(eq(locations.id, params.id)); + + if (!location) error(404, 'Location not found'); + + // Parent name + let parentName: string | null = null; + if (location.parentId) { + const [parent] = await db + .select({ name: locations.name }) + .from(locations) + .where(eq(locations.id, location.parentId)); + parentName = parent?.name ?? null; + } + + // Child locations + const children = await db + .select({ id: locations.id, name: locations.name }) + .from(locations) + .where(eq(locations.parentId, params.id)) + .orderBy(locations.name); + + // Devices at this location + const deviceList = await db + .select({ + id: devices.id, + title: devices.title, + category: devices.category, + brand: devices.brand, + model: devices.model, + condition: devices.condition + }) + .from(devices) + .where(and(eq(devices.locationId, params.id), eq(devices.disabled, false))) + .orderBy(devices.title); + + // Components stored at this location (not installed in a device) + const componentList = await db + .select({ + id: components.id, + title: components.title, + componentType: components.componentType, + condition: components.condition + }) + .from(components) + .where(and(eq(components.locationId, params.id), isNull(components.currentDeviceId))) + .orderBy(components.title); + + return { location, parentName, children, devices: deviceList, components: componentList }; +}; diff --git a/src/routes/(app)/locations/[id]/+page.svelte b/src/routes/(app)/locations/[id]/+page.svelte new file mode 100644 index 0000000..da0151f --- /dev/null +++ b/src/routes/(app)/locations/[id]/+page.svelte @@ -0,0 +1,131 @@ + + +{data.location.description}
+ {/if} +No devices at this location.
+ {:else} +| Device | +Category | +Condition | +
|---|---|---|
| + + {device.title} + + {#if device.brand || device.model} + {[device.brand, device.model].filter(Boolean).join(' ')} + {/if} + | +{device.category} | ++ + {device.condition} + + | +
No components stored at this location.
+ {:else} +| Component | +Type | +Condition | +
|---|---|---|
| + + {comp.title} + + | +{comp.componentType} | ++ + {comp.condition} + + | +