2021-05-24 22:29:49 +02:00
|
|
|
import NoteContextAwareWidget from "../note_context_aware_widget.js";
|
|
|
|
import utils from "../../services/utils.js";
|
2022-09-15 23:09:24 +02:00
|
|
|
import branchService from "../../services/branches.js";
|
2023-05-02 22:46:39 +02:00
|
|
|
import dialogService from "../../services/dialog.js";
|
|
|
|
import server from "../../services/server.js";
|
|
|
|
import toastService from "../../services/toast.js";
|
|
|
|
import ws from "../../services/ws.js";
|
|
|
|
import appContext from "../../components/app_context.js";
|
2024-08-01 14:26:37 +08:00
|
|
|
import { t } from "../../services/i18n.js";
|
2020-01-19 13:19:40 +01:00
|
|
|
|
|
|
|
const TPL = `
|
|
|
|
<div class="dropdown note-actions">
|
2021-06-13 22:55:31 +02:00
|
|
|
<style>
|
|
|
|
.note-actions {
|
|
|
|
width: 35px;
|
|
|
|
height: 35px;
|
|
|
|
}
|
|
|
|
|
2020-02-27 00:58:10 +01:00
|
|
|
.note-actions .dropdown-menu {
|
2021-05-26 22:41:55 +02:00
|
|
|
width: 15em;
|
2020-02-27 00:58:10 +01:00
|
|
|
}
|
2020-03-25 11:28:44 +01:00
|
|
|
|
|
|
|
.note-actions .dropdown-item[disabled], .note-actions .dropdown-item[disabled]:hover {
|
|
|
|
color: var(--muted-text-color) !important;
|
|
|
|
background-color: transparent !important;
|
2020-03-29 22:15:09 +02:00
|
|
|
pointer-events: none; /* makes it unclickable */
|
2020-03-25 11:28:44 +01:00
|
|
|
}
|
2020-02-27 00:58:10 +01:00
|
|
|
</style>
|
|
|
|
|
2021-05-18 22:49:47 +02:00
|
|
|
<button type="button" data-toggle="dropdown" aria-haspopup="true"
|
2021-05-28 22:47:59 +02:00
|
|
|
aria-expanded="false" class="icon-action bx bx-dots-vertical-rounded"></button>
|
2021-05-18 22:49:47 +02:00
|
|
|
|
2020-01-19 13:19:40 +01:00
|
|
|
<div class="dropdown-menu dropdown-menu-right">
|
2024-08-01 14:26:37 +08:00
|
|
|
<a data-trigger-command="convertNoteIntoAttachment" class="dropdown-item">${t('note_actions.convert_into_attachment')}</a>
|
|
|
|
<a data-trigger-command="renderActiveNote" class="dropdown-item render-note-button"><kbd data-command="renderActiveNote"></kbd> ${t('note_actions.re_render_note')}</a>
|
|
|
|
<a data-trigger-command="findInText" class="dropdown-item find-in-text-button">${t('note_actions.search_in_note')} <kbd data-command="findInText"></kbd></a>
|
|
|
|
<a data-trigger-command="showNoteSource" class="dropdown-item show-source-button"><kbd data-command="showNoteSource"></kbd> ${t('note_actions.note_source')}</a>
|
|
|
|
<a data-trigger-command="showAttachments" class="dropdown-item"><kbd data-command="showAttachments"></kbd> ${t('note_actions.note_attachments')}</a>
|
2023-05-03 10:23:20 +02:00
|
|
|
<a data-trigger-command="openNoteExternally" class="dropdown-item open-note-externally-button"
|
2024-08-01 14:26:37 +08:00
|
|
|
title="${t('note_actions.open_note_externally_title')}">
|
2023-05-03 10:23:20 +02:00
|
|
|
<kbd data-command="openNoteExternally"></kbd>
|
2024-08-01 14:26:37 +08:00
|
|
|
${t('note_actions.open_note_externally')}
|
2023-05-03 10:23:20 +02:00
|
|
|
</a>
|
2024-08-01 14:26:37 +08:00
|
|
|
<a data-trigger-command="openNoteCustom" class="dropdown-item open-note-custom-button"><kbd data-command="openNoteCustom"></kbd> ${t('note_actions.open_note_custom')}</a>
|
|
|
|
<a class="dropdown-item import-files-button">${t('note_actions.import_files')}</a>
|
|
|
|
<a class="dropdown-item export-note-button">${t('note_actions.export_note')}</a>
|
|
|
|
<a class="dropdown-item delete-note-button">${t('note_actions.delete_note')}</a>
|
|
|
|
<a data-trigger-command="printActiveNote" class="dropdown-item print-active-note-button"><kbd data-command="printActiveNote"></kbd> ${t('note_actions.print_note')}</a>
|
|
|
|
<a data-trigger-command="forceSaveRevision" class="dropdown-item save-revision-button"><kbd data-command="forceSaveRevision"></kbd> ${t('note_actions.save_revision')}</a>
|
2020-01-19 13:19:40 +01:00
|
|
|
</div>
|
|
|
|
</div>`;
|
|
|
|
|
2021-05-22 12:35:41 +02:00
|
|
|
export default class NoteActionsWidget extends NoteContextAwareWidget {
|
2021-09-30 13:02:07 +02:00
|
|
|
isEnabled() {
|
2022-12-06 23:48:44 +01:00
|
|
|
return this.note?.type !== 'launcher';
|
2021-09-30 13:02:07 +02:00
|
|
|
}
|
|
|
|
|
2020-01-19 13:19:40 +01:00
|
|
|
doRender() {
|
|
|
|
this.$widget = $(TPL);
|
2023-09-08 00:43:18 +02:00
|
|
|
this.$widget.on('show.bs.dropdown', () => this.refreshVisibility(this.note));
|
2020-01-19 13:19:40 +01:00
|
|
|
|
2023-05-02 22:46:39 +02:00
|
|
|
this.$convertNoteIntoAttachmentButton = this.$widget.find("[data-trigger-command='convertNoteIntoAttachment']");
|
2021-10-21 21:28:44 +02:00
|
|
|
this.$findInTextButton = this.$widget.find('.find-in-text-button');
|
|
|
|
this.$printActiveNoteButton = this.$widget.find('.print-active-note-button');
|
2020-01-20 22:35:52 +01:00
|
|
|
this.$showSourceButton = this.$widget.find('.show-source-button');
|
2021-03-19 22:34:56 +01:00
|
|
|
this.$renderNoteButton = this.$widget.find('.render-note-button');
|
2020-01-21 21:43:23 +01:00
|
|
|
|
2020-01-20 22:35:52 +01:00
|
|
|
this.$exportNoteButton = this.$widget.find('.export-note-button');
|
2020-01-21 21:43:23 +01:00
|
|
|
this.$exportNoteButton.on("click", () => {
|
|
|
|
if (this.$exportNoteButton.hasClass("disabled")) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-06-16 15:04:57 +02:00
|
|
|
this.triggerCommand("showExportDialog", {
|
|
|
|
notePath: this.noteContext.notePath,
|
|
|
|
defaultType: "single"
|
|
|
|
});
|
2020-01-21 21:43:23 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
this.$importNoteButton = this.$widget.find('.import-files-button');
|
2022-06-16 14:21:24 +02:00
|
|
|
this.$importNoteButton.on("click", () => this.triggerCommand("showImportDialog", {noteId: this.noteId}));
|
2020-01-20 22:35:52 +01:00
|
|
|
|
2021-10-21 20:53:35 +02:00
|
|
|
this.$widget.on('click', '.dropdown-item', () => this.$widget.find("[data-toggle='dropdown']").dropdown('toggle'));
|
2021-04-24 21:56:44 +02:00
|
|
|
|
|
|
|
this.$openNoteExternallyButton = this.$widget.find(".open-note-externally-button");
|
2023-05-16 11:57:28 +00:00
|
|
|
this.$openNoteCustomButton = this.$widget.find(".open-note-custom-button");
|
2022-09-15 23:09:24 +02:00
|
|
|
|
|
|
|
this.$deleteNoteButton = this.$widget.find(".delete-note-button");
|
|
|
|
this.$deleteNoteButton.on("click", () => {
|
|
|
|
if (this.note.noteId === 'root') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
branchService.deleteNotes([this.note.getParentBranches()[0].branchId], true);
|
|
|
|
});
|
2020-01-19 13:19:40 +01:00
|
|
|
}
|
2020-01-20 22:35:52 +01:00
|
|
|
|
2023-09-08 00:43:18 +02:00
|
|
|
async refreshVisibility(note) {
|
2023-05-02 22:46:39 +02:00
|
|
|
this.$convertNoteIntoAttachmentButton.toggle(note.isEligibleForConversionToAttachment());
|
|
|
|
|
2023-07-17 22:32:07 +02:00
|
|
|
this.toggleDisabled(this.$findInTextButton, ['text', 'code', 'book'].includes(note.type));
|
2021-10-21 21:28:44 +02:00
|
|
|
|
2023-09-08 21:53:57 +02:00
|
|
|
this.toggleDisabled(this.$showSourceButton, ['text', 'code', 'relationMap', 'mermaid', 'canvas'].includes(note.type));
|
2021-03-19 22:34:56 +01:00
|
|
|
|
2021-10-21 21:28:44 +02:00
|
|
|
this.toggleDisabled(this.$printActiveNoteButton, ['text', 'code'].includes(note.type));
|
|
|
|
|
2021-03-19 22:34:56 +01:00
|
|
|
this.$renderNoteButton.toggle(note.type === 'render');
|
2020-03-25 11:28:44 +01:00
|
|
|
|
2023-09-08 00:43:18 +02:00
|
|
|
this.toggleDisabled(this.$openNoteExternallyButton, utils.isElectron() && !['search', 'book'].includes(note.type));
|
2023-07-17 22:32:07 +02:00
|
|
|
this.toggleDisabled(this.$openNoteCustomButton,
|
|
|
|
utils.isElectron()
|
|
|
|
&& !utils.isMac() // no implementation for Mac yet
|
2023-09-08 00:43:18 +02:00
|
|
|
&& !['search', 'book'].includes(note.type)
|
2023-07-17 22:32:07 +02:00
|
|
|
);
|
2023-07-15 09:35:03 +02:00
|
|
|
|
|
|
|
// I don't want to handle all special notes like this, but intuitively user might want to export content of backend log
|
|
|
|
this.toggleDisabled(this.$exportNoteButton, !['_backendLog'].includes(note.noteId));
|
2023-07-17 22:32:07 +02:00
|
|
|
|
|
|
|
this.toggleDisabled(this.$importNoteButton, !['search'].includes(note.type));
|
2020-04-29 00:01:07 +02:00
|
|
|
}
|
|
|
|
|
2023-05-02 22:46:39 +02:00
|
|
|
async convertNoteIntoAttachmentCommand() {
|
|
|
|
if (!await dialogService.confirm(`Are you sure you want to convert note '${this.note.title}' into an attachment of the parent note?`)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const {attachment: newAttachment} = await server.post(`notes/${this.noteId}/convert-to-attachment`);
|
|
|
|
|
|
|
|
if (!newAttachment) {
|
|
|
|
toastService.showMessage(`Converting note '${this.note.title}' failed.`);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
toastService.showMessage(`Note '${newAttachment.title}' has been converted to attachment.`);
|
|
|
|
await ws.waitForMaxKnownEntityChangeId();
|
2023-07-14 17:01:56 +02:00
|
|
|
await appContext.tabManager.getActiveContext().setNote(newAttachment.ownerId, {
|
2023-05-02 22:46:39 +02:00
|
|
|
viewScope: {
|
|
|
|
viewMode: 'attachments',
|
|
|
|
attachmentId: newAttachment.attachmentId
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-03-19 22:34:56 +01:00
|
|
|
toggleDisabled($el, enable) {
|
|
|
|
if (enable) {
|
|
|
|
$el.removeAttr('disabled');
|
|
|
|
} else {
|
|
|
|
$el.attr('disabled', 'disabled');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-29 00:01:07 +02:00
|
|
|
entitiesReloadedEvent({loadResults}) {
|
|
|
|
if (loadResults.isNoteReloaded(this.noteId)) {
|
|
|
|
this.refresh();
|
|
|
|
}
|
2020-01-20 22:35:52 +01:00
|
|
|
}
|
2020-07-03 22:27:45 +02:00
|
|
|
}
|