π 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 importation module & css fixes
Smaug673936680e044546
diff --git a/frontend/composables/structuresTree.ts b/frontend/composables/structuresTree.tsindex aa897412..07fe60a5 100644--- a/frontend/composables/structuresTree.ts+++ b/frontend/composables/structuresTree.ts@@ -61,6 +61,7 @@ export function useSidebarTree() {};return {+ structure,getSubTreeById,categories,tree,diff --git a/frontend/helpers/importations.ts b/frontend/helpers/importations.tsnew file mode 100644index 00000000..fbe656be--- /dev/null+++ b/frontend/helpers/importations.ts@@ -0,0 +1,76 @@+import type { Category, DB_Category, DB_Document, DB_Ressource } from '~/stores';++interface ImportationStructure {+ documents: DB_Document[];+ categories: DB_Category[];+ ressources: DB_Ressource[];+}++function analyseFile(file: File): Promise<ImportationStructure> {+ return new Promise((resolve, reject) => {+ const reader = new FileReader();+ reader.onload = event => {+ const content = event.target?.result;+ if (typeof content === 'string') {+ try {+ const data = JSON.parse(content);+ resolve(data);+ } catch (error) {+ reject(new Error('Invalid JSON format'));+ }+ } else {+ reject(new Error('File content is not a string'));+ }+ };+ reader.onerror = () => {+ reject(new Error('Error reading file'));+ };+ reader.readAsText(file);+ });+}++function validateFileStructure(data: any): data is ImportationStructure {+ if (typeof data === 'object' && data !== null && Array.isArray(data.documents)) {+ return true;+ }+ return false;+}++function compareDocumentsAndLocal(data: ImportationStructure) {+ const diff: DB_Document[] = [];+ const local = useSidebarTree().structure.value;+ for (const doc of data.documents) {+ const localDoc = local.getItem(doc.id);+ if (!localDoc) {+ diff.push(doc);+ }+ }+ return diff;+}++function prepareNewDocuments(new_docs: Partial<DB_Document>[]) {+ // For each document, check if parent_id and category are valid+ // If not, set them to null+ const local = useSidebarTree().structure.value;+ for (const doc of new_docs) {+ if (doc.parent_id && !local.getItem(doc.parent_id)) {+ doc.parent_id = null;+ }+ if (doc.category && !local.getItem(doc.category)) {+ doc.category = undefined;+ }+ }+}++async function uploadDocument(document: DB_Document) {+ const documentsStore = useDocumentsStore();+ await documentsStore.post({ type: 'document', ...document });+}+async function uploadDocuments(documents: DB_Document[]) {+ const documentsStore = useDocumentsStore();+ for (const doc of documents) {+ await documentsStore.post({ type: 'document', ...doc });+ }+}++export { analyseFile, validateFileStructure, compareDocumentsAndLocal, prepareNewDocuments, uploadDocument, uploadDocuments };diff --git a/frontend/pages/dashboard/categories/index.vue b/frontend/pages/dashboard/categories/index.vueindex 76bbf440..7a469b3d 100644--- a/frontend/pages/dashboard/categories/index.vue+++ b/frontend/pages/dashboard/categories/index.vue@@ -1,7 +1,7 @@<template><div style="padding: 24px; gap: 16px" class="card-component"><header>- <h1 style="font-size: 20px">Workspaces & Categories</h1>+ <h1 style="font-size: 20px">Workspaces & Categories <span class="tag blue" style="padding: 6px">New</span></h1><div style="display: flex; gap: 8px"><AppButton type="primary" @click="createWorkspace">+ Workspace</AppButton><AppButton type="primary" @click="createCategory">+ Category</AppButton>@@ -51,7 +51,6 @@ header {.workspace {display: flex;flex-direction: column;- background-color: #fff;padding: 5px 15px;border-radius: 10px;border: var(--border-color) 1px solid;diff --git a/frontend/pages/dashboard/cdn.vue b/frontend/pages/dashboard/cdn.vueindex d64a4b91..ccb761ac 100644--- a/frontend/pages/dashboard/cdn.vue+++ b/frontend/pages/dashboard/cdn.vue@@ -7,7 +7,7 @@<span>{{ selectedFile.name }}</span><div class="file-size">{{ readableFileSize(selectedFile.size) }}</div></div>- <div v-else>Drop file here or <span class="clickable" @click="triggerFileSelect">click to select from computed</span>.</div>+ <div v-else>Drop file here or <span class="clickable" @click="triggerFileSelect">click to select from computer</span>.</div></div><AppButton @click="submitFile" type="primary" :disabled="!selectedFile">Upload on server</AppButton><div v-if="isLoading" class="loading-spinner"></div>diff --git a/frontend/pages/dashboard/import.vue b/frontend/pages/dashboard/import.vuenew file mode 100644index 00000000..ab994c85--- /dev/null+++ b/frontend/pages/dashboard/import.vue@@ -0,0 +1,166 @@+<template>+ <div style="padding: 24px; gap: 16px" class="card-component">+ <header>+ <h1 style="font-size: 20px">Import documents <span class="tag yellow" style="padding: 6px">Beta</span></h1>++ <p>You can import documents from a previous export. If you don't have export, you can create a new one from the <NuxtLink to="/dashboard/settings?p=backup">settings</NuxtLink> page.</p>+ </header>+ <div class="dropzone" :class="{ 'drag-over': isDragOver }" @dragover.prevent @drop.prevent="handleFileDrop" @dragenter.prevent="dragEnter" @dragleave.prevent="dragLeave">+ <input type="file" ref="fileInput" @change="handleFileSelect" />+ <div v-if="selectedFile" class="file-info">+ <span>{{ selectedFile.name }}</span>+ <div class="file-size">{{ readableFileSize(selectedFile.size) }}</div>+ </div>+ <div v-else>Drop file here or <span class="clickable" @click="triggerFileSelect">click to select from computer</span>.</div>+ </div>+ <div class="submit">+ <AppButton @click="submit" type="primary" :disabled="!selectedFile">Analyse file</AppButton>+ </div>+ <div v-if="files_to_import.length">+ <h2>Files to import</h2>+ <div v-for="file in files_to_import" :key="file.id" class="card-component" style="padding: 15px">+ <p style="display: flex">+ <Icon name="file" />+ {{ file.name }}+ <span v-if="file.tags" v-for="tag in file.tags?.split(',')" :key="tag" class="tag blue">{{ tag.trim() }}</span>+ </p>+ <p>Created at: {{ new Date(file.created_timestamp).toLocaleDateString() }}</p>+ <p>Updated at: {{ new Date(file.updated_timestamp).toLocaleDateString() }}</p>+ <AppButton type="success" @click="importDoc(file)">Import single</AppButton>+ </div>+ <p style="display: flex; justify-content: flex-end">+ <AppButton type="primary" @click="importAllDocs()">Import all documents</AppButton>+ </p>+ </div>+ </div>+</template>++<script setup lang="ts">+import { analyseFile, validateFileStructure, compareDocumentsAndLocal, prepareNewDocuments, uploadDocument, uploadDocuments } from '@/helpers/importations';+import type { DB_Document } from '~/stores';+definePageMeta({ breadcrumb: 'Importations' });++const selectedFile: Ref<File | null | undefined> = ref(null);+const isDragOver = ref(false);+const fileInput: Ref<HTMLInputElement | null> = ref(null);+const triggerFileSelect = () => fileInput.value!.click();+const handleFileSelect = (event: Event) => (selectedFile.value = (event.target as HTMLInputElement | null)?.files?.[0] || null);++const handleFileDrop = (event: DragEvent) => {+ if (event.dataTransfer?.files && event.dataTransfer.files.length > 0) {+ selectedFile.value = event.dataTransfer.files[0];+ isDragOver.value = false;+ }+};++const dragEnter = () => (isDragOver.value = true);+const dragLeave = () => (isDragOver.value = false);+const readableFileSize = (size: number): string => {+ const i = Math.floor(Math.log(size) / Math.log(1024));+ return `${(size / Math.pow(1024, i)).toFixed(2)} ${['B', 'kB', 'MB', 'GB', 'TB'][i]}`;+};++const files_to_import = ref<DB_Document[]>([]);+async function submit() {+ try {+ if (!selectedFile.value) return;+ const file = selectedFile.value;+ const fileContent = await analyseFile(file);+ const valid = validateFileStructure(fileContent);+ if (!valid) useNotifications().add({ type: 'error', title: 'Invalid file structure', timeout: 3000 });+ else useNotifications().add({ type: 'success', title: 'File structure is valid', timeout: 3000 });+ files_to_import.value = compareDocumentsAndLocal(fileContent);+ } catch (e) {+ if (e instanceof Error) useNotifications().add({ type: 'error', title: 'Error while analysing file', message: e.message, timeout: 3000 });+ else useNotifications().add({ type: 'error', title: 'Error while analysing file', message: 'Unknown error', timeout: 3000 });+ selectedFile.value = null;+ }+}+function importDoc(file: DB_Document) {+ const fileContent = files_to_import.value.find(i => i.id === file.id);+ if (!fileContent) {+ useNotifications().add({ type: 'error', title: 'File not found', timeout: 3000 });+ return;+ }+ prepareNewDocuments([fileContent]);+ uploadDocument(fileContent)+ .then(() => {+ useNotifications().add({ type: 'success', title: 'Document imported successfully', timeout: 3000 });+ files_to_import.value = files_to_import.value.filter(i => i.id !== file.id);+ })+ .catch(e => useNotifications().add({ type: 'error', title: 'Error while importing document', message: e, timeout: 3000 }));+}+function importAllDocs() {+ if (!files_to_import.value.length) return;+ const files = [...files_to_import.value];+ prepareNewDocuments(files);+ uploadDocuments(files)+ .then(() => {+ useNotifications().add({ type: 'success', title: 'Documents imported successfully', timeout: 3000 });+ files_to_import.value = [];+ })+ .catch(e => useNotifications().add({ type: 'error', title: 'Error while importing documents', message: e, timeout: 3000 }));+}+</script>++<style scoped lang="scss">+header {+ padding-bottom: 16px;+ a {+ color: $primary-color;+ }+}+.card-component {+ display: block;+ margin: 2px 0;+ width: 100%;+}++.dropzone {+ display: flex;+ align-items: center;+ justify-content: center;+ width: 100%;+ height: 150px;+ border: 2px dashed #9e9e9e;+ border-radius: 4px;+ font-size: 14px;+ color: #9e9e9e;+ position: relative;+ transition: background-color $transition-duration;+ background-color: var(--dropzone-bg, transparent);++ &:hover {+ background-color: var(--bg-contrast);+ }++ input[type='file'] {+ display: none;+ }+}++.drag-over {+ background-color: #e3f2fd;+ border-color: #2196f3;+ transition: background-color $transition-duration, border-color $transition-duration;+}++.file-info {+ display: flex;+ flex-direction: column;+ align-items: center;+ color: #2196f3;+ color: #2196f3;++ .file-size {+ font-size: 0.8rem;+ color: #757575;+ margin-top: 5px;+ }+}+.submit {+ display: flex;+ justify-content: center;+ margin-top: 10px;+}+</style>diff --git a/frontend/stores/notifications.store.ts b/frontend/stores/notifications.store.tsindex fb0f9b55..fff05a75 100644--- a/frontend/stores/notifications.store.ts+++ b/frontend/stores/notifications.store.ts@@ -1,7 +1,7 @@export interface Notification {id: number;title: string;- message: string;+ message?: string;type: 'success' | 'error' | 'warning' | 'info';timeout: number;}diff --git a/frontend/styles/_variables.scss b/frontend/styles/_variables.scssindex ba7efaa6..3e848c92 100644--- a/frontend/styles/_variables.scss+++ b/frontend/styles/_variables.scss@@ -66,11 +66,11 @@ $primary-dark: color.adjust(#007aff, $lightness: -10%);}.dark-mode {- --bg-color: #333a44;+ --bg-color: #31363F;--bg-contrast: #3d4550;--bg-contrast-2: #4e545e;--selection-color: #4a90e2;- --font-color: #e5e5e5;+ --font-color: #cccccc;--font-color-dark: #ccc;--font-color-light: rgb(179, 179, 179);--border-color: rgba(255, 255, 255, 0.1);