mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
tree context menu to convert notes into attachments
This commit is contained in:
parent
735ac55bb8
commit
d232694dec
@ -147,6 +147,8 @@ class BAttachment extends AbstractBeccaEntity {
|
|||||||
if (fixedContent !== origContent) {
|
if (fixedContent !== origContent) {
|
||||||
parentNote.setContent(fixedContent);
|
parentNote.setContent(fixedContent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
noteService.asyncPostProcessContent(note, fixedContent);
|
||||||
}
|
}
|
||||||
|
|
||||||
return { note, branch };
|
return { note, branch };
|
||||||
|
@ -5,6 +5,9 @@ import noteCreateService from "../services/note_create.js";
|
|||||||
import contextMenu from "./context_menu.js";
|
import contextMenu from "./context_menu.js";
|
||||||
import appContext from "../components/app_context.js";
|
import appContext from "../components/app_context.js";
|
||||||
import noteTypesService from "../services/note_types.js";
|
import noteTypesService from "../services/note_types.js";
|
||||||
|
import server from "../services/server.js";
|
||||||
|
import toastService from "../services/toast.js";
|
||||||
|
import dialogService from "../services/dialog.js";
|
||||||
|
|
||||||
export default class TreeContextMenu {
|
export default class TreeContextMenu {
|
||||||
/**
|
/**
|
||||||
@ -66,7 +69,8 @@ export default class TreeContextMenu {
|
|||||||
{ title: 'Collapse subtree <kbd data-command="collapseSubtree"></kbd>', command: "collapseSubtree", uiIcon: "bx bx-collapse", enabled: noSelectedNotes },
|
{ title: 'Collapse subtree <kbd data-command="collapseSubtree"></kbd>', command: "collapseSubtree", uiIcon: "bx bx-collapse", enabled: noSelectedNotes },
|
||||||
{ title: "Force note sync", command: "forceNoteSync", uiIcon: "bx bx-refresh", enabled: noSelectedNotes },
|
{ title: "Force note sync", command: "forceNoteSync", uiIcon: "bx bx-refresh", enabled: noSelectedNotes },
|
||||||
{ title: 'Sort by ... <kbd data-command="sortChildNotes"></kbd>', command: "sortChildNotes", uiIcon: "bx bx-empty", enabled: noSelectedNotes && notSearch },
|
{ title: 'Sort by ... <kbd data-command="sortChildNotes"></kbd>', command: "sortChildNotes", uiIcon: "bx bx-empty", enabled: noSelectedNotes && notSearch },
|
||||||
{ title: 'Recent changes in subtree', command: "recentChangesInSubtree", uiIcon: "bx bx-history", enabled: noSelectedNotes }
|
{ title: 'Recent changes in subtree', command: "recentChangesInSubtree", uiIcon: "bx bx-history", enabled: noSelectedNotes },
|
||||||
|
{ title: 'Convert to attachment', command: "convertNoteToAttachment", uiIcon: "bx bx-empty", enabled: isNotRoot && !isHoisted }
|
||||||
] },
|
] },
|
||||||
{ title: "----" },
|
{ title: "----" },
|
||||||
{ title: "Protect subtree", command: "protectSubtree", uiIcon: "bx bx-check-shield", enabled: noSelectedNotes },
|
{ title: "Protect subtree", command: "protectSubtree", uiIcon: "bx bx-check-shield", enabled: noSelectedNotes },
|
||||||
@ -129,6 +133,27 @@ export default class TreeContextMenu {
|
|||||||
|
|
||||||
this.treeWidget.triggerCommand("openNewNoteSplit", {ntxId, notePath});
|
this.treeWidget.triggerCommand("openNewNoteSplit", {ntxId, notePath});
|
||||||
}
|
}
|
||||||
|
else if (command === 'convertNoteToAttachment') {
|
||||||
|
if (!await dialogService.confirm(`Are you sure you want to convert note selected notes into attachments of their parent notes?`)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let converted = 0;
|
||||||
|
|
||||||
|
for (const noteId of this.treeWidget.getSelectedOrActiveNoteIds(this.node)) {
|
||||||
|
const note = await froca.getNote(noteId);
|
||||||
|
|
||||||
|
if (note.isEligibleForConversionToAttachment()) {
|
||||||
|
const {attachment} = await server.post(`notes/${note.noteId}/convert-to-attachment`);
|
||||||
|
|
||||||
|
if (attachment) {
|
||||||
|
converted++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
toastService.showMessage(`${converted} notes have been converted to attachments.`);
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
this.treeWidget.triggerCommand(command, {
|
this.treeWidget.triggerCommand(command, {
|
||||||
node: this.node,
|
node: this.node,
|
||||||
|
@ -874,7 +874,7 @@ function eraseAttachments(attachmentIdsToErase) {
|
|||||||
|
|
||||||
function eraseUnusedBlobs() {
|
function eraseUnusedBlobs() {
|
||||||
const unusedBlobIds = sql.getColumn(`
|
const unusedBlobIds = sql.getColumn(`
|
||||||
SELECT blobId
|
SELECT blobs.blobId
|
||||||
FROM blobs
|
FROM blobs
|
||||||
LEFT JOIN notes ON notes.blobId = blobs.blobId
|
LEFT JOIN notes ON notes.blobId = blobs.blobId
|
||||||
LEFT JOIN attachments ON attachments.blobId = blobs.blobId
|
LEFT JOIN attachments ON attachments.blobId = blobs.blobId
|
||||||
|
Loading…
x
Reference in New Issue
Block a user