Skip to content

Commit

Permalink
New file system improvments
Browse files Browse the repository at this point in the history
  • Loading branch information
Smaug6739 committed Apr 1, 2024
1 parent d19796b commit de5b9dd
Show file tree
Hide file tree
Showing 14 changed files with 150 additions and 101 deletions.
2 changes: 1 addition & 1 deletion @alexandrie/styles/src/_variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ $transition-duration: 0.3s;
--red: #DC3545;
--red-bg: rgba(220, 53, 69, 0.15);
--red-border: rgba(220, 53, 69, 0.3);
--yellow: #fdbf4c;
--yellow: #f7b32d;
--yellow-bg: rgba(255, 193, 7, 0.15);
--yellow-border: rgba(255, 193, 7, 0.3);
--turquoise: #17A2B8;
Expand Down
6 changes: 4 additions & 2 deletions backend/classes/DocumentsManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,14 @@ export default class DocumentsManager extends Base {
if (!data.author_id) return reject(new Error('[MISSING_KEY] : author_id must be provided'));

this.app.db.query<DocumentDB[]>(
'INSERT INTO documents (`id`, `name`, `description`, `tags`, `category`, `accessibility`, `content_markdown`, `content_html`, `author_id`, `created_timestamp`, `updated_timestamp`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
'INSERT INTO documents (`id`, `name`, `description`, `tags`, `category`, `parent_id`, `accessibility`, `content_markdown`, `content_html`, `author_id`, `created_timestamp`, `updated_timestamp`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
[
id,
data.name,
data.description,
data.tags,
data.category,
data.parent_id,
data.accessibility,
data.content_markdown,
data.content_html,
Expand All @@ -86,12 +87,13 @@ export default class DocumentsManager extends Base {
if (!data.author_id) return reject(new Error('[MISSING_KEY] : author_id must be provided'));
const time = Date.now().toString();
this.app.db.query<DocumentDB[]>(
'UPDATE documents SET name = ?, description = ?, tags = ?, category = ?, accessibility = ?, content_markdown = ?, content_html = ?, updated_timestamp = ? WHERE id = ?',
'UPDATE documents SET name = ?, description = ?, tags = ?, category = ?, parent_id = ?, accessibility = ?, content_markdown = ?, content_html = ?, updated_timestamp = ? WHERE id = ?',
[
data.name,
data.description,
data.tags,
data.category,
data.parent_id,
data.accessibility,
data.content_markdown,
data.content_html,
Expand Down
2 changes: 2 additions & 0 deletions backend/controllers/documents.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export default class DocumentsController {
description: req.body.description,
tags: req.body.tags,
category: req.body.category,
parent_id: req.body.parent_id,
accessibility: req.body.accessibility,
content_markdown: req.body.content_markdown,
content_html: req.body.content_html,
Expand All @@ -69,6 +70,7 @@ export default class DocumentsController {
description: req.body.description,
tags: req.body.tags,
category: req.body.category,
parent_id: req.body.parent_id,
accessibility: req.body.accessibility,
content_markdown: req.body.content_markdown,
content_html: req.body.content_html,
Expand Down
1 change: 1 addition & 0 deletions backend/types/Structures.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export interface Document {
description?: string;
tags?: string;
category?: string;
parent_id?: string;
accessibility: number; // 0: No; 1: Yes;
content_markdown?: string;
content_html?: string;
Expand Down
2 changes: 1 addition & 1 deletion dashboard/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import { useDocumentsStore, useCategoriesStore } from './store';
// @ts-ignore
useDocumentsStore().fetch({ fields: ['id', 'name', 'description', 'accessibility', 'category', 'created_timestamp'] });
useDocumentsStore().fetch({ fields: ['id', 'name', 'description', 'accessibility', 'category', 'parent_id', 'created_timestamp'] });
useCategoriesStore().fetch();
</script>
Expand Down
10 changes: 8 additions & 2 deletions dashboard/components/MarkdownEditor/Toolbar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
<option value="1">Visible</option>
<option value="2">Draf</option>
<option value="3">Archive</option>
<option value="4">Trash</option>
</select>
<select v-model="copy.category">
<optgroup v-for="cat in categoriesStore.getParents" :label="cat.name" :key="cat.id">
Expand All @@ -19,14 +18,21 @@
</option>
</optgroup>
</select>
<select v-model="copy.parent_id">
<option selected :value="null"> No parent </option>
<option v-for="doc in documentsStore.getByCategories(copy.category || '')" :value="doc.id" :key="doc.id"
v-text="doc.name">
</option>
</select>
</div>
</div>
</template>

<script setup lang="ts">
import { useCategoriesStore, type Document, type Category } from "~/store";
import { useCategoriesStore, useDocumentsStore, type Document, type Category } from "~/store";
const categoriesStore = useCategoriesStore();
const documentsStore = useDocumentsStore();
const props = defineProps<{ document: Partial<Document> }>();
const copy = ref(props.document);
Expand Down
5 changes: 3 additions & 2 deletions dashboard/components/sidebar/Collapse.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<template>
<div class="collapse-header item" @click="toggleShow">
<svg :class="{ 'rotated': !show }" xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 -960 960 960" width="24">
<div class="collapse-header item">
<svg @click="toggleShow" :class="{ 'rotated': !show }" xmlns="http://www.w3.org/2000/svg" height="24"
viewBox="0 -960 960 960" width="24">
<path d="M480-345 240-585l56-56 184 184 184-184 56 56-240 240Z" />
</svg>
<slot name="header"></slot>
Expand Down
55 changes: 6 additions & 49 deletions dashboard/components/sidebar/CollapseItem.vue
Original file line number Diff line number Diff line change
@@ -1,66 +1,23 @@
<template>
<Collapse>
<Collapse v-if="item.childrens.length">
<template v-slot:header>
<NuxtLink class="item">
<i v-if="item.icon" v-html="item.icon" class="icon"></i>
<span>{{ item.title }}</span>
</NuxtLink>
<SidebarItem :item="item" />
</template>
<template v-slot:body>
<template v-for="(child, index) in item.childrens">
<div style="margin-left:15px;">
<div style="margin-left:25px;">
<CollapseItem v-if="child.childrens?.length" :item="child" :key="index" />
<NuxtLink v-else class="item" :to="child.route" :class="{ active: isActive(child.id) }">
<i v-html="child.icon" class="icon"></i>
<span>{{ child.title }}</span>
</NuxtLink>
<SidebarItem v-else :item="child" />
</div>
</template>
</template>
</Collapse>
<SidebarItem v-else :item="item" />
</template>
<script setup lang="ts">
import { type Item } from './helpers';
import Collapse from './Collapse.vue';
import SidebarItem from './SidebarItem.vue';
defineProps<{ item: Item }>();
const route = useRoute();
const doc_id = computed(() => route.query.doc as string);
const isActive = (id: string) => doc_id.value === id;
</script>

<style lang="scss" scoped>
.item {
display: flex;
justify-content: flex-start;
align-items: center;
height: 30px;
padding: 0 2.5px;
margin: 2.5px 0;
border-radius: 5px;
color: var(--font-color);
cursor: pointer;
width: 90%;
&:hover,
&.active {
background: var(--bg-contrast-2);
}
.icon {
display: flex;
align-items: center;
&:deep(svg) {
fill: var(--blue);
width: 22px;
height: 20px;
margin-right: 7px;
path {
fill: var(--blue);
}
}
}
}
</style>
49 changes: 40 additions & 9 deletions dashboard/components/sidebar/Sidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ const items = computed((): Item[] => [
...formatTree()
]);
type DocumentTree = Document & { childrens: DocumentTree[] };
function formatTree(): Item[] {
console.log('formatTree');
const parents = categoriesStore.getParents;
const items: Item[] = [];
parents.forEach((parent) => {
Expand All @@ -42,8 +45,8 @@ function formatTree(): Item[] {
id: child.id,
title: child.name,
icon: child.icon,
route: `/dashboard/?category=${child.id}`,
childrens: documentsToItems(documentsStore.getByCategories(child.id))
route: '',
childrens: documentsTreeToItems(convertDocumentsToTree(documentsStore.getByCategories(child.id)))
});
});
items.push({
Expand All @@ -57,20 +60,48 @@ function formatTree(): Item[] {
return items;
}
function documentsToItems(documents: Document[]): Item[] {
function convertDocumentsToTree(documents: Document[]): DocumentTree[] {
const documentMap: { [id: string]: DocumentTree } = {};
// Create a map of documents indexed by their id
documents.forEach(doc => {
documentMap[doc.id] = { ...doc, childrens: [] };
});
// Build the tree structure
const documentTree: DocumentTree[] = [];
documents.forEach(doc => {
if (doc.parent_id && documentMap[doc.parent_id]) {
documentMap[doc.parent_id].childrens.push(documentMap[doc.id]);
} else {
documentTree.push(documentMap[doc.id]);
}
});
return documentTree;
}
function documentsTreeToItems(documentsTree: DocumentTree[]): Item[] {
const items: Item[] = [];
documents.forEach((document) => {
documentsTree.forEach((doc) => {
const childrens: Item[] = documentsTreeToItems(doc.childrens);
items.push({
id: document.id,
title: document.name,
icon: '<svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 -960 960 960" width="24"><path style="fill:var(--yellow);" d="M320-240h320v-80H320v80Zm0-160h320v-80H320v80ZM240-80q-33 0-56.5-23.5T160-160v-640q0-33 23.5-56.5T240-880h320l240 240v480q0 33-23.5 56.5T720-80H240Zm280-520v-200H240v640h480v-440H520ZM240-800v200-200 640-640Z"/></svg>',
route: `/dashboard?doc=${document.id}`,
childrens: []
id: doc.id,
title: doc.name,
icon: defaultIcon(childrens.length > 0),
route: `/dashboard?doc=${doc.id}`,
childrens: childrens,
});
});
return items;
}
function defaultIcon(hasChild: boolean): string {
if (hasChild) return '<svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 -960 960 960" width="24"><path style="fill:var(--green);" d="M200-120q-33 0-56.5-23.5T120-200v-560q0-33 23.5-56.5T200-840h560q33 0 56.5 23.5T840-760v560q0 33-23.5 56.5T760-120H200Zm0-80h240v-560H200v560Zm320 0h240v-280H520v280Zm0-360h240v-200H520v200Z"/></svg>';
return '<svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 -960 960 960" width="24"><path style="fill:var(--yellow);" d="M320-240h320v-80H320v80Zm0-160h320v-80H320v80ZM240-80q-33 0-56.5-23.5T160-160v-640q0-33 23.5-56.5T240-880h320l240 240v480q0 33-23.5 56.5T720-80H240Zm280-520v-200H240v640h480v-440H520ZM240-800v200-200 640-640Z"/></svg>';
}
onMounted(() => {
hasSidebar.value = true;
if (!process.client) return;
Expand Down
51 changes: 51 additions & 0 deletions dashboard/components/sidebar/SidebarItem.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<template>
<NuxtLink class="item" :to="item.route" :class="{ active: isActive(item.id) }">
<i v-html="item.icon" class="icon"></i>
<span>{{ item.title }}</span>
</NuxtLink>
</template>

<script setup lang="ts">
import { type Item } from './helpers';
const route = useRoute();
defineProps<{ item: Item }>();
const doc_id = computed(() => route.query.doc as string);
const isActive = (id: string) => doc_id.value === id;
</script>

<style lang="scss" scoped>
.item {
display: flex;
justify-content: flex-start;
align-items: center;
min-height: 30px;
padding: 0 2.5px;
margin: 2.5px 0;
border-radius: 5px;
color: var(--font-color);
cursor: pointer;
width: 90%;
&:hover,
&.active {
background: var(--bg-contrast-2);
}
.icon {
display: flex;
align-items: center;
&:deep(svg) {
fill: var(--blue);
width: 22px;
height: 20px;
margin-right: 7px;
path {
fill: var(--blue);
}
}
}
}
</style>
60 changes: 26 additions & 34 deletions dashboard/components/sidebar/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,39 +13,31 @@ export interface Item {

export const defaultItems: Item[] = [
{
id: '#1',
title: 'Navigattion',
icon: '<svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 -960 960 960" width="24"><path d="M320-160q-117 0-198.5-81.5T40-440q0-107 70.5-186.5T287-718l-63-66 56-56 160 160-160 160-56-57 59-59q-71 14-117 69t-46 127q0 83 58.5 141.5T320-240h120v80H320Zm200-360v-280h360v280H520Zm0 360v-280h360v280H520Zm80-80h200v-120H600v120Z"/></svg>',
route: '/dashboard/scategory&ettings',
childrens: [
{
id: 'manage-categories',
title: 'Manage categories',
icon: '<svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 -960 960 960" width="24"><path d="M320-320h480v-480h-80v280l-100-60-100 60v-280H320v480Zm0 80q-33 0-56.5-23.5T240-320v-480q0-33 23.5-56.5T320-880h480q33 0 56.5 23.5T880-800v480q0 33-23.5 56.5T800-240H320ZM160-80q-33 0-56.5-23.5T80-160v-560h80v560h560v80H160Zm360-720h200-200Zm-200 0h480-480Z"/></svg>',
route: '/dashboard/categories',
childrens: [],
},
{
id: 'cdn',
title: 'CDN',
icon: '<svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 -960 960 960" width="24"><path d="M485-440h163q26 0 44-18t18-44q0-26-18-44.5T648-565h-2q-5-32-29-53.5T560-640q-26 0-47 13.5T481-590q-30 2-50.5 23.5T410-515q0 30 21.5 52.5T485-440ZM120-120q-33 0-56.5-23.5T40-200v-520h80v520h680v80H120Zm160-160q-33 0-56.5-23.5T200-360v-440q0-33 23.5-56.5T280-880h200l80 80h280q33 0 56.5 23.5T920-720v360q0 33-23.5 56.5T840-280H280Zm0-80h560v-360H527l-80-80H280v440Zm0 0v-440 440Z"/></svg>',
route: '/dashboard/cdn',
childrens: [],
},
{
id: 'backup',
title: 'Backup',
icon: '<svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 -960 960 960" width="24"><path d="M260-160q-91 0-155.5-63T40-377q0-78 47-139t123-78q17-72 85-137t145-65q33 0 56.5 23.5T520-716v242l64-62 56 56-160 160-160-160 56-56 64 62v-242q-76 14-118 73.5T280-520h-20q-58 0-99 41t-41 99q0 58 41 99t99 41h480q42 0 71-29t29-71q0-42-29-71t-71-29h-60v-80q0-48-22-89.5T600-680v-93q74 35 117 103.5T760-520q69 8 114.5 59.5T920-340q0 75-52.5 127.5T740-160H260Zm220-358Z"/></svg>',
route: '/dashboard/backup',
childrens: [],
},
{
id: 'new-page',
title: 'New page',
icon: '<svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 -960 960 960" width="24"><path d="M440-280h80v-160h160v-80H520v-160h-80v160H280v80h160v160ZM200-120q-33 0-56.5-23.5T120-200v-560q0-33 23.5-56.5T200-840h560q33 0 56.5 23.5T840-760v560q0 33-23.5 56.5T760-120H200Zm0-80h560v-560H200v560Zm0-560v560-560Z"/></svg>',
route: '/dashboard/new',
childrens: [],
},
],
id: 'manage-categories',
title: 'Manage categories',
icon: '<svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 -960 960 960" width="24"><path d="M320-320h480v-480h-80v280l-100-60-100 60v-280H320v480Zm0 80q-33 0-56.5-23.5T240-320v-480q0-33 23.5-56.5T320-880h480q33 0 56.5 23.5T880-800v480q0 33-23.5 56.5T800-240H320ZM160-80q-33 0-56.5-23.5T80-160v-560h80v560h560v80H160Zm360-720h200-200Zm-200 0h480-480Z"/></svg>',
route: '/dashboard/categories',
childrens: [],
},
{
id: 'cdn',
title: 'CDN',
icon: '<svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 -960 960 960" width="24"><path d="M485-440h163q26 0 44-18t18-44q0-26-18-44.5T648-565h-2q-5-32-29-53.5T560-640q-26 0-47 13.5T481-590q-30 2-50.5 23.5T410-515q0 30 21.5 52.5T485-440ZM120-120q-33 0-56.5-23.5T40-200v-520h80v520h680v80H120Zm160-160q-33 0-56.5-23.5T200-360v-440q0-33 23.5-56.5T280-880h200l80 80h280q33 0 56.5 23.5T920-720v360q0 33-23.5 56.5T840-280H280Zm0-80h560v-360H527l-80-80H280v440Zm0 0v-440 440Z"/></svg>',
route: '/dashboard/cdn',
childrens: [],
},
{
id: 'backup',
title: 'Backup',
icon: '<svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 -960 960 960" width="24"><path d="M260-160q-91 0-155.5-63T40-377q0-78 47-139t123-78q17-72 85-137t145-65q33 0 56.5 23.5T520-716v242l64-62 56 56-160 160-160-160 56-56 64 62v-242q-76 14-118 73.5T280-520h-20q-58 0-99 41t-41 99q0 58 41 99t99 41h480q42 0 71-29t29-71q0-42-29-71t-71-29h-60v-80q0-48-22-89.5T600-680v-93q74 35 117 103.5T760-520q69 8 114.5 59.5T920-340q0 75-52.5 127.5T740-160H260Zm220-358Z"/></svg>',
route: '/dashboard/backup',
childrens: [],
},
{
id: 'new-page',
title: 'New page',
icon: '<svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 -960 960 960" width="24"><path d="M440-280h80v-160h160v-80H520v-160h-80v160H280v80h160v160ZM200-120q-33 0-56.5-23.5T120-200v-560q0-33 23.5-56.5T200-840h560q33 0 56.5 23.5T840-760v560q0 33-23.5 56.5T760-120H200Zm0-80h560v-560H200v560Zm0-560v560-560Z"/></svg>',
route: '/dashboard/new',
childrens: [],
},
];
5 changes: 4 additions & 1 deletion dashboard/pages/dashboard/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ watchEffect(async () => {
});
const print = () => window.print();
const deleteDoc = () => doc.value?.id ? documentsStore.delete(doc.value.id) : null;
const deleteDoc = () => {
showDeleteModal.value = false;
doc.value?.id ? documentsStore.delete(doc.value.id) : null
};
</script>

<style lang="scss" scoped>
Expand Down
Loading

0 comments on commit de5b9dd

Please sign in to comment.