From d23b0ee0941f67df04d13adf3e15bb89457dc24c Mon Sep 17 00:00:00 2001 From: Nassim Tabchiche Date: Mon, 12 Feb 2024 21:38:25 +0100 Subject: [PATCH] Prevent deletion of referenced libraries --- frontend/src/routes/(app)/libraries/+page.server.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/frontend/src/routes/(app)/libraries/+page.server.ts b/frontend/src/routes/(app)/libraries/+page.server.ts index 5ee001177..54bfa5aaf 100644 --- a/frontend/src/routes/(app)/libraries/+page.server.ts +++ b/frontend/src/routes/(app)/libraries/+page.server.ts @@ -9,13 +9,13 @@ import { urlParamModelVerboseName } from '$lib/utils/crud'; import { z } from 'zod'; import { tableSourceMapper } from '@skeletonlabs/skeleton'; import { listViewFields } from '$lib/utils/table'; -import type { urlModel } from '$lib/utils/types'; +import type { Library, urlModel } from '$lib/utils/types'; export const load = (async ({ fetch }) => { const endpoint = `${BASE_API_URL}/libraries/`; const res = await fetch(endpoint); - const libraries = await res.json().then((res) => res.results); + const libraries: Library[] = await res.json().then((res) => res.results); function countObjects(library: Library) { let result: { [key: string]: any } = new Object(); @@ -41,6 +41,7 @@ export const load = (async ({ fetch }) => { `Packager: ${row.packager}`, ...Object.entries(countObjects(row)).map(([key, value]) => `${key}: ${value}`) ]; + row.preventDelete = (row.reference_count && row.reference_count > 0) ?? false; }); const headData: Record = listViewFields['libraries' as urlModel].body.reduce(