Sync completed + Navigation links improved

This commit is contained in:
2024-08-21 14:05:27 +02:00
parent a9a98b9618
commit 62ba72515b
17 changed files with 125 additions and 889 deletions

View File

@@ -11,8 +11,6 @@ export default defineCachedEventHandler(async (e) => {
return;
}
console.log(query);
const where = ["project = $project"];
const criteria: Record<string, any> = { $project: project };

View File

@@ -1,7 +1,9 @@
import useDatabase from '~/composables/useDatabase';
import { Navigation } from '~/types/api';
export default defineEventHandler(async (e) => {
const project = getRouterParam(e, "projectId");
const { user } = await getUserSession(e);
if(!project)
{
@@ -11,14 +13,33 @@ export default defineEventHandler(async (e) => {
const db = useDatabase();
const content = db.query(`SELECT "path", "title", "type", "order" FROM explorer_files WHERE project = ?1 and navigable = 1 and private = 0`).all(project!).sort((a: any, b: any) => a.path.length - b.path.length) as any[];
const content = db.query(`SELECT "path", "title", "type", "order", "private", "navigable", "owner" FROM explorer_files WHERE project = ?1`).all(project!).sort((a: any, b: any) => a.path.length - b.path.length) as Navigation[];
if(content.length > 0)
{
const navigation: Navigation[] = [];
for(const item of content)
for(const idx in content)
{
const item = content[idx];
if(!!item.private && (user?.id ?? -1) !== item.owner || !item.navigable)
{
delete content[idx];
continue;
}
const parent = item.path.includes('/') ? item.path.substring(0, item.path.lastIndexOf('/')) : undefined;
if(parent && !content.find(e => e && e.path === parent))
{
delete content[idx];
continue;
}
}
for(const item of content.filter(e => !!e))
{
addChild(navigation, item);
}
return navigation;
}
@@ -39,6 +60,11 @@ function addChild(arr: Navigation[], e: Navigation): void
}
else
{
arr.push({ title: e.title, path: e.path, type: e.type, order: e.order });
arr.push({ title: e.title, path: e.path, type: e.type, order: e.order, private: e.private });
arr.sort((a, b) => {
if(a.order && b.order)
return a.order - b.order;
return a.title.localeCompare(b.title);
});
}
}

File diff suppressed because one or more lines are too long