π The open-source, offline-first Notion, Obsidian & Confluence alternative. Advanced Markdown, multi-tenant teams, OIDC/SSO, and local S3 backups. Deploy in one command.
Vue dockergolangkanbanknowledge-baseknowledge-managementmarkdownnote-takingnotesnotes-appnotionnuxtnuxtjsoffline-firstoidcpwaselfhostedssovuevuejswiki
New workspaces system
Smaug673979516b6ad8de
diff --git a/backend/classes/CategoriesManager.ts b/backend/classes/CategoriesManager.tsindex f4249eb1..43c89a41 100644--- a/backend/classes/CategoriesManager.ts+++ b/backend/classes/CategoriesManager.ts@@ -12,6 +12,8 @@ export class CategoriesManager extends Base {name: { minLength: 1, maxLength: 50, type: 'string', error: 'category name invalid' },icon: { maxLength: 10_000, type: 'string', error: 'category icon invalid', optional: true },order: { type: 'number', error: 'category order invalid', optional: true },+ role: { type: 'number', minLength: 1, maxLength: 2, error: 'category role invalid' },+ workspace_id: { maxLength: 50, type: 'string', error: 'category workspace id invalid', optional: true },parent_id: { maxLength: 50, type: 'string', error: 'category parent id invalid', optional: true },author_id: { minLength: 1, maxLength: 50, type: 'string', error: 'category author id invalid' },});@@ -46,8 +48,8 @@ export class CategoriesManager extends Base {const error = this.validator.validate(data);if (error) return reject(error);this.app.db.query(- 'INSERT INTO categories (`id`, `name`,`icon`, `order`, `parent_id`, `author_id`) VALUES (?, ?, ?, ?, ?, ?)',- [data.id, data.name, data.icon, data.order, data.parent_id, data.author_id],+ 'INSERT INTO categories (`id`, `name`,`icon`, `order`, `role`, `workspace_id`, `parent_id`, `author_id`) VALUES (?, ?, ?, ?, ?, ?, ?, ?)',+ [data.id, data.name, data.icon, data.order, data.role, data.workspace_id, data.parent_id, data.author_id],err => {if (err) return reject('Internal database error.');else resolve(data);@@ -61,8 +63,8 @@ export class CategoriesManager extends Base {const error = this.validator.validate(data);if (error) return reject(error);this.app.db.query(- 'UPDATE categories SET name = ?, icon = ?, `order` = ?, parent_id = ? WHERE id = ?',- [data.name, data.icon, data.order, data.parent_id, data.id],+ 'UPDATE categories SET name = ?, icon = ?, `order` = ?, role = ?, workspace_id = ?, parent_id = ? WHERE id = ?',+ [data.name, data.icon, data.order, data.role, data.workspace_id, data.parent_id, data.id],err => {if (err) return reject('Internal database error.');else resolve(data);diff --git a/backend/controllers/categories.controller.ts b/backend/controllers/categories.controller.tsindex 82051870..f6274cbb 100644--- a/backend/controllers/categories.controller.ts+++ b/backend/controllers/categories.controller.ts@@ -20,7 +20,9 @@ export default class CategoriesController extends BaseController<CategoriesManagname: req.body.name,icon: req.body.icon,order: req.body.order || 0,+ role: req.body.role || 1,parent_id: req.body.parent_id || null,+ workspace_id: req.body.workspace_id || null,author_id: req.user_id!,}).then(r => res.status(201).json(this.utils.success(r)))@@ -36,7 +38,9 @@ export default class CategoriesController extends BaseController<CategoriesManagname: req.body.name,icon: req.body.icon,order: req.body.order,+ role: req.body.role,parent_id: req.body.parent_id,+ workspace_id: req.body.workspace_id,author_id: req.user_id!,});return res.status(200).json(this.utils.success(r));diff --git a/backend/types/Structures.d.ts b/backend/types/Structures.d.tsindex 55ed3f53..a0ac55fb 100644--- a/backend/types/Structures.d.ts+++ b/backend/types/Structures.d.ts@@ -20,6 +20,8 @@ export interface Category {name: string;icon?: string;order?: number;+ role: number; // 1 Category; 2 Workspace;+ workspace_id?: string;parent_id?: string;author_id: string;}diff --git a/frontend/components/AppSelect.vue b/frontend/components/AppSelect.vuenew file mode 100644index 00000000..7700a136--- /dev/null+++ b/frontend/components/AppSelect.vue@@ -0,0 +1,108 @@+<template>+ <div class="dropdown-container" @click="toggleDropdown">+ <div class="dropdown-selected" :class="{ open: isOpen }">+ <span v-if="selectedOption"><AppSelectOption :option="selectedOption" /></span>+ <span v-else class="placeholder">{{ placeholder }}</span>+ <span class="dropdown-arrow"></span>+ </div>+ <ul v-if="isOpen" class="dropdown-options">+ <li v-for="option in options" :class="{ selected: option.value === selected }" @click="selectOption(option)">+ <AppSelectOption :option="option" />+ </li>+ </ul>+ </div>+</template>+<script setup lang="ts">+interface Option {+ text: string;+ value: string;+}+const props = defineProps<{+ value?: string;+ options: Option[];+ placeholder?: string;+}>();+const isOpen = ref(false);+const selected = ref(props.value);+const emit = defineEmits(['input']);+const selectedOption = computed(() => props.options.find(option => option.value === selected.value));+const toggleDropdown = () => (isOpen.value = !isOpen.value);+const selectOption = (option: Option) => {+ selected.value = option.value;+ emit('input', selected.value);+ isOpen.value = false;+};+const closeDropdown = () => (isOpen.value = false);+const handleClickOutside = (event: MouseEvent) => {+ if (!(event.target as HTMLElement)!.closest('.dropdown-container')) {+ closeDropdown();+ }+};+onMounted(() => document.addEventListener('click', handleClickOutside));+onBeforeUnmount(() => document.removeEventListener('click', handleClickOutside));+</script>++<style scoped lang="scss">+.dropdown-container {+ position: relative;+ width: calc(100% - 4px);+}++.dropdown-selected {+ display: flex;+ justify-content: space-between;+ align-items: center;+ padding: 2px 8px;+ border: 1px solid var(--border-color);+ margin: 4px;+ border-radius: 8px;+ cursor: pointer;+}+.placeholder {+ color: var(--font-color-light);+}++.dropdown-selected.open {+ border-color: var(--selection-color);+ box-shadow: 0 0 5px rgba(0, 123, 255, 0.5);+}++.dropdown-arrow {+ width: 8px;+ height: 8px;+ border: solid #333;+ border-width: 0 2px 2px 0;+ padding: 4px;+ transform: rotate(-45deg);+ transition: transform 0.3s ease;+}++.dropdown-selected.open .dropdown-arrow {+ transform: rotate(45deg);+}++.dropdown-options {+ position: absolute;+ width: 95%;+ margin: 0;+ padding: 0;+ list-style: none;+ background-color: var(--bg-color);+ border: 1px solid var(--border-color);+ color: var(--font-color);+ border-radius: 8px;+ overflow-y: auto;+ z-index: 100;+}++li {+ padding: 4px;+ cursor: pointer;+}++li.selected,+li:hover {+ background-color: var(--selection-color);+ color: var(--font-color);+}+</style>diff --git a/frontend/components/AppSelectOption.vue b/frontend/components/AppSelectOption.vuenew file mode 100644index 00000000..c5cf36b1--- /dev/null+++ b/frontend/components/AppSelectOption.vue@@ -0,0 +1,34 @@+<template>+ <div>+ <svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" width="18px" height="18px">+ <g id="SVGRepo_bgCarrier" stroke-width="0"></g>+ <g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g>+ <g id="SVGRepo_iconCarrier">+ <path+ fill-rule="evenodd"+ clip-rule="evenodd"+ d="M6 5C5.44772 5 5 5.44772 5 6V18C5 18.5523 5.44772 19 6 19H13V14C13 13.4477 13.4477 13 14 13H19V6C19 5.44772 18.5523 5 18 5H6ZM17.5858 15H15V17.5858L17.5858 15ZM3 6C3 4.34315 4.34315 3 6 3H18C19.6569 3 21 4.34315 21 6V14C21 14.2652 20.8946 14.5196 20.7071 14.7071L14.7071 20.7071C14.5196 20.8946 14.2652 21 14 21H6C4.34315 21 3 19.6569 3 18V6Z"+ fill="#000000"+ ></path>+ </g>+ </svg>+ {{ option.text }}+ </div>+</template>++<script setup lang="ts">+defineProps<{+ option: Option;+}>();+interface Option {+ text: string;+ value: string;+}+</script>++<style scoped lang="scss">+div {+ display: flex;+ align-items: center;+}+</style>diff --git a/frontend/components/Sidebar/Sidebar.vue b/frontend/components/Sidebar/Sidebar.vueindex 3c9d9cdf..dd9cdec9 100644--- a/frontend/components/Sidebar/Sidebar.vue+++ b/frontend/components/Sidebar/Sidebar.vue@@ -21,6 +21,7 @@<Icon name="logout" @click="logoutUser" class="logout" /></div></div>+ <AppSelect :value="filterWorkspace" placeholder="Select workspace" :options="workspaces" @input="v => (filterWorkspace = v)" /><Search /><CollapseItem v-for="(item, index) in items" :key="index" :item="item" :root="true" /></div>@@ -41,7 +42,12 @@ const categoriesStore = useCategoriesStore();const documentsStore = useDocumentsStore();const userStore = useUserStore();const filter = ref<string>('');+const filterWorkspace = ref<string>(localStorage.getItem('filterWorkspace') || 'all');const showSearchModal = ref<boolean>(false);+const workspaces = computed(() => [{ text: 'All workspaces', value: 'all' }, ...categoriesStore.categories.filter(c => c.role === 2).map(c => ({ text: c.name, value: c.id }))]);+watch(filterWorkspace, () => {+ localStorage.setItem('filterWorkspace', filterWorkspace.value);+});const handleSearchShortCut = (e: KeyboardEvent) => {if (e.ctrlKey && e.key === 'q') showSearchModal.value = !showSearchModal.value;@@ -71,7 +77,7 @@ const items = computed((): Item[] => {data: category,show: !category.parent_id && localStorage.getItem(`collapse-${category.id}`) === 'false' ? ref(false) : ref(true),}))- .filter(c => c.data.name.toLowerCase().includes(filter.value.toLowerCase()));+ .filter(c => c.data.role === 1 && c.data.name.toLowerCase().includes(filter.value.toLowerCase()));const documents: Item[] = documentsStore.documents.map(document => ({id: document.id,@@ -84,7 +90,10 @@ const items = computed((): Item[] => {.filter(c => c.data.name.toLowerCase().includes(filter.value.toLowerCase()));if (filter.value) return new ItemsManager([...navigation, ...documents]).generateTree();- return new ItemsManager([...navigation, ...documents, ...categories]).generateTree();+ return new ItemsManager([...navigation, ...documents, ...categories]).generateTree().filter(c => {+ if (c.data.type === 'category' && filterWorkspace.value != 'all') return c.data.workspace_id == filterWorkspace.value;+ return true;+ });});const handleClickOutside = (e: MouseEvent) => {diff --git a/frontend/pages/dashboard/categories/edit.vue b/frontend/pages/dashboard/categories/edit.vueindex 9f0ef0d2..b2c512f4 100644--- a/frontend/pages/dashboard/categories/edit.vue+++ b/frontend/pages/dashboard/categories/edit.vue@@ -1,47 +1,42 @@<template>- <div style="width: 100%">- <div class="category-form-container">- <h2>Update category</h2>- <form @submit.prevent="updateCategory">- <div class="input-group">- <label for="id">ID</label>- <input type="text" v-model="category.id" id="id" disabled />- </div>- <div class="input-group">- <label for="name">Name</label>- <input type="text" v-model="category.name" id="name" required />- </div>- <div class="input-group">- <label for="icon">Icon (svg supported)</label>- <textarea type="text" v-model="category.icon" id="icon" rows="5"></textarea>- </div>- <div class="input-group">- <label for="parent">Parent</label>- <select v-model="category.parent_id" id="parent">- <option value="">Aucun</option>- <option v-for="mainCategory in categoriesStore.getParents" :key="mainCategory.id" :value="mainCategory.id">- {{ mainCategory.name }}- </option>- </select>- </div>- <div class="input-group">- <label for="order">Order</label>- <input type="number" v-model.number="category.order" id="order" />- </div>- <div style="display: flex; justify-content: flex-end">- <AppButton type="danger" @click="deleteCategory()">Delete</AppButton>- <AppButton type="primary" class="btn primary">Update</AppButton>- </div>- </form>- </div>+ <div class="category-form-container">+ <h2>Update category & workspace</h2>+ <form @submit.prevent="updateCategory">+ <label>ID</label>+ <input type="text" v-model="category.id" id="id" disabled />+ <label>Role</label>+ <select v-model="category.role">+ <option :value="1">Category</option>+ <option :value="2">Workspace</option>+ </select>+ <label>Name</label>+ <input type="text" v-model="category.name" id="name" required />+ <label>Icon (svg supported)</label>+ <textarea type="text" v-model="category.icon" rows="5"></textarea>+ <label>Workspace (for top categories)</label>+ <select v-model="category.workspace_id">+ <option :value="null">None</option>+ <option v-for="wp in categoriesStore.getAll.filter(a => a.id != categoryId && a.role == 2)" :value="wp.id">{{ wp.name }}</option>+ </select>+ <label>Parent</label>+ <select v-model="category.parent_id">+ <option :value="null">None</option>+ <option v-for="cp in categoriesStore.getParents.filter(a => a.id != categoryId && a.role == 1)" :value="cp.id">{{ cp.name }}</option>+ </select>+ <label for="order">Order</label>+ <input type="number" v-model.number="category.order" id="order" />+ <div style="display: flex; justify-content: flex-end">+ <AppButton type="danger" @click="deleteCategory()">Delete</AppButton>+ <AppButton type="primary" class="btn primary">Update</AppButton>+ </div>+ </form></div></template><script lang="ts" setup>-const route = useRoute();const categoriesStore = useCategoriesStore();-const category = computed(() => categoriesStore.getById(categoryId as string) || { id: '', name: '', icon: '', parent_id: '', order: 0, type: 'category' as const });-const categoryId = route.query.category;+const categoryId = useRoute().query.category;+const category = computed(() => categoriesStore.getById(categoryId as string) || { id: '', role: 1, name: '', icon: '', workspace_id: '', parent_id: '', order: 0, type: 'category' as const });definePageMeta({ breadcrumb: 'Edit' });@@ -71,24 +66,25 @@ const deleteCategory = async () => {.category-form-container {padding: 25px;margin: 40px auto;- background-color: var(--bg-contrast);- box-shadow: 0px 3px 10px rgba(0, 0, 0, 0.05);+ background-color: var(--bg-color);+ box-shadow: 0 0 10px 0 rgba(0, 0, 0, 0.1);border-radius: 12px;- min-width: 30%;- max-width: 600px;+ min-width: 40%;+ max-width: 800px;}h2 {font-size: 26px;text-align: center;}--.input-group {- margin-bottom: 20px;+label {+ margin-top: 10px;}input,-textarea {+textarea,+select {width: 100%;+ background-color: var(--bg-contrast);}</style>diff --git a/frontend/pages/dashboard/categories/new.vue b/frontend/pages/dashboard/categories/new.vueindex a839cbae..71a67c89 100644--- a/frontend/pages/dashboard/categories/new.vue+++ b/frontend/pages/dashboard/categories/new.vue@@ -1,32 +1,30 @@<template>- <div style="width: 100%">- <div class="category-form-container">- <h2>Add new category</h2>- <form @submit.prevent="createCategory">- <div class="input-group">- <label for="name">Name</label>- <input type="text" v-model="category.name" id="name" required />- </div>- <div class="input-group">- <label for="icon">Icon (svg supported)</label>- <input type="text" v-model="category.icon" id="icon" />- </div>- <div class="input-group">- <label for="parent">Parent</label>- <select v-model="category.parent_id" id="parent">- <option value="">None</option>- <option v-for="mainCategory in categoriesStore.getParents" :key="mainCategory.id" :value="mainCategory.id">- {{ mainCategory.name }}- </option>- </select>- </div>- <div class="input-group">- <label for="order">Order</label>- <input type="number" v-model.number="category.order" id="order" />- </div>- <AppButton type="primary">Create</AppButton>- </form>- </div>+ <div class="category-form-container">+ <h2>Add new category</h2>+ <form @submit.prevent="createCategory">+ <label for="name">Name</label>+ <input type="text" v-model="category.name" id="name" required />+ <label>Role</label>+ <select v-model="category.role">+ <option :value="1">Category</option>+ <option :value="2">Workspace</option>+ </select>+ <label for="icon">Icon (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" :key="pc.id" :value="pc.id">{{ pc.name }}</option>+ </select>+ <label>Workspace (for top 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>@@ -34,7 +32,7 @@import type { Category } from '~/stores';const categoriesStore = useCategoriesStore();-const category = ref<Category>({ id: '', name: '', icon: '', parent_id: '', order: 0, type: 'category' });+const category = ref<Category>({ id: '', role: 1, name: '', icon: '', parent_id: '', order: 0, type: 'category' });definePageMeta({ breadcrumb: 'New' });function createCategory() {@@ -51,23 +49,26 @@ function createCategory() {<style scoped lang="scss">.category-form-container {padding: 25px;- background-color: var(--bg-contrast);- box-shadow: 0px 3px 10px rgba(0, 0, 0, 0.05);margin: 40px auto;+ background-color: var(--bg-color);+ box-shadow: 0 0 10px 0 rgba(0, 0, 0, 0.1);border-radius: 12px;- min-width: 30%;- max-width: 600px;+ min-width: 40%;+ max-width: 800px;}h2 {font-size: 26px;- margin-bottom: 30px;- color: var(--font-color);text-align: center;}+label {+ margin-top: 10px;+}-.input-group {- margin-bottom: 20px;- position: relative;+input,+textarea,+select {+ width: 100%;+ background-color: var(--bg-contrast);}</style>diff --git a/frontend/stores/categories.store.ts b/frontend/stores/categories.store.tsindex e775eb03..58dd38f4 100644--- a/frontend/stores/categories.store.ts+++ b/frontend/stores/categories.store.ts@@ -1,4 +1,3 @@-import { defineStore } from 'pinia';import { makeRequest, type FetchOptions } from './_utils';import type { Category, DB_Category } from './db_strustures';diff --git a/frontend/stores/db_strustures.d.ts b/frontend/stores/db_strustures.d.tsindex bae4929c..47073d96 100644--- a/frontend/stores/db_strustures.d.ts+++ b/frontend/stores/db_strustures.d.ts@@ -21,6 +21,8 @@ export interface DB_Category {name: string;icon?: string;order?: number;+ role: number; // 1 Category; 2 Workspace+ workspace_id?: string;parent_id?: string;}export interface Category extends DB_Category {