mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 02:16:05 +01:00 
			
		
		
		
	continuing work on hoisting notes
This commit is contained in:
		| @@ -1,5 +1,6 @@ | |||||||
| import optionsInit from './options_init.js'; | import optionsInit from './options_init.js'; | ||||||
| import server from "./server.js"; | import server from "./server.js"; | ||||||
|  | import tree from "./tree.js"; | ||||||
|  |  | ||||||
| let hoistedNoteId; | let hoistedNoteId; | ||||||
|  |  | ||||||
| @@ -17,6 +18,8 @@ async function setHoistedNoteId(noteId) { | |||||||
|     hoistedNoteId = noteId; |     hoistedNoteId = noteId; | ||||||
|  |  | ||||||
|     await server.put('options/hoistedNoteId/' + noteId); |     await server.put('options/hoistedNoteId/' + noteId); | ||||||
|  |  | ||||||
|  |     await tree.reload(); | ||||||
| } | } | ||||||
|  |  | ||||||
| export default { | export default { | ||||||
|   | |||||||
| @@ -14,6 +14,7 @@ import treeBuilder from "./tree_builder.js"; | |||||||
| import treeKeyBindings from "./tree_keybindings.js"; | import treeKeyBindings from "./tree_keybindings.js"; | ||||||
| import Branch from '../entities/branch.js'; | import Branch from '../entities/branch.js'; | ||||||
| import NoteShort from '../entities/note_short.js'; | import NoteShort from '../entities/note_short.js'; | ||||||
|  | import hoistedNoteService from '../services/hoisted_note.js'; | ||||||
|  |  | ||||||
| const $tree = $("#tree"); | const $tree = $("#tree"); | ||||||
| const $createTopLevelNoteButton = $("#create-top-level-note-button"); | const $createTopLevelNoteButton = $("#create-top-level-note-button"); | ||||||
| @@ -88,10 +89,11 @@ async function expandToNote(notePath, expandOpts) { | |||||||
|  |  | ||||||
|     const noteId = treeUtils.getNoteIdFromNotePath(notePath); |     const noteId = treeUtils.getNoteIdFromNotePath(notePath); | ||||||
|  |  | ||||||
|     let parentNoteId = 'none'; |     let parentNoteId = null; | ||||||
|  |  | ||||||
|     for (const childNoteId of runPath) { |     for (const childNoteId of runPath) { | ||||||
|         const node = getNodesByNoteId(childNoteId).find(node => node.data.parentNoteId === parentNoteId); |         // for first node (!parentNoteId) it doesn't matter which node is found | ||||||
|  |         const node = getNodesByNoteId(childNoteId).find(node => !parentNoteId || node.data.parentNoteId === parentNoteId); | ||||||
|  |  | ||||||
|         if (!node) { |         if (!node) { | ||||||
|             console.error(`Can't find node for noteId=${childNoteId} with parentNoteId=${parentNoteId}`); |             console.error(`Can't find node for noteId=${childNoteId} with parentNoteId=${parentNoteId}`); | ||||||
| @@ -143,6 +145,8 @@ async function getRunPath(notePath) { | |||||||
|         path.push('root'); |         path.push('root'); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     const hoistedNoteId = await hoistedNoteService.getHoistedNoteId(); | ||||||
|  |  | ||||||
|     const effectivePath = []; |     const effectivePath = []; | ||||||
|     let childNoteId = null; |     let childNoteId = null; | ||||||
|     let i = 0; |     let i = 0; | ||||||
| @@ -195,13 +199,12 @@ async function getRunPath(notePath) { | |||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         if (parentNoteId === 'none') { |         effectivePath.push(parentNoteId); | ||||||
|  |         childNoteId = parentNoteId; | ||||||
|  |  | ||||||
|  |         if (parentNoteId === hoistedNoteId) { | ||||||
|             break; |             break; | ||||||
|         } |         } | ||||||
|         else { |  | ||||||
|             effectivePath.push(parentNoteId); |  | ||||||
|             childNoteId = parentNoteId; |  | ||||||
|         } |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     return effectivePath.reverse(); |     return effectivePath.reverse(); | ||||||
|   | |||||||
| @@ -12,8 +12,16 @@ async function prepareTree(noteRows, branchRows, relations) { | |||||||
|     treeCache.load(noteRows, branchRows, relations); |     treeCache.load(noteRows, branchRows, relations); | ||||||
|  |  | ||||||
|     const hoistedNoteId = await hoistedNoteService.getHoistedNoteId(); |     const hoistedNoteId = await hoistedNoteService.getHoistedNoteId(); | ||||||
|     const hoistedNote = await treeCache.getNote(hoistedNoteId); |  | ||||||
|     const hoistedBranch = (await hoistedNote.getBranches())[0]; |     let hoistedBranch; | ||||||
|  |  | ||||||
|  |     if (hoistedNoteId === 'root') { | ||||||
|  |         hoistedBranch = await treeCache.getBranch('root'); | ||||||
|  |     } | ||||||
|  |     else { | ||||||
|  |         const hoistedNote = await treeCache.getNote(hoistedNoteId); | ||||||
|  |         hoistedBranch = (await hoistedNote.getBranches())[0]; | ||||||
|  |     } | ||||||
|  |  | ||||||
|     return [ await prepareNode(hoistedBranch) ]; |     return [ await prepareNode(hoistedBranch) ]; | ||||||
| } | } | ||||||
|   | |||||||
| @@ -38,6 +38,7 @@ async function getNotes(noteIds) { | |||||||
| async function getRelations(noteIds) { | async function getRelations(noteIds) { | ||||||
|     // we need to fetch both parentNoteId and noteId matches because we can have loaded child |     // we need to fetch both parentNoteId and noteId matches because we can have loaded child | ||||||
|     // of which only some of the parents has been loaded. |     // of which only some of the parents has been loaded. | ||||||
|  |     // also now with note hoisting, it is possible to have the note displayed without its parent chain being loaded | ||||||
|  |  | ||||||
|     const relations = await sql.getManyRows(`SELECT branchId, noteId AS 'childNoteId', parentNoteId, notePosition FROM branches WHERE isDeleted = 0  |     const relations = await sql.getManyRows(`SELECT branchId, noteId AS 'childNoteId', parentNoteId, notePosition FROM branches WHERE isDeleted = 0  | ||||||
|          AND (parentNoteId IN (???) OR noteId IN (???))`, noteIds); |          AND (parentNoteId IN (???) OR noteId IN (???))`, noteIds); | ||||||
| @@ -65,6 +66,9 @@ async function getTree() { | |||||||
|           ) |           ) | ||||||
|         SELECT branches.* FROM tree JOIN branches USING(noteId) WHERE branches.isDeleted = 0 ORDER BY branches.notePosition`, [hoistedNoteId]); |         SELECT branches.* FROM tree JOIN branches USING(noteId) WHERE branches.isDeleted = 0 ORDER BY branches.notePosition`, [hoistedNoteId]); | ||||||
|  |  | ||||||
|  |     // we also want root branch in there because all the paths start with root | ||||||
|  |     branches.push(await sql.getRow(`SELECT * FROM branches WHERE branchId = 'root'`)); | ||||||
|  |  | ||||||
|     const noteIds = Array.from(new Set(branches.map(b => b.noteId))); |     const noteIds = Array.from(new Set(branches.map(b => b.noteId))); | ||||||
|  |  | ||||||
|     const notes = await getNotes(noteIds); |     const notes = await getNotes(noteIds); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user