π 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
Fix design and multiple imports of new backup system
Smaug6739c2d59bb9871a
diff --git a/frontend/app/pages/dashboard/import/_components/ImportActions.vue b/frontend/app/pages/dashboard/import/_components/ImportActions.vueindex aeded2cc..ecc0ed10 100644--- a/frontend/app/pages/dashboard/import/_components/ImportActions.vue+++ b/frontend/app/pages/dashboard/import/_components/ImportActions.vue@@ -11,28 +11,27 @@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' }}+ <Icon name="download" :size="16" />+ {{ isImporting ? 'Importing...' : 'Import All' }}</AppButton></div></div></template><script setup lang="ts">-import type { DB_Node } from '~/stores';+import type { DB_Node, ImportJob } from '~/stores';-defineProps<{+const props = defineProps<{toCreate: DB_Node[];toUpdate: DB_Node[];- isImporting: boolean;- importProgress: number;- importTotal: number;+ importJob: ImportJob;resetImport: () => void;importAll: () => void;}>();const preserveTimestamps = defineModel<boolean>('preserveTimestamps');const skipExisting = defineModel<boolean>('skipExisting');++const isImporting = computed(() => props.importJob.status === 'in_progress');</script><style scoped lang="scss">diff --git a/frontend/app/pages/dashboard/import/_components/ImportHeader.vue b/frontend/app/pages/dashboard/import/_components/ImportHeader.vueindex 000c72f5..6bb3ba58 100644--- a/frontend/app/pages/dashboard/import/_components/ImportHeader.vue+++ b/frontend/app/pages/dashboard/import/_components/ImportHeader.vue@@ -1,7 +1,7 @@<template>- <div class="info-card">+ <div><header>- <h2>Backup Information</h2>+ <h2>Backup Information <tag yellow>Beta</tag></h2><AppButton type="secondary" size="sm" class="btn-close" @click="resetImport"><Icon name="close" :size="14" />Change file@@ -61,56 +61,55 @@ const { numericDate } = useDateFormatters();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-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;+.info-item {+ display: flex;+ flex-direction: column;+ gap: 0.25rem;- .label {- font-size: 0.75rem;- color: var(--font-color-dark);- text-transform: uppercase;- }+ .label {+ font-size: 0.75rem;+ color: var(--font-color-dark);+ text-transform: uppercase;+ }- .value {- font-weight: 600;- color: var(--font-color);- }+ .value {+ font-weight: 600;+ color: var(--font-color);}+}- .backup-options {- display: flex;- flex-wrap: wrap;- gap: 0.5rem;+.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;+ .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);- }+ &.active {+ opacity: 1;+ background: var(--primary-bg);+ color: var(--primary);}}}diff --git a/frontend/app/pages/dashboard/import/_components/ImportProgress.vue b/frontend/app/pages/dashboard/import/_components/ImportProgress.vuenew file mode 100644index 00000000..5d20063e--- /dev/null+++ b/frontend/app/pages/dashboard/import/_components/ImportProgress.vue@@ -0,0 +1,99 @@+<template>+ <div class="container">+ <div class="progress-header">+ <span class="status">+ <strong>Status</strong><span class="status-badge" :class="importJob.status"> {{ statusLabel }} </span>+ </span>+ <span v-if="importJob.status === 'in_progress'" class="progress-percent"> {{ progress }}% </span>+ </div>++ <div v-if="importJob.status === 'in_progress'" class="progress-bar-container">+ <div class="progress-bar" :style="{ width: progress + '%' }"></div>+ </div>+ </div>+</template>++<script setup lang="ts">+import type { ImportJob } from '~/stores';++const props = defineProps<{ importJob: ImportJob; toCreate: number; toUpdate: number }>();++const progress = computed(() => Math.floor(((props.importJob.created.length + props.importJob.updated.length) * 100) / (props.toCreate + props.toUpdate)));+const statusLabel = computed(() => {+ switch (props.importJob.status) {+ case 'pending':+ return 'Pending';+ case 'in_progress':+ return 'In Progress';+ case 'completed':+ return 'Completed';+ case 'failed':+ return 'Failed';+ default:+ return 'Unknown';+ }+});+</script>++<style scoped lang="scss">+.progress-header {+ display: flex;+ align-items: center;+ justify-content: space-between;+ margin-bottom: 0.75rem;+}++.status {+ display: flex;+ align-items: center;+ gap: 0.5rem;+}++.status-badge {+ padding: 0.25rem 0.75rem;+ border-radius: $radius-sm;+ font-size: 0.875rem;+ font-weight: 500;++ &.pending {+ background: var(--yellow-bg);+ color: var(--yellow);+ }++ &.in_progress {+ background: var(--primary-bg);+ color: var(--primary);+ }++ &.completed {+ background: var(--green-bg);+ color: var(--green);+ }++ &.failed {+ background: var(--red-bg);+ color: var(--red);+ }+}++.progress-percent {+ font-weight: 600;+ color: var(--primary);+}++.progress-bar-container {+ width: 100%;+ height: 8px;+ background: var(--border-color);+ border-radius: 4px;+ overflow: hidden;+ margin-bottom: 0.75rem;+}++.progress-bar {+ height: 100%;+ background: var(--primary);+ border-radius: 4px;+ transition: width 0.3s ease;+}+</style>diff --git a/frontend/app/pages/dashboard/import/_components/ImportSummary.vue b/frontend/app/pages/dashboard/import/_components/ImportSummary.vueindex 4e30fa3e..75ccf5c1 100644--- a/frontend/app/pages/dashboard/import/_components/ImportSummary.vue+++ b/frontend/app/pages/dashboard/import/_components/ImportSummary.vue@@ -1,5 +1,5 @@<template>- <div>+ <div class="ctn"><h2>Import Summary</h2><div class="stats"><div class="stat new">@@ -18,18 +18,31 @@<span class="label">Unchanged</span></div></div>+ <div class="progess">+ <ImportProgress :import-job="importJob" :to-create="toCreate" :to-update="toUpdate" />+ </div></div></template><script setup lang="ts">+import ImportProgress from './ImportProgress.vue';++import type { ImportJob } from '~/stores';defineProps<{toCreate: number;toUpdate: number;unchangedCount: number;+ importJob: ImportJob;}>();</script><style scoped lang="scss">+.ctn {+ display: flex;+ flex-direction: column;+ gap: 1rem;+}+.stats {display: flex;justify-content: space-around;@@ -71,4 +84,8 @@ defineProps<{color: var(--font-color-dark);}}++.progess {+ margin-top: 1rem;+}</style>diff --git a/frontend/app/pages/dashboard/import/_components/ImportTabs.vue b/frontend/app/pages/dashboard/import/_components/ImportTabs.vueindex 259b28a9..11001036 100644--- a/frontend/app/pages/dashboard/import/_components/ImportTabs.vue+++ b/frontend/app/pages/dashboard/import/_components/ImportTabs.vue@@ -109,13 +109,12 @@<script setup lang="ts">import { getRoleName, resolveIcon } from '~/helpers/node';-import type { DB_Node } from '~/stores';+import type { DB_Node, ImportJob } from '~/stores';import type { ManifestExtended } from '~/helpers/backups/types';-const props = defineProps<{ manifest: ManifestExtended; toCreate: DB_Node[]; toUpdate: DB_Node[]; isImporting: boolean }>();+const props = defineProps<{ manifest: ManifestExtended; toCreate: DB_Node[]; toUpdate: DB_Node[]; importJob: ImportJob }>();const emit = defineEmits<{- (e: 'importSingle', doc: DB_Node, type: 'create' | 'update'): void;- (e: 'importSelected', type: 'create' | 'update', ids: string[]): void;+ (e: 'import', type: 'create' | 'update', nodeIds: string[]): void;(e: 'importLocalSettings'): void;}>();@@ -130,6 +129,8 @@ const selectedUpdate = ref<string[]>([]);const selectAllCreate = ref(false);const selectAllUpdate = ref(false);+const isImporting = computed(() => props.importJob.status === 'in_progress');+function toggleSelectAllCreate(value: boolean) {if (value) {selectedCreate.value = props.toCreate.map(d => d.id);@@ -159,11 +160,11 @@ function getExistingNode(id: string): DB_Node | undefined {return store.getById(id);}function importSingle(doc: DB_Node, type: 'create' | 'update') {- emit('importSingle', doc, type);+ emit('import', type, [doc.id]);}function importSelected(type: 'create' | 'update') {const ids = type === 'create' ? selectedCreate.value : selectedUpdate.value;- emit('importSelected', type, ids);+ emit('import', type, ids);}function importLocalSettings() {emit('importLocalSettings');@@ -186,8 +187,10 @@ function importLocalSettings() {color: var(--font-color-dark);cursor: pointer;border-bottom: 2px solid transparent;- transition: all 0.2s;+ transition: all 0.2s ease;flex: 1;+ font-size: 15px;+&:hover {color: var(--font-color);}diff --git a/frontend/app/pages/dashboard/import/index.vue b/frontend/app/pages/dashboard/import/index.vueindex e0424130..3837f7b6 100644--- a/frontend/app/pages/dashboard/import/index.vue+++ b/frontend/app/pages/dashboard/import/index.vue@@ -24,16 +24,15 @@<ImportHeader :manifest="manifest" :reset-import="resetImport" /><!-- Import Summary -->- <SummaryCard :to-create="toCreate.length" :to-update="toUpdate.length" :unchanged-count="unchangedCount" />+ <SummaryCard :to-create="toCreate.length" :to-update="toUpdate.length" :unchanged-count="unchangedCount" :import-job="importJob" /><!-- Tabs for New / Updates --><ImportTabs:manifest="manifest":to-create="toCreate":to-update="toUpdate"- :is-importing="isImporting"- @import-single="importSingle"- @import-selected="importSelected"+ :import-job="importJob"+ @import="importNodes"@import-local-settings="importLocalSettings"/>@@ -43,11 +42,9 @@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"+ :import-job="importJob"/></template></div>@@ -60,7 +57,7 @@ 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';+import type { DB_Node, ImportJob } from '~/stores/db_strustures';definePageMeta({ breadcrumb: 'Importations' });@@ -81,9 +78,14 @@ 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);+const importJob = ref<ImportJob>({+ status: 'pending',+ toCreate: 0,+ toUpdate: 0,+ created: [],+ updated: [],+ failures: 0,+});// Optionsconst importOptions = reactive({@@ -140,63 +142,35 @@ function resetImport() {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;- }+ importJob.value = {+ status: 'pending',+ toCreate: 0,+ toUpdate: 0,+ created: [],+ updated: [],+ failures: 0,+ };}-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);- }+async function importNodes(type: 'create' | 'update', ids: string[]) {+ const nodes: DB_Node[] = type === 'create' ? toCreate.value.filter(d => ids.includes(d.id)) : toUpdate.value.filter(d => ids.includes(d.id));++ if (type === 'create') {+ importJob.value.toCreate = nodes.length;+ await nodesStore.importMultipleNodes({ toCreate: nodes, toUpdate: [] }, importJob);+ toCreate.value = toCreate.value.filter(d => !importJob.value.created.includes(d.id));+ } else if (type == 'update') {+ importJob.value.toUpdate = nodes.length;+ await nodesStore.importMultipleNodes({ toCreate: [], toUpdate: nodes }, importJob);+ toUpdate.value = toUpdate.value.filter(d => !importJob.value.updated.includes(d.id));}notifications.add({type: 'success',title: 'Import complete',- message: `${importProgress.value} documents ${type === 'create' ? 'imported' : 'updated'}`,+ message: `${importJob.value.created.length + importJob.value.updated.length} documents ${type === 'create' ? 'imported' : 'updated'}`,});-- isImporting.value = false;}function importLocalSettings() {@@ -212,93 +186,21 @@ function importLocalSettings() {}async function importAll() {- const createDocs = importOptions.skipExisting ? toCreate.value : toCreate.value;+ const createDocs = 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);- }- }- }+ importJob.value.toCreate = createDocs.length;+ importJob.value.toUpdate = updateDocs.length;++ await nodesStore.importMultipleNodes({ toCreate: createDocs, toUpdate: updateDocs }, importJob);+ toCreate.value = toCreate.value.filter(d => !importJob.value.created.includes(d.id));+ toUpdate.value = toUpdate.value.filter(d => !importJob.value.updated.includes(d.id));notifications.add({type: 'success',title: 'Import complete',- message: `${successCount} documents imported successfully`,+ message: `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>diff --git a/frontend/app/stores/db_strustures.d.ts b/frontend/app/stores/db_strustures.d.tsindex 0d537fd2..bbac2ffb 100644--- a/frontend/app/stores/db_strustures.d.ts+++ b/frontend/app/stores/db_strustures.d.ts@@ -88,3 +88,15 @@ export interface ConnectionLog {type: string;timestamp: number;}++// Internal structures++export interface ImportJob {+ status: 'pending' | 'in_progress' | 'completed' | 'failed';+ toCreate: number;+ created: string[];+ toUpdate: number;+ updated: string[];+ failures: number;+ error_message?: string;+}diff --git a/frontend/app/stores/nodes.store.ts b/frontend/app/stores/nodes.store.tsindex f4a0bf7a..c90ac307 100644--- a/frontend/app/stores/nodes.store.ts+++ b/frontend/app/stores/nodes.store.ts@@ -1,6 +1,6 @@import { makeRequest, type FetchOptions } from './_utils';import { Collection } from './collection';-import type { DB_Node, Node, NodeSearchResult, Permission } from './db_strustures';+import type { DB_Node, ImportJob, Node, NodeSearchResult, Permission } from './db_strustures';export interface SearchOptions {query?: string;@@ -382,6 +382,11 @@ export const useNodesStore = defineStore('nodes', {});return { deletedIds, failedIds };},++ /* Backup import helpers */++ // Prepare nodes for import by checking which nodes need to be created or updated+ // Based on node id and updated_timestampprepareImport(nodes: DB_Node[]): { toCreate: DB_Node[]; toUpdate: DB_Node[] } {const toCreate: DB_Node[] = [];const toUpdate: DB_Node[] = [];@@ -398,6 +403,68 @@ export const useNodesStore = defineStore('nodes', {}return { toCreate, toUpdate };},+ async importMultipleNodes(nodes: { toCreate: DB_Node[]; toUpdate: DB_Node[] }, job: Ref<ImportJob>) {+ job.value.status = 'in_progress';+ try {+ await this.importAllNodes(nodes.toCreate, job);+ await this.updateAllNodes(nodes.toUpdate, job);+ job.value.status = 'completed';+ } catch (error) {+ job.value.status = 'failed';+ job.value.error_message = (error as Error).message;+ }+ },+ async importAllNodes(nodes: DB_Node[], job?: Ref<ImportJob>) {+ const nodesById = new Map(nodes.map(n => [n.id, n]));+ const corresponding: Record<string, string> = {};++ for (const node of nodes) {+ await this.importNode(node, nodesById, corresponding, job);+ }+ },+ async importNode(node: DB_Node, nodesById: Map<string, DB_Node>, corresponding: Record<string, string>, job?: Ref<ImportJob>): Promise<void> {+ // Already imported+ if (corresponding[node.id]) return;++ // Handle the parent++ if (node.parent_id && !this.getById(node.parent_id)) {+ const newParentId = corresponding[node.parent_id];++ if (!newParentId) {+ const parent = nodesById.get(node.parent_id); // Parent from the backup (future import)++ if (parent) {+ // Import the parent first+ await this.importNode(parent, nodesById, corresponding);+ } else {+ // Parent not found β detach+ delete node.parent_id;+ }+ }++ // Update parent_id after import+ if (corresponding[node.parent_id!]) {+ node.parent_id = corresponding[node.parent_id!];+ }+ }++ // Import of the node+ const res = await this.post(node);+ if (job) job.value.created.push(node.id);+ await new Promise(resolve => setTimeout(resolve, 75)); // slight delay to avoid overwhelming the server+ corresponding[node.id] = res.id;+ },++ async updateAllNodes(nodes: DB_Node[], job?: Ref<ImportJob>) {+ for (const node of nodes) {+ if (!this.getById(node.id)) continue;+ await this.update({ ...(node as Node), partial: false, shared: false, permissions: [] });+ if (job) job.value.updated.push(node.id);+ await new Promise(resolve => setTimeout(resolve, 75)); // slight delay to avoid overwhelming the server+ }+ },+clear() {this.nodes.clear();this.public_nodes.clear();diff --git a/frontend/app/styles/components.scss b/frontend/app/styles/components.scssindex f77b622f..64845855 100644--- a/frontend/app/styles/components.scss+++ b/frontend/app/styles/components.scss@@ -81,6 +81,8 @@border-radius: $radius-md;box-shadow: 0 2px 6px var(--shadow);gap: 16px;+ max-height: 100%;+ overflow: auto;header {display: flex;