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 treePrefixInputEl = $("#tree-prefix-input");
|
||||||
const noteTitleEl = $('#tree-prefix-note-title');
|
const noteTitleEl = $('#tree-prefix-note-title');
|
||||||
|
|
||||||
|
let noteTreeId;
|
||||||
|
|
||||||
async function showDialog() {
|
async function showDialog() {
|
||||||
glob.activeDialog = dialogEl;
|
glob.activeDialog = dialogEl;
|
||||||
|
|
||||||
@ -16,6 +18,8 @@ const editTreePrefix = (function() {
|
|||||||
|
|
||||||
const currentNode = noteTree.getCurrentNode();
|
const currentNode = noteTree.getCurrentNode();
|
||||||
|
|
||||||
|
noteTreeId = currentNode.data.note_tree_id;
|
||||||
|
|
||||||
treePrefixInputEl.val(currentNode.data.prefix).focus();
|
treePrefixInputEl.val(currentNode.data.prefix).focus();
|
||||||
|
|
||||||
const noteTitle = noteTree.getNoteTitle(currentNode.data.note_id);
|
const noteTitle = noteTree.getNoteTitle(currentNode.data.note_id);
|
||||||
@ -25,8 +29,6 @@ const editTreePrefix = (function() {
|
|||||||
|
|
||||||
formEl.submit(() => {
|
formEl.submit(() => {
|
||||||
const prefix = treePrefixInputEl.val();
|
const prefix = treePrefixInputEl.val();
|
||||||
const currentNode = noteTree.getCurrentNode();
|
|
||||||
const noteTreeId = currentNode.data.note_tree_id;
|
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: baseApiUrl + 'tree/' + noteTreeId + '/setPrefix',
|
url: baseApiUrl + 'tree/' + noteTreeId + '/setPrefix',
|
||||||
@ -35,15 +37,7 @@ const editTreePrefix = (function() {
|
|||||||
data: JSON.stringify({
|
data: JSON.stringify({
|
||||||
prefix: prefix
|
prefix: prefix
|
||||||
}),
|
}),
|
||||||
success: () => {
|
success: () => noteTree.setPrefix(noteTreeId, prefix),
|
||||||
currentNode.data.prefix = prefix;
|
|
||||||
|
|
||||||
const noteTitle = noteTree.getNoteTitle(currentNode.data.note_id);
|
|
||||||
|
|
||||||
const title = (prefix ? (prefix + " - ") : "") + noteTitle;
|
|
||||||
|
|
||||||
currentNode.setTitle(title);
|
|
||||||
},
|
|
||||||
error: () => showError("Error setting prefix.")
|
error: () => showError("Error setting prefix.")
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -64,17 +64,33 @@ const noteTree = (function() {
|
|||||||
const noteId = getCurrentNoteId();
|
const noteId = getCurrentNoteId();
|
||||||
|
|
||||||
if (noteId) {
|
if (noteId) {
|
||||||
return getNodes(noteId);
|
return getNodesByNoteId(noteId);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return [];
|
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);
|
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) {
|
function prepareNoteTree(notes) {
|
||||||
parentToChildren = {};
|
parentToChildren = {};
|
||||||
childToParents = {};
|
childToParents = {};
|
||||||
@ -218,7 +234,7 @@ const noteTree = (function() {
|
|||||||
let parentNoteId = 'root';
|
let parentNoteId = 'root';
|
||||||
|
|
||||||
for (const childNoteId of runPath) {
|
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) {
|
if (childNoteId === noteId) {
|
||||||
await node.setActive();
|
await node.setActive();
|
||||||
@ -348,7 +364,7 @@ const noteTree = (function() {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"f2": node => {
|
"f2": node => {
|
||||||
editTreePrefix.showDialog();
|
editTreePrefix.showDialog(node);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -548,11 +564,7 @@ const noteTree = (function() {
|
|||||||
if (currentNoteId) {
|
if (currentNoteId) {
|
||||||
noteIdToTitle[currentNoteId] = title;
|
noteIdToTitle[currentNoteId] = title;
|
||||||
|
|
||||||
getCurrentClones().map(clone => {
|
getNodesByNoteId(currentNoteId).map(clone => treeUtils.setNodeTitleWithPrefix(clone));
|
||||||
const fullTitle = (clone.data.prefix ? (clone.data.prefix + " - ") : "") + title;
|
|
||||||
|
|
||||||
clone.setTitle(fullTitle)
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -628,6 +640,8 @@ const noteTree = (function() {
|
|||||||
getAutocompleteItems,
|
getAutocompleteItems,
|
||||||
setCurrentNoteTitle,
|
setCurrentNoteTitle,
|
||||||
createNewTopLevelNote,
|
createNewTopLevelNote,
|
||||||
createNote
|
createNote,
|
||||||
|
setPrefix,
|
||||||
|
getNodesByNoteTreeId
|
||||||
};
|
};
|
||||||
})();
|
})();
|
@ -38,11 +38,21 @@ const treeUtils = (function() {
|
|||||||
return path.reverse().join("/");
|
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 {
|
return {
|
||||||
getParentProtectedStatus,
|
getParentProtectedStatus,
|
||||||
getNodeByKey,
|
getNodeByKey,
|
||||||
getFullNameForPath,
|
getFullNameForPath,
|
||||||
getNotePath,
|
getNotePath,
|
||||||
getNoteIdFromNotePath
|
getNoteIdFromNotePath,
|
||||||
|
setNodeTitleWithPrefix
|
||||||
};
|
};
|
||||||
})();
|
})();
|
Loading…
x
Reference in New Issue
Block a user