clone to notes now has overview of notes to clone and is available from context menu

This commit is contained in:
zadam 2019-11-10 22:06:43 +01:00
parent 7539e6a616
commit b53e2a3570
5 changed files with 44 additions and 18 deletions

View File

@ -2,7 +2,6 @@ import noteAutocompleteService from "../services/note_autocomplete.js";
import utils from "../services/utils.js";
import cloningService from "../services/cloning.js";
import treeUtils from "../services/tree_utils.js";
import noteDetailService from "../services/note_detail.js";
import toastService from "../services/toast.js";
import treeCache from "../services/tree_cache.js";
@ -10,14 +9,17 @@ const $dialog = $("#clone-to-dialog");
const $form = $("#clone-to-form");
const $noteAutoComplete = $("#clone-to-note-autocomplete");
const $clonePrefix = $("#clone-prefix");
const $noteList = $("#clone-to-note-list");
let clonedNoteId;
let clonedNoteIds;
export async function showDialog(noteId) {
clonedNoteId = noteId || noteDetailService.getActiveTabNoteId();
export async function showDialog(noteIds) {
clonedNoteIds = [];
if (!clonedNoteId) {
return;
for (const noteId of noteIds) {
if (!clonedNoteIds.includes(noteId)) {
clonedNoteIds.push(noteId);
}
}
utils.closeActiveDialog();
@ -28,24 +30,38 @@ export async function showDialog(noteId) {
$noteAutoComplete.val('').trigger('focus');
$noteList.empty();
for (const noteId of clonedNoteIds) {
const note = await treeCache.getNote(noteId);
$noteList.append($("<li>").text(note.title));
}
noteAutocompleteService.initNoteAutocomplete($noteAutoComplete);
noteAutocompleteService.showRecentNotes($noteAutoComplete);
}
async function cloneNotesTo(notePath) {
const targetNoteId = treeUtils.getNoteIdFromNotePath(notePath);
for (const cloneNoteId of clonedNoteIds) {
await cloningService.cloneNoteTo(cloneNoteId, targetNoteId, $clonePrefix.val());
const clonedNote = await treeCache.getNote(cloneNoteId);
const targetNote = await treeCache.getNote(targetNoteId);
toastService.showMessage(`Note "${clonedNote.title}" has been cloned into ${targetNote.title}`);
}
}
$form.on('submit', () => {
const notePath = $noteAutoComplete.getSelectedPath();
if (notePath) {
$dialog.modal('hide');
const targetNoteId = treeUtils.getNoteIdFromNotePath(notePath);
cloningService.cloneNoteTo(clonedNoteId, targetNoteId, $clonePrefix.val()).then(async () => {
const clonedNote = await treeCache.getNote(clonedNoteId);
const targetNote = await treeCache.getNote(targetNoteId);
toastService.showMessage(`Note "${clonedNote.title}" has been cloned into ${targetNote.title}`);
});
cloneNotesTo(notePath);
}
else {
console.error("No path to clone to.");

View File

@ -16,7 +16,6 @@ const HELP = "../dialogs/help.js";
const NOTE_INFO = "../dialogs/note_info.js";
const ABOUT = "../dialogs/about.js";
const LINK_MAP = "../dialogs/link_map.js";
const CLONE_TO = "../dialogs/clone_to.js";
function registerEntrypoints() {
// hot keys are active also inside inputs and content editables
@ -185,8 +184,6 @@ function registerEntrypoints() {
return false;
});
utils.bindGlobalShortcut('ctrl+e', () => import(CLONE_TO).then(d => d.showDialog()));
}
export default {

View File

@ -342,6 +342,7 @@ function getSelectedOrActiveNodes(node) {
if (notes.length === 0) {
notes.push(node);
}
return notes;
}

View File

@ -64,6 +64,8 @@ class TreeContextMenu {
{ title: "----" },
{ title: "Copy / clone <kbd>Ctrl+C</kbd>", cmd: "copy", uiIcon: "copy",
enabled: isNotRoot },
{ title: "Clone to ...", cmd: "cloneTo", uiIcon: "empty",
enabled: isNotRoot },
{ title: "Cut <kbd>Ctrl+X</kbd>", cmd: "cut", uiIcon: "cut",
enabled: isNotRoot && !isHoisted && parentNotSearch },
{ title: "Paste into <kbd>Ctrl+V</kbd>", cmd: "pasteInto", uiIcon: "paste",
@ -121,6 +123,12 @@ class TreeContextMenu {
else if (cmd === "copy") {
clipboard.copy(treeService.getSelectedOrActiveNodes(this.node));
}
else if (cmd === "cloneTo") {
const nodes = treeService.getSelectedOrActiveNodes(this.node);
const noteIds = nodes.map(node => node.data.noteId);
import("../dialogs/clone_to.js").then(d => d.showDialog(noteIds))
}
else if (cmd === "cut") {
clipboard.cut(treeService.getSelectedOrActiveNodes(this.node));
}

View File

@ -2,7 +2,7 @@
<div class="modal-dialog modal-lg" style="max-width: 1000px" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title mr-auto">Clone note to ...</h5>
<h5 class="modal-title mr-auto">Clone notes to ...</h5>
<button type="button" class="help-button" title="Help on links" data-help-page="Cloning-notes">?</button>
@ -12,6 +12,10 @@
</div>
<form id="clone-to-form">
<div class="modal-body">
<h5>Notes to clone</h5>
<ul id="clone-to-note-list" style="max-height: 200px; overflow: auto;"></ul>
<div class="form-group">
<label for="clone-to-note-autocomplete">Target parent note</label>