Skip to content

📚 The open-source, offline-first Notion, Obsidian & Confluence alternative. Advanced Markdown, multi-tenant teams, OIDC/SSO, and local S3 backups. Deploy in one command.

Many updates and refactors

Smaug6739d89e854b0710
diff --git a/frontend/components/AppHint.vue b/frontend/components/AppHint.vue
new file mode 100644
index 00000000..9d2f4ca8
--- /dev/null
+++ b/frontend/components/AppHint.vue
@@ -0,0 +1,57 @@
+<template>
+ <div class="hint-wrapper" @mouseenter="show = true" @mouseleave="show = false">
+ <div class="hint-icon">i</div>
+ <div v-if="show" class="hint-tooltip">
+ {{ text }}
+ </div>
+ </div>
+</template>
+
+<script setup lang="ts">
+import { ref } from 'vue';
+
+const props = defineProps<{
+ text: string;
+}>();
+
+const show = ref(false);
+</script>
+
+<style scoped lang="scss">
+.hint-wrapper {
+ position: relative;
+ display: inline-block;
+ margin-left: 0.25rem;
+}
+
+.hint-icon {
+ width: 1rem;
+ height: 1rem;
+ background-color: $primary-color;
+ color: white;
+ font-weight: bold;
+ border-radius: 50%;
+ font-size: 0.75rem;
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ cursor: default;
+ user-select: none;
+}
+
+.hint-tooltip {
+ position: absolute;
+ top: 100%;
+ left: 50%;
+ transform: translateX(-50%);
+ margin-top: 0.4rem;
+ background-color: #1f2937;
+ color: white;
+ padding: 0.4rem 0.6rem;
+ border-radius: 0.4rem;
+ white-space: nowrap;
+ font-size: 0.75rem;
+ z-index: 100;
+ box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
+}
+</style>
diff --git a/frontend/components/AppSelect.vue b/frontend/components/AppSelect.vue
new file mode 100644
index 00000000..a271426c
--- /dev/null
+++ b/frontend/components/AppSelect.vue
@@ -0,0 +1,73 @@
+<template>
+ <div class="category-select">
+ <button class="select-button" @click="toggleDropdown">
+ {{ selected?.title || placeholder }}
+ </button>
+
+ <div v-if="open" class="dropdown">
+ <ul class="tree-list">
+ <AppSelectNode v-for="item in items" :key="item.id" :node="item" :level="0" @select="handleSelect" />
+ </ul>
+ </div>
+ </div>
+</template>
+
+<script setup lang="ts">
+defineProps<{
+ items: Item[];
+ placeholder?: string;
+}>();
+
+const emit = defineEmits(['update:modelValue']);
+
+const open = ref(false);
+const selected = ref<Item | null>(null);
+
+function toggleDropdown() {
+ open.value = !open.value;
+}
+
+function handleSelect(node: any) {
+ selected.value = node;
+ emit('update:modelValue', node);
+ open.value = false;
+}
+</script>
+
+<style scoped>
+.category-select {
+ position: relative;
+ width: 100%;
+ max-width: 400px;
+}
+
+.select-button {
+ width: 100%;
+ padding: 8px 12px;
+ border: 1px solid #ccc;
+ background: white;
+ text-align: left;
+ border-radius: 4px;
+ cursor: pointer;
+}
+
+.dropdown {
+ position: absolute;
+ top: 100%;
+ left: 0;
+ right: 0;
+ max-height: 300px;
+ overflow-y: auto;
+ border: 1px solid #ccc;
+ background: white;
+ border-radius: 4px;
+ margin-top: 4px;
+ z-index: 1000;
+}
+
+.tree-list {
+ list-style: none;
+ padding: 0;
+ margin: 0;
+}
+</style>
diff --git a/frontend/components/AppSelectNode.vue b/frontend/components/AppSelectNode.vue
new file mode 100644
index 00000000..4dc980e2
--- /dev/null
+++ b/frontend/components/AppSelectNode.vue
@@ -0,0 +1,45 @@
+<template>
+ <li>
+ <button class="tree-node" :style="{ paddingLeft: `${level * 20 + 12}px`, fontWeight: node.childrens?.length ? 700 : 400 }" @click.stop="select">
+ {{ node.title }}
+ </button>
+ <ul v-if="node.childrens?.length">
+ <AppSelectNode v-for="child in node.childrens" :key="child.id" :node="child" :level="level + 1" @select="$emit('select', $event)" />
+ </ul>
+ </li>
+</template>
+
+<script setup lang="ts">
+const props = defineProps<{
+ node: Item;
+ level: number;
+}>();
+
+const emit = defineEmits(['select']);
+
+function select() {
+ emit('select', props.node);
+}
+</script>
+
+<style scoped>
+.tree-node {
+ display: block;
+ width: 100%;
+ padding: 6px 12px;
+ text-align: left;
+ background: none;
+ border: none;
+ cursor: pointer;
+}
+
+.tree-node:hover {
+ background-color: #f0f0f0;
+}
+ul,
+li {
+ list-style: none;
+ margin: 0;
+ padding: 0;
+}
+</style>
diff --git a/frontend/components/Modal.vue b/frontend/components/Modal.vue
index 98d8f9c4..7a10fc4e 100644
--- a/frontend/components/Modal.vue
+++ b/frontend/components/Modal.vue
@@ -1,5 +1,5 @@
<template>
- <Transition name="modal">
+ <Transition name="modals">
<div v-if="show" class="modal-mask">
<div class="modal-container">
<slot></slot>
diff --git a/frontend/components/ModalManager.vue b/frontend/components/ModalManager.vue
index e5cd91c8..f8e09dc7 100644
--- a/frontend/components/ModalManager.vue
+++ b/frontend/components/ModalManager.vue
@@ -2,12 +2,12 @@
<!-- This component is used to manage modals in the application. -->
<template>
<Transition name="modal">
- <div v-if="modals.length" class="modal-mask">
- <div v-for="(modal, index) in modals" :key="modal.name" class="modal-pos" :style="{ zIndex: 120 + index }">
- <!-- Overlay sur les modals du dessous -->
+ <!-- Mettre le v-if directement sur le div Ă  animer -->
+ <div v-if="modals.length">
+ <div v-for="(modal, index) in modals" :key="modal.name" class="modal-mask modal-pos" :style="{ zIndex: 120 + index }">
<div v-if="index !== modals.length - 1" class="modal-overlay"></div>
-
<div class="modal-container">
+ <button @click="close(modal)" class="close-btn"><Icon name="close" :big="true" /></button>
<component :is="modal.component" v-bind="modal.props" />
</div>
</div>
@@ -16,12 +16,18 @@
</template>
<script setup lang="ts">
const modals = useModal().modals;
+
+const close = (modal: Modal) => {
+ modal.onClose?.();
+ const index = modals.value.findIndex(m => m.name === modal.name);
+ if (index !== -1) {
+ modals.value.splice(index, 1);
+ }
+};
</script>
<style scoped lang="scss">
.modal-container {
- width: 75%;
- max-width: 800px;
margin: auto;
padding: 20px;
background-color: var(--bg-contrast);
@@ -29,15 +35,17 @@ const modals = useModal().modals;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.33);
transition: all 0.3s ease;
font-size: initial;
+ position: relative;
}
.modal-overlay {
position: absolute;
inset: 0;
- background-color: rgba(0, 0, 0, 0.2); // ou plus sombre selon l’effet souhaité
+ background-color: rgba(0, 0, 0, 0.2);
border-radius: 10px;
- z-index: 1; // juste en-dessous du contenu du modal
- pointer-events: none; // le masque ne bloque pas les interactions
+ z-index: 1;
+ pointer-events: none;
}
+
.modal-enter-from,
.modal-leave-to {
opacity: 0;
@@ -48,4 +56,23 @@ const modals = useModal().modals;
-webkit-transform: scale(1.1);
transform: scale(1.1);
}
+
+.close-btn {
+ position: absolute;
+ right: 0px;
+ top: 1rem;
+ background: none;
+ z-index: 1000;
+}
+
+.modal-mask {
+ position: fixed;
+ z-index: 120;
+ top: 0;
+ left: 0;
+ width: 100vw;
+ height: 100vh;
+ background-color: rgba(0, 0, 0, 0.5);
+ display: flex;
+}
</style>
diff --git a/frontend/components/Sidebar/CollapseItem.vue b/frontend/components/Sidebar/CollapseItem.vue
index 11c63e9a..73240b99 100644
--- a/frontend/components/Sidebar/CollapseItem.vue
+++ b/frontend/components/Sidebar/CollapseItem.vue
@@ -19,7 +19,7 @@
<SidebarItem v-else :item="item" />
</template>
<script setup lang="ts">
-import type { Item } from '../../composables/tree_builder';
+import type { Item } from '../../composables/SidebarTreeManager';
const props = defineProps<{ item: Item; root?: boolean }>();
diff --git a/frontend/components/Sidebar/Sidebar.vue b/frontend/components/Sidebar/Sidebar.vue
index 5297bf84..96a7d6d4 100644
--- a/frontend/components/Sidebar/Sidebar.vue
+++ b/frontend/components/Sidebar/Sidebar.vue
@@ -1,5 +1,5 @@
<template>
- <div :class="{ 'modal-mask': isMobile() && isOpened }"></div>
+ <div :class="{ 'sidebar-mask': isMobile() && isOpened }"></div>
<Resizable>
<div class="sidebar" :class="{ compact: preferences.get('compactMode') }">
<section class="header">
@@ -89,8 +89,7 @@ const items = computed((): Item[] => {
show: localStorage.getItem(`collapse-${document.id}`) === 'false' ? ref(false) : ref(true),
}))
.filter(c => c.data.name.toLowerCase().includes(filter.value.toLowerCase()));
-
- return new ItemsManager([...navigation, ...documents, ...categories]).generateTree().filter(c => {
+ return new SidebarTreeManager([...navigation, ...documents, ...categories]).generateTree().filter(c => {
if (c.data.type === 'category' && workspaceId.value) return c.data.workspace_id == workspaceId.value;
if (c.data.type === 'document' && workspaceId.value) return c.data.category === workspaceId.value;
return true;
@@ -203,4 +202,15 @@ onBeforeUnmount(() => {
padding: 0 2.5px;
margin: 0;
}
+
+.sidebar-mask {
+ position: fixed;
+ z-index: 50;
+ top: 0;
+ left: 0;
+ width: 100vw;
+ height: 100vh;
+ background-color: rgba(0, 0, 0, 0.5);
+ display: flex;
+}
</style>
diff --git a/frontend/composables/tree_builder.ts b/frontend/composables/SidebarTreeManager.ts
similarity index 85%
rename from frontend/composables/tree_builder.ts
rename to frontend/composables/SidebarTreeManager.ts
index ae46a7e9..9531ee09 100644
--- a/frontend/composables/tree_builder.ts
+++ b/frontend/composables/SidebarTreeManager.ts
@@ -4,32 +4,31 @@ import type { DefaultItem } from '../components/Sidebar/helpers';
export interface Item<T = Document | Category | DefaultItem> {
id: string;
title: string;
- route: string;
parent_id: string;
data: T;
childrens?: Item<T>[];
show: Ref<boolean>;
}
-export class ItemsManager {
+export class SidebarTreeManager {
private itemMap: Map<string, Item>; // Utilisation de Map pour les recherches rapides
constructor(public readonly items: Item[]) {
this.itemMap = new Map(items.map(item => [item.id, item]));
}
- // Récupère un élément par son ID
+ // Get item by ID
public getItem(id: string): Item | undefined {
return this.itemMap.get(id);
}
- // Génère l'arbre dynamiquement, sans indexation préalable
+ // Generate the tree structure without indexing
public generateTree(): Item[] {
return this.items
.filter(item => item.parent_id === '' || !this.itemMap.has(item.parent_id) || (item.data.type === 'category' && item.data.role === 2)) // Racines
.map(rootItem => this.buildTree(rootItem));
}
- // Construit un sous-arbre dynamiquement
+ // Generate sub tree
private buildTree(item: Item): Item {
const children = this.items.filter(child => child.parent_id === item.id || (child.data.type === 'category' && child.data.workspace_id === item.id));
return {
diff --git a/frontend/composables/TreeManager.ts b/frontend/composables/TreeManager.ts
new file mode 100644
index 00000000..56c84cf6
--- /dev/null
+++ b/frontend/composables/TreeManager.ts
@@ -0,0 +1,32 @@
+export interface ANode<T = any> {
+ id: string;
+ title: string;
+ icon?: string;
+ route?: string;
+ parent_id: string;
+ children: ANode[];
+ data: T;
+}
+
+export class TreeManager<T> {
+ private nodeMap: Map<string, ANode<T>> = new Map();
+ public items: ANode<T>[] = [];
+
+ constructor(items: ANode<T>[]) {
+ this.nodeMap = new Map(items.map(item => [item.id, item]));
+ this.items = items;
+ }
+
+ public buildTree() {
+ return this.items
+ .filter(item => item.parent_id === '' || !this.nodeMap.has(item.parent_id)) // Racines
+ .map(rootItem => this.buildSubTree(rootItem));
+ }
+ private buildSubTree(item: ANode<T>): ANode<T> {
+ const children = this.items.filter(child => child.parent_id === item.id);
+ return {
+ ...item,
+ children: children.map(child => this.buildSubTree(child)),
+ };
+ }
+}
diff --git a/frontend/composables/modal_bus.ts b/frontend/composables/modal_bus.ts
index 71edd477..d377f02c 100644
--- a/frontend/composables/modal_bus.ts
+++ b/frontend/composables/modal_bus.ts
@@ -1,9 +1,13 @@
// Modal bus for managing modal state
-const modals = ref<{ component: any; name: string; props: any }[]>([]);
+const modals = ref<Modal[]>([]);
export function useModal() {
return {
modals,
};
}
+
+export class Modal {
+ constructor(public component: any, public name: string, public props: any, public onClose: () => void = () => {}) {}
+}
diff --git a/frontend/composables/utils.ts b/frontend/composables/utils.ts
index 472f422d..1bf9f8ef 100644
--- a/frontend/composables/utils.ts
+++ b/frontend/composables/utils.ts
@@ -67,17 +67,3 @@ export function parseUserAgent(uaString?: string) {
return { os, browser };
}
-
-export interface ANode {
- id: string;
- name: string;
- title: string;
- icon: string;
- openedIcon: string;
- closedIcon: string;
- isOpen: boolean;
- isParent: boolean;
- showLoading: boolean;
- buttons: Array<{ icon: string; title: string; click: (node: ANode) => void }>;
- children: ANode[];
-}
diff --git a/frontend/pages/dashboard/categories/_modals/CreateCategoryModal.vue b/frontend/pages/dashboard/categories/_modals/CreateCategoryModal.vue
index f17159a9..ad388760 100644
--- a/frontend/pages/dashboard/categories/_modals/CreateCategoryModal.vue
+++ b/frontend/pages/dashboard/categories/_modals/CreateCategoryModal.vue
@@ -1,75 +1,53 @@
<!-- Category creation modal -->
<!-- Should be like folder creation on linux or mac -->
<template>
- <div class="modal fade" id="createCategoryModal" tabindex="-1" role="dialog" aria-labelledby="createCategoryModalLabel" aria-hidden="true">
- <div class="modal-dialog modal-dialog-centered" role="document">
- <div class="modal-content">
- <div class="modal-header">
- <h5 class="modal-title" id="createCategoryModalLabel">Create Category</h5>
- <button type="button" class="close" aria-label="Close">
- <span aria-hidden="true">&times;</span>
- </button>
- </div>
- <div class="modal-body">
- <div>
- <div class="form-group">
- <label for="categoryName">Category Name</label>
- <input type="text" class="form-control" id="categoryName" v-model="category.name" required />
- </div>
- <AppButton type="primary" @click="createCategory">Create</AppButton>
- </div>
- </div>
- </div>
- </div>
+ <div class="modal">
+ <h2>Create a new {{ role == 1 ? 'category' : 'workspace' }}</h2>
+ <form @submit.prevent="createCategory">
+ <label for="name">Name</label>
+ <input type="text" v-model="category.name" id="name" required />
+ <label for="icon">Icon <AppHint text="SVG supported" /></label>
+ <input type="text" v-model="category.icon" id="icon" />
+ <label for="parent">Parent</label>
+ <select v-model="category.parent_id" id="parent">
+ <option :value="null">None</option>
+ <option v-for="pc in categoriesStore.getParents.filter(c => c.role == 1)" :key="pc.id" :value="pc.id">{{ pc.name }}</option>
+ </select>
+ <label>Workspace <AppHint text="Only for root categories" /></label>
+ <select v-model="category.workspace_id">
+ <option :value="null">None</option>
+ <option v-for="wp in categoriesStore.getAll.filter(a => a.role == 2)" :key="wp.id" :value="wp.id">{{ wp.name }}</option>
+ </select>
+ <label for="order">Order</label>
+ <input type="number" v-model.number="category.order" id="order" />
+ <AppButton type="primary">Create</AppButton>
+ </form>
</div>
</template>
<script setup lang="ts">
import type { Category } from '~/stores';
-import test_wp2 from './test_wp2.vue';
const categoriesStore = useCategoriesStore();
+const props = defineProps<{ role: number }>();
const category = ref<Category>({
name: '',
type: 'category',
id: '',
- role: 0,
+ role: props.role,
});
+
const createCategory = () => {
- useModal().modals.value.push({
- component: shallowRef(test_wp2),
- name: 'CreateCategoryModal',
- props: undefined,
- });
// categoriesStore.post(category.value)
};
</script>
<style scoped lang="scss">
-.modal-header {
- background-color: #f8f9fa;
- border-bottom: 1px solid #dee2e6;
-}
-
-.modal-title {
- font-size: 1.25rem;
- font-weight: 500;
-}
-
-.modal-body {
- padding: 1.5rem;
-}
-
-.form-group {
- margin-bottom: 1rem;
-}
-
-.form-control {
- width: 100%;
-}
-
-.close {
- cursor: pointer;
+.modal {
+ background-color: var(--bg-contrast);
+ padding: 1rem;
+ border-radius: 8px;
+ min-width: 700px;
}
</style>
diff --git a/frontend/pages/dashboard/categories/_modals/test_wp2.vue b/frontend/pages/dashboard/categories/_modals/test_wp2.vue
deleted file mode 100644
index 8f0617cc..00000000
--- a/frontend/pages/dashboard/categories/_modals/test_wp2.vue
+++ /dev/null
@@ -1 +0,0 @@
-<template>Test2</template>
diff --git a/frontend/pages/dashboard/categories/index.vue b/frontend/pages/dashboard/categories/index.vue
index f340a5d2..1aa3d721 100644
--- a/frontend/pages/dashboard/categories/index.vue
+++ b/frontend/pages/dashboard/categories/index.vue
@@ -1,8 +1,7 @@
<template>
- <div style="padding: 24px; gap: 16px">
+ <div style="padding: 24px; gap: 16px" class="card-component">
<header>
- <h1 style="font-size: 20px; font-weight: bold">Workspaces & Categories</h1>
-
+ <h1 style="font-size: 20px">Workspaces & Categories</h1>
<div style="display: flex; gap: 8px">
<AppButton type="primary" @click="createWorkspace">+ Workspace</AppButton>
<AppButton type="primary" @click="createCategory">+ Category</AppButton>
@@ -10,9 +9,9 @@
</div>
</header>
<div style="padding: 10px 0; border-top: 1px solid #ddd; display: flex; justify-content: space-between; align-items: center">
- <input v-model="search" placeholder="Search category..." style="width: 50%; padding: 8px; border: 1px solid #ccc; border-radius: 4px" />
+ <input placeholder="Search category..." style="width: 50%; padding: 8px; border: 1px solid #ccc; border-radius: 4px" />
</div>
- <div v-if="workspaces.length" class="workspace" v-for="workspace in workspaces" :key="workspace.id">
+ <div v-if="custom_tree.length" class="workspace" v-for="workspace in custom_tree" :key="workspace.id">
<h3 class="wp-name">{{ workspace.title }}</h3>
<WorkspaceTree v-for="node in workspace.childrens" :node="node" @edit="editNode" @delete="deleteNode" />
</div>
@@ -24,37 +23,27 @@
<script setup lang="ts">
import CreateCategoryModal from './_modals/CreateCategoryModal.vue';
import type { Category } from '~/stores';
-
const categories = useCategoriesStore().getAll;
-const tree = new ItemsManager(
+const tree = new SidebarTreeManager(
categories.map((c: Category) => {
return {
id: c.id,
title: c.name,
type: 'category',
- route: `/categories/${c.id}`,
parent_id: c.parent_id || '',
data: c,
show: ref(true),
} as Item<Category>;
}),
).generateTree() as Item<Category>[];
-console.log(tree);
-const workspaces = tree.filter((i: Item<Category>) => i.data.role === 2);
-console.log(workspaces);
-const search = ref('');
+
+const custom_tree = tree.filter((i: Item<Category>) => i.data.role === 2);
function createWorkspace() {
- // logique de création de workspace
- useModal().modals.value?.push({
- component: shallowRef(CreateCategoryModal),
- name: '',
- props: undefined,
- });
+ useModal().modals.value?.push(new Modal(shallowRef(CreateCategoryModal), '', { role: 2 }));
}
-
function createCategory() {
- // logique de création de catégorie
+ useModal().modals.value?.push(new Modal(shallowRef(CreateCategoryModal), '', { role: 1 }));
}
function editNode(node: Item) {
diff --git a/frontend/stores/ressources.store.ts b/frontend/stores/ressources.store.ts
index 30e66ffb..d87f6085 100644
--- a/frontend/stores/ressources.store.ts
+++ b/frontend/stores/ressources.store.ts
@@ -39,8 +39,6 @@ export const useRessourcesStore = defineStore('ressources', {
delete(id: string) {
return new Promise(async (resolve, reject) => {
const request = await makeRequest(`ressources/${id}`, 'DELETE', {});
- console.log(request);
-
if (request.status == 'success') resolve((this.ressources = this.ressources.filter(c => c.id != id)));
else reject(request.message);
});