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.

Improve new workspaces system

Smaug6739607624a2aca3
diff --git a/backend/controllers/documents.controller.ts b/backend/controllers/documents.controller.ts
index a89395ea..755e9ca3 100644
--- a/backend/controllers/documents.controller.ts
+++ b/backend/controllers/documents.controller.ts
@@ -50,14 +50,14 @@ export default class DocumentsController extends BaseController<DocumentsManager
const db_doc = await this.manager.get(req.params.id as string, req.user_id!);
if (!db_doc) return res.status(404).json(this.utils.error('Document not found or unauthorized.'));
const result = await this.manager.put(req.params.id as string, {
- name: req.body.name ?? db_doc.name,
- description: req.body.description ?? db_doc.description,
- tags: req.body.tags ?? db_doc.tags,
- category: req.body.category ?? db_doc.category,
- parent_id: req.body.parent_id ?? db_doc.parent_id,
- accessibility: req.body.accessibility ?? db_doc.accessibility,
- content_markdown: req.body.content_markdown ?? db_doc.content_markdown,
- content_html: req.body.content_html ?? db_doc.content_html,
+ name: req.body.name,
+ 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,
author_id: db_doc.author_id,
updated_timestamp: Date.now().toString(),
});
diff --git a/frontend/components/MarkdownEditor/Toolbar.vue b/frontend/components/MarkdownEditor/Toolbar.vue
index e1ab55ab..9f8d698d 100644
--- a/frontend/components/MarkdownEditor/Toolbar.vue
+++ b/frontend/components/MarkdownEditor/Toolbar.vue
@@ -7,7 +7,9 @@
<option :value="3">Archive</option>
</select>
<select v-if="!minimal" v-model="copy.category" style="margin-right: 5px">
- <optgroup v-for="cat in categoriesStore.getParents" :label="cat.name" :key="cat.id">
+ <option :value="null">All notes</option>
+ <option v-for="wp in categoriesStore.getParents.filter(c => c.role == 2)" :value="wp.id" v-text="wp.name"></option>
+ <optgroup v-for="cat in categoriesStore.getParents.filter(c => c.role == 1)" :label="cat.name" :key="cat.id">
<option v-for="subCat in categoriesStore.getChilds(cat.id)" :value="subCat.id" :key="subCat.id" v-text="subCat.name"></option>
</optgroup>
</select>
diff --git a/frontend/components/Sidebar/Resizable.vue b/frontend/components/Sidebar/Resizable.vue
index 10f3f6df..6234bcf9 100644
--- a/frontend/components/Sidebar/Resizable.vue
+++ b/frontend/components/Sidebar/Resizable.vue
@@ -61,6 +61,11 @@ nav {
overflow-x: hidden;
height: 100%;
display: flex;
+ &:hover {
+ .separator {
+ background-color: var(--bg-contrast);
+ }
+ }
}
.open {
@@ -72,14 +77,6 @@ nav {
cursor: col-resize;
}
-.sidebar {
- &:hover {
- .separator {
- background-color: var(--bg-contrast);
- }
- }
-}
-
/* Disable text selection while resizing */
/* Selection can cause problems with selection */
/* PREVENT SELECTION DURING MOUSE EVENTS */
diff --git a/frontend/components/Sidebar/Sidebar.vue b/frontend/components/Sidebar/Sidebar.vue
index dd9cdec9..26ec93e7 100644
--- a/frontend/components/Sidebar/Sidebar.vue
+++ b/frontend/components/Sidebar/Sidebar.vue
@@ -1,35 +1,34 @@
<template>
<div :class="{ 'modal-mask': isMobile() && isOpened }"></div>
- <Resizable>
- <div class="sidebar">
- <section class="header">
- <span class="name">
- <IconApp />
- <NuxtLink style="font-size: 19px; font-weight: 600" to="/">Alexandrie</NuxtLink>
- </span>
- <IconClose class="btn" />
- </section>
- <input type="text" placeholder="Search or ctrl + q" class="search" v-model="filter" />
+ <Resizable class="sidebar">
+ <section class="header">
+ <span class="name">
+ <IconApp />
+ <NuxtLink style="font-size: 19px; font-weight: 600" to="/">Alexandrie</NuxtLink>
+ </span>
+ <IconClose class="btn" />
+ </section>
+ <input type="text" placeholder="Search or ctrl + q" class="search" v-model="filter" />
- <div class="user" v-if="userStore.user">
- <img :src="useAvatar(userStore.user)" alt="Avatar" style="width: 25px; height: 25px; border-radius: 50%" />
- <div class="details">
- <div>
- <div>{{ userStore.user.username }}</div>
- <div class="email">{{ userStore.user.email }}</div>
- </div>
- <Icon name="logout" @click="logoutUser" class="logout" />
+ <div class="user" v-if="userStore.user">
+ <img :src="useAvatar(userStore.user)" alt="Avatar" style="width: 25px; height: 25px; border-radius: 50%" />
+ <div class="details">
+ <div>
+ <div>{{ userStore.user.username }}</div>
+ <div class="email">{{ userStore.user.email }}</div>
</div>
+ <Icon name="logout" @click="logoutUser" class="logout" />
</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>
+ <SidebarWorkspaces :options="workspaces" />
+ <Search />
+ <CollapseItem v-for="item in items" :key="item.id" :item="item" :root="true" />
</Resizable>
</template>
<script setup lang="ts">
import CollapseItem from './CollapseItem.vue';
+import SidebarWorkspaces from './SidebarWorkspaces.vue';
import Resizable from './Resizable.vue';
import IconClose from './IconClose.vue';
import Search from './Search.vue';
@@ -37,17 +36,13 @@ import { ItemsManager, type Item } from './tree_builder';
import { navigationItems } from './helpers';
import type { Category } from '~/stores';
-const { isOpened, hasSidebar } = useSidebar();
+const { isOpened, hasSidebar, workspaceId } = useSidebar();
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 workspaces = computed(() => [{ text: 'All workspaces', value: null }, ...categoriesStore.categories.filter(c => c.role === 2).map(c => ({ text: c.name, value: c.id }))]);
const handleSearchShortCut = (e: KeyboardEvent) => {
if (e.ctrlKey && e.key === 'q') showSearchModal.value = !showSearchModal.value;
@@ -89,9 +84,9 @@ 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().filter(c => {
- if (c.data.type === 'category' && filterWorkspace.value != 'all') return c.data.workspace_id == filterWorkspace.value;
+ 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;
});
});
@@ -102,21 +97,21 @@ const handleClickOutside = (e: MouseEvent) => {
onMounted(() => {
hasSidebar.value = true;
- if (isMobile()) return window.addEventListener('click', handleClickOutside);
+ if (isMobile()) return document.addEventListener('click', handleClickOutside);
// ELSE: Desktop
isOpened.value = true;
document.addEventListener('keypress', handleSearchShortCut);
});
onBeforeUnmount(() => {
hasSidebar.value = false;
- window.removeEventListener('click', handleClickOutside);
+ document.removeEventListener('click', handleClickOutside);
document.removeEventListener('keypress', handleSearchShortCut);
});
</script>
<style scoped lang="scss">
.sidebar {
- margin: 0 0 0 10px;
+ padding: 0 0 0 10px;
}
.header {
@@ -136,7 +131,6 @@ onBeforeUnmount(() => {
align-items: center;
font-size: 1rem;
font-weight: 400;
- font-family: Inter;
}
}
diff --git a/frontend/components/AppSelectOption.vue b/frontend/components/Sidebar/SidebarWorkspace.vue
similarity index 93%
rename from frontend/components/AppSelectOption.vue
rename to frontend/components/Sidebar/SidebarWorkspace.vue
index c5cf36b1..da1a3971 100644
--- a/frontend/components/AppSelectOption.vue
+++ b/frontend/components/Sidebar/SidebarWorkspace.vue
@@ -17,13 +17,10 @@
</template>
<script setup lang="ts">
+import type { Workspace } from './helpers';
defineProps<{
- option: Option;
+ option: Workspace;
}>();
-interface Option {
- text: string;
- value: string;
-}
</script>
<style scoped lang="scss">
diff --git a/frontend/components/AppSelect.vue b/frontend/components/Sidebar/SidebarWorkspaces.vue
similarity index 75%
rename from frontend/components/AppSelect.vue
rename to frontend/components/Sidebar/SidebarWorkspaces.vue
index 7700a136..438ddc8d 100644
--- a/frontend/components/AppSelect.vue
+++ b/frontend/components/Sidebar/SidebarWorkspaces.vue
@@ -2,41 +2,34 @@
<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)">
+ <ul v-show="isOpen" class="dropdown-options">
+ <li v-for="option in options" :class="{ selected: option.value === workspaceId }" @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;
-}>();
+import AppSelectOption from './SidebarWorkspace.vue';
+import type { Workspace } from './helpers';
+const { workspaceId } = useSidebar();
+workspaceId.value = localStorage.getItem('filterWorkspace');
+
+const props = defineProps<{ options: Workspace[] }>();
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 selectedOption = computed(() => props.options.find(option => option.value == workspaceId.value) || props.options.find(option => !option.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 selectOption = (option: Workspace) => {
+ workspaceId.value = option.value;
+ if (option.value) localStorage.setItem('filterWorkspace', option.value);
+ else localStorage.removeItem('filterWorkspace');
+};
const handleClickOutside = (event: MouseEvent) => {
- if (!(event.target as HTMLElement)!.closest('.dropdown-container')) {
- closeDropdown();
- }
+ if (!(event.target as HTMLElement)!.closest('.dropdown-container')) closeDropdown();
};
onMounted(() => document.addEventListener('click', handleClickOutside));
onBeforeUnmount(() => document.removeEventListener('click', handleClickOutside));
diff --git a/frontend/components/Sidebar/helpers.ts b/frontend/components/Sidebar/helpers.ts
index 80da21fe..36cc6478 100644
--- a/frontend/components/Sidebar/helpers.ts
+++ b/frontend/components/Sidebar/helpers.ts
@@ -6,6 +6,10 @@ export interface DefaultItem {
route: string;
childrens: DefaultItem[];
}
+export interface Workspace {
+ text: string;
+ value: string | null;
+}
export const navigationItems: DefaultItem[] = [
{
diff --git a/frontend/composables/Sidebar.ts b/frontend/composables/Sidebar.ts
index 92c835d7..eb861e7f 100644
--- a/frontend/composables/Sidebar.ts
+++ b/frontend/composables/Sidebar.ts
@@ -2,6 +2,7 @@ const isOpened = ref(false);
const hasSidebar = ref(false);
const paneWidth = ref(360); // initial width of pane 1
const isResizing = ref(false);
+const workspaceId = ref<string | null>(null);
export function useSidebar() {
const toggleSidebar = () => (isOpened.value = !isOpened.value);
@@ -12,5 +13,6 @@ export function useSidebar() {
hasSidebar,
paneWidth,
isResizing,
+ workspaceId,
};
}
diff --git a/frontend/pages/dashboard/categories/new.vue b/frontend/pages/dashboard/categories/new.vue
index 71a67c89..3e2c2c48 100644
--- a/frontend/pages/dashboard/categories/new.vue
+++ b/frontend/pages/dashboard/categories/new.vue
@@ -14,7 +14,7 @@
<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>
+ <option v-for="pc in categoriesStore.getParents.filter(c => c.role == 1)" :key="pc.id" :value="pc.id">{{ pc.name }}</option>
</select>
<label>Workspace (for top categories)</label>
<select v-model="category.workspace_id">