-
/{{ selected.parent ? selected.parent + '/' : '' }}
+
/{{ selected.path === '' ? getPath(selected) : selected.path }}
@@ -79,6 +80,7 @@ import type { Instruction } from '@atlaskit/pragmatic-drag-and-drop-hitbox/dist/
import { parsePath } from '#shared/general.utils';
import type { ProjectItem } from '~/schemas/project';
import type { FileType } from '~/schemas/file';
+import { iconByType } from '#shared/general.utils';
definePageMeta({
rights: ['admin', 'editor'],
@@ -192,7 +194,7 @@ const tree = {
for (const item of data)
{
- if (item[prop]?.toString()?.includes(value))
+ if (item[prop]?.toString().toLowerCase()?.startsWith(value.toLowerCase()))
arr.push(item);
if (tree.hasChildren(item)) {
@@ -236,10 +238,8 @@ function add(type: FileType): void
return;
}
- const news = [...tree.search(navigation.value, 'name', 'nouveau'), ...tree.search(navigation.value, 'title', 'Nouveau')].filter((e, i, a) => a.indexOf(e) === i);
- console.log(news);
-
- const item: ProjectItem = { navigable: true, private: false, parent: '', path: '', title: `Nouveau${news.length > 0 ? ' (' + news.length +')' : ''}`, type: type, order: 0, name: `nouveau${news.length > 0 ? '-' + news.length : ''}`, children: type === 'folder' ? [] : undefined };
+ const news = [...tree.search(navigation.value, 'title', 'Nouveau')].filter((e, i, a) => a.indexOf(e) === i);
+ const item: ProjectItem = { navigable: true, private: false, parent: '', path: '', title: `Nouveau${news.length > 0 ? ' (' + news.length +')' : ''}`, type: type, order: 0, children: type === 'folder' ? [] : undefined };
if(!selected.value)
{
@@ -254,8 +254,6 @@ function add(type: FileType): void
{
navigation.value = tree.insertAfter(navigation.value, getPath(selected.value), item);
}
-
- selected.value = item;
}
function updateTree(instruction: Instruction, itemId: string, targetId: string) : ProjectItem[] | undefined {
if(!navigation.value)
@@ -318,7 +316,6 @@ function drop(instruction: Instruction, itemId: string, targetId: string)
}
function rebuildPath(tree: ProjectItem[] | null | undefined, parentPath: string)
{
- debugger;
if(!tree)
return;
@@ -352,6 +349,6 @@ async function save(redirect: boolean): Promise
}
function getPath(item: ProjectItem): string
{
- return [item.parent, parsePath(item?.name ?? item.title)].filter(e => !!e).join('/');
+ return [item.parent, parsePath(item.title)].filter(e => !!e).join('/');
}
\ No newline at end of file
diff --git a/schemas/project.ts b/schemas/project.ts
index 26360ad..3c43805 100644
--- a/schemas/project.ts
+++ b/schemas/project.ts
@@ -4,7 +4,6 @@ import { fileType } from "./file";
const baseItem = z.object({
path: z.string(),
parent: z.string(),
- name: z.string().optional(),
title: z.string(),
type: fileType,
navigable: z.boolean(),
diff --git a/server/api/project.post.ts b/server/api/project.post.ts
index 5a2d136..c54a735 100644
--- a/server/api/project.post.ts
+++ b/server/api/project.post.ts
@@ -3,6 +3,7 @@ import useDatabase from '~/composables/useDatabase';
import { explorerContentTable } from '~/db/schema';
import { project, type ProjectItem } from '~/schemas/project';
import { parsePath } from "#shared/general.utils";
+import { eq, getTableColumns } from "drizzle-orm";
export default defineEventHandler(async (e) => {
const { user } = await getUserSession(e);
@@ -22,6 +23,15 @@ export default defineEventHandler(async (e) => {
const items = buildOrder(body.data.items);
const db = useDatabase();
+ const { content, ...cols } = getTableColumns(explorerContentTable);
+ const full = db.select(cols).from(explorerContentTable).all();
+
+ for(let i = full.length - 1; i >= 0; i--)
+ {
+ if(items.find(e => (e.path === '' ? [e.parent, parsePath(e.title)].filter(e => !!e).join('/') : e.path) === full[i].path))
+ full.splice(i, 1);
+ }
+
db.transaction((tx) => {
for(let i = 0; i < items.length; i++)
{
@@ -35,10 +45,10 @@ export default defineEventHandler(async (e) => {
navigable: item.navigable,
private: item.private,
order: item.order,
- content: Buffer.from('', 'utf-8'),
+ content: null,
}).onConflictDoUpdate({
set: {
- path: [item.parent, parsePath(item?.name ?? item.title)].filter(e => !!e).join('/'),
+ path: [item.parent, parsePath(item.title)].filter(e => !!e).join('/'),
title: item.title,
type: item.type,
navigable: item.navigable,
@@ -48,6 +58,10 @@ export default defineEventHandler(async (e) => {
target: explorerContentTable.path,
}).run();
}
+ for(let i = 0; i < full.length; i++)
+ {
+ tx.delete(explorerContentTable).where(eq(explorerContentTable.path, full[i].path)).run();
+ }
});
});
diff --git a/shared/general.utils.ts b/shared/general.utils.ts
index 58fabe4..efb2b4f 100644
--- a/shared/general.utils.ts
+++ b/shared/general.utils.ts
@@ -1,3 +1,5 @@
+import type { FileType } from "~/schemas/file";
+
export function unifySlug(slug: string | string[]): string
{
return (Array.isArray(slug) ? slug.join('/') : slug);
@@ -43,4 +45,11 @@ export function clamp(x: number, min: number, max: number): number {
if (x < min)
return min;
return x;
+}
+
+export const iconByType: Record = {
+ 'folder': 'lucide:folder',
+ 'canvas': 'ph:graph-light',
+ 'file': 'radix-icons:file',
+ 'markdown': 'radix-icons:file',
}
\ No newline at end of file