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.");