Skip to content

Build your personal knowledge base with Trilium Notes

import & export fixed

zadam55d1f9e9f086
diff --git a/src/public/javascripts/desktop.js b/src/public/javascripts/desktop.js
index 9ba8c36017..77ba2395c4 100644
--- a/src/public/javascripts/desktop.js
+++ b/src/public/javascripts/desktop.js
@@ -116,46 +116,6 @@ if (utils.isElectron()) {
});
}
-const $noteTabContainer = $("#note-tab-container");
-
-$noteTabContainer.on("click", ".export-note-button", function () {
- if ($(this).hasClass("disabled")) {
- return;
- }
-
- import('./dialogs/export.js').then(d => d.showDialog(appContext.getMainNoteTree().getActiveNode(), 'single'));
-});
-
-$noteTabContainer.on("click", ".import-files-button",
- () => import('./dialogs/import.js').then(d => d.showDialog(appContext.getMainNoteTree().getActiveNode())));
-
-async function printActiveNote() {
- if ($(this).hasClass("disabled")) {
- return;
- }
-
- const $tabContext = appContext.getActiveTabContext();
- if (!$tabContext) {
- return;
- }
-
- await libraryLoader.requireLibrary(libraryLoader.PRINT_THIS);
-
- $tabContext.$tabContent.find('.note-detail-printable:visible').printThis({
- header: $("<h2>").text($tabContext.note && $tabContext.note.title).prop('outerHTML') ,
- importCSS: false,
- loadCSS: [
- "libraries/codemirror/codemirror.css",
- "libraries/ckeditor/ckeditor-content.css"
- ],
- debug: true
- });
-}
-
-keyboardActionService.setGlobalActionHandler("PrintActiveNote", printActiveNote);
-
-$noteTabContainer.on("click", ".print-note-button", printActiveNote);
-
$('[data-toggle="tooltip"]').tooltip({
html: true
});
diff --git a/src/public/javascripts/dialogs/export.js b/src/public/javascripts/dialogs/export.js
index fc8b392bea..895eb46ea5 100644
--- a/src/public/javascripts/dialogs/export.js
+++ b/src/public/javascripts/dialogs/export.js
@@ -2,6 +2,7 @@ import treeUtils from "../services/tree_utils.js";
import utils from "../services/utils.js";
import ws from "../services/ws.js";
import toastService from "../services/toast.js";
+import treeCache from "../services/tree_cache.js";
const $dialog = $("#export-dialog");
const $form = $("#export-form");
@@ -16,7 +17,7 @@ const $opmlVersions = $("#opml-versions");
let taskId = '';
let branchId = null;
-export async function showDialog(node, defaultType) {
+export async function showDialog(notePath, defaultType) {
utils.closeActiveDialog();
// each opening of the dialog resets the taskId so we don't associate it with previous exports anymore
@@ -42,9 +43,11 @@ export async function showDialog(node, defaultType) {
$dialog.modal();
- branchId = node.data.branchId;
+ const {noteId, parentNoteId} = treeUtils.getNoteIdAndParentIdFromNotePath(notePath);
- const noteTitle = await treeUtils.getNoteTitle(node.data.noteId);
+ branchId = await treeCache.getBranchId(parentNoteId, noteId);
+
+ const noteTitle = await treeUtils.getNoteTitle(noteId);
$noteTitle.html(noteTitle);
}
diff --git a/src/public/javascripts/dialogs/import.js b/src/public/javascripts/dialogs/import.js
index d527bd6fef..828eb1d594 100644
--- a/src/public/javascripts/dialogs/import.js
+++ b/src/public/javascripts/dialogs/import.js
@@ -15,7 +15,7 @@ const $explodeArchivesCheckbox = $("#explode-archives-checkbox");
let parentNoteId = null;
-export async function showDialog(node) {
+export async function showDialog(noteId) {
utils.closeActiveDialog();
$fileUploadInput.val('').trigger('change'); // to trigger Import button disabling listener below
@@ -28,7 +28,7 @@ export async function showDialog(node) {
glob.activeDialog = $dialog;
- parentNoteId = node.data.noteId;
+ parentNoteId = noteId;
$noteTitle.text(await treeUtils.getNoteTitle(parentNoteId));
diff --git a/src/public/javascripts/services/tab_context.js b/src/public/javascripts/services/tab_context.js
index a94dabdd5f..a1961a929c 100644
--- a/src/public/javascripts/services/tab_context.js
+++ b/src/public/javascripts/services/tab_context.js
@@ -96,6 +96,10 @@ class TabContext extends Component {
}
}
+ isActive() {
+ return this.appContext.activeTabId === this.tabId;
+ }
+
getTabState() {
if (!this.notePath) {
return null;
diff --git a/src/public/javascripts/services/tree_cache.js b/src/public/javascripts/services/tree_cache.js
index 0b7eef9577..737e6c349d 100644
--- a/src/public/javascripts/services/tree_cache.js
+++ b/src/public/javascripts/services/tree_cache.js
@@ -193,6 +193,12 @@ class TreeCache {
return this.branches[branchId];
}
}
+
+ async getBranchId(parentNoteId, childNoteId) {
+ const child = await this.getNote(childNoteId);
+
+ return child.parentToBranch[parentNoteId];
+ }
}
const treeCache = new TreeCache();
diff --git a/src/public/javascripts/services/tree_context_menu.js b/src/public/javascripts/services/tree_context_menu.js
index f4b73f0181..8d268a55bd 100644
--- a/src/public/javascripts/services/tree_context_menu.js
+++ b/src/public/javascripts/services/tree_context_menu.js
@@ -99,9 +99,9 @@ class TreeContextMenu {
}
async selectContextMenuItem(event, cmd) {
- if (cmd === 'openInTab') {
- const notePath = await treeUtils.getNotePath(this.node);
+ const notePath = await treeUtils.getNotePath(this.node);
+ if (cmd === 'openInTab') {
noteDetailService.openInTab(notePath, false);
}
else if (cmd.startsWith("insertNoteAfter")) {
@@ -160,11 +160,11 @@ class TreeContextMenu {
}
else if (cmd === "export") {
const exportDialog = await import('../dialogs/export.js');
- exportDialog.showDialog(this.node,"subtree");
+ exportDialog.showDialog(notePath,"subtree");
}
else if (cmd === "importIntoNote") {
const importDialog = await import('../dialogs/import.js');
- importDialog.showDialog(this.node);
+ importDialog.showDialog(this.node.data.noteId);
}
else if (cmd === "collapseSubtree") {
this.treeWidget.collapseTree(this.node);
diff --git a/src/public/javascripts/widgets/note_actions.js b/src/public/javascripts/widgets/note_actions.js
index 089c4f2646..4676da2a71 100644
--- a/src/public/javascripts/widgets/note_actions.js
+++ b/src/public/javascripts/widgets/note_actions.js
@@ -1,4 +1,7 @@
import TabAwareWidget from "./tab_aware_widget.js";
+import appContext from "../services/app_context.js";
+import libraryLoader from "../services/library_loader.js";
+import keyboardActionService from "../services/keyboard_actions.js";
const TPL = `
<div class="dropdown note-actions">
@@ -37,7 +40,20 @@ export default class NoteActionsWidget extends TabAwareWidget {
this.$showNoteInfoButton = this.$widget.find('.show-note-info-button');
this.$showNoteInfoButton.on('click', e => this.triggerEvent(e, 'showNoteInfo'));
+ this.$printNoteButton = this.$widget.find('.print-note-button');
+ this.$printNoteButton.on('click', e => this.triggerEvent(e, 'printActiveNote'));
+
this.$exportNoteButton = this.$widget.find('.export-note-button');
+ this.$exportNoteButton.on("click", () => {
+ if (this.$exportNoteButton.hasClass("disabled")) {
+ return;
+ }
+
+ import('../dialogs/export.js').then(d => d.showDialog(this.tabContext.notePath, 'single'));
+ });
+
+ this.$importNoteButton = this.$widget.find('.import-files-button');
+ this.$importNoteButton.on("click", () => import('../dialogs/import.js').then(d => d.showDialog(this.tabContext.note.noteId)));
return this.$widget;
}
diff --git a/src/public/javascripts/widgets/note_detail.js b/src/public/javascripts/widgets/note_detail.js
index 98e303a83c..98a84d8a72 100644
--- a/src/public/javascripts/widgets/note_detail.js
+++ b/src/public/javascripts/widgets/note_detail.js
@@ -4,6 +4,7 @@ import protectedSessionHolder from "../services/protected_session_holder.js";
import appContext from "../services/app_context.js";
import SpacedUpdate from "../services/spaced_update.js";
import server from "../services/server.js";
+import libraryLoader from "../services/library_loader.js";
const TPL = `
<div class="note-detail">
@@ -182,4 +183,22 @@ export default class NoteDetailWidget extends TabAwareWidget {
await this.spacedUpdate.updateNowIfNecessary();
}
}
+
+ async printActiveNoteListener() {
+ if (!this.tabContext.isActive()) {
+ return;
+ }
+
+ await libraryLoader.requireLibrary(libraryLoader.PRINT_THIS);
+
+ this.$widget.find('.note-detail-printable:visible').printThis({
+ header: $("<h2>").text(this.tabContext.note && this.tabContext.note.title).prop('outerHTML') ,
+ importCSS: false,
+ loadCSS: [
+ "libraries/codemirror/codemirror.css",
+ "libraries/ckeditor/ckeditor-content.css"
+ ],
+ debug: true
+ });
+ }
}
\ No newline at end of file