mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 09:58:32 +02:00
unify API for creating note links
This commit is contained in:
parent
b8d6ff0542
commit
d467db2227
@ -44,7 +44,10 @@ export async function showDialog() {
|
||||
const note = await treeCache.getNote(change.noteId);
|
||||
const notePath = await treeService.getSomeNotePath(note);
|
||||
|
||||
noteLink = await linkService.createNoteLinkWithPath(notePath, change.title);
|
||||
noteLink = await linkService.createNoteLink(notePath, {
|
||||
title: change.title,
|
||||
showNotePath: true
|
||||
});
|
||||
}
|
||||
|
||||
changesListEl.append($('<li>')
|
||||
|
@ -9,7 +9,11 @@ function getNotePathFromUrl(url) {
|
||||
return notePathMatch === null ? null : notePathMatch[1];
|
||||
}
|
||||
|
||||
async function createNoteLink(notePath, noteTitle = null, tooltip = true) {
|
||||
async function createNoteLink(notePath, options = {}) {
|
||||
let noteTitle = options.title;
|
||||
const showTooltip = options.showTooltip === undefined ? true : options.showTooltip;
|
||||
const showNotePath = options.showNotePath === undefined ? false : options.showNotePath;
|
||||
|
||||
if (!noteTitle) {
|
||||
const {noteId, parentNoteId} = treeUtils.getNoteIdAndParentIdFromNotePath(notePath);
|
||||
|
||||
@ -22,30 +26,26 @@ async function createNoteLink(notePath, noteTitle = null, tooltip = true) {
|
||||
}).attr('data-action', 'note')
|
||||
.attr('data-note-path', notePath);
|
||||
|
||||
if (!tooltip) {
|
||||
if (!showTooltip) {
|
||||
$noteLink.addClass("no-tooltip-preview");
|
||||
}
|
||||
|
||||
return $noteLink;
|
||||
}
|
||||
const $container = $("<span>").append($noteLink);
|
||||
|
||||
async function createNoteLinkWithPath(notePath, noteTitle = null) {
|
||||
const $link = await createNoteLink(notePath, noteTitle);
|
||||
if (showNotePath) {
|
||||
notePath = await treeService.resolveNotePath(notePath);
|
||||
|
||||
const $res = $("<span>").append($link);
|
||||
|
||||
if (notePath.includes("/")) {
|
||||
const noteIds = notePath.split("/");
|
||||
noteIds.pop(); // remove last element
|
||||
|
||||
const parentNotePath = noteIds.join("/").trim();
|
||||
|
||||
if (parentNotePath) {
|
||||
$res.append($("<small>").text(" (" + await treeUtils.getNotePathTitle(parentNotePath) + ")"));
|
||||
$container.append($("<small>").text(" (" + await treeUtils.getNotePathTitle(parentNotePath) + ")"));
|
||||
}
|
||||
}
|
||||
|
||||
return $res;
|
||||
return $container;
|
||||
}
|
||||
|
||||
function getNotePathFromLink($link) {
|
||||
@ -180,7 +180,6 @@ $(document).on('contextmenu', ".note-detail-render a", newTabContextMenu);
|
||||
export default {
|
||||
getNotePathFromUrl,
|
||||
createNoteLink,
|
||||
createNoteLinkWithPath,
|
||||
addLinkToEditor,
|
||||
addTextToEditor,
|
||||
goToLink
|
||||
|
@ -88,7 +88,7 @@ export default class LinkMap {
|
||||
.addClass("note-box")
|
||||
.prop("id", noteBoxId);
|
||||
|
||||
linkService.createNoteLink(noteId, note.title).then($link => {
|
||||
linkService.createNoteLink(noteId, {title: note.title}).then($link => {
|
||||
$link.on('click', e => {
|
||||
try {
|
||||
$link.tooltip('dispose');
|
||||
|
@ -137,7 +137,7 @@ class NoteDetailBook {
|
||||
.attr('data-note-id', childNote.noteId)
|
||||
.css("flex-basis", ZOOMS[this.zoomLevel].width)
|
||||
.addClass("type-" + type)
|
||||
.append($('<h5 class="note-book-title">').append(await linkService.createNoteLink(childNotePath, null, false)))
|
||||
.append($('<h5 class="note-book-title">').append(await linkService.createNoteLink(childNotePath, {showTooltip: false})))
|
||||
.append($('<div class="note-book-content">')
|
||||
.css("max-height", ZOOMS[this.zoomLevel].height)
|
||||
.append(await this.getNoteContent(type, childNote)));
|
||||
|
@ -494,7 +494,7 @@ class NoteDetailRelationMap {
|
||||
}
|
||||
|
||||
async createNoteBox(noteId, title, x, y) {
|
||||
const $link = await linkService.createNoteLink(noteId, title);
|
||||
const $link = await linkService.createNoteLink(noteId, {title});
|
||||
$link.mousedown(e => {
|
||||
console.log(e);
|
||||
|
||||
|
@ -379,7 +379,7 @@ class TabContext {
|
||||
async addPath(notePath, isCurrent) {
|
||||
const title = await treeUtils.getNotePathTitle(notePath);
|
||||
|
||||
const noteLink = await linkService.createNoteLink(notePath, title);
|
||||
const noteLink = await linkService.createNoteLink(notePath, {title});
|
||||
|
||||
noteLink
|
||||
.addClass("no-tooltip-preview")
|
||||
|
@ -45,7 +45,7 @@ class EditedNotesWidget extends StandardWidget {
|
||||
$item.append($("<i>").text(editedNote.title + " (deleted)"));
|
||||
}
|
||||
else {
|
||||
$item.append(editedNote.notePath ? await linkService.createNoteLinkWithPath(editedNote.notePath.join("/")) : editedNote.title);
|
||||
$item.append(editedNote.notePath ? await linkService.createNoteLink(editedNote.notePath.join("/"), {showNotePath: true}) : editedNote.title);
|
||||
}
|
||||
|
||||
$list.append($item);
|
||||
|
@ -39,7 +39,7 @@ class SimilarNotesWidget extends StandardWidget {
|
||||
}
|
||||
|
||||
const $item = $("<li>")
|
||||
.append(await linkService.createNoteLinkWithPath(similarNote.notePath.join("/")));
|
||||
.append(await linkService.createNoteLink(similarNote.notePath.join("/"), {showNotePath: true}));
|
||||
|
||||
$list.append($item);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user