From dbf004d67388c4882fa45ea9be5a15f4d09bd51f Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Fri, 31 Jan 2025 21:18:24 +0200 Subject: [PATCH] feat(print): add option to print as PDF (not yet implemented) --- src/public/app/widgets/buttons/note_actions.ts | 12 ++++++++++-- src/public/app/widgets/note_detail.js | 8 ++++++++ src/public/translations/en/translation.json | 3 ++- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/public/app/widgets/buttons/note_actions.ts b/src/public/app/widgets/buttons/note_actions.ts index 047a950bb..c5a0dafcb 100644 --- a/src/public/app/widgets/buttons/note_actions.ts +++ b/src/public/app/widgets/buttons/note_actions.ts @@ -59,8 +59,12 @@ const TPL = ` + ${t("note_actions.print_note")} + + @@ -111,6 +115,7 @@ export default class NoteActionsWidget extends NoteContextAwareWidget { private $convertNoteIntoAttachmentButton!: JQuery; private $findInTextButton!: JQuery; private $printActiveNoteButton!: JQuery; + private $exportAsPdfButton!: JQuery; private $showSourceButton!: JQuery; private $showAttachmentsButton!: JQuery; private $renderNoteButton!: JQuery; @@ -136,6 +141,7 @@ export default class NoteActionsWidget extends NoteContextAwareWidget { this.$convertNoteIntoAttachmentButton = this.$widget.find("[data-trigger-command='convertNoteIntoAttachment']"); this.$findInTextButton = this.$widget.find(".find-in-text-button"); this.$printActiveNoteButton = this.$widget.find(".print-active-note-button"); + this.$exportAsPdfButton = this.$widget.find("export-as-pdf-button"); this.$showSourceButton = this.$widget.find(".show-source-button"); this.$showAttachmentsButton = this.$widget.find(".show-attachments-button"); this.$renderNoteButton = this.$widget.find(".render-note-button"); @@ -185,7 +191,9 @@ export default class NoteActionsWidget extends NoteContextAwareWidget { this.toggleDisabled(this.$showAttachmentsButton, !isInOptions); this.toggleDisabled(this.$showSourceButton, ["text", "code", "relationMap", "mermaid", "canvas", "mindMap", "geoMap"].includes(note.type)); - this.toggleDisabled(this.$printActiveNoteButton, ["text", "code"].includes(note.type)); + const canPrint = ["text", "code"].includes(note.type); + this.toggleDisabled(this.$printActiveNoteButton, canPrint); + this.toggleDisabled(this.$exportAsPdfButton, canPrint); this.$renderNoteButton.toggle(note.type === "render"); diff --git a/src/public/app/widgets/note_detail.js b/src/public/app/widgets/note_detail.js index 3fad9f138..ae38b1b93 100644 --- a/src/public/app/widgets/note_detail.js +++ b/src/public/app/widgets/note_detail.js @@ -291,6 +291,14 @@ export default class NoteDetailWidget extends NoteContextAwareWidget { }); } + async exportAsPdfEvent() { + if (!this.noteContext.isActive()) { + return; + } + + alert("Hi"); + } + hoistedNoteChangedEvent({ ntxId }) { if (this.isNoteContext(ntxId)) { this.refresh(); diff --git a/src/public/translations/en/translation.json b/src/public/translations/en/translation.json index d58f0fd56..c0d7d0eb1 100644 --- a/src/public/translations/en/translation.json +++ b/src/public/translations/en/translation.json @@ -672,7 +672,8 @@ "save_revision": "Save revision", "convert_into_attachment_failed": "Converting note '{{title}}' failed.", "convert_into_attachment_successful": "Note '{{title}}' has been converted to attachment.", - "convert_into_attachment_prompt": "Are you sure you want to convert note '{{title}}' into an attachment of the parent note?" + "convert_into_attachment_prompt": "Are you sure you want to convert note '{{title}}' into an attachment of the parent note?", + "print_pdf": "Export as PDF..." }, "onclick_button": { "no_click_handler": "Button widget '{{componentId}}' has no defined click handler"