mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
fix setting title
This commit is contained in:
parent
40a522a9aa
commit
7038636d2e
@ -6,6 +6,8 @@ const editTreePrefix = (function() {
|
||||
const treePrefixInputEl = $("#tree-prefix-input");
|
||||
const noteTitleEl = $('#tree-prefix-note-title');
|
||||
|
||||
let noteTreeId;
|
||||
|
||||
async function showDialog() {
|
||||
glob.activeDialog = dialogEl;
|
||||
|
||||
@ -16,6 +18,8 @@ const editTreePrefix = (function() {
|
||||
|
||||
const currentNode = noteTree.getCurrentNode();
|
||||
|
||||
noteTreeId = currentNode.data.note_tree_id;
|
||||
|
||||
treePrefixInputEl.val(currentNode.data.prefix).focus();
|
||||
|
||||
const noteTitle = noteTree.getNoteTitle(currentNode.data.note_id);
|
||||
@ -25,8 +29,6 @@ const editTreePrefix = (function() {
|
||||
|
||||
formEl.submit(() => {
|
||||
const prefix = treePrefixInputEl.val();
|
||||
const currentNode = noteTree.getCurrentNode();
|
||||
const noteTreeId = currentNode.data.note_tree_id;
|
||||
|
||||
$.ajax({
|
||||
url: baseApiUrl + 'tree/' + noteTreeId + '/setPrefix',
|
||||
@ -35,15 +37,7 @@ const editTreePrefix = (function() {
|
||||
data: JSON.stringify({
|
||||
prefix: prefix
|
||||
}),
|
||||
success: () => {
|
||||
currentNode.data.prefix = prefix;
|
||||
|
||||
const noteTitle = noteTree.getNoteTitle(currentNode.data.note_id);
|
||||
|
||||
const title = (prefix ? (prefix + " - ") : "") + noteTitle;
|
||||
|
||||
currentNode.setTitle(title);
|
||||
},
|
||||
success: () => noteTree.setPrefix(noteTreeId, prefix),
|
||||
error: () => showError("Error setting prefix.")
|
||||
});
|
||||
|
||||
|
@ -64,17 +64,33 @@ const noteTree = (function() {
|
||||
const noteId = getCurrentNoteId();
|
||||
|
||||
if (noteId) {
|
||||
return getNodes(noteId);
|
||||
return getNodesByNoteId(noteId);
|
||||
}
|
||||
else {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
function getNodes(noteId) {
|
||||
function getNodesByNoteTreeId(noteTreeId) {
|
||||
const noteTree = notesTreeMap[noteTreeId];
|
||||
|
||||
return getNodesByNoteId(noteTree.note_id).filter(node => node.data.note_tree_id === noteTreeId);
|
||||
}
|
||||
|
||||
function getNodesByNoteId(noteId) {
|
||||
return getTree().getNodesByRef(noteId);
|
||||
}
|
||||
|
||||
function setPrefix(noteTreeId, prefix) {
|
||||
notesTreeMap[noteTreeId].prefix = prefix;
|
||||
|
||||
getNodesByNoteTreeId(noteTreeId).map(node => {
|
||||
node.data.prefix = prefix;
|
||||
|
||||
treeUtils.setNodeTitleWithPrefix(node);
|
||||
});
|
||||
}
|
||||
|
||||
function prepareNoteTree(notes) {
|
||||
parentToChildren = {};
|
||||
childToParents = {};
|
||||
@ -218,7 +234,7 @@ const noteTree = (function() {
|
||||
let parentNoteId = 'root';
|
||||
|
||||
for (const childNoteId of runPath) {
|
||||
const node = getNodes(childNoteId).find(node => node.data.note_pid === parentNoteId);
|
||||
const node = getNodesByNoteId(childNoteId).find(node => node.data.note_pid === parentNoteId);
|
||||
|
||||
if (childNoteId === noteId) {
|
||||
await node.setActive();
|
||||
@ -348,7 +364,7 @@ const noteTree = (function() {
|
||||
}
|
||||
},
|
||||
"f2": node => {
|
||||
editTreePrefix.showDialog();
|
||||
editTreePrefix.showDialog(node);
|
||||
}
|
||||
};
|
||||
|
||||
@ -548,11 +564,7 @@ const noteTree = (function() {
|
||||
if (currentNoteId) {
|
||||
noteIdToTitle[currentNoteId] = title;
|
||||
|
||||
getCurrentClones().map(clone => {
|
||||
const fullTitle = (clone.data.prefix ? (clone.data.prefix + " - ") : "") + title;
|
||||
|
||||
clone.setTitle(fullTitle)
|
||||
});
|
||||
getNodesByNoteId(currentNoteId).map(clone => treeUtils.setNodeTitleWithPrefix(clone));
|
||||
}
|
||||
}
|
||||
|
||||
@ -628,6 +640,8 @@ const noteTree = (function() {
|
||||
getAutocompleteItems,
|
||||
setCurrentNoteTitle,
|
||||
createNewTopLevelNote,
|
||||
createNote
|
||||
createNote,
|
||||
setPrefix,
|
||||
getNodesByNoteTreeId
|
||||
};
|
||||
})();
|
@ -38,11 +38,21 @@ const treeUtils = (function() {
|
||||
return path.reverse().join("/");
|
||||
}
|
||||
|
||||
function setNodeTitleWithPrefix(node) {
|
||||
const noteTitle = noteTree.getNoteTitle(node.data.note_id);
|
||||
const prefix = node.data.prefix;
|
||||
|
||||
const title = (prefix ? (prefix + " - ") : "") + noteTitle;
|
||||
|
||||
node.setTitle(title);
|
||||
}
|
||||
|
||||
return {
|
||||
getParentProtectedStatus,
|
||||
getNodeByKey,
|
||||
getFullNameForPath,
|
||||
getNotePath,
|
||||
getNoteIdFromNotePath
|
||||
getNoteIdFromNotePath,
|
||||
setNodeTitleWithPrefix
|
||||
};
|
||||
})();
|
Loading…
x
Reference in New Issue
Block a user