mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
refactoring of note tree
This commit is contained in:
parent
74862536a8
commit
5204ab5a7e
BIN
src/public/images/icons/search-small.png
Normal file
BIN
src/public/images/icons/search-small.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 354 B |
@ -14,10 +14,20 @@ const noteTree = (function() {
|
|||||||
let childToParents = {};
|
let childToParents = {};
|
||||||
|
|
||||||
let parentChildToNoteTreeId = {};
|
let parentChildToNoteTreeId = {};
|
||||||
let noteIdToTitle = {};
|
let noteIdToNote = {};
|
||||||
|
|
||||||
let hiddenInAutocomplete = {};
|
let hiddenInAutocomplete = {};
|
||||||
|
|
||||||
|
function getNote(noteId) {
|
||||||
|
const note = noteIdToNote[noteId];
|
||||||
|
|
||||||
|
if (!note) {
|
||||||
|
throwError("Can't find title for noteId='" + noteId + "'");
|
||||||
|
}
|
||||||
|
|
||||||
|
return note;
|
||||||
|
}
|
||||||
|
|
||||||
function getNoteTreeId(parentNoteId, childNoteId) {
|
function getNoteTreeId(parentNoteId, childNoteId) {
|
||||||
assertArguments(parentNoteId, childNoteId);
|
assertArguments(parentNoteId, childNoteId);
|
||||||
|
|
||||||
@ -31,11 +41,7 @@ const noteTree = (function() {
|
|||||||
function getNoteTitle(noteId, parentNoteId = null) {
|
function getNoteTitle(noteId, parentNoteId = null) {
|
||||||
assertArguments(noteId);
|
assertArguments(noteId);
|
||||||
|
|
||||||
let title = noteIdToTitle[noteId];
|
let title = getNote(noteId).title;
|
||||||
|
|
||||||
if (!title) {
|
|
||||||
throwError("Can't find title for noteId='" + noteId + "'");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (parentNoteId !== null) {
|
if (parentNoteId !== null) {
|
||||||
const noteTreeId = getNoteTreeId(parentNoteId, noteId);
|
const noteTreeId = getNoteTreeId(parentNoteId, noteId);
|
||||||
@ -131,9 +137,14 @@ const noteTree = (function() {
|
|||||||
for (const note of notes) {
|
for (const note of notes) {
|
||||||
notesTreeMap[note.noteTreeId] = note;
|
notesTreeMap[note.noteTreeId] = note;
|
||||||
|
|
||||||
noteIdToTitle[note.noteId] = note.title;
|
noteIdToNote[note.noteId] = {
|
||||||
|
title: note.title,
|
||||||
|
isProtected: note.isProtected,
|
||||||
|
type: note.type,
|
||||||
|
mime: note.mime
|
||||||
|
};
|
||||||
|
|
||||||
delete note.title; // this should not be used. Use noteIdToTitle instead
|
delete note.title; // this should not be used. Use noteIdToNote instead
|
||||||
|
|
||||||
setParentChildRelation(note.noteTreeId, note.parentNoteId, note.noteId);
|
setParentChildRelation(note.noteTreeId, note.parentNoteId, note.noteId);
|
||||||
}
|
}
|
||||||
@ -174,7 +185,7 @@ const noteTree = (function() {
|
|||||||
const noteTreeId = getNoteTreeId(parentNoteId, noteId);
|
const noteTreeId = getNoteTreeId(parentNoteId, noteId);
|
||||||
const noteTree = notesTreeMap[noteTreeId];
|
const noteTree = notesTreeMap[noteTreeId];
|
||||||
|
|
||||||
const title = (noteTree.prefix ? (noteTree.prefix + " - ") : "") + noteIdToTitle[noteTree.noteId];
|
const title = (noteTree.prefix ? (noteTree.prefix + " - ") : "") + getNote(noteTree.noteId).title;
|
||||||
|
|
||||||
const node = {
|
const node = {
|
||||||
noteId: noteTree.noteId,
|
noteId: noteTree.noteId,
|
||||||
@ -585,7 +596,7 @@ const noteTree = (function() {
|
|||||||
init: (event, data) => {
|
init: (event, data) => {
|
||||||
const noteId = treeUtils.getNoteIdFromNotePath(startNotePath);
|
const noteId = treeUtils.getNoteIdFromNotePath(startNotePath);
|
||||||
|
|
||||||
if (noteIdToTitle[noteId] === undefined) {
|
if (noteIdToNote[noteId] === undefined) {
|
||||||
// note doesn't exist so don't try to activate it
|
// note doesn't exist so don't try to activate it
|
||||||
startNotePath = null;
|
startNotePath = null;
|
||||||
}
|
}
|
||||||
@ -742,7 +753,7 @@ const noteTree = (function() {
|
|||||||
function setNoteTitle(noteId, title) {
|
function setNoteTitle(noteId, title) {
|
||||||
assertArguments(noteId);
|
assertArguments(noteId);
|
||||||
|
|
||||||
noteIdToTitle[noteId] = title;
|
getNote(noteId).title = title;
|
||||||
|
|
||||||
getNodesByNoteId(noteId).map(clone => treeUtils.setNodeTitleWithPrefix(clone));
|
getNodesByNoteId(noteId).map(clone => treeUtils.setNodeTitleWithPrefix(clone));
|
||||||
}
|
}
|
||||||
@ -775,7 +786,12 @@ const noteTree = (function() {
|
|||||||
|
|
||||||
notesTreeMap[result.noteTreeId] = result;
|
notesTreeMap[result.noteTreeId] = result;
|
||||||
|
|
||||||
noteIdToTitle[result.noteId] = newNoteName;
|
noteIdToNote[result.noteId] = {
|
||||||
|
title: result.title,
|
||||||
|
isProtected: result.isProtected,
|
||||||
|
type: result.type,
|
||||||
|
mime: result.mime
|
||||||
|
};
|
||||||
|
|
||||||
noteEditor.newNoteCreated();
|
noteEditor.newNoteCreated();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user