Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
added cloning to the "add link" dialog
azivner84faa413215c
diff --git a/public/javascripts/dialogs/add_link.js b/public/javascripts/dialogs/add_link.jsindex bd20629210..d69d1abeca 100644--- a/public/javascripts/dialogs/add_link.js+++ b/public/javascripts/dialogs/add_link.js@@ -1,18 +1,28 @@"use strict";const addLink = (function() {- const dialogEl = $("#insert-link-dialog");- const formEl = $("#insert-link-form");+ const dialogEl = $("#add-link-dialog");+ const formEl = $("#add-link-form");const autoCompleteEl = $("#note-autocomplete");- const noteDetailEl = $('#note-detail');const linkTitleEl = $("#link-title");+ const clonePrefixEl = $("#clone-prefix");+ const linkTitleFormGroup = $("#add-link-title-form-group");+ const prefixFormGroup = $("#add-link-prefix-form-group");function showDialog() {glob.activeDialog = dialogEl;+ $('input:radio[name="add-link-type"]').filter('[value="html"]').attr('checked', true);++ linkTitleEl.val('');+ clonePrefixEl.val('');++ linkTitleFormGroup.show();+ prefixFormGroup.hide();+dialogEl.dialog({modal: true,- width: 500+ width: 700});autoCompleteEl.val('').focus();@@ -51,18 +61,48 @@ const addLink = (function() {const value = autoCompleteEl.val();const notePath = link.getNodePathFromLabel(value);+ const noteId = treeUtils.getNoteIdFromNotePath(notePath);if (notePath) {- const linkTitle = linkTitleEl.val();+ const linkType = $("input[name='add-link-type']:checked").val();++ if (linkType === 'html') {+ const linkTitle = linkTitleEl.val();++ dialogEl.dialog("close");++ link.addLinkToEditor(linkTitle, '#' + notePath);+ }+ else if (linkType === 'selected-to-current') {+ const prefix = clonePrefixEl.val();- dialogEl.dialog("close");+ treeChanges.cloneNoteTo(noteId, noteEditor.getCurrentNoteId(), prefix);- link.addLinkToEditor(linkTitle, '#' + notePath);+ dialogEl.dialog("close");+ }+ else if (linkType === 'current-to-selected') {+ const prefix = clonePrefixEl.val();++ treeChanges.cloneNoteTo(noteEditor.getCurrentNoteId(), noteId, prefix);++ dialogEl.dialog("close");+ }}return false;});+ $("input[name='add-link-type']").change(function() {+ if (this.value === 'html') {+ linkTitleFormGroup.show();+ prefixFormGroup.hide();+ }+ else {+ linkTitleFormGroup.hide();+ prefixFormGroup.show();+ }+ });+$(document).bind('keydown', 'ctrl+l', e => {showDialog();diff --git a/public/javascripts/tree_changes.js b/public/javascripts/tree_changes.jsindex 3a16b8e685..fcb387e0b2 100644--- a/public/javascripts/tree_changes.js+++ b/public/javascripts/tree_changes.js@@ -38,8 +38,10 @@ const treeChanges = (function() {});}- async function cloneNoteTo(childNoteId, parentNoteId) {- const resp = await server.put('notes/' + childNoteId + '/clone-to/' + parentNoteId);+ async function cloneNoteTo(childNoteId, parentNoteId, prefix) {+ const resp = await server.put('notes/' + childNoteId + '/clone-to/' + parentNoteId, {+ prefix: prefix+ });if (!resp.success) {alert(resp.message);diff --git a/routes/api/notes_move.js b/routes/api/notes_move.jsindex 49b8ab583a..ec4ff5f1da 100644--- a/routes/api/notes_move.js+++ b/routes/api/notes_move.js@@ -90,6 +90,7 @@ router.put('/:noteTreeId/move-after/:afterNoteTreeId', async (req, res, next) =>router.put('/:childNoteId/clone-to/:parentNoteId', auth.checkApiAuth, async (req, res, next) => {const parentNoteId = req.params.parentNoteId;const childNoteId = req.params.childNoteId;+ const prefix = req.body.prefix;const sourceId = req.headers.source_id;const existing = await sql.getSingleValue('SELECT * FROM notes_tree WHERE note_id = ? AND parent_note_id = ?', [childNoteId, parentNoteId]);@@ -116,6 +117,7 @@ router.put('/:childNoteId/clone-to/:parentNoteId', auth.checkApiAuth, async (reqnote_tree_id: utils.newNoteTreeId(),note_id: childNoteId,parent_note_id: parentNoteId,+ prefix: prefix,note_position: newNotePos,is_expanded: 0,date_modified: utils.nowDate(),diff --git a/services/build.js b/services/build.jsindex ced7c3dbc3..6b31c60957 100644--- a/services/build.js+++ b/services/build.js@@ -1 +1 @@-module.exports = { build_date:"2017-12-20T22:39:26-05:00", build_revision: "111d92bd81c23653ad4fa13b868611449aed8329" };+module.exports = { build_date:"2017-12-20T23:16:51-05:00", build_revision: "57c4465a37f7b2d67dde4dca0ba42c938c09bbbc" };diff --git a/views/index.ejs b/views/index.ejsindex 3e7190345b..6a4a47b04a 100644--- a/views/index.ejs+++ b/views/index.ejs@@ -119,18 +119,37 @@</p></div>- <div id="insert-link-dialog" title="Insert link" style="display: none;">- <form id="insert-link-form">+ <div id="add-link-dialog" title="Add link" style="display: none;">+ <form id="add-link-form">+ <div class="radio">+ <label title="Add HTML link to the selected note at cursor in current note">+ <input type="radio" name="add-link-type" value="html"/>+ add normal HTML link</label>++ <label title="Add selected note as a child of current note">+ <input type="radio" name="add-link-type" value="selected-to-current"/>+ add selected note to current note</label>++ <label title="Add current note as a child of the selected note">+ <input type="radio" name="add-link-type" value="current-to-selected"/>+ add current note to selected note</label>+ </div>+<div class="form-group">- <label for="note-autocomplete">Link to note</label>+ <label for="note-autocomplete">Note</label><input id="note-autocomplete" style="width: 100%;"></div>- <div class="form-group">+ <div class="form-group" id="add-link-title-form-group"><label for="link-title">Link title</label><input id="link-title" style="width: 100%;"></div>+ <div class="form-group" id="add-link-prefix-form-group" title="Cloned note will be shown in note tree with given prefix">+ <label for="clone-prefix">Prefix (optional)</label>+ <input id="clone-prefix" style="width: 100%;">+ </div>+<button class="btn btn-sm">Add link</button></form></div>