diff --git a/src/routes/(app)/components/[id]/+page.server.ts b/src/routes/(app)/components/[id]/+page.server.ts index 9d405d7..3162150 100644 --- a/src/routes/(app)/components/[id]/+page.server.ts +++ b/src/routes/(app)/components/[id]/+page.server.ts @@ -22,6 +22,7 @@ export const load: PageServerLoad = async ({ params }) => { deviceTitle: devices.title, locationId: components.locationId, locationName: locations.name, + locationParentId: locations.parentId, createdAt: components.createdAt, updatedAt: components.updatedAt }) @@ -32,6 +33,15 @@ export const load: PageServerLoad = async ({ params }) => { if (!component) error(404, 'Component not found'); + let parentLocationName: string | null = null; + if (component.locationParentId) { + const [parent] = await db + .select({ name: locations.name }) + .from(locations) + .where(eq(locations.id, component.locationParentId)); + parentLocationName = parent?.name ?? null; + } + const images = await db .select() .from(componentImages) @@ -57,7 +67,7 @@ export const load: PageServerLoad = async ({ params }) => { .where(eq(installationLog.componentId, params.id)) .orderBy(desc(installationLog.performedAt)); - return { component, images, documents, history }; + return { component, parentLocationName, images, documents, history }; }; export const actions: Actions = { diff --git a/src/routes/(app)/components/[id]/+page.svelte b/src/routes/(app)/components/[id]/+page.svelte index 5521732..17b62f6 100644 --- a/src/routes/(app)/components/[id]/+page.svelte +++ b/src/routes/(app)/components/[id]/+page.svelte @@ -68,7 +68,7 @@ {c.deviceTitle}
{:else if c.locationName} -In storage at {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/+page.server.ts b/src/routes/(app)/devices/+page.server.ts index 61625f4..bd0b15f 100644 --- a/src/routes/(app)/devices/+page.server.ts +++ b/src/routes/(app)/devices/+page.server.ts @@ -47,7 +47,8 @@ export const load: PageServerLoad = async ({ url }) => { model: devices.model, condition: devices.condition, year: devices.year, - locationName: locations.name + locationName: locations.name, + locationParentId: locations.parentId }) .from(devices) .leftJoin(locations, eq(devices.locationId, locations.id)) @@ -56,6 +57,17 @@ export const load: PageServerLoad = async ({ url }) => { .limit(pageSize) .offset((page - 1) * pageSize); + // Resolve parent location names + const parentIds = [...new Set(deviceList.filter(d => d.locationParentId).map(d => d.locationParentId!))]; + let parentNameMap: Record{device.locationName}
+ {#if device.fullLocation} +{device.fullLocation}
{/if} diff --git a/src/routes/(app)/devices/[id]/+page.server.ts b/src/routes/(app)/devices/[id]/+page.server.ts index e627de1..6940a1c 100644 --- a/src/routes/(app)/devices/[id]/+page.server.ts +++ b/src/routes/(app)/devices/[id]/+page.server.ts @@ -38,6 +38,7 @@ export const load: PageServerLoad = async ({ params }) => { generalNotes: devices.generalNotes, locationId: devices.locationId, locationName: locations.name, + locationParentId: locations.parentId, disabled: devices.disabled, createdAt: devices.createdAt, updatedAt: devices.updatedAt @@ -49,6 +50,16 @@ export const load: PageServerLoad = async ({ params }) => { if (!device) error(404, 'Device not found'); if (device.disabled) error(404, 'Device not found'); + // Resolve parent location name + let parentLocationName: string | null = null; + if (device.locationParentId) { + const [parent] = await db + .select({ name: locations.name }) + .from(locations) + .where(eq(locations.id, device.locationParentId)); + parentLocationName = parent?.name ?? null; + } + // Computer details let compDetails = null; if (device.category === 'Computer') { @@ -138,6 +149,7 @@ export const load: PageServerLoad = async ({ params }) => { return { device, + parentLocationName, computerDetails: compDetails, images, documents, diff --git a/src/routes/(app)/devices/[id]/+page.svelte b/src/routes/(app)/devices/[id]/+page.svelte index 80102b3..bce58da 100644 --- a/src/routes/(app)/devices/[id]/+page.svelte +++ b/src/routes/(app)/devices/[id]/+page.svelte @@ -544,7 +544,9 @@ {#if data.device.locationName}