simplification of "add link" dialog

This commit is contained in:
zadam 2019-11-05 22:40:44 +01:00
parent d87c469fbb
commit b685d7ffb5
3 changed files with 15 additions and 96 deletions

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{
"name": "trilium",
"version": "0.36.2",
"version": "0.36.3",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

View File

@ -1,4 +1,3 @@
import cloningService from '../services/cloning.js';
import linkService from '../services/link.js';
import noteDetailService from '../services/note_detail.js';
import treeUtils from '../services/tree_utils.js';
@ -9,49 +8,18 @@ const $dialog = $("#add-link-dialog");
const $form = $("#add-link-form");
const $autoComplete = $("#note-autocomplete");
const $linkTitle = $("#link-title");
const $clonePrefix = $("#clone-prefix");
const $linkTitleFormGroup = $("#add-link-title-form-group");
const $prefixFormGroup = $("#add-link-prefix-form-group");
const $linkTypeDiv = $("#add-link-type-div");
const $linkTypes = $("input[name='add-link-type']");
const $linkTypeHtml = $linkTypes.filter('input[value="html"]');
const $addLinkTitleFormGroup = $("#add-link-title-form-group");
function setLinkType(linkType) {
$linkTypes.each(function () {
$(this).prop('checked', $(this).val() === linkType);
});
linkTypeChanged();
}
export async function showDialogForClone() {
showDialog('selected-to-active');
}
export async function showDialog(linkType) {
export async function showDialog() {
utils.closeActiveDialog();
$addLinkTitleFormGroup.toggle(!hasSelection());
glob.activeDialog = $dialog;
if (noteDetailService.getActiveTabNoteType() === 'text') {
$linkTypeHtml.prop('disabled', false);
setLinkType('html');
}
else {
$linkTypeHtml.prop('disabled', true);
setLinkType('selected-to-active');
}
if (linkType === 'selected-to-active') {
setLinkType(linkType);
}
$dialog.modal();
$autoComplete.val('').focus();
$clonePrefix.val('');
$linkTitle.val('');
async function setDefaultLinkTitle(noteId) {
@ -85,42 +53,23 @@ export async function showDialog(linkType) {
$form.submit(() => {
const notePath = $autoComplete.getSelectedPath();
const noteId = treeUtils.getNoteIdFromNotePath(notePath);
if (notePath) {
const linkType = $("input[name='add-link-type']:checked").val();
const linkTitle = $linkTitle.val();
if (linkType === 'html') {
const linkTitle = $linkTitle.val();
$dialog.modal('hide');
$dialog.modal('hide');
const linkHref = '#' + notePath;
const editor = noteDetailService.getActiveEditor();
const linkHref = '#' + notePath;
const editor = noteDetailService.getActiveEditor();
if (hasSelection()) {
editor.execute('link', linkHref);
}
else {
linkService.addLinkToEditor(linkTitle, linkHref);
}
editor.editing.view.focus();
if (hasSelection()) {
editor.execute('link', linkHref);
}
else if (linkType === 'selected-to-active') {
const prefix = $clonePrefix.val();
cloningService.cloneNoteTo(noteId, noteDetailService.getActiveTabNoteId(), prefix);
$dialog.modal('hide');
else {
linkService.addLinkToEditor(linkTitle, linkHref);
}
else if (linkType === 'active-to-selected') {
const prefix = $clonePrefix.val();
cloningService.cloneNoteTo(noteDetailService.getActiveTabNoteId(), noteId, prefix);
$dialog.modal('hide');
}
editor.editing.view.focus();
}
else {
console.error("No path to add link.");
@ -135,15 +84,4 @@ function hasSelection() {
const selection = model.document.selection;
return !selection.isCollapsed;
}
function linkTypeChanged() {
const value = $linkTypes.filter(":checked").val();
$linkTitleFormGroup.toggle(!hasSelection() && value === 'html');
$prefixFormGroup.toggle(!hasSelection() && value !== 'html');
$linkTypeDiv.toggle(!hasSelection());
}
$linkTypes.change(linkTypeChanged);
}

View File

@ -12,20 +12,6 @@
</div>
<form id="add-link-form">
<div class="modal-body">
<div id="add-link-type-div" class="radio">
<label title="Add HTML link to the selected note at cursor in active note">
<input type="radio" name="add-link-type" value="html"/>
add normal HTML link</label>
<label title="Add selected note as a child of active note">
<input type="radio" name="add-link-type" value="selected-to-active"/>
add selected note to active note</label>
<label title="Add active note as a child of the selected note">
<input type="radio" name="add-link-type" value="active-to-selected"/>
add active note to selected note</label>
</div>
<div class="form-group">
<label for="note-autocomplete">Note</label>
@ -38,11 +24,6 @@
<label for="link-title">Link title</label>
<input id="link-title" class="form-control" 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" class="form-control" style="width: 100%;">
</div>
</div>
<div class="modal-footer" style="display: flex; justify-content: space-between;">
<button type="submit" class="btn btn-primary">Add note link <kbd>enter</kbd></button>