mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
fixes after refactorings
This commit is contained in:
parent
b96a1274c5
commit
df27533b66
@ -6,6 +6,7 @@ class TreeCache {
|
|||||||
this.children = [];
|
this.children = [];
|
||||||
this.childParentToBranch = {};
|
this.childParentToBranch = {};
|
||||||
|
|
||||||
|
/** @type {Object.<string, NoteShort>} */
|
||||||
this.notes = {};
|
this.notes = {};
|
||||||
for (const noteRow of noteRows) {
|
for (const noteRow of noteRows) {
|
||||||
const note = new NoteShort(this, noteRow);
|
const note = new NoteShort(this, noteRow);
|
||||||
@ -13,11 +14,11 @@ class TreeCache {
|
|||||||
this.notes[note.noteId] = note;
|
this.notes[note.noteId] = note;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @type {Object.<string, Branch>} */
|
||||||
this.branches = {};
|
this.branches = {};
|
||||||
for (const branchRow of branchRows) {
|
for (const branchRow of branchRows) {
|
||||||
const branch = new Branch(this, branchRow);
|
const branch = new Branch(this, branchRow);
|
||||||
|
|
||||||
this.branches[branch.branchId] = branch;
|
|
||||||
this.addBranch(branch);
|
this.addBranch(branch);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -27,6 +28,8 @@ class TreeCache {
|
|||||||
}
|
}
|
||||||
|
|
||||||
addBranch(branch) {
|
addBranch(branch) {
|
||||||
|
this.branches[branch.branchId] = branch;
|
||||||
|
|
||||||
this.parents[branch.noteId] = this.parents[branch.noteId] || [];
|
this.parents[branch.noteId] = this.parents[branch.noteId] || [];
|
||||||
this.parents[branch.noteId].push(this.notes[branch.parentNoteId]);
|
this.parents[branch.noteId].push(this.notes[branch.parentNoteId]);
|
||||||
|
|
||||||
@ -42,7 +45,11 @@ class TreeCache {
|
|||||||
this.addBranch(branch);
|
this.addBranch(branch);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getBranch(childNoteId, parentNoteId) {
|
getBranch(branchId) {
|
||||||
|
return this.branches[branchId];
|
||||||
|
}
|
||||||
|
|
||||||
|
getBranchByParentChild(childNoteId, parentNoteId) {
|
||||||
return this.childParentToBranch[childNoteId + '-' + parentNoteId];
|
return this.childParentToBranch[childNoteId + '-' + parentNoteId];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -62,7 +69,7 @@ class NoteShort {
|
|||||||
const branches = [];
|
const branches = [];
|
||||||
|
|
||||||
for (const parent of this.treeCache.parents[this.noteId]) {
|
for (const parent of this.treeCache.parents[this.noteId]) {
|
||||||
branches.push(await this.treeCache.getBranch(this.noteId, p.noteId));
|
branches.push(await this.treeCache.getBranchByParentChild(this.noteId, p.noteId));
|
||||||
}
|
}
|
||||||
|
|
||||||
return branches;
|
return branches;
|
||||||
@ -72,7 +79,7 @@ class NoteShort {
|
|||||||
const branches = [];
|
const branches = [];
|
||||||
|
|
||||||
for (const child of this.treeCache.children[this.noteId]) {
|
for (const child of this.treeCache.children[this.noteId]) {
|
||||||
branches.push(await this.treeCache.getBranch(child.noteId, this.noteId));
|
branches.push(await this.treeCache.getBranchByParentChild(child.noteId, this.noteId));
|
||||||
}
|
}
|
||||||
|
|
||||||
return branches;
|
return branches;
|
||||||
@ -126,13 +133,8 @@ const treeService = (function() {
|
|||||||
|
|
||||||
let startNotePath = null;
|
let startNotePath = null;
|
||||||
|
|
||||||
/** @type {Object.<string, NoteShort>} */
|
|
||||||
let noteMap = {};
|
|
||||||
/** @type {Object.<string, Branch>} */
|
|
||||||
let branchMap = {};
|
|
||||||
|
|
||||||
function getNote(noteId) {
|
function getNote(noteId) {
|
||||||
const note = noteMap[noteId];
|
const note = treeCache.getNote(noteId);
|
||||||
|
|
||||||
if (!note) {
|
if (!note) {
|
||||||
utils.throwError("Can't find title for noteId='" + noteId + "'");
|
utils.throwError("Can't find title for noteId='" + noteId + "'");
|
||||||
@ -147,7 +149,7 @@ const treeService = (function() {
|
|||||||
let title = treeCache.getNote(noteId).title;
|
let title = treeCache.getNote(noteId).title;
|
||||||
|
|
||||||
if (parentNoteId !== null) {
|
if (parentNoteId !== null) {
|
||||||
const branch = treeCache.getBranch(noteId, parentNoteId);
|
const branch = treeCache.getBranchByParentChild(noteId, parentNoteId);
|
||||||
|
|
||||||
if (branch && branch.prefix) {
|
if (branch && branch.prefix) {
|
||||||
title = branch.prefix + ' - ' + title;
|
title = branch.prefix + ' - ' + title;
|
||||||
@ -171,7 +173,7 @@ const treeService = (function() {
|
|||||||
function getNodesByBranchId(branchId) {
|
function getNodesByBranchId(branchId) {
|
||||||
utils.assertArguments(branchId);
|
utils.assertArguments(branchId);
|
||||||
|
|
||||||
const branch = branchMap[branchId];
|
const branch = treeCache.getBranch(branchId);
|
||||||
|
|
||||||
return getNodesByNoteId(branch.noteId).filter(node => node.data.branchId === branchId);
|
return getNodesByNoteId(branch.noteId).filter(node => node.data.branchId === branchId);
|
||||||
}
|
}
|
||||||
@ -186,14 +188,14 @@ const treeService = (function() {
|
|||||||
function setPrefix(branchId, prefix) {
|
function setPrefix(branchId, prefix) {
|
||||||
utils.assertArguments(branchId);
|
utils.assertArguments(branchId);
|
||||||
|
|
||||||
branchMap[branchId].prefix = prefix;
|
treeCache.getBranch(branchId).prefix = prefix;
|
||||||
|
|
||||||
getNodesByBranchId(branchId).map(node => setNodeTitleWithPrefix(node));
|
getNodesByBranchId(branchId).map(node => setNodeTitleWithPrefix(node));
|
||||||
}
|
}
|
||||||
|
|
||||||
function setNodeTitleWithPrefix(node) {
|
function setNodeTitleWithPrefix(node) {
|
||||||
const noteTitle = getNoteTitle(node.data.noteId);
|
const noteTitle = getNoteTitle(node.data.noteId);
|
||||||
const branch = branchMap[node.data.branchId];
|
const branch = treeCache.getBranch(node.data.branchId);
|
||||||
|
|
||||||
const prefix = branch.prefix;
|
const prefix = branch.prefix;
|
||||||
|
|
||||||
@ -211,15 +213,6 @@ const treeService = (function() {
|
|||||||
// FIXME
|
// FIXME
|
||||||
}
|
}
|
||||||
|
|
||||||
function setParentChildRelation(branchId, parentNoteId, childNoteId) {
|
|
||||||
utils.assertArguments(branchId, parentNoteId, childNoteId);
|
|
||||||
|
|
||||||
const parentNote = noteMap[parentNoteId];
|
|
||||||
const childNote = noteMap[childNoteId];
|
|
||||||
|
|
||||||
// FIXME: assert
|
|
||||||
}
|
|
||||||
|
|
||||||
async function prepareBranch(noteRows, branchRows) {
|
async function prepareBranch(noteRows, branchRows) {
|
||||||
utils.assertArguments(noteRows);
|
utils.assertArguments(noteRows);
|
||||||
|
|
||||||
@ -268,7 +261,7 @@ const treeService = (function() {
|
|||||||
branchId: branch.branchId,
|
branchId: branch.branchId,
|
||||||
isProtected: note.isProtected,
|
isProtected: note.isProtected,
|
||||||
title: utils.escapeHtml(title),
|
title: utils.escapeHtml(title),
|
||||||
extraClasses: getExtraClasses(note),
|
extraClasses: await getExtraClasses(note),
|
||||||
refKey: note.noteId,
|
refKey: note.noteId,
|
||||||
expanded: note.type !== 'search' && branch.isExpanded
|
expanded: note.type !== 'search' && branch.isExpanded
|
||||||
};
|
};
|
||||||
@ -676,7 +669,7 @@ const treeService = (function() {
|
|||||||
init: (event, data) => {
|
init: (event, data) => {
|
||||||
const noteId = treeUtils.getNoteIdFromNotePath(startNotePath);
|
const noteId = treeUtils.getNoteIdFromNotePath(startNotePath);
|
||||||
|
|
||||||
if (noteMap[noteId] === undefined) {
|
if (treeCache.getNote(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;
|
||||||
}
|
}
|
||||||
@ -705,7 +698,7 @@ const treeService = (function() {
|
|||||||
mode: "hide" // Grayout unmatched nodes (pass "hide" to remove unmatched node instead)
|
mode: "hide" // Grayout unmatched nodes (pass "hide" to remove unmatched node instead)
|
||||||
},
|
},
|
||||||
dnd: dragAndDropSetup,
|
dnd: dragAndDropSetup,
|
||||||
lazyLoad: async function(event, data){
|
lazyLoad: function(event, data){
|
||||||
const noteId = data.node.data.noteId;
|
const noteId = data.node.data.noteId;
|
||||||
const note = getNote(noteId);
|
const note = getNote(noteId);
|
||||||
|
|
||||||
@ -713,7 +706,7 @@ const treeService = (function() {
|
|||||||
data.result = loadSearchNote(noteId);
|
data.result = loadSearchNote(noteId);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
data.result = await prepareBranchInner(note);
|
data.result = prepareBranchInner(note);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
clones: {
|
clones: {
|
||||||
@ -734,15 +727,13 @@ const treeService = (function() {
|
|||||||
for (const noteId of noteIds) {
|
for (const noteId of noteIds) {
|
||||||
const branchId = "virt" + utils.randomString(10);
|
const branchId = "virt" + utils.randomString(10);
|
||||||
|
|
||||||
branchMap[branchId] = {
|
treeCache.addBranch({
|
||||||
branchId: branchId,
|
branchId: branchId,
|
||||||
noteId: noteId,
|
noteId: noteId,
|
||||||
parentNoteId: searchNoteId,
|
parentNoteId: searchNoteId,
|
||||||
prefix: '',
|
prefix: '',
|
||||||
virtual: true
|
virtual: true
|
||||||
};
|
});
|
||||||
|
|
||||||
setParentChildRelation(branchId, searchNoteId, noteId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return await prepareBranchInner(searchNoteId);
|
return await prepareBranchInner(searchNoteId);
|
||||||
@ -889,17 +880,17 @@ const treeService = (function() {
|
|||||||
isProtected: isProtected
|
isProtected: isProtected
|
||||||
});
|
});
|
||||||
|
|
||||||
setParentChildRelation(result.branchId, parentNoteId, result.noteId);
|
const note = new NoteShort(treeCache, {
|
||||||
|
|
||||||
branchMap[result.branchId] = result;
|
|
||||||
|
|
||||||
noteMap[result.noteId] = {
|
|
||||||
noteId: result.noteId,
|
noteId: result.noteId,
|
||||||
title: result.title,
|
title: result.title,
|
||||||
isProtected: result.isProtected,
|
isProtected: result.isProtected,
|
||||||
type: result.type,
|
type: result.type,
|
||||||
mime: result.mime
|
mime: result.mime
|
||||||
};
|
});
|
||||||
|
|
||||||
|
const branch = new Branch(treeCache, result);
|
||||||
|
|
||||||
|
treeCache.add(note, branch);
|
||||||
|
|
||||||
noteEditor.newNoteCreated();
|
noteEditor.newNoteCreated();
|
||||||
|
|
||||||
@ -910,7 +901,7 @@ const treeService = (function() {
|
|||||||
refKey: result.noteId,
|
refKey: result.noteId,
|
||||||
branchId: result.branchId,
|
branchId: result.branchId,
|
||||||
isProtected: isProtected,
|
isProtected: isProtected,
|
||||||
extraClasses: getExtraClasses(result.note)
|
extraClasses: await getExtraClasses(note)
|
||||||
};
|
};
|
||||||
|
|
||||||
if (target === 'after') {
|
if (target === 'after') {
|
||||||
@ -1031,7 +1022,6 @@ const treeService = (function() {
|
|||||||
setPrefix,
|
setPrefix,
|
||||||
getNotePathTitle,
|
getNotePathTitle,
|
||||||
removeParentChildRelation,
|
removeParentChildRelation,
|
||||||
setParentChildRelation,
|
|
||||||
getSelectedNodes,
|
getSelectedNodes,
|
||||||
sortAlphabetically,
|
sortAlphabetically,
|
||||||
noteExists,
|
noteExists,
|
||||||
|
@ -117,6 +117,7 @@ const treeChanges = (function() {
|
|||||||
|
|
||||||
node.data.parentNoteId = utils.isTopLevelNode(node) ? 'root' : node.getParent().data.noteId;
|
node.data.parentNoteId = utils.isTopLevelNode(node) ? 'root' : node.getParent().data.noteId;
|
||||||
|
|
||||||
|
// FIXME!!!
|
||||||
treeService.setParentChildRelation(node.data.branchId, node.data.parentNoteId, node.data.noteId);
|
treeService.setParentChildRelation(node.data.branchId, node.data.parentNoteId, node.data.noteId);
|
||||||
|
|
||||||
treeService.setCurrentNotePathToHash(node);
|
treeService.setCurrentNotePathToHash(node);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user