π 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 preferences system, ressources sidebar
Smaug6739542f2f5ba4a0
diff --git a/frontend/components/Sidebar/SidebarItem.vue b/frontend/components/Sidebar/SidebarItem.vueindex 91c796fd..22b9d411 100644--- a/frontend/components/Sidebar/SidebarItem.vue+++ b/frontend/components/Sidebar/SidebarItem.vue@@ -20,6 +20,7 @@ const customClass = ref('');const icon = computed(() => {if ('color' in props.item.data) customClass.value = props.item.data.color ? `item-icon ${getAppColor(props.item.data.color as number)}` : '';if ('icon' in props.item.data && props.item.data.icon) return props.item.data.icon;+ if ('icon' in props.item && props.item.icon) return props.item.icon;if (props.item.data.type === 'category') return 'folder';if (props.item.data.type === 'document' && props.item.childrens?.length) return 'file_parent';if (props.item.data.type === 'document' && props.item.data.accessibility == 2) return 'draft';diff --git a/frontend/composables/TreeStructure.ts b/frontend/composables/TreeStructure.tsindex 596bd352..be8fd533 100644--- a/frontend/composables/TreeStructure.ts+++ b/frontend/composables/TreeStructure.ts@@ -1,4 +1,4 @@-import type { Document, Category } from '~/stores';+import type { Document, Category, DB_Ressource, Ressource } from '~/stores';import type { DefaultItem } from '../components/Sidebar/helpers';export interface ANode {@@ -8,17 +8,18 @@ export interface ANode {childrens?: ANode[];}-export interface Item<T = Document | Category | DefaultItem> extends ANode {+export interface Item<T = Document | Category | DefaultItem | Ressource> extends ANode {id: string;route: string;data: T;show: Ref<boolean>;childrens?: Item<T>[];+ icon?: string;}export class TreeStructure {public readonly items: Item[];- private itemMap: Map<string, Item>; // Utilisation de Map pour les recherches rapides- private childrenMap: Map<string, Item[]>; // Utilisation de Map pour les recherches rapides+ public itemMap: Map<string, Item>; // Utilisation de Map pour les recherches rapides+ public childrenMap: Map<string, Item[]>; // Utilisation de Map pour les recherches rapidesconstructor(items: Item[]) {this.items = items;this.itemMap = new Map(items.map(item => [item.id, item]));diff --git a/frontend/composables/structuresTree.ts b/frontend/composables/useSidebarTree.tssimilarity index 60%rename from frontend/composables/structuresTree.tsrename to frontend/composables/useSidebarTree.tsindex 502743b7..924f2ae0 100644--- a/frontend/composables/structuresTree.ts+++ b/frontend/composables/useSidebarTree.ts@@ -1,4 +1,4 @@-import { useCategoriesStore, useDocumentsStore, type Category } from '~/stores';+import { type Category } from '~/stores';function getCollapseState(id: string): boolean {const stored = localStorage.getItem(`collapse-${id}`);@@ -8,6 +8,8 @@ function getCollapseState(id: string): boolean {export function useSidebarTree() {const categoriesStore = useCategoriesStore();const documentsStore = useDocumentsStore();+ const ressourcesStore = useRessourcesStore();+ const preferencesStore = usePreferencesStore();const { workspaceId } = useSidebar();const categories = computed<Item[]>(() =>@@ -17,7 +19,6 @@ export function useSidebarTree() {label: cat.name,route: cat.parent_id ? `/dashboard/categories/${cat.id}` : '',icon: cat.icon,- type: 'category',data: cat,show: ref(getCollapseState(cat.id)),})),@@ -29,15 +30,39 @@ export function useSidebarTree() {parent_id: doc.parent_id || doc.category || '',label: doc.name,route: `/dashboard/docs/${doc.id}`,- type: 'document',+ icon: doc.accessibility == 1 ? 'file' : doc.accessibility == 2 ? 'draft' : 'archive',data: doc,show: ref(getCollapseState(doc.id)),})),);+ const ressources = computed<Item[]>(() => {+ if (!preferencesStore.get('hideSidebarRessources'))+ return ressourcesStore.getAll+ .filter(res => res.parent_id)+ .map(cat => ({+ id: cat.id,+ parent_id: cat.parent_id || '',+ label: cat.filename,+ route: `/dashboard/cdn/${cat.id}`,+ icon: 'image',+ data: cat,+ show: ref(true),+ }));+ return [];+ });- const allItems = computed(() => [...documents.value, ...categories.value.filter(cat => (cat as Item<Category>).data.role == 1)]);+ const allItems = computed(() => [...documents.value, ...ressources.value, ...categories.value.filter(cat => (cat as Item<Category>).data.role == 1)]);const structure = computed(() => new TreeStructure(allItems.value));+ // Special icons:+ for (const i of structure.value.childrenMap.keys()) {+ if (!preferencesStore.get('normalizeFileIcons')) {+ const ref = structure.value.itemMap.get(i);+ const subs = structure.value.childrenMap.get(i);+ if (ref?.data.type === 'document' && subs?.some(c => c.data.type != 'ressource')) structure.value.itemMap.get(i)!.icon = 'file_parent';+ }+ }+const tree = computed(() => structure.value.generateTree());const filtered = computed(() => {diff --git a/frontend/helpers/icons.ts b/frontend/helpers/icons.tsindex e17400a8..e0306435 100644--- a/frontend/helpers/icons.ts+++ b/frontend/helpers/icons.ts@@ -13,8 +13,9 @@ const icons = {edit: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960" fill="var(--font-color)"><path d="M200-200h57l391-391-57-57-391 391v57Zm-80 80v-170l528-527q12-11 26.5-17t30.5-6q16 0 31 6t26 18l55 56q12 11 17.5 26t5.5 30q0 16-5.5 30.5T817-647L290-120H120Zm640-584-56-56 56 56Zm-141 85-28-29 57 57-29-28Z"/></svg>`,file: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path style="fill:var(--red);" d="M200-200h360v-200h200v-360H200v560Zm0 80q-33 0-56.5-23.5T120-200v-560q0-33 23.5-56.5T200-840h560q33 0 56.5 23.5T840-760v400L600-120H200Zm80-280v-80h200v80H280Zm0-160v-80h400v80H280Zm-80 360v-560 560Z"/></svg>`,file_parent: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path style="fill:var(--green);" d="M320-320h200v-200H320v200Zm0-280h480v-200H320v200Zm280 280h200v-200H600v200Zm-280 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-560h80v560h560v80H160Z"/></svg>`,- folder: `<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" style="fill:var(--yellow)"><path style="fill:var(--yellow)" d="M160-160q-33 0-56.5-23.5T80-240v-480q0-33 23.5-56.5T160-800h240l80 80h320q33 0 56.5 23.5T880-640H447l-80-80H160v480l96-320h684L837-217q-8 26-29.5 41.5T760-160H160Zm84-80h516l72-240H316l-72 240Zm0 0 72-240-72 240Zm-84-400v-80 80Z"/></svg>`,- import: `<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#1f1f1f"><path d="m720-80 120-120-28-28-72 72v-164h-40v164l-72-72-28 28L720-80ZM480-800 243-663l237 137 237-137-237-137ZM120-321v-318q0-22 10.5-40t29.5-29l280-161q10-5 19.5-8t20.5-3q11 0 21 3t19 8l280 161q19 11 29.5 29t10.5 40v159h-80v-116L479-434 200-596v274l240 139v92L160-252q-19-11-29.5-29T120-321ZM720 0q-83 0-141.5-58.5T520-200q0-83 58.5-141.5T720-400q83 0 141.5 58.5T920-200q0 83-58.5 141.5T720 0ZM480-491Z"/></svg>`,+ folder: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960" style="fill:var(--yellow)"><path style="fill:var(--yellow)" d="M160-160q-33 0-56.5-23.5T80-240v-480q0-33 23.5-56.5T160-800h240l80 80h320q33 0 56.5 23.5T880-640H447l-80-80H160v480l96-320h684L837-217q-8 26-29.5 41.5T760-160H160Zm84-80h516l72-240H316l-72 240Zm0 0 72-240-72 240Zm-84-400v-80 80Z"/></svg>`,+ image: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><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-80h560v-560H200v560Zm40-80h480L570-480 450-320l-90-120-120 160Zm-40 80v-560 560Z"/></svg>`,+ import: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path d="m720-80 120-120-28-28-72 72v-164h-40v164l-72-72-28 28L720-80ZM480-800 243-663l237 137 237-137-237-137ZM120-321v-318q0-22 10.5-40t29.5-29l280-161q10-5 19.5-8t20.5-3q11 0 21 3t19 8l280 161q19 11 29.5 29t10.5 40v159h-80v-116L479-434 200-596v274l240 139v92L160-252q-19-11-29.5-29T120-321ZM720 0q-83 0-141.5-58.5T520-200q0-83 58.5-141.5T720-400q83 0 141.5 58.5T920-200q0 83-58.5 141.5T720 0ZM480-491Z"/></svg>`,logout: `<svg xmlns="http://www.w3.org/2000/svg" style="fill:var(--font-color);" viewBox="0 -960 960 960"><path d="M200-120q-33 0-56.5-23.5T120-200v-560q0-33 23.5-56.5T200-840h280v80H200v560h280v80H200Zm440-160-55-58 102-102H360v-80h327L585-622l55-58 200 200-200 200Z"/></svg>`,plus: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path d="M440-440H200v-80h240v-240h80v240h240v80H520v240h-80v-240Z"/></svg>`,profil: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path d="M234-276q51-39 114-61.5T480-360q69 0 132 22.5T726-276q35-41 54.5-93T800-480q0-133-93.5-226.5T480-800q-133 0-226.5 93.5T160-480q0 59 19.5 111t54.5 93Zm246-164q-59 0-99.5-40.5T340-580q0-59 40.5-99.5T480-720q59 0 99.5 40.5T620-580q0 59-40.5 99.5T480-440Zm0 360q-83 0-156-31.5T197-197q-54-54-85.5-127T80-480q0-83 31.5-156T197-763q54-54 127-85.5T480-880q83 0 156 31.5T763-763q54 54 85.5 127T880-480q0 83-31.5 156T763-197q-54 54-127 85.5T480-80Zm0-80q53 0 100-15.5t86-44.5q-39-29-86-44.5T480-280q-53 0-100 15.5T294-220q39 29 86 44.5T480-160Zm0-360q26 0 43-17t17-43q0-26-17-43t-43-17q-26 0-43 17t-17 43q0 26 17 43t43 17Zm0-60Zm0 360Z"/></svg>`,diff --git a/frontend/pages/dashboard.vue b/frontend/pages/dashboard.vueindex 2d118ebb..020e1d61 100644--- a/frontend/pages/dashboard.vue+++ b/frontend/pages/dashboard.vue@@ -12,5 +12,5 @@</template><script setup lang="ts">definePageMeta({ breadcrumb: 'Home' });-await Promise.all([useDocumentsStore().fetch(), useCategoriesStore().fetch(), useUserStore().fetch()]);+await Promise.all([useDocumentsStore().fetch(), useCategoriesStore().fetch(), useUserStore().fetch(), useRessourcesStore().fetch()]);</script>diff --git a/frontend/pages/dashboard/categories/index.vue b/frontend/pages/dashboard/categories/index.vueindex cf541c88..0084624e 100644--- a/frontend/pages/dashboard/categories/index.vue+++ b/frontend/pages/dashboard/categories/index.vue@@ -67,4 +67,9 @@ header {display: block;margin: 2px 0;}+@media screen and (max-width: 768px) {+ header {+ flex-direction: column;+ }+}</style>diff --git a/frontend/pages/dashboard/cdn.vue b/frontend/pages/dashboard/cdn.vueindex 1fe7f232..78393804 100644--- a/frontend/pages/dashboard/cdn.vue+++ b/frontend/pages/dashboard/cdn.vue@@ -4,5 +4,4 @@<script setup lang="ts">definePageMeta({ breadcrumb: 'CDN' });-useRessourcesStore().fetch();</script>diff --git a/frontend/pages/dashboard/cdn/[id].vue b/frontend/pages/dashboard/cdn/[id].vueindex 87503300..1ab1d604 100644--- a/frontend/pages/dashboard/cdn/[id].vue+++ b/frontend/pages/dashboard/cdn/[id].vue@@ -25,12 +25,17 @@<input type="text" :value="ressource.original_path" id="original_path" disabled /><label>Path</label><input type="text" :value="ressource.transformed_path" id="path" disabled />- <p>+ <p style="overflow-wrap: break-word">Ressource: <a :href="`${CDN}/${ressource.author_id}/${ressource.transformed_path || ressource.original_path}`" target="_blank">{{ `${CDN}/${ressource.author_id}/${ressource.transformed_path || ressource.original_path}` }}</a></p><div style="display: flex; justify-content: flex-end"><AppButton type="primary" class="btn primary" @click="updateCategory">Update</AppButton></div>+ <h4>Preview</h4>+ <div class="preview">+ <img v-if="ressource.filetype.startsWith('image/')" :src="`${CDN}/${ressource.author_id}/${ressource.transformed_path || ressource.original_path}`" alt="Preview" />+ <p v-else>Preview not available for this file type.</p>+ </div></form></div></template>diff --git a/frontend/pages/dashboard/settings/_views/preferences.vue b/frontend/pages/dashboard/settings/_views/preferences.vueindex 2f6f81a8..6e194cfb 100644--- a/frontend/pages/dashboard/settings/_views/preferences.vue+++ b/frontend/pages/dashboard/settings/_views/preferences.vue@@ -1,8 +1,11 @@<template><h1>Preferences</h1>- <div v-for="(option, index) in options" :key="option.id" class="form-group">- <label :for="option.id">{{ option.label }}</label>- <AppToggle :active="option.value" @toggle="toggleOption(index)" />+ <div v-for="(list, index) in options" :key="index">+ <h2>{{ list.label }}</h2>+ <div v-for="(option, index) in list.options" class="form-group">+ <label>{{ option.label }}</label>+ <AppToggle :active="option.value" @toggle="toggleOption(option)" />+ </div></div></template>@@ -12,35 +15,60 @@ const preferencesStore = usePreferencesStore();const options = ref([{- id: 'print-mode-toggle',- label: 'Enable Print Mode',- value: Boolean(preferencesStore.get('printMode')),- storageKey: 'printMode' as const,+ label: 'General',+ options: [+ {+ label: 'Enable Dark Mode',+ value: colorMode.value === 'dark',+ storageKey: 'darkMode' as const,+ onToggle: () => (colorMode.value === 'light' ? (colorMode.preference = 'dark') : (colorMode.preference = 'light')),+ },+ ],},{- id: 'dark-mode-toggle',- label: 'Enable Dark Mode',- value: colorMode.value === 'dark',- storageKey: 'darkMode' as const,- onToggle: () => (colorMode.value === 'light' ? (colorMode.preference = 'dark') : (colorMode.preference = 'light')),+ label: 'Documents',+ options: [+ {+ label: 'Enable Print Mode',+ value: Boolean(preferencesStore.get('printMode')),+ storageKey: 'printMode' as const,+ },+ {+ label: 'Hide Table of Content',+ value: Boolean(preferencesStore.get('hideTOC')),+ storageKey: 'hideTOC' as const,+ },+ ],},{- id: 'hide-toc',- label: 'Hide Table of Content',- value: Boolean(preferencesStore.get('hideTOC')),- storageKey: 'hideTOC' as const,- },- {- id: 'compact-mode',- label: 'Enable Compact Mode',- value: Boolean(preferencesStore.get('compactMode')),- storageKey: 'compactMode' as const,+ label: 'Sidebar',+ options: [+ {+ label: 'Enable Compact Mode',+ value: Boolean(preferencesStore.get('compactMode')),+ storageKey: 'compactMode' as const,+ },+ {+ label: 'Normalize file icons',+ value: Boolean(preferencesStore.get('normalizeFileIcons')),+ storageKey: 'normalizeFileIcons' as const,+ },+ {+ label: 'Hide ressources',+ value: Boolean(preferencesStore.get('hideSidebarRessources')),+ storageKey: 'hideSidebarRessources' as const,+ },+ ],},]);+interface Option {+ label: string;+ value: boolean;+ storageKey: PreferenceKey;+ onToggle?: () => void;+}-const toggleOption = (index: number) => {- const option = options.value[index];- if (!option) return;+const toggleOption = (option: Option) => {option.value = !option.value;preferencesStore.set({ key: option.storageKey, value: option.value });if (option.onToggle) option.onToggle();diff --git a/frontend/stores/db_strustures.d.ts b/frontend/stores/db_strustures.d.tsindex ecb13a87..b14a343b 100644--- a/frontend/stores/db_strustures.d.ts+++ b/frontend/stores/db_strustures.d.ts@@ -63,3 +63,7 @@ export interface DB_Ressource {author_id: string;created_timestamp: string;}++export interface Ressource extends DB_Ressource {+ type: 'ressource';+}diff --git a/frontend/stores/preferences.store.ts b/frontend/stores/preferences.store.tsindex e69de012..92544ca8 100644--- a/frontend/stores/preferences.store.ts+++ b/frontend/stores/preferences.store.ts@@ -1,6 +1,6 @@/* Store to save user local preferences *//* Only local settings with localStorage but no db or requests */-type PreferenceKey = 'printMode' | 'darkMode' | 'hideTOC' | 'compactMode';+export type PreferenceKey = 'printMode' | 'darkMode' | 'hideTOC' | 'compactMode' | 'hideSidebarRessources' | 'normalizeFileIcons';export interface Preference {key: PreferenceKey;value: any;diff --git a/frontend/stores/ressources.store.ts b/frontend/stores/ressources.store.tsindex 8c0bc46c..77e084eb 100644--- a/frontend/stores/ressources.store.ts+++ b/frontend/stores/ressources.store.ts@@ -1,9 +1,9 @@import { makeRequest } from './_utils';-import type { DB_Ressource } from './db_strustures';+import type { DB_Ressource, Ressource } from './db_strustures';export const useRessourcesStore = defineStore('ressources', {state: () => ({- ressources: ref<DB_Ressource[]>([]),+ ressources: ref<Ressource[]>([]),}),getters: {getAll: state => state.ressources,@@ -15,17 +15,17 @@ export const useRessourcesStore = defineStore('ressources', {return new Promise(async (resolve, reject) => {const request = await makeRequest(`ressources/@me`, 'GET', {});if (request.status == 'success') {- this.ressources = request.result as DB_Ressource[];+ this.ressources = (request.result as DB_Ressource[]).map((d: DB_Ressource) => ({ ...d, type: 'ressource' })) as Ressource[];resolve(this.ressources);} else reject(request.message);});},- post(ressource: FormData): Promise<DB_Ressource | string> {+ post(ressource: FormData): Promise<Ressource | string> {return new Promise(async (resolve, reject) => {const request = await makeRequest(`ressources`, 'POST', ressource);if (request.status == 'success') {- this.ressources.push(request.result as DB_Ressource);- resolve(request.result as DB_Ressource);+ this.ressources.push(request.result as Ressource);+ resolve(request.result as Ressource);} else reject(request.message);});},@@ -37,13 +37,13 @@ export const useRessourcesStore = defineStore('ressources', {} else reject(request.message);});},- update(ressource: DB_Ressource): Promise<DB_Ressource | string> {+ update(ressource: Ressource): Promise<Ressource | string> {return new Promise(async (resolve, reject) => {const request = await makeRequest(`ressources/${ressource.id}`, 'PUT', ressource);if (request.status == 'success') {const index = this.ressources.findIndex(c => c.id == ressource.id);- if (index != -1) this.ressources[index] = ressource as DB_Ressource;- resolve(request.result as DB_Ressource);+ if (index != -1) this.ressources[index] = ressource as Ressource;+ resolve(request.result as Ressource);} else reject(request.message);});},