mirror of
https://github.com/zadam/trilium.git
synced 2025-11-02 19:36:12 +01:00
fixed recent notes
This commit is contained in:
@@ -16,28 +16,28 @@ const recentNotes = (function() {
|
||||
list = result.map(r => r.note_tree_id);
|
||||
});
|
||||
|
||||
function addRecentNote(noteTreeId) {
|
||||
function addRecentNote(notePath) {
|
||||
setTimeout(() => {
|
||||
// we include the note into recent list only if the user stayed on the note at least 5 seconds
|
||||
if (noteTreeId === noteTree.getCurrentNoteTreeId()) {
|
||||
if (notePath === noteTree.getCurrentNotePath()) {
|
||||
$.ajax({
|
||||
url: baseApiUrl + 'recent-notes/' + noteTreeId,
|
||||
url: baseApiUrl + 'recent-notes/' + encodeURIComponent(notePath),
|
||||
type: 'PUT',
|
||||
error: () => showError("Error setting recent notes.")
|
||||
}).then(result => {
|
||||
list = result.map(r => r.note_tree_id);
|
||||
list = result.map(r => r.note_path);
|
||||
});
|
||||
}
|
||||
}, 1500);
|
||||
}
|
||||
|
||||
function removeRecentNote(noteTreeIdToRemove) {
|
||||
function removeRecentNote(notePathIdToRemove) {
|
||||
$.ajax({
|
||||
url: baseApiUrl + 'recent-notes/' + noteTreeIdToRemove,
|
||||
url: baseApiUrl + 'recent-notes/' + notePathIdToRemove,
|
||||
type: 'DELETE',
|
||||
error: () => showError("Error removing note from recent notes.")
|
||||
}).then(result => {
|
||||
list = result.map(r => r.note_tree_id);
|
||||
list = result.map(r => r.note_path);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -54,17 +54,13 @@ const recentNotes = (function() {
|
||||
selectBoxEl.find('option').remove();
|
||||
|
||||
// remove the current note
|
||||
const recNotes = list.filter(note => note !== noteEditor.getCurrentNoteId());
|
||||
const recNotes = list.filter(note => note !== noteTree.getCurrentNotePath());
|
||||
|
||||
$.each(recNotes, (key, valueNoteTreeId) => {
|
||||
const noteTitle = treeUtils.getFullName(valueNoteTreeId);
|
||||
|
||||
if (!noteTitle) {
|
||||
return;
|
||||
}
|
||||
$.each(recNotes, (key, valueNotePath) => {
|
||||
const noteTitle = treeUtils.getFullNameForPath(valueNotePath);
|
||||
|
||||
const option = $("<option></option>")
|
||||
.attr("value", valueNoteTreeId)
|
||||
.attr("value", valueNotePath)
|
||||
.text(noteTitle);
|
||||
|
||||
// select the first one (most recent one) by default
|
||||
@@ -76,22 +72,22 @@ const recentNotes = (function() {
|
||||
});
|
||||
}
|
||||
|
||||
function getSelectedNoteIdFromRecentNotes() {
|
||||
function getSelectedNotePathFromRecentNotes() {
|
||||
return selectBoxEl.find("option:selected").val();
|
||||
}
|
||||
|
||||
function setActiveNoteBasedOnRecentNotes() {
|
||||
const noteId = getSelectedNoteIdFromRecentNotes();
|
||||
const notePath = getSelectedNotePathFromRecentNotes();
|
||||
|
||||
noteTree.activateNode(noteId);
|
||||
noteTree.activateNode(notePath);
|
||||
|
||||
dialogEl.dialog('close');
|
||||
}
|
||||
|
||||
function addLinkBasedOnRecentNotes() {
|
||||
const noteId = getSelectedNoteIdFromRecentNotes();
|
||||
const notePath = getSelectedNotePathFromRecentNotes();
|
||||
|
||||
const linkTitle = treeUtils.getNoteTitle(noteId);
|
||||
const linkTitle = treeUtils.getNoteTitle(notePath);
|
||||
|
||||
dialogEl.dialog("close");
|
||||
|
||||
@@ -99,7 +95,7 @@ const recentNotes = (function() {
|
||||
|
||||
noteDetailEl.summernote('createLink', {
|
||||
text: linkTitle,
|
||||
url: 'app#' + noteId,
|
||||
url: 'app#' + notePath,
|
||||
isNewWindow: true
|
||||
});
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ const noteTree = (function() {
|
||||
let counter = 1;
|
||||
let noteTreeIdToKey = {};
|
||||
let parentChildToNoteTreeId = {};
|
||||
let noteIdToTitle = {};
|
||||
|
||||
function getNoteTreeIdFromKey(key) {
|
||||
const node = treeUtils.getNodeByKey(key);
|
||||
@@ -41,12 +42,25 @@ const noteTree = (function() {
|
||||
const noteTreeId = parentChildToNoteTreeId[key];
|
||||
|
||||
if (!noteTreeId) {
|
||||
console.trace();
|
||||
|
||||
throw new Error("Can't find note tree id for parent=" + parentNoteId + ", child=" + childNoteId);
|
||||
}
|
||||
|
||||
return noteTreeId;
|
||||
}
|
||||
|
||||
function getNoteTitle(notePath) {
|
||||
const noteId = treeUtils.getNoteIdFromNotePath(notePath);
|
||||
const title = noteIdToTitle[noteId];
|
||||
|
||||
if (!title) {
|
||||
throw new Error("Can't find title for noteId=" + noteId);
|
||||
}
|
||||
|
||||
return title;
|
||||
}
|
||||
|
||||
function prepareNoteTree(notes) {
|
||||
parentToChildren = {};
|
||||
childToParents = {};
|
||||
@@ -55,6 +69,8 @@ const noteTree = (function() {
|
||||
for (const note of notes) {
|
||||
notesMap[note.note_tree_id] = note;
|
||||
|
||||
noteIdToTitle[note.note_id] = note.note_title;
|
||||
|
||||
const key = note.note_pid + "-" + note.note_id;
|
||||
|
||||
parentChildToNoteTreeId[key] = note.note_tree_id;
|
||||
@@ -225,10 +241,11 @@ const noteTree = (function() {
|
||||
scrollParent: $("#tree"),
|
||||
activate: (event, data) => {
|
||||
const node = data.node.data;
|
||||
const currentNotePath = treeUtils.getNotePath(data.node);
|
||||
|
||||
document.location.hash = treeUtils.getNotePath(data.node);
|
||||
document.location.hash = currentNotePath;
|
||||
|
||||
recentNotes.addRecentNote(node.note_tree_id);
|
||||
recentNotes.addRecentNote(currentNotePath);
|
||||
|
||||
noteEditor.switchToNote(node.note_id);
|
||||
},
|
||||
@@ -400,6 +417,12 @@ const noteTree = (function() {
|
||||
return node.data.note_tree_id;
|
||||
}
|
||||
|
||||
function getCurrentNotePath() {
|
||||
const node = getCurrentNode();
|
||||
|
||||
return treeUtils.getNotePath(node);
|
||||
}
|
||||
|
||||
function setCurrentNoteTreeBasedOnProtectedStatus() {
|
||||
const node = getCurrentNode();
|
||||
|
||||
@@ -445,6 +468,8 @@ const noteTree = (function() {
|
||||
setCurrentNoteTreeBasedOnProtectedStatus,
|
||||
getCurrentNode,
|
||||
getCurrentNoteTreeId,
|
||||
activateNode
|
||||
activateNode,
|
||||
getCurrentNotePath,
|
||||
getNoteTitle
|
||||
};
|
||||
})();
|
||||
@@ -21,19 +21,17 @@ const treeUtils = (function() {
|
||||
return getNodeByKey(key);
|
||||
}
|
||||
|
||||
function getNoteTitle(noteId) {
|
||||
const note = treeUtils.getNodeByKey(noteId);
|
||||
if (!note) {
|
||||
return;
|
||||
}
|
||||
function getNoteIdFromNotePath(notePath) {
|
||||
const path = notePath.split("/");
|
||||
|
||||
let noteTitle = note.title;
|
||||
return path[path.length - 1];
|
||||
}
|
||||
|
||||
if (noteTitle.endsWith(" (clone)")) {
|
||||
noteTitle = noteTitle.substr(0, noteTitle.length - 8);
|
||||
}
|
||||
function getFullNameForPath(notePath) {
|
||||
const path = notePath.split("/");
|
||||
const titlePath = path.map(noteId => noteTree.getNoteTitle(noteId));
|
||||
|
||||
return noteTitle;
|
||||
return titlePath.join(" > ");
|
||||
}
|
||||
|
||||
function getFullName(noteTreeId) {
|
||||
@@ -73,8 +71,9 @@ const treeUtils = (function() {
|
||||
getParentProtectedStatus,
|
||||
getNodeByKey,
|
||||
getNodeByNoteTreeId,
|
||||
getNoteTitle,
|
||||
getFullName,
|
||||
getNotePath
|
||||
getFullNameForPath,
|
||||
getNotePath,
|
||||
getNoteIdFromNotePath
|
||||
};
|
||||
})();
|
||||
Reference in New Issue
Block a user