mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
import & export fixed
This commit is contained in:
parent
96a7b4e45e
commit
55d1f9e9f0
@ -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
|
||||
});
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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));
|
||||
|
||||
|
@ -96,6 +96,10 @@ class TabContext extends Component {
|
||||
}
|
||||
}
|
||||
|
||||
isActive() {
|
||||
return this.appContext.activeTabId === this.tabId;
|
||||
}
|
||||
|
||||
getTabState() {
|
||||
if (!this.notePath) {
|
||||
return null;
|
||||
|
@ -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();
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
});
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user