π 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 import system & fix some local state
Smaug6739ffa18a3d8caf
diff --git a/frontend/app/App.vue b/frontend/app/App.vueindex bf50bc12..61b48694 100644--- a/frontend/app/App.vue+++ b/frontend/app/App.vue@@ -11,9 +11,17 @@// @ts-expect-error ignore missing typesimport 'virtual:svg-icons-register';-const color = usePreferences().get('primaryColor').value;-const { setAppColor } = useAppColors();useFavicon();+const preferences = usePreferences();+const { setAppColor } = useAppColors();++const primaryColor = computed(() => preferences.get('primaryColor').value);-setAppColor(Number(color));+watch(+ primaryColor,+ color => {+ setAppColor(Number(color));+ },+ { immediate: true },+);</script>diff --git a/frontend/app/composables/Preferences.ts b/frontend/app/composables/Preferences.tsindex 83e65031..6be9a90b 100644--- a/frontend/app/composables/Preferences.ts+++ b/frontend/app/composables/Preferences.ts@@ -93,12 +93,18 @@ export function usePreferences() {savePreferences();}+ function importPreferences(newPreferences: Partial<Preferences>) {+ Object.assign(preferences, newPreferences);+ savePreferences();+ }+const all = preferences;return {get,set,reset,+ importPreferences,all,};}diff --git a/frontend/app/composables/useDateFormatters.ts b/frontend/app/composables/useDateFormatters.tsindex 1c8ecb44..4a8d635d 100644--- a/frontend/app/composables/useDateFormatters.ts+++ b/frontend/app/composables/useDateFormatters.ts@@ -7,8 +7,8 @@ function shortDate(timestamp: number | undefined): string {}/** Format a timestamp to a numeric date string (e.g., "12/15/2024") */-function numericDate(timestamp: number | string): string {- return new Date(timestamp).toLocaleDateString(locale, {+function numericDate(timestamp?: number | string): string {+ return new Date(timestamp || '').toLocaleDateString(locale, {year: 'numeric',month: '2-digit',day: '2-digit',diff --git a/frontend/app/helpers/backups/index.ts b/frontend/app/helpers/backups/index.tsnew file mode 100644index 00000000..20612418--- /dev/null+++ b/frontend/app/helpers/backups/index.ts@@ -0,0 +1,85 @@+import { ZipReader, BlobReader, BlobWriter, type FileEntry } from '@zip.js/zip.js';+import type { Manifest, ManifestExtended } from './types';+import type { DB_Node } from '~/stores';++export async function readZipFile(file: File): Promise<FileEntry[]> {+ const entries: FileEntry[] = [];+ const zipReader = new ZipReader(new BlobReader(file));+ const zipEntries = await zipReader.getEntries();+ for (const entry of zipEntries) {+ if (!entry.directory && entry.filename.endsWith('.json')) {+ entries.push(entry);+ }+ }+ await zipReader.close();+ return entries;+}++async function _readJSONFile(fileEntry: FileEntry): Promise<object> {+ const blob = await fileEntry.getData!(new BlobWriter('application/json'));+ const text = await blob.text();+ const data = JSON.parse(text);+ return data;+}++export async function readBackupManifest(fileEntry: FileEntry): Promise<Manifest> {+ const data = await _readJSONFile(fileEntry);++ // Validate manifest structure+ if (typeof data !== 'object' || !('version' in data) || !('created_at' in data) || !('options' in data) || !('statistics' in data)) {+ throw new Error('Invalid manifest structure');+ }++ return data as Manifest;+}++export async function readBackupDocuments(fileEntry: FileEntry): Promise<DB_Node[]> {+ const data = (await _readJSONFile(fileEntry)) as DB_Node[];+ if (!Array.isArray(data)) {+ throw new Error('Invalid documents structure');+ }+ // Check each item+ for (const item of data) {+ if (!('name' in item) || typeof item.name !== 'string') {+ throw new Error('Invalid document item structure');+ }+ }+ return data;+}++export async function readLocalData(fileEntry: FileEntry): Promise<object> {+ const data = await _readJSONFile(fileEntry);+ return data;+}++export async function handleBackupFile(file: File): Promise<{+ manifest: Manifest;+ documents: DB_Node[] | null;+ localData: object | null;+}> {+ const entries = await readZipFile(file);+ let manifest: ManifestExtended | null = null;+ let documents: DB_Node[] | null = null;+ let localData: object | null = null;+ for (const entry of entries) {+ if (entry.filename === 'manifest.json') {+ manifest = await readBackupManifest(entry);+ } else if (entry.filename === 'documents.json') {+ documents = await readBackupDocuments(entry);+ } else if (entry.filename === 'local_data.json') {+ localData = await readLocalData(entry);+ }+ }++ if (!manifest) {+ throw new Error('Manifest file is missing in the backup');+ }+ if (localData) {+ manifest.includeSettings = true; // Indicate that settings are included in the backup+ }+ return {+ manifest,+ documents,+ localData,+ };+}diff --git a/frontend/app/helpers/backups/types.ts b/frontend/app/helpers/backups/types.tsnew file mode 100644index 00000000..3ad6969e--- /dev/null+++ b/frontend/app/helpers/backups/types.ts@@ -0,0 +1,20 @@+export interface Manifest {+ version: string;+ created_at: string;+ options: {+ include_documents: boolean;+ include_files: boolean;+ include_metadata: boolean;+ local_data: object | null;+ };+ statistics: {+ total_nodes: number;+ total_documents: number;+ total_files: number;+ total_size_bytes: number;+ };+}++export interface ManifestExtended extends Manifest {+ includeSettings?: boolean;+}diff --git a/frontend/app/helpers/node.ts b/frontend/app/helpers/node.tsindex 864a9492..dda51eb5 100644--- a/frontend/app/helpers/node.ts+++ b/frontend/app/helpers/node.ts@@ -5,10 +5,10 @@import type { DB_Node, Node } from '~/stores';/** Resolve the appropriate icon for a node based on its role and properties */-export const resolveIcon = (item: Node): string => {+export const resolveIcon = (item: Node | DB_Node): string => {if (item.icon) return item.icon;if (item.role === 1) return 'workspace';- if (item.role === 2) return item.shared ? 'shared_folder' : 'folder';+ if (item.role === 2 && 'shared' in item) return item.shared ? 'shared_folder' : 'folder';if (item.role === 3) return item.accessibility == 1 ? 'sidebar/file' : item.accessibility == 2 ? 'draft' : 'shared_doc';if (item.role === 4) return item.metadata?.filetype == 'application/pdf' ? 'pdf' : 'sidebar/image';return 'sidebar/file';@@ -22,67 +22,13 @@ export const resolveNodeLink = (node: Node): string => {return '/dashboard';};+export const getRoleName = (role: number): string => {+ const roles: Record<number, string> = { 1: 'Workspace', 2: 'Category', 3: 'Document', 4: 'Resource' };+ return roles[role] || 'Unknown';+};+/** Get human-readable type name for a node */export const resolveNodeType = (node: Node): string => {const types: Record<number, string> = { 1: 'Workspace', 2: 'Category', 3: 'Document', 4: 'Resource' };return types[node.role] || '';};--// Node importation structure-interface ImportationStructure {- nodes: DB_Node[];-}--// Analyze the uploaded file and parse its content as JSON-export 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 {- 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);- });-}--export function validateFileStructure(data: ImportationStructure): data is ImportationStructure {- if (typeof data === 'object' && data !== null && Array.isArray(data.nodes)) {- return true;- }- return false;-}--export function compareDocumentsAndLocal(data: ImportationStructure) {- const diff: DB_Node[] = [];- const local = useSidebarTree().structure.value;- for (const doc of data.nodes) {- const localDoc = local.getItem(doc.id);- if (!localDoc) {- diff.push(doc);- }- }- return diff;-}--export function prepareNewDocuments(new_docs: Partial<DB_Node>[]) {- // 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 = undefined;- }- }-}diff --git a/frontend/app/pages/dashboard/import.vue b/frontend/app/pages/dashboard/import.vuedeleted file mode 100644index 71287106..00000000--- a/frontend/app/pages/dashboard/import.vue+++ /dev/null@@ -1,115 +0,0 @@-<template>- <div class="card-component">- <header>- <h1 style="font-size: 20px">Import documents <tag class="yellow">Beta</tag></h1>- </header>- <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" style="color: var(--primary)">settings</NuxtLink> page.- </p>- <AppDrop ref="dropComponent" @select="handleFileSelect" />- <div class="submit">- <AppButton type="primary" :disabled="!selectedFile" @click="submit">Analyse file</AppButton>- </div>- <div v-if="filesToImport.length">- <h2>Files to import</h2>- <div v-for="file in filesToImport" :key="file.id" class="card-component" style="padding: 15px">- <div style="display: flex; align-items: center">- <Icon name="file" />- {{ file.name }}- <div style="margin: 0 5px">- <tag v-for="tag in file.tags?.split(',')" :key="tag" class="blue">{{ tag.trim() }}</tag>- </div>- </div>- <p>Created at: {{ numericDate(file.created_timestamp) }}</p>- <p>Updated at: {{ numericDate(file.updated_timestamp) }}</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 } from '~/helpers/node';-import type { DB_Node } from '~/stores';--definePageMeta({ breadcrumb: 'Importations' });--const { numericDate } = useDateFormatters();--const selectedFile: Ref<File | undefined> = ref();-const filesToImport = ref<DB_Node[]>([]);-const dropComponent = ref();--const handleFileSelect = (file?: File) => (selectedFile.value = file);--async function submit() {- try {- if (!selectedFile.value) return;- const fileContent = await analyseFile(selectedFile.value);- const valid = validateFileStructure(fileContent);- if (!valid) useNotifications().add({ type: 'error', title: 'Invalid file structure' });- else useNotifications().add({ type: 'success', title: 'File structure is valid' });- filesToImport.value = compareDocumentsAndLocal(fileContent);- } catch (e) {- if (e instanceof Error) useNotifications().add({ type: 'error', title: 'Error while analysing file', message: e.message });- else useNotifications().add({ type: 'error', title: 'Error while analysing file', message: 'Unknown error' });- } finally {- dropComponent.value.reset(); // Reset drop component- selectedFile.value = undefined; // Reset selected file after processing- }-}--async function uploadDocument(document: DB_Node) {- const documentsStore = useNodesStore();- await documentsStore.post(document);-}-async function uploadDocuments(documents: DB_Node[]) {- const documentsStore = useNodesStore();- for (const doc of documents) {- await documentsStore.post(doc);- }-}--function importDoc(file: DB_Node) {- const fileContent = filesToImport.value.find(i => i.id === file.id);- if (!fileContent) return useNotifications().add({ type: 'error', title: 'File not found' });- prepareNewDocuments([fileContent]);- uploadDocument(fileContent)- .then(() => {- useNotifications().add({ type: 'success', title: 'Document imported successfully' });- filesToImport.value = filesToImport.value.filter(i => i.id !== file.id);- })- .catch(e => useNotifications().add({ type: 'error', title: 'Error while importing document', message: e }));-}-function importAllDocs() {- if (!filesToImport.value.length) return;- const files = [...filesToImport.value];- prepareNewDocuments(files);- uploadDocuments(files)- .then(() => {- useNotifications().add({ type: 'success', title: 'Documents imported successfully' });- filesToImport.value = [];- })- .catch(e => useNotifications().add({ type: 'error', title: 'Error while importing documents', message: e }));-}-</script>--<style scoped lang="scss">-header {- padding-bottom: 16px;-- a {- color: var(--primary);- }-}--.submit {- display: flex;- justify-content: center;- margin-top: 10px;-}-</style>diff --git a/frontend/app/pages/dashboard/import/_components/ImportActions.vue b/frontend/app/pages/dashboard/import/_components/ImportActions.vuenew file mode 100644index 00000000..81727c95--- /dev/null+++ b/frontend/app/pages/dashboard/import/_components/ImportActions.vue@@ -0,0 +1,63 @@+<template>+ <div class="actions-card">+ <div class="import-options">+ <h3>Import Options</h3>+ <AppCheck v-model="preserveTimestamps"> Preserve original timestamps </AppCheck>+ <AppCheck v-model="skipExisting"> Skip documents that already exist (import new only) </AppCheck>+ </div>+ <div class="actions-buttons">+ <AppButton type="secondary" @click="resetImport">+ <Icon name="close" :size="16" />+ Cancel+ </AppButton>+ <AppButton type="primary" :disabled="isImporting || (toCreate.length === 0 && toUpdate.length === 0)" @click="importAll">+ <LoaderSpinner v-if="isImporting" :size="16" />+ <Icon v-else name="download" :size="16" />+ {{ isImporting ? `Importing... (${importProgress}/${importTotal})` : 'Import All' }}+ </AppButton>+ </div>+ </div>+</template>++<script setup lang="ts">+import type { DB_Node } from '~/stores';++defineProps<{+ toCreate: DB_Node[];+ toUpdate: DB_Node[];+ isImporting: boolean;+ importProgress: number;+ importTotal: number;+ resetImport: () => void;+ importAll: () => void;+}>();+const preserveTimestamps = defineModel<boolean>('preserveTimestamps');+const skipExisting = defineModel<boolean>('skipExisting');+</script>++<style scoped lang="scss">+.actions-card {+ display: flex;+ justify-content: space-between;+ align-items: center;+ padding: 1rem;+ background: var(--card-bg);+ border-radius: $radius-md;++ .import-options {+ display: flex;+ flex-direction: column;+ gap: 0.5rem;+ }+}+.actions-buttons {+ display: flex;+ gap: 0.5rem;++ button {+ display: flex;+ align-items: center;+ gap: 0.5rem;+ }+}+</style>diff --git a/frontend/app/pages/dashboard/import/_components/ImportHeader.vue b/frontend/app/pages/dashboard/import/_components/ImportHeader.vuenew file mode 100644index 00000000..000c72f5--- /dev/null+++ b/frontend/app/pages/dashboard/import/_components/ImportHeader.vue@@ -0,0 +1,117 @@+<template>+ <div class="info-card">+ <header>+ <h2>Backup Information</h2>+ <AppButton type="secondary" size="sm" class="btn-close" @click="resetImport">+ <Icon name="close" :size="14" />+ Change file+ </AppButton>+ </header>++ <div class="info-grid">+ <div class="info-item">+ <span class="label">Created</span>+ <span class="value">{{ numericDate(manifest.created_at) }}</span>+ </div>+ <div class="info-item">+ <span class="label">Version</span>+ <span class="value">{{ manifest.version }}</span>+ </div>+ <div class="info-item">+ <span class="label">Total Documents</span>+ <span class="value">{{ manifest.statistics.total_documents }}</span>+ </div>+ <div class="info-item">+ <span class="label">Total Size</span>+ <span class="value">{{ readableFileSize(manifest.statistics.total_size_bytes) }}</span>+ </div>+ </div>++ <!-- Backup options used -->+ <div class="backup-options">+ <span class="badge" :class="{ active: manifest.options.include_documents }">+ <Icon name="folder" :size="14" />+ Documents+ </span>+ <span class="badge" :class="{ active: manifest.options.include_files }">+ <Icon name="image" :size="14" />+ Files+ </span>+ <span class="badge" :class="{ active: manifest.options.include_metadata }">+ <Icon name="layers" :size="14" />+ Metadata+ </span>+ <span class="badge" :class="{ active: manifest.includeSettings }">+ <Icon name="settings" :size="14" />+ Settings+ </span>+ </div>+ </div>+</template>++<script setup lang="ts">+import type { ManifestExtended } from '~/helpers/backups/types';+import { readableFileSize } from '~/helpers/resources';+defineProps<{ manifest: ManifestExtended; resetImport: () => void }>();++const { numericDate } = useDateFormatters();+</script>++<style scoped lang="scss">+h2 {+ border-bottom: none;+}+.btn-close {+ display: flex;+ align-items: center;+}+.info-card {+ .info-grid {+ display: grid;+ grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));+ gap: 1rem;+ margin-bottom: 1rem;+ }++ .info-item {+ display: flex;+ flex-direction: column;+ gap: 0.25rem;++ .label {+ font-size: 0.75rem;+ color: var(--font-color-dark);+ text-transform: uppercase;+ }++ .value {+ font-weight: 600;+ color: var(--font-color);+ }+ }++ .backup-options {+ display: flex;+ flex-wrap: wrap;+ gap: 0.5rem;++ .badge {+ display: inline-flex;+ align-items: center;+ gap: 0.25rem;+ padding: 0.25rem 0.5rem;+ border-radius: $radius-sm;+ font-size: 0.75rem;+ background: var(--bg-color-2);+ color: var(--font-color-dark);+ opacity: 0.5;++ &.active {+ opacity: 1;+ background: var(--primary-bg);+ color: var(--primary);+ }+ }+ }+}+</style>diff --git a/frontend/app/pages/dashboard/import/_components/ImportSummary.vue b/frontend/app/pages/dashboard/import/_components/ImportSummary.vuenew file mode 100644index 00000000..4e30fa3e--- /dev/null+++ b/frontend/app/pages/dashboard/import/_components/ImportSummary.vue@@ -0,0 +1,74 @@+<template>+ <div>+ <h2>Import Summary</h2>+ <div class="stats">+ <div class="stat new">+ <Icon name="plus" :size="20" />+ <span class="count">{{ toCreate }}</span>+ <span class="label">New documents</span>+ </div>+ <div class="stat update">+ <Icon name="update" :size="20" />+ <span class="count">{{ toUpdate }}</span>+ <span class="label">Documents to update</span>+ </div>+ <div class="stat unchanged">+ <Icon name="check" :size="20" />+ <span class="count">{{ unchangedCount }}</span>+ <span class="label">Unchanged</span>+ </div>+ </div>+ </div>+</template>++<script setup lang="ts">+defineProps<{+ toCreate: number;+ toUpdate: number;+ unchangedCount: number;+}>();+</script>++<style scoped lang="scss">+.stats {+ display: flex;+ justify-content: space-around;+ flex-wrap: wrap;+ gap: 1rem;+}++.stat {+ display: flex;+ flex-direction: column;+ align-items: center;+ gap: 0.25rem;+ padding: 1rem;+ width: 200px;+ border-radius: $radius-sm;++ .count {+ font-size: 1.75rem;+ font-weight: 700;+ }++ .label {+ font-size: 0.8rem;+ color: var(--font-color-dark);+ }++ &.new {+ background: var(--green-bg);+ color: var(--green);+ }++ &.update {+ background: var(--primary-bg);+ color: var(--primary);+ }++ &.unchanged {+ background: var(--grey-bg);+ color: var(--font-color-dark);+ }+}+</style>diff --git a/frontend/app/pages/dashboard/import/_components/ImportTabs.vue b/frontend/app/pages/dashboard/import/_components/ImportTabs.vuenew file mode 100644index 00000000..acfb63c8--- /dev/null+++ b/frontend/app/pages/dashboard/import/_components/ImportTabs.vue@@ -0,0 +1,339 @@+<template>+ <div>+ <div class="tabs">+ <button :class="{ active: activeTab === 'create' }" @click="activeTab = 'create'">New Documents ({{ toCreate.length }})</button>+ <button :class="{ active: activeTab === 'update' }" @click="activeTab = 'update'">Updates ({{ toUpdate.length }})</button>+ <button :class="{ active: activeTab === 'local' }" @click="activeTab = 'local'">+ Local settings and preferences ({{ manifest?.includeSettings ? 1 : 0 }})+ </button>+ </div>++ <!-- Tab: New Documents -->+ <div v-if="activeTab === 'create'" class="tab-content">+ <div v-if="toCreate.length === 0" class="empty-state">+ <Icon name="folder" :size="32" />+ <p>No new documents to import</p>+ </div>+ <template v-else>+ <div class="list-header">+ <AppCheck v-model="selectAllCreate" @update:model-value="toggleSelectAllCreate"> Select all </AppCheck>+ <AppButton type="primary" size="sm" :disabled="selectedCreate.length === 0 || isImporting" @click="importSelected('create')">+ <LoaderSpinner v-if="isImporting" :size="14" />+ Import selected ({{ selectedCreate.length }})+ </AppButton>+ </div>+ <div class="documents-list">+ <div v-for="doc in toCreate" :key="doc.id" class="document-item">+ <AppCheck :checked="selectedCreate.includes(doc.id)" @change="toggleSelection(doc.id, 'create')" />+ <div class="doc-info">+ <Icon :name="resolveIcon(doc)" :size="18" />+ <div class="doc-details">+ <span class="doc-name">{{ doc.name }}</span>+ <span class="doc-meta">+ {{ getRoleName(doc.role) }}+ <span v-if="doc.description" class="separator">β’</span>+ {{ doc.description || '' }}+ </span>+ </div>+ </div>+ <div class="doc-actions">+ <AppButton type="ghost" size="sm">+ <Icon name="eye" :size="14" />+ </AppButton>+ <AppButton type="primary" size="sm" :disabled="isImporting" @click="importSingle(doc, 'create')"> Import </AppButton>+ </div>+ </div>+ </div>+ </template>+ </div>++ <!-- Tab: Updates -->+ <div v-if="activeTab === 'update'" class="tab-content">+ <div v-if="toUpdate.length === 0" class="empty-state">+ <Icon name="update" :size="32" />+ <p>No documents to update</p>+ </div>+ <template v-else>+ <div class="list-header">+ <AppCheck v-model="selectAllUpdate" @update:model-value="toggleSelectAllUpdate"> Select all </AppCheck>+ <AppButton type="primary" size="sm" :disabled="selectedUpdate.length === 0 || isImporting" @click="importSelected('update')">+ <LoaderSpinner v-if="isImporting" :size="14" />+ Update selected ({{ selectedUpdate.length }})+ </AppButton>+ </div>+ <div class="documents-list">+ <div v-for="doc in toUpdate" :key="doc.id" class="document-item update-item">+ <AppCheck :checked="selectedUpdate.includes(doc.id)" @change="toggleSelection(doc.id, 'update')" />+ <div class="doc-info">+ <Icon :name="resolveIcon(doc)" :size="18" />+ <div class="doc-details">+ <span class="doc-name">{{ doc.name }}</span>+ <span class="doc-meta">+ {{ getRoleName(doc.role) }}+ </span>+ </div>+ </div>+ <div class="comparison">+ <div class="version current">+ <span class="version-label">Current</span>+ <span class="version-date">{{ numericDate(getExistingNode(doc.id)?.updated_timestamp) }}</span>+ </div>+ <Icon name="arrow-right" :size="14" class="arrow" />+ <div class="version backup">+ <span class="version-label">Backup</span>+ <span class="version-date">{{ numericDate(doc.updated_timestamp) }}</span>+ </div>+ </div>+ <div class="doc-actions">+ <AppButton type="ghost" size="sm">+ <Icon name="diff" :size="14" />+ Compare+ </AppButton>+ <AppButton type="primary" size="sm" :disabled="isImporting" @click="importSingle(doc, 'update')"> Update </AppButton>+ </div>+ </div>+ </div>+ </template>+ </div>++ <!-- Tab: Local Settings -->+ <div v-if="activeTab === 'local'" class="tab-content">+ <div v-if="!manifest.includeSettings" class="empty-state">+ <Icon name="settings" :size="32" />+ <p>No local settings and preferences found in the backup</p>+ </div>+ <div v-else class="empty-state">+ <Icon name="settings" :size="32" />+ <p>Local settings and preferences can be imported</p>+ <p>Do you want to replace your local settings and preferences with those from the backup?</p>+ <p class="warning">+ <Icon name="warning" :size="14" /> This will overwrite your current local settings and preferences including <strong>your snippets</strong>+ </p>+ <AppButton type="primary" size="md" :disabled="isImporting" @click="importLocalSettings"> Import Local Settings </AppButton>+ </div>+ </div>+ </div>+</template>++<script setup lang="ts">+import { getRoleName, resolveIcon } from '~/helpers/node';+import type { DB_Node } from '~/stores';+import type { ManifestExtended } from '~/helpers/backups/types';++const props = defineProps<{ manifest: ManifestExtended; toCreate: DB_Node[]; toUpdate: DB_Node[]; isImporting: boolean }>();+const emit = defineEmits<{+ (e: 'importSingle', doc: DB_Node, type: 'create' | 'update'): void;+ (e: 'importSelected', type: 'create' | 'update', ids: string[]): void;+ (e: 'importLocalSettings'): void;+}>();++const store = useNodesStore();++const { numericDate } = useDateFormatters();++// Selection+const activeTab = ref<'create' | 'update' | 'local'>('create');+const selectedCreate = ref<string[]>([]);+const selectedUpdate = ref<string[]>([]);+const selectAllCreate = ref(false);+const selectAllUpdate = ref(false);++function toggleSelectAllCreate(value: boolean) {+ if (value) {+ selectedCreate.value = props.toCreate.map(d => d.id);+ } else {+ selectedCreate.value = [];+ }+}++function toggleSelection(id: string, type: 'create' | 'update') {+ const arr = type === 'create' ? selectedCreate : selectedUpdate;+ const idx = arr.value.indexOf(id);+ if (idx === -1) {+ arr.value.push(id);+ } else {+ arr.value.splice(idx, 1);+ }+}++function toggleSelectAllUpdate(value: boolean) {+ if (value) {+ selectedUpdate.value = props.toUpdate.map(d => d.id);+ } else {+ selectedUpdate.value = [];+ }+}+function getExistingNode(id: string): DB_Node | undefined {+ return store.getById(id);+}+function importSingle(doc: DB_Node, type: 'create' | 'update') {+ emit('importSingle', doc, type);+}+function importSelected(type: 'create' | 'update') {+ const ids = type === 'create' ? selectedCreate.value : selectedUpdate.value;+ emit('importSelected', type, ids);+}+function importLocalSettings() {+ emit('importLocalSettings');+}+</script>++<style scoped lang="scss">+// Documents Card+.tabs {+ display: flex;+ gap: 0;+ border-bottom: 1px solid var(--border-color);+ margin: -1.5rem -1.5rem 1rem;+ padding: 0 1.5rem;++ button {+ padding: 1rem 1.5rem;+ background: none;+ border: none;+ color: var(--font-color-dark);+ cursor: pointer;+ border-bottom: 2px solid transparent;+ transition: all 0.2s;++ &:hover {+ color: var(--font-color);+ }++ &.active {+ color: var(--primary);+ border-bottom-color: var(--primary);+ }+ }+}++.tab-content {+ min-height: 200px;+}++.empty-state {+ display: flex;+ flex-direction: column;+ align-items: center;+ justify-content: center;+ padding: 3rem;+ color: var(--font-color-dark);++ p {+ margin-top: 0.5rem;+ }+}++.list-header {+ display: flex;+ align-items: center;+ justify-content: space-between;+ margin-bottom: 1rem;+ padding-bottom: 1rem;+ border-bottom: 1px solid var(--border-color);+}++.documents-list {+ display: flex;+ flex-direction: column;+ gap: 0.5rem;+ max-height: 400px;+ overflow-y: auto;+}++.document-item {+ display: flex;+ align-items: center;+ gap: 1rem;+ padding: 0.75rem;+ background: var(--bg-color-2);+ border-radius: $radius-sm;+ transition: background 0.2s;++ &:hover {+ background: var(--bg-color-3);+ }++ .doc-info {+ display: flex;+ align-items: center;+ gap: 0.75rem;+ flex: 1;+ min-width: 0;+ }++ .doc-details {+ display: flex;+ flex-direction: column;+ min-width: 0;+ }++ .doc-name {+ font-weight: 500;+ white-space: nowrap;+ overflow: hidden;+ text-overflow: ellipsis;+ }++ .doc-meta {+ font-size: 0.75rem;+ color: var(--font-color-dark);++ .separator {+ margin: 0 0.25rem;+ }+ }++ .doc-actions {+ display: flex;+ gap: 0.5rem;+ flex-shrink: 0;+ }++ &.update-item {+ flex-wrap: wrap;++ .comparison {+ display: flex;+ align-items: center;+ gap: 0.5rem;+ padding: 0.25rem 0.5rem;+ background: var(--bg-color);+ border-radius: $radius-sm;+ font-size: 0.75rem;++ .version {+ display: flex;+ flex-direction: column;+ align-items: center;++ .version-label {+ font-weight: 500;+ font-size: 0.65rem;+ text-transform: uppercase;+ }++ .version-date {+ color: var(--font-color-dark);+ }++ &.backup .version-date {+ color: var(--primary);+ }+ }++ .arrow {+ color: var(--font-color-dark);+ }+ }+ }+}++.warning {+ color: var(--red);+ margin-top: 1rem;+ display: flex;+ align-items: center;+ gap: 0.5rem;+}+</style>diff --git a/frontend/app/pages/dashboard/import/index.vue b/frontend/app/pages/dashboard/import/index.vuenew file mode 100644index 00000000..bdbcde0d--- /dev/null+++ b/frontend/app/pages/dashboard/import/index.vue@@ -0,0 +1,325 @@+<template>+ <div class="import-page card-component">+ <!-- Step 1: File Selection -->+ <div v-if="step === 'select'">+ <header>+ <h1 style="font-size: 20px">Import documents <tag class="yellow">Beta</tag></h1>+ </header>+ <p>+ You can import documents from a previous export. If you don't have an export, you can create one from the+ <NuxtLink to="/dashboard/settings?p=backup" style="color: var(--primary)">settings</NuxtLink> page.+ </p>+ <AppDrop ref="dropComponent" @select="handleFileSelect as (file: File) => void" />+ <div class="submit">+ <AppButton type="primary" :disabled="!selectedFile || isAnalyzing" @click="analyzeFile">+ {{ isAnalyzing ? 'Analyzing...' : 'Analyze file' }}+ </AppButton>+ </div>+ <p v-if="analyzeError" class="error-text">{{ analyzeError }}</p>+ </div>++ <!-- Step 2: Preview & Import -->+ <template v-if="step === 'preview' && manifest">+ <!-- Backup Info Card -->+ <ImportHeader :manifest="manifest" :reset-import="resetImport" />++ <!-- Import Summary -->+ <SummaryCard :to-create="toCreate.length" :to-update="toUpdate.length" :unchanged-count="unchangedCount" />++ <!-- Tabs for New / Updates -->+ <ImportTabs+ :manifest="manifest"+ :to-create="toCreate"+ :to-update="toUpdate"+ :is-importing="isImporting"+ @import-single="importSingle"+ @import-selected="importSelected"+ @import-local-settings="importLocalSettings"+ />++ <!-- Import All Actions -->+ <ImportActions+ v-model:preserve-timestamps="importOptions.preserveTimestamps"+ v-model:skip-existing="importOptions.skipExisting"+ :to-create="toCreate"+ :to-update="toUpdate"+ :is-importing="isImporting"+ :import-progress="importProgress"+ :import-total="importTotal"+ :reset-import="resetImport"+ :import-all="importAll"+ />+ </template>+ </div>+</template>++<script setup lang="ts">+import ImportHeader from './_components/ImportHeader.vue';+import SummaryCard from './_components/ImportSummary.vue';+import ImportTabs from './_components/ImportTabs.vue';+import ImportActions from './_components/ImportActions.vue';+import { handleBackupFile } from '~/helpers/backups';+import type { Manifest } from '~/helpers/backups/types';+import type { DB_Node, Node } from '~/stores/db_strustures';++definePageMeta({ breadcrumb: 'Importations' });++const nodesStore = useNodesStore();+const notifications = useNotifications();++// State+const step = ref<'select' | 'preview'>('select');+const selectedFile = ref<File>();+const isAnalyzing = ref(false);+const analyzeError = ref('');++// Backup data+const manifest = ref<Manifest | null>(null);+const backupDocuments = ref<DB_Node[]>([]);+const toCreate = ref<DB_Node[]>([]);+const toUpdate = ref<DB_Node[]>([]);+const localData = ref<object | null>(null);++// Import state+const isImporting = ref(false);+const importProgress = ref(0);+const importTotal = ref(0);++// Options+const importOptions = reactive({+ preserveTimestamps: false,+ skipExisting: false,+});++// Computed+const unchangedCount = computed(() => {+ if (!backupDocuments.value.length) return 0;+ return backupDocuments.value.length - toCreate.value.length - toUpdate.value.length;+});++// Methods+const handleFileSelect = (file?: File) => {+ selectedFile.value = file;+ analyzeError.value = '';+};++async function analyzeFile() {+ if (!selectedFile.value) return;++ isAnalyzing.value = true;+ analyzeError.value = '';++ try {+ const result = await handleBackupFile(selectedFile.value);+ manifest.value = result.manifest;+ localData.value = result.localData;++ if (result.documents?.length) {+ backupDocuments.value = result.documents;+ const { toCreate: create, toUpdate: update } = nodesStore.prepareImport(result.documents);+ toCreate.value = create;+ toUpdate.value = update;+ } else {+ backupDocuments.value = [];+ toCreate.value = [];+ toUpdate.value = [];+ }++ step.value = 'preview';+ } catch (e) {+ analyzeError.value = e instanceof Error ? e.message : 'Failed to analyze backup file';+ } finally {+ isAnalyzing.value = false;+ }+}++function resetImport() {+ step.value = 'select';+ selectedFile.value = undefined;+ manifest.value = null;+ backupDocuments.value = [];+ toCreate.value = [];+ toUpdate.value = [];+}++function getExistingNode(id: string): Node | undefined {+ return nodesStore.nodes.get(id);+}++async function importSingle(doc: DB_Node, type: 'create' | 'update') {+ isImporting.value = true;++ try {+ if (type === 'create') {+ await nodesStore.post(prepareNodeForImport(doc));+ toCreate.value = toCreate.value.filter(d => d.id !== doc.id);+ notifications.add({ type: 'success', title: 'Imported', message: `"${doc.name}" has been imported` });+ } else {+ const nodeToUpdate = prepareNodeForUpdate(doc);+ await nodesStore.update(nodeToUpdate as Node);+ toUpdate.value = toUpdate.value.filter(d => d.id !== doc.id);+ notifications.add({ type: 'success', title: 'Updated', message: `"${doc.name}" has been updated` });+ }+ } catch {+ notifications.add({ type: 'error', title: 'Error', message: `Failed to ${type} "${doc.name}"` });+ } finally {+ isImporting.value = false;+ }+}++async function importSelected(type: 'create' | 'update', ids: string[]) {+ const docs = type === 'create' ? toCreate.value.filter(d => ids.includes(d.id)) : toUpdate.value.filter(d => ids.includes(d.id));++ isImporting.value = true;+ importProgress.value = 0;+ importTotal.value = docs.length;++ for (const doc of docs) {+ try {+ if (type === 'create') {+ await nodesStore.post(prepareNodeForImport(doc));+ toCreate.value = toCreate.value.filter(d => d.id !== doc.id);+ } else {+ const nodeToUpdate = prepareNodeForUpdate(doc);+ await nodesStore.update(nodeToUpdate as Node);+ toUpdate.value = toUpdate.value.filter(d => d.id !== doc.id);+ }+ importProgress.value++;+ } catch (e) {+ console.error(`Failed to ${type} ${doc.name}:`, e);+ }+ }++ notifications.add({+ type: 'success',+ title: 'Import complete',+ message: `${importProgress.value} documents ${type === 'create' ? 'imported' : 'updated'}`,+ });++ isImporting.value = false;+}++function importLocalSettings() {+ if (!manifest.value) return;++ const preferences = usePreferences();+ if (localData.value) {+ preferences.importPreferences(localData.value);+ notifications.add({ type: 'success', title: 'Settings Imported', message: 'Local settings have been imported successfully.' });+ } else {+ notifications.add({ type: 'error', title: 'Import Failed', message: 'No local settings found in the backup.' });+ }+}++async function importAll() {+ const createDocs = importOptions.skipExisting ? toCreate.value : toCreate.value;+ const updateDocs = importOptions.skipExisting ? [] : toUpdate.value;+ const allDocs = [...createDocs, ...updateDocs];++ isImporting.value = true;+ importProgress.value = 0;+ importTotal.value = allDocs.length;++ let successCount = 0;++ // Import new documents+ for (const doc of createDocs) {+ try {+ await nodesStore.post(prepareNodeForImport(doc));+ toCreate.value = toCreate.value.filter(d => d.id !== doc.id);+ successCount++;+ importProgress.value++;+ } catch (e) {+ console.error(`Failed to create ${doc.name}:`, e);+ }+ }++ // Update existing documents+ if (!importOptions.skipExisting) {+ for (const doc of updateDocs) {+ try {+ const nodeToUpdate = prepareNodeForUpdate(doc);+ await nodesStore.update(nodeToUpdate as Node);+ toUpdate.value = toUpdate.value.filter(d => d.id !== doc.id);+ successCount++;+ importProgress.value++;+ } catch (e) {+ console.error(`Failed to update ${doc.name}:`, e);+ }+ }+ }++ notifications.add({+ type: 'success',+ title: 'Import complete',+ message: `${successCount} documents imported successfully`,+ });++ // Reset selection+ isImporting.value = false;+}++function prepareNodeForImport(doc: DB_Node): Partial<Node> {+ const prepared: Partial<Node> = {+ name: doc.name,+ description: doc.description,+ role: doc.role,+ parent_id: doc.parent_id,+ tags: doc.tags,+ color: doc.color,+ icon: doc.icon,+ accessibility: doc.accessibility,+ access: doc.access,+ content: doc.content,+ content_compiled: doc.content_compiled,+ };++ return prepared;+}++function prepareNodeForUpdate(doc: DB_Node): Partial<Node> {+ const existing = getExistingNode(doc.id);+ if (!existing) throw new Error('Node not found');++ const updated: Node = {+ ...existing,+ name: doc.name,+ description: doc.description,+ tags: doc.tags,+ color: doc.color,+ icon: doc.icon,+ accessibility: doc.accessibility,+ access: doc.access,+ content: doc.content,+ content_compiled: doc.content_compiled,+ };++ if (importOptions.preserveTimestamps) {+ updated.updated_timestamp = doc.updated_timestamp;+ }++ return updated;+}+</script>++<style scoped lang="scss">+.import-page {+ display: flex;+ flex-direction: column;+ gap: 1.5rem;+ margin: 0 auto;+}++.submit {+ display: flex;+ justify-content: center;+ margin-top: 1rem;+}++.error-text {+ color: var(--red);+ text-align: center;+ margin-top: 0.5rem;+ font-size: 0.9rem;+}+</style>diff --git a/frontend/app/pages/dashboard/settings/_views/backups.vue b/frontend/app/pages/dashboard/settings/_views/backups.vueindex c630dc58..e43b1dca 100644--- a/frontend/app/pages/dashboard/settings/_views/backups.vue+++ b/frontend/app/pages/dashboard/settings/_views/backups.vue@@ -366,7 +366,6 @@ onUnmounted(() => {}.link-section {- margin-top: 1.5rem;padding: 1rem;background: var(--bg-color-2);border-radius: $radius-sm;diff --git a/frontend/app/stores/nodes.store.ts b/frontend/app/stores/nodes.store.tsindex 1f8b8f1d..53921385 100644--- a/frontend/app/stores/nodes.store.ts+++ b/frontend/app/stores/nodes.store.ts@@ -381,6 +381,22 @@ export const useNodesStore = defineStore('nodes', {});return { deletedIds, failedIds };},+ prepareImport(nodes: DB_Node[]): { toCreate: DB_Node[]; toUpdate: DB_Node[] } {+ const toCreate: DB_Node[] = [];+ const toUpdate: DB_Node[] = [];+ for (const backupNode of nodes) {+ const existingNode = this.nodes.get(backupNode.id);+ if (!existingNode) {+ toCreate.push(backupNode);+ } else {+ // Check if any field is different+ if (backupNode.updated_timestamp !== existingNode.updated_timestamp) {+ toUpdate.push(backupNode);+ }+ }+ }+ return { toCreate, toUpdate };+ },clear() {this.nodes.clear();this.public_nodes.clear();diff --git a/frontend/bun.lock b/frontend/bun.lockindex 7534341f..b88ac50c 100644--- a/frontend/bun.lock+++ b/frontend/bun.lock@@ -21,6 +21,7 @@"@types/markdown-it-container": "^2.0.11","@types/node": "^25.0.3","@vite-pwa/nuxt": "^1.1.0",+ "@zip.js/zip.js": "^2.8.11","eslint": "^9.39.2","eslint-config-prettier": "^10.1.8","katex": "^0.16.27",@@ -837,6 +838,8 @@"@vue/shared": ["@vue/[email protected]", "", {}, "sha512-7Z6/y3uFI5PRoKeorTOSXKcDj0MSasfNNltcslbFrPpcw6aXRUALq4IfJlaTRspiWIUOEZbrpM+iQGmCOiWe4A=="],+ "@zip.js/zip.js": ["@zip.js/[email protected]", "", {}, "sha512-0fztsk/0ryJ+2PPr9EyXS5/Co7OK8q3zY/xOoozEWaUsL5x+C0cyZ4YyMuUffOO2Dx/rAdq4JMPqW0VUtm+vzA=="],+"abbrev": ["[email protected]", "", {}, "sha512-AO2ac6pjRB3SJmGJo+v5/aK6Omggp6fsLrs6wN9bd35ulu4cCwaAU9+7ZhXjeqHVkaHThLuzH0nZr0YpCDhygg=="],"abort-controller": ["[email protected]", "", { "dependencies": { "event-target-shim": "^5.0.0" } }, "sha512-h8lQ8tacZYnR3vNQTgibj+tODHI5/+l06Au2Pcriv/Gmet0eaj4TwWH41sO9wnHDiQsEj19q0drzdWdeAHtweg=="],diff --git a/frontend/package.json b/frontend/package.jsonindex ae175835..dc8b69ff 100644--- a/frontend/package.json+++ b/frontend/package.json@@ -34,6 +34,7 @@"@types/markdown-it-container": "^2.0.11","@types/node": "^25.0.3","@vite-pwa/nuxt": "^1.1.0",+ "@zip.js/zip.js": "^2.8.11","eslint": "^9.39.2","eslint-config-prettier": "^10.1.8","katex": "^0.16.27",