mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
fixes after refactoring, base functionality works again
This commit is contained in:
parent
5ea060a054
commit
0f6b00e1c8
@ -19,7 +19,7 @@ const addLink = (function() {
|
|||||||
linkTypeChanged();
|
linkTypeChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
function showDialog() {
|
async function showDialog() {
|
||||||
glob.activeDialog = $dialog;
|
glob.activeDialog = $dialog;
|
||||||
|
|
||||||
if (noteEditor.getCurrentNoteType() === 'text') {
|
if (noteEditor.getCurrentNoteType() === 'text') {
|
||||||
@ -49,7 +49,7 @@ const addLink = (function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$autoComplete.autocomplete({
|
$autoComplete.autocomplete({
|
||||||
source: treeService.getAutocompleteItems(),
|
source: await treeService.getAutocompleteItems(),
|
||||||
minLength: 0,
|
minLength: 0,
|
||||||
change: () => {
|
change: () => {
|
||||||
const val = $autoComplete.val();
|
const val = $autoComplete.val();
|
||||||
|
@ -211,7 +211,7 @@ $(document).ready(() => {
|
|||||||
if (isElectron()) {
|
if (isElectron()) {
|
||||||
require('electron').ipcRenderer.on('create-day-sub-note', async function(event, parentNoteId) {
|
require('electron').ipcRenderer.on('create-day-sub-note', async function(event, parentNoteId) {
|
||||||
// this might occur when day note had to be created
|
// this might occur when day note had to be created
|
||||||
if (!treeService.noteExists(parentNoteId)) {
|
if (!await treeService.noteExists(parentNoteId)) {
|
||||||
await treeService.reload();
|
await treeService.reload();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -311,7 +311,7 @@ const treeService = (function() {
|
|||||||
async function expandToNote(notePath, expandOpts) {
|
async function expandToNote(notePath, expandOpts) {
|
||||||
assertArguments(notePath);
|
assertArguments(notePath);
|
||||||
|
|
||||||
const runPath = getRunPath(notePath);
|
const runPath = await getRunPath(notePath);
|
||||||
|
|
||||||
const noteId = treeUtils.getNoteIdFromNotePath(notePath);
|
const noteId = treeUtils.getNoteIdFromNotePath(notePath);
|
||||||
|
|
||||||
@ -345,7 +345,7 @@ const treeService = (function() {
|
|||||||
* Accepts notePath and tries to resolve it. Part of the path might not be valid because of note moving (which causes
|
* Accepts notePath and tries to resolve it. Part of the path might not be valid because of note moving (which causes
|
||||||
* path change) or other corruption, in that case this will try to get some other valid path to the correct note.
|
* path change) or other corruption, in that case this will try to get some other valid path to the correct note.
|
||||||
*/
|
*/
|
||||||
function getRunPath(notePath) {
|
async function getRunPath(notePath) {
|
||||||
assertArguments(notePath);
|
assertArguments(notePath);
|
||||||
|
|
||||||
const path = notePath.split("/").reverse();
|
const path = notePath.split("/").reverse();
|
||||||
@ -363,20 +363,21 @@ const treeService = (function() {
|
|||||||
const parentNoteId = path[i++];
|
const parentNoteId = path[i++];
|
||||||
|
|
||||||
if (childNoteId !== null) {
|
if (childNoteId !== null) {
|
||||||
const parents = childToParents[childNoteId];
|
const child = treeCache.getNote(childNoteId);
|
||||||
|
const parents = await child.getParentNotes();
|
||||||
|
|
||||||
if (!parents) {
|
if (!parents) {
|
||||||
messaging.logError("No parents found for " + childNoteId);
|
messaging.logError("No parents found for " + childNoteId);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!parents.includes(parentNoteId)) {
|
if (!parents.some(p => p.noteId === parentNoteId)) {
|
||||||
console.log(now(), "Did not find parent " + parentNoteId + " for child " + childNoteId);
|
console.log(now(), "Did not find parent " + parentNoteId + " for child " + childNoteId);
|
||||||
|
|
||||||
if (parents.length > 0) {
|
if (parents.length > 0) {
|
||||||
console.log(now(), "Available parents:", parents);
|
console.log(now(), "Available parents:", parents);
|
||||||
|
|
||||||
const someNotePath = getSomeNotePath(parents[0]);
|
const someNotePath = await getSomeNotePath(parents[0]);
|
||||||
|
|
||||||
if (someNotePath) { // in case it's root the path may be empty
|
if (someNotePath) { // in case it's root the path may be empty
|
||||||
const pathToRoot = someNotePath.split("/").reverse();
|
const pathToRoot = someNotePath.split("/").reverse();
|
||||||
@ -407,12 +408,13 @@ const treeService = (function() {
|
|||||||
return effectivePath.reverse();
|
return effectivePath.reverse();
|
||||||
}
|
}
|
||||||
|
|
||||||
function showParentList(noteId, node) {
|
async function showParentList(noteId, node) {
|
||||||
assertArguments(noteId, node);
|
assertArguments(noteId, node);
|
||||||
|
|
||||||
const parents = childToParents[noteId];
|
const note = treeCache.getNote(noteId);
|
||||||
|
const parents = await note.getParentNotes();
|
||||||
|
|
||||||
if (!parents) {
|
if (!parents.length) {
|
||||||
throwError("Can't find parents for noteId=" + noteId);
|
throwError("Can't find parents for noteId=" + noteId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -423,15 +425,15 @@ const treeService = (function() {
|
|||||||
$parentList.show();
|
$parentList.show();
|
||||||
$parentListList.empty();
|
$parentListList.empty();
|
||||||
|
|
||||||
for (const parentNoteId of parents) {
|
for (const parentNote of parents) {
|
||||||
const parentNotePath = getSomeNotePath(parentNoteId);
|
const parentNotePath = await getSomeNotePath(parentNote);
|
||||||
// this is to avoid having root notes leading '/'
|
// this is to avoid having root notes leading '/'
|
||||||
const notePath = parentNotePath ? (parentNotePath + '/' + noteId) : noteId;
|
const notePath = parentNotePath ? (parentNotePath + '/' + noteId) : noteId;
|
||||||
const title = getNotePathTitle(notePath);
|
const title = getNotePathTitle(notePath);
|
||||||
|
|
||||||
let item;
|
let item;
|
||||||
|
|
||||||
if (node.getParent().data.noteId === parentNoteId) {
|
if (node.getParent().data.noteId === parentNote.noteId) {
|
||||||
item = $("<span/>").attr("title", "Current note").append(title);
|
item = $("<span/>").attr("title", "Current note").append(title);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -459,21 +461,23 @@ const treeService = (function() {
|
|||||||
return titlePath.join(' / ');
|
return titlePath.join(' / ');
|
||||||
}
|
}
|
||||||
|
|
||||||
function getSomeNotePath(noteId) {
|
async function getSomeNotePath(note) {
|
||||||
assertArguments(noteId);
|
assertArguments(note);
|
||||||
|
|
||||||
const path = [];
|
const path = [];
|
||||||
|
|
||||||
let cur = noteId;
|
let cur = note;
|
||||||
|
|
||||||
while (cur !== 'root') {
|
while (cur.noteId !== 'root') {
|
||||||
path.push(cur);
|
path.push(cur.noteId);
|
||||||
|
|
||||||
if (!childToParents[cur]) {
|
const parents = await cur.getParentNotes();
|
||||||
|
|
||||||
|
if (!parents.length) {
|
||||||
throwError("Can't find parents for " + cur);
|
throwError("Can't find parents for " + cur);
|
||||||
}
|
}
|
||||||
|
|
||||||
cur = childToParents[cur][0];
|
cur = parents[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
return path.reverse().join('/');
|
return path.reverse().join('/');
|
||||||
@ -821,12 +825,15 @@ const treeService = (function() {
|
|||||||
setBranchBackgroundBasedOnProtectedStatus(noteId);
|
setBranchBackgroundBasedOnProtectedStatus(noteId);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getAutocompleteItems(parentNoteId, notePath, titlePath) {
|
async function getAutocompleteItems(parentNoteId, notePath, titlePath) {
|
||||||
if (!parentNoteId) {
|
if (!parentNoteId) {
|
||||||
parentNoteId = 'root';
|
parentNoteId = 'root';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!parentToChildren[parentNoteId]) {
|
const parentNote = treeCache.getNote(parentNoteId);
|
||||||
|
const childNotes = await parentNote.getChildNotes();
|
||||||
|
|
||||||
|
if (!childNotes.length) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -843,20 +850,20 @@ const treeService = (function() {
|
|||||||
|
|
||||||
const autocompleteItems = [];
|
const autocompleteItems = [];
|
||||||
|
|
||||||
for (const childNoteId of parentToChildren[parentNoteId]) {
|
for (const childNote of childNotes) {
|
||||||
if (hiddenInAutocomplete[childNoteId]) {
|
if (childNote.hideInAutocomplete) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const childNotePath = (notePath ? (notePath + '/') : '') + childNoteId;
|
const childNotePath = (notePath ? (notePath + '/') : '') + childNote.noteId;
|
||||||
const childTitlePath = (titlePath ? (titlePath + ' / ') : '') + getNoteTitle(childNoteId, parentNoteId);
|
const childTitlePath = (titlePath ? (titlePath + ' / ') : '') + getNoteTitle(childNote.noteId, parentNoteId);
|
||||||
|
|
||||||
autocompleteItems.push({
|
autocompleteItems.push({
|
||||||
value: childTitlePath + ' (' + childNotePath + ')',
|
value: childTitlePath + ' (' + childNotePath + ')',
|
||||||
label: childTitlePath
|
label: childTitlePath
|
||||||
});
|
});
|
||||||
|
|
||||||
const childItems = getAutocompleteItems(childNoteId, childNotePath, childTitlePath);
|
const childItems = await getAutocompleteItems(childNote.noteId, childNotePath, childTitlePath);
|
||||||
|
|
||||||
for (const childItem of childItems) {
|
for (const childItem of childItems) {
|
||||||
autocompleteItems.push(childItem);
|
autocompleteItems.push(childItem);
|
||||||
@ -953,8 +960,8 @@ const treeService = (function() {
|
|||||||
await reload();
|
await reload();
|
||||||
}
|
}
|
||||||
|
|
||||||
function noteExists(noteId) {
|
async function noteExists(noteId) {
|
||||||
return !!childToParents[noteId];
|
return !!treeCache.getNote(noteId);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getInstanceName() {
|
function getInstanceName() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user