reservations applyable, fixed folder views, checkmarks

This commit is contained in:
Karlsson
2025-11-22 13:00:24 +01:00
parent a3a001d8e1
commit 74537558a8
15 changed files with 434 additions and 137 deletions

View File

@ -4,17 +4,22 @@ import { eq, and, isNull, inArray, sql } from 'drizzle-orm';
import { error } from '@sveltejs/kit';
import { processProperties } from '$lib/utils/propertyUtils';
import { getOrSeedHomeFolder } from '$lib/server/db/utils';
export const load = async ({ params, url }: { params: { path: string }, url: URL }) => {
const pathSegments = params.path.split('/').filter(Boolean);
let currentFolder = null;
const breadcrumbs: any[] = [];
let parentId = null;
// Start with Home folder as the root parent
const homeFolder = await getOrSeedHomeFolder();
let parentId: string | null = homeFolder.id;
for (const segment of pathSegments) {
const folder = await db.select().from(folders)
.where(and(
eq(folders.name, decodeURIComponent(segment)),
parentId ? eq(folders.parentId, parentId) : isNull(folders.parentId)
eq(folders.parentId, parentId)
))
.limit(1);
@ -31,9 +36,13 @@ export const load = async ({ params, url }: { params: { path: string }, url: URL
});
}
if (!currentFolder) {
throw error(404, 'Folder not found');
}
// Fetch subfolders
const subfolders = await db.select().from(folders)
.where(currentFolder ? eq(folders.parentId, currentFolder.id) : isNull(folders.parentId));
.where(eq(folders.parentId, currentFolder.id));
// Fetch items
const folderItems = await db.select({
@ -49,7 +58,7 @@ export const load = async ({ params, url }: { params: { path: string }, url: URL
})
.from(items)
.leftJoin(categories, eq(items.categoryId, categories.id))
.where(currentFolder ? eq(items.folderId, currentFolder.id) : isNull(items.folderId));
.where(eq(items.folderId, currentFolder.id));
const allCategories = await db.select().from(categories);
const allFolders = await db.select().from(folders);
@ -79,7 +88,7 @@ export const actions = {
},
createItem: async ({ request }: { request: Request }) => {
const data = await request.formData();
const name = data.get('name') as string;
const name = (data.get('name') as string) || null;
const folderId = data.get('folderId') as string;
const categoryId = data.get('categoryId') as string;
const count = parseInt(data.get('count') as string) || 0;
@ -88,7 +97,7 @@ export const actions = {
await db.insert(items).values({
name,
folderId: folderId || null,
folderId: folderId,
categoryId,
count,
properties
@ -99,7 +108,7 @@ export const actions = {
updateItem: async ({ request }: { request: Request }) => {
const data = await request.formData();
const id = data.get('id') as string;
const name = data.get('name') as string;
const name = (data.get('name') as string) || null;
const categoryId = data.get('categoryId') as string;
const count = parseInt(data.get('count') as string) || 0;
const folderId = data.get('folderId') as string;
@ -115,7 +124,7 @@ export const actions = {
};
if (folderId !== undefined) {
updateData.folderId = folderId || null;
updateData.folderId = folderId;
}
await db.update(items)
@ -134,7 +143,7 @@ export const actions = {
const data = await request.formData();
const id = data.get('id') as string;
const folderId = data.get('folderId') as string;
await db.update(items).set({ folderId: folderId || null }).where(eq(items.id, id));
await db.update(items).set({ folderId: folderId }).where(eq(items.id, id));
return { success: true };
},
bulkDelete: async ({ request }: { request: Request }) => {
@ -150,7 +159,7 @@ export const actions = {
const ids = JSON.parse(data.get('ids') as string);
const folderId = data.get('folderId') as string;
if (ids.length > 0) {
await db.update(items).set({ folderId: folderId || null }).where(inArray(items.id, ids));
await db.update(items).set({ folderId: folderId }).where(inArray(items.id, ids));
}
return { success: true };
},