| 
									
										
										
										
											2017-11-04 19:38:50 -04:00
										 |  |  | "use strict"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-24 20:41:27 -04:00
										 |  |  | class TreeCache { | 
					
						
							| 
									
										
										
										
											2018-03-24 21:39:15 -04:00
										 |  |  |     constructor(noteRows, branchRows) { | 
					
						
							| 
									
										
										
										
											2018-03-24 20:41:27 -04:00
										 |  |  |         this.parents = []; | 
					
						
							|  |  |  |         this.children = []; | 
					
						
							| 
									
										
										
										
											2018-03-24 21:39:15 -04:00
										 |  |  |         this.childParentToBranch = {}; | 
					
						
							| 
									
										
										
										
											2018-03-24 20:41:27 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |         this.notes = {}; | 
					
						
							|  |  |  |         for (const noteRow of noteRows) { | 
					
						
							|  |  |  |             const note = new NoteShort(this, noteRow); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             this.notes[note.noteId] = note; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-24 21:39:15 -04:00
										 |  |  |         this.branches = {}; | 
					
						
							|  |  |  |         for (const branchRow of branchRows) { | 
					
						
							|  |  |  |             const branch = new Branch(this, branchRow); | 
					
						
							| 
									
										
										
										
											2018-03-24 20:41:27 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-24 21:39:15 -04:00
										 |  |  |             this.branches[branch.branchId] = branch; | 
					
						
							|  |  |  |             this.addBranch(branch); | 
					
						
							| 
									
										
										
										
											2018-03-24 20:41:27 -04:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     getNote(noteId) { | 
					
						
							|  |  |  |         return this.notes[noteId]; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-24 21:39:15 -04:00
										 |  |  |     addBranch(branch) { | 
					
						
							|  |  |  |         this.parents[branch.noteId] = this.parents[branch.noteId] || []; | 
					
						
							|  |  |  |         this.parents[branch.noteId].push(this.notes[branch.parentNoteId]); | 
					
						
							| 
									
										
										
										
											2018-03-24 20:41:27 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-24 21:39:15 -04:00
										 |  |  |         this.children[branch.parentNoteId] = this.children[branch.parentNoteId] || []; | 
					
						
							|  |  |  |         this.children[branch.parentNoteId].push(this.notes[branch.noteId]); | 
					
						
							| 
									
										
										
										
											2018-03-24 20:41:27 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-24 21:39:15 -04:00
										 |  |  |         this.childParentToBranch[branch.noteId + '-' + branch.parentNoteId] = branch; | 
					
						
							| 
									
										
										
										
											2018-03-24 20:41:27 -04:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-24 21:39:15 -04:00
										 |  |  |     add(note, branch) { | 
					
						
							| 
									
										
										
										
											2018-03-24 20:41:27 -04:00
										 |  |  |         this.notes[note.noteId] = note; | 
					
						
							| 
									
										
										
										
											2018-03-24 21:39:15 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |         this.addBranch(branch); | 
					
						
							| 
									
										
										
										
											2018-03-24 20:41:27 -04:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-24 21:39:15 -04:00
										 |  |  |     async getBranch(childNoteId, parentNoteId) { | 
					
						
							|  |  |  |         return this.childParentToBranch[childNoteId + '-' + parentNoteId]; | 
					
						
							| 
									
										
										
										
											2018-03-24 20:41:27 -04:00
										 |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class NoteShort { | 
					
						
							|  |  |  |     constructor(treeCache, row) { | 
					
						
							|  |  |  |         this.treeCache = treeCache; | 
					
						
							|  |  |  |         this.noteId = row.noteId; | 
					
						
							|  |  |  |         this.title = row.title; | 
					
						
							|  |  |  |         this.isProtected = row.isProtected; | 
					
						
							|  |  |  |         this.type = row.type; | 
					
						
							|  |  |  |         this.mime = row.mime; | 
					
						
							|  |  |  |         this.hideInAutocomplete = row.hideInAutocomplete; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-24 21:39:15 -04:00
										 |  |  |     async getBranches() { | 
					
						
							|  |  |  |         const branches = []; | 
					
						
							| 
									
										
										
										
											2018-03-24 20:41:27 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |         for (const parent of this.treeCache.parents[this.noteId]) { | 
					
						
							| 
									
										
										
										
											2018-03-24 21:39:15 -04:00
										 |  |  |             branches.push(await this.treeCache.getBranch(this.noteId, p.noteId)); | 
					
						
							| 
									
										
										
										
											2018-03-24 20:41:27 -04:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-24 21:39:15 -04:00
										 |  |  |         return branches; | 
					
						
							| 
									
										
										
										
											2018-03-24 20:41:27 -04:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-24 21:39:15 -04:00
										 |  |  |     async getChildBranches() { | 
					
						
							|  |  |  |         const branches = []; | 
					
						
							| 
									
										
										
										
											2018-03-24 20:41:27 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |         for (const child of this.treeCache.children[this.noteId]) { | 
					
						
							| 
									
										
										
										
											2018-03-24 21:39:15 -04:00
										 |  |  |             branches.push(await this.treeCache.getBranch(child.noteId, this.noteId)); | 
					
						
							| 
									
										
										
										
											2018-03-24 20:41:27 -04:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-24 21:39:15 -04:00
										 |  |  |         return branches; | 
					
						
							| 
									
										
										
										
											2018-03-24 20:41:27 -04:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     async getParentNotes() { | 
					
						
							|  |  |  |         return this.treeCache.parents[this.noteId] || []; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     async getChildNotes() { | 
					
						
							|  |  |  |         return this.treeCache.children[this.noteId] || []; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     get toString() { | 
					
						
							|  |  |  |         return `Note(noteId=${this.noteId}, title=${this.title})`; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-24 21:39:15 -04:00
										 |  |  | class Branch { | 
					
						
							| 
									
										
										
										
											2018-03-24 20:41:27 -04:00
										 |  |  |     constructor(treeCache, row) { | 
					
						
							|  |  |  |         this.treeCache = treeCache; | 
					
						
							| 
									
										
										
										
											2018-03-24 21:39:15 -04:00
										 |  |  |         this.branchId = row.branchId; | 
					
						
							| 
									
										
										
										
											2018-03-24 20:41:27 -04:00
										 |  |  |         this.noteId = row.noteId; | 
					
						
							|  |  |  |         this.note = null; | 
					
						
							|  |  |  |         this.parentNoteId = row.parentNoteId; | 
					
						
							|  |  |  |         this.notePosition = row.notePosition; | 
					
						
							|  |  |  |         this.prefix = row.prefix; | 
					
						
							|  |  |  |         this.isExpanded = row.isExpanded; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     async getNote() { | 
					
						
							|  |  |  |         return this.treeCache.getNote(this.noteId); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     get toString() { | 
					
						
							| 
									
										
										
										
											2018-03-24 21:39:15 -04:00
										 |  |  |         return `Branch(branchId=${this.branchId})`; | 
					
						
							| 
									
										
										
										
											2018-03-24 20:41:27 -04:00
										 |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-24 21:39:15 -04:00
										 |  |  | const treeService = (function() { | 
					
						
							| 
									
										
										
										
											2018-03-24 20:41:27 -04:00
										 |  |  |     let treeCache; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-14 23:31:20 -05:00
										 |  |  |     const $tree = $("#tree"); | 
					
						
							|  |  |  |     const $parentList = $("#parent-list"); | 
					
						
							|  |  |  |     const $parentListList = $("#parent-list-inner"); | 
					
						
							| 
									
										
										
										
											2018-03-24 00:54:50 -04:00
										 |  |  |     const $createTopLevelNoteButton = $("#create-top-level-note-button"); | 
					
						
							|  |  |  |     const $collapseTreeButton = $("#collapse-tree-button"); | 
					
						
							|  |  |  |     const $scrollToCurrentNoteButton = $("#scroll-to-current-note-button"); | 
					
						
							| 
									
										
										
										
											2017-11-21 20:04:06 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-24 21:23:04 -05:00
										 |  |  |     let instanceName = null; // should have better place
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-06 23:15:53 -05:00
										 |  |  |     let startNotePath = null; | 
					
						
							| 
									
										
										
										
											2017-11-18 17:05:50 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-24 20:41:27 -04:00
										 |  |  |     /** @type {Object.<string, NoteShort>} */ | 
					
						
							|  |  |  |     let noteMap = {}; | 
					
						
							| 
									
										
										
										
											2018-03-24 21:39:15 -04:00
										 |  |  |     /** @type {Object.<string, Branch>} */ | 
					
						
							|  |  |  |     let branchMap = {}; | 
					
						
							| 
									
										
										
										
											2018-02-13 22:30:33 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-12 20:00:19 -04:00
										 |  |  |     function getNote(noteId) { | 
					
						
							| 
									
										
										
										
											2018-03-24 20:41:27 -04:00
										 |  |  |         const note = noteMap[noteId]; | 
					
						
							| 
									
										
										
										
											2018-03-12 20:00:19 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if (!note) { | 
					
						
							|  |  |  |             throwError("Can't find title for noteId='" + noteId + "'"); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return note; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-24 21:39:15 -04:00
										 |  |  |     function getBranchId(parentNoteId, childNoteId) { | 
					
						
							| 
									
										
										
										
											2017-12-23 11:02:38 -05:00
										 |  |  |         assertArguments(parentNoteId, childNoteId); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-24 20:41:27 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-19 11:28:46 -05:00
										 |  |  |         const key = parentNoteId + "-" + childNoteId; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-29 22:03:03 -05:00
										 |  |  |         // this can return undefined and client code should deal with it somehow
 | 
					
						
							| 
									
										
										
										
											2017-11-19 11:28:46 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-24 21:39:15 -04:00
										 |  |  |         return parentChildToBranchId[key]; | 
					
						
							| 
									
										
										
										
											2017-11-19 11:28:46 -05:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-29 22:03:03 -05:00
										 |  |  |     function getNoteTitle(noteId, parentNoteId = null) { | 
					
						
							| 
									
										
										
										
											2017-12-23 11:02:38 -05:00
										 |  |  |         assertArguments(noteId); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-24 20:41:27 -04:00
										 |  |  |         let title = treeCache.getNote(noteId).title; | 
					
						
							| 
									
										
										
										
											2017-11-19 12:06:48 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-29 22:03:03 -05:00
										 |  |  |         if (parentNoteId !== null) { | 
					
						
							| 
									
										
										
										
											2018-03-24 21:39:15 -04:00
										 |  |  |             const branchId = getBranchId(parentNoteId, noteId); | 
					
						
							| 
									
										
										
										
											2017-11-29 22:03:03 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-24 21:39:15 -04:00
										 |  |  |             if (branchId) { | 
					
						
							|  |  |  |                 const branch = branchMap[branchId]; | 
					
						
							| 
									
										
										
										
											2017-11-29 22:03:03 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-24 21:39:15 -04:00
										 |  |  |                 if (branch.prefix) { | 
					
						
							|  |  |  |                     title = branch.prefix + ' - ' + title; | 
					
						
							| 
									
										
										
										
											2017-11-29 22:03:03 -05:00
										 |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-19 12:06:48 -05:00
										 |  |  |         return title; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-28 19:30:14 -05:00
										 |  |  |     // note that if you want to access data like noteId or isProtected, you need to go into "data" property
 | 
					
						
							| 
									
										
										
										
											2017-11-23 20:12:39 -05:00
										 |  |  |     function getCurrentNode() { | 
					
						
							| 
									
										
										
										
											2018-02-14 23:31:20 -05:00
										 |  |  |         return $tree.fancytree("getActiveNode"); | 
					
						
							| 
									
										
										
										
											2017-11-23 20:12:39 -05:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     function getCurrentNotePath() { | 
					
						
							|  |  |  |         const node = getCurrentNode(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return treeUtils.getNotePath(node); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-24 21:39:15 -04:00
										 |  |  |     function getNodesByBranchId(branchId) { | 
					
						
							|  |  |  |         assertArguments(branchId); | 
					
						
							| 
									
										
										
										
											2017-12-23 11:02:38 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-24 21:39:15 -04:00
										 |  |  |         const branch = branchMap[branchId]; | 
					
						
							| 
									
										
										
										
											2017-11-28 10:17:30 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-24 21:39:15 -04:00
										 |  |  |         return getNodesByNoteId(branch.noteId).filter(node => node.data.branchId === branchId); | 
					
						
							| 
									
										
										
										
											2017-11-28 10:17:30 -05:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     function getNodesByNoteId(noteId) { | 
					
						
							| 
									
										
										
										
											2017-12-23 11:02:38 -05:00
										 |  |  |         assertArguments(noteId); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-12 22:26:40 -05:00
										 |  |  |         const list = getTree().getNodesByRef(noteId); | 
					
						
							|  |  |  |         return list ? list : []; // if no nodes with this refKey are found, fancy tree returns null
 | 
					
						
							| 
									
										
										
										
											2017-11-23 20:12:39 -05:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-24 21:39:15 -04:00
										 |  |  |     function setPrefix(branchId, prefix) { | 
					
						
							|  |  |  |         assertArguments(branchId); | 
					
						
							| 
									
										
										
										
											2017-12-23 11:02:38 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-24 21:39:15 -04:00
										 |  |  |         branchMap[branchId].prefix = prefix; | 
					
						
							| 
									
										
										
										
											2017-11-28 10:17:30 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-24 21:39:15 -04:00
										 |  |  |         getNodesByBranchId(branchId).map(node => setNodeTitleWithPrefix(node)); | 
					
						
							| 
									
										
										
										
											2018-03-12 23:14:09 -04:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-11-28 10:17:30 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-12 23:14:09 -04:00
										 |  |  |     function setNodeTitleWithPrefix(node) { | 
					
						
							|  |  |  |         const noteTitle = getNoteTitle(node.data.noteId); | 
					
						
							| 
									
										
										
										
											2018-03-24 21:39:15 -04:00
										 |  |  |         const branch = branchMap[node.data.branchId]; | 
					
						
							| 
									
										
										
										
											2018-03-12 23:14:09 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-24 21:39:15 -04:00
										 |  |  |         const prefix = branch.prefix; | 
					
						
							| 
									
										
										
										
											2018-03-12 23:14:09 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |         const title = (prefix ? (prefix + " - ") : "") + noteTitle; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         node.setTitle(escapeHtml(title)); | 
					
						
							| 
									
										
										
										
											2017-11-28 10:17:30 -05:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-17 16:28:13 -05:00
										 |  |  |     function removeParentChildRelation(parentNoteId, childNoteId) { | 
					
						
							| 
									
										
										
										
											2017-12-23 11:02:38 -05:00
										 |  |  |         assertArguments(parentNoteId, childNoteId); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-24 20:41:27 -04:00
										 |  |  |         const parentNote = noteMap[parentNoteId]; | 
					
						
							|  |  |  |         const childNote = noteMap[childNoteId]; | 
					
						
							| 
									
										
										
										
											2017-12-17 16:28:13 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-24 21:39:15 -04:00
										 |  |  |         // FIXME
 | 
					
						
							| 
									
										
										
										
											2017-12-17 16:28:13 -05:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-24 21:39:15 -04:00
										 |  |  |     function setParentChildRelation(branchId, parentNoteId, childNoteId) { | 
					
						
							|  |  |  |         assertArguments(branchId, parentNoteId, childNoteId); | 
					
						
							| 
									
										
										
										
											2017-12-23 11:02:38 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-24 20:41:27 -04:00
										 |  |  |         const parentNote = noteMap[parentNoteId]; | 
					
						
							|  |  |  |         const childNote = noteMap[childNoteId]; | 
					
						
							| 
									
										
										
										
											2017-12-09 21:53:21 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-24 20:41:27 -04:00
										 |  |  |         // FIXME: assert
 | 
					
						
							| 
									
										
										
										
											2017-12-09 21:53:21 -05:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-24 21:39:15 -04:00
										 |  |  |     async function prepareBranch(noteRows, branchRows) { | 
					
						
							| 
									
										
										
										
											2018-03-24 20:41:27 -04:00
										 |  |  |         assertArguments(noteRows); | 
					
						
							| 
									
										
										
										
											2017-11-18 17:05:50 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-24 21:39:15 -04:00
										 |  |  |         treeCache = new TreeCache(noteRows, branchRows); | 
					
						
							| 
									
										
										
										
											2017-11-18 18:57:50 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-24 21:39:15 -04:00
										 |  |  |         return await prepareBranchInner(treeCache.getNote('root')); | 
					
						
							| 
									
										
										
										
											2017-11-17 21:31:54 -05:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-24 20:41:27 -04:00
										 |  |  |     async function getExtraClasses(note) { | 
					
						
							| 
									
										
										
										
											2017-12-23 11:02:38 -05:00
										 |  |  |         assertArguments(note); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-25 09:59:48 -05:00
										 |  |  |         const extraClasses = []; | 
					
						
							| 
									
										
										
										
											2017-11-23 20:12:39 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-28 19:30:14 -05:00
										 |  |  |         if (note.isProtected) { | 
					
						
							| 
									
										
										
										
											2017-12-25 09:59:48 -05:00
										 |  |  |             extraClasses.push("protected"); | 
					
						
							| 
									
										
										
										
											2017-11-23 20:12:39 -05:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-24 20:41:27 -04:00
										 |  |  |         if ((await note.getParentNotes()).length > 1) { | 
					
						
							| 
									
										
										
										
											2017-12-25 09:59:48 -05:00
										 |  |  |             extraClasses.push("multiple-parents"); | 
					
						
							| 
									
										
										
										
											2017-11-23 20:12:39 -05:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-11 10:49:22 -04:00
										 |  |  |         extraClasses.push(note.type); | 
					
						
							| 
									
										
										
										
											2018-01-26 22:32:44 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-25 09:59:48 -05:00
										 |  |  |         return extraClasses.join(" "); | 
					
						
							| 
									
										
										
										
											2017-11-23 20:12:39 -05:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-24 21:39:15 -04:00
										 |  |  |     async function prepareBranchInner(parentNote) { | 
					
						
							| 
									
										
										
										
											2018-03-24 20:41:27 -04:00
										 |  |  |         assertArguments(parentNote); | 
					
						
							| 
									
										
										
										
											2017-12-23 11:02:38 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-24 21:39:15 -04:00
										 |  |  |         const childBranches = await parentNote.getChildBranches(); | 
					
						
							| 
									
										
										
										
											2018-03-24 20:41:27 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-24 21:39:15 -04:00
										 |  |  |         if (!childBranches) { | 
					
						
							| 
									
										
										
										
											2018-03-24 20:41:27 -04:00
										 |  |  |             messaging.logError(`No children for ${parentNote}. This shouldn't happen.`); | 
					
						
							| 
									
										
										
										
											2017-11-19 16:43:49 -05:00
										 |  |  |             return; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-17 21:31:54 -05:00
										 |  |  |         const noteList = []; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-24 21:39:15 -04:00
										 |  |  |         for (const branch of childBranches) { | 
					
						
							|  |  |  |             const note = await branch.getNote(); | 
					
						
							|  |  |  |             const title = (branch.prefix ? (branch.prefix + " - ") : "") + note.title; | 
					
						
							| 
									
										
										
										
											2017-12-28 19:00:31 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-23 20:12:39 -05:00
										 |  |  |             const node = { | 
					
						
							| 
									
										
										
										
											2018-03-24 20:41:27 -04:00
										 |  |  |                 noteId: note.noteId, | 
					
						
							| 
									
										
										
										
											2018-03-24 21:39:15 -04:00
										 |  |  |                 parentNoteId: branch.parentNoteId, | 
					
						
							|  |  |  |                 branchId: branch.branchId, | 
					
						
							| 
									
										
										
										
											2018-03-12 23:14:09 -04:00
										 |  |  |                 isProtected: note.isProtected, | 
					
						
							| 
									
										
										
										
											2017-12-28 19:00:31 -05:00
										 |  |  |                 title: escapeHtml(title), | 
					
						
							| 
									
										
										
										
											2018-03-12 23:14:09 -04:00
										 |  |  |                 extraClasses: getExtraClasses(note), | 
					
						
							| 
									
										
										
										
											2018-03-24 20:41:27 -04:00
										 |  |  |                 refKey: note.noteId, | 
					
						
							| 
									
										
										
										
											2018-03-24 21:39:15 -04:00
										 |  |  |                 expanded: note.type !== 'search' && branch.isExpanded | 
					
						
							| 
									
										
										
										
											2017-11-23 20:12:39 -05:00
										 |  |  |             }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-24 20:41:27 -04:00
										 |  |  |             const hasChildren = (await note.getChildNotes()).length > 0; | 
					
						
							| 
									
										
										
										
											2018-03-12 23:14:09 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |             if (hasChildren || note.type === 'search') { | 
					
						
							| 
									
										
										
										
											2017-11-22 23:16:54 -05:00
										 |  |  |                 node.folder = true; | 
					
						
							| 
									
										
										
										
											2017-11-17 21:31:54 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-13 19:31:07 -04:00
										 |  |  |                 if (node.expanded && note.type !== 'search') { | 
					
						
							| 
									
										
										
										
											2018-03-24 21:39:15 -04:00
										 |  |  |                     node.children = await prepareBranchInner(note); | 
					
						
							| 
									
										
										
										
											2017-11-17 21:31:54 -05:00
										 |  |  |                 } | 
					
						
							|  |  |  |                 else { | 
					
						
							| 
									
										
										
										
											2017-11-22 23:16:54 -05:00
										 |  |  |                     node.lazy = true; | 
					
						
							| 
									
										
										
										
											2017-11-17 21:31:54 -05:00
										 |  |  |                 } | 
					
						
							| 
									
										
										
										
											2017-11-04 19:28:49 -04:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2017-11-17 21:31:54 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-22 23:16:54 -05:00
										 |  |  |             noteList.push(node); | 
					
						
							| 
									
										
										
										
											2017-11-04 19:28:49 -04:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2017-11-17 21:31:54 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return noteList; | 
					
						
							| 
									
										
										
										
											2017-11-04 19:28:49 -04:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-15 20:54:22 -05:00
										 |  |  |     async function expandToNote(notePath, expandOpts) { | 
					
						
							| 
									
										
										
										
											2017-12-23 11:02:38 -05:00
										 |  |  |         assertArguments(notePath); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-24 23:00:12 -04:00
										 |  |  |         const runPath = await getRunPath(notePath); | 
					
						
							| 
									
										
										
										
											2017-12-23 12:19:15 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-03 17:46:56 -05:00
										 |  |  |         const noteId = treeUtils.getNoteIdFromNotePath(notePath); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         let parentNoteId = 'root'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         for (const childNoteId of runPath) { | 
					
						
							| 
									
										
										
										
											2018-01-28 19:30:14 -05:00
										 |  |  |             const node = getNodesByNoteId(childNoteId).find(node => node.data.parentNoteId === parentNoteId); | 
					
						
							| 
									
										
										
										
											2017-12-03 17:46:56 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |             if (childNoteId === noteId) { | 
					
						
							| 
									
										
										
										
											2018-01-15 20:54:22 -05:00
										 |  |  |                 return node; | 
					
						
							| 
									
										
										
										
											2017-12-03 17:46:56 -05:00
										 |  |  |             } | 
					
						
							|  |  |  |             else { | 
					
						
							| 
									
										
										
										
											2018-01-15 20:54:22 -05:00
										 |  |  |                 await node.setExpanded(true, expandOpts); | 
					
						
							| 
									
										
										
										
											2017-12-03 17:46:56 -05:00
										 |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             parentNoteId = childNoteId; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2018-01-15 20:54:22 -05:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     async function activateNode(notePath) { | 
					
						
							|  |  |  |         assertArguments(notePath); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         const node = await expandToNote(notePath); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         await node.setActive(); | 
					
						
							| 
									
										
										
										
											2018-01-01 18:53:52 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |         clearSelectedNodes(); | 
					
						
							| 
									
										
										
										
											2017-12-03 17:46:56 -05:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * 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. | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2018-03-24 23:00:12 -04:00
										 |  |  |     async function getRunPath(notePath) { | 
					
						
							| 
									
										
										
										
											2017-12-23 11:02:38 -05:00
										 |  |  |         assertArguments(notePath); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-19 08:47:22 -05:00
										 |  |  |         const path = notePath.split("/").reverse(); | 
					
						
							| 
									
										
										
										
											2017-12-03 17:46:56 -05:00
										 |  |  |         path.push('root'); | 
					
						
							| 
									
										
										
										
											2017-11-19 08:47:22 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |         const effectivePath = []; | 
					
						
							| 
									
										
										
										
											2017-11-19 11:28:46 -05:00
										 |  |  |         let childNoteId = null; | 
					
						
							| 
									
										
										
										
											2017-11-19 18:16:50 -05:00
										 |  |  |         let i = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         while (true) { | 
					
						
							| 
									
										
										
										
											2017-11-30 00:02:32 -05:00
										 |  |  |             if (i >= path.length) { | 
					
						
							|  |  |  |                 break; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             const parentNoteId = path[i++]; | 
					
						
							| 
									
										
										
										
											2017-11-19 11:28:46 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |             if (childNoteId !== null) { | 
					
						
							| 
									
										
										
										
											2018-03-24 23:00:12 -04:00
										 |  |  |                 const child = treeCache.getNote(childNoteId); | 
					
						
							|  |  |  |                 const parents = await child.getParentNotes(); | 
					
						
							| 
									
										
										
										
											2017-11-19 11:28:46 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-26 21:00:42 -05:00
										 |  |  |                 if (!parents) { | 
					
						
							| 
									
										
										
										
											2017-12-01 22:28:22 -05:00
										 |  |  |                     messaging.logError("No parents found for " + childNoteId); | 
					
						
							| 
									
										
										
										
											2017-11-26 21:00:42 -05:00
										 |  |  |                     return; | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-24 23:00:12 -04:00
										 |  |  |                 if (!parents.some(p => p.noteId === parentNoteId)) { | 
					
						
							| 
									
										
										
										
											2017-12-18 22:06:24 -05:00
										 |  |  |                     console.log(now(), "Did not find parent " + parentNoteId + " for child " + childNoteId); | 
					
						
							| 
									
										
										
										
											2017-11-19 11:28:46 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |                     if (parents.length > 0) { | 
					
						
							| 
									
										
										
										
											2017-12-23 11:02:38 -05:00
										 |  |  |                         console.log(now(), "Available parents:", parents); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-24 23:00:12 -04:00
										 |  |  |                         const someNotePath = await getSomeNotePath(parents[0]); | 
					
						
							| 
									
										
										
										
											2017-12-23 12:19:15 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |                         if (someNotePath) { // in case it's root the path may be empty
 | 
					
						
							|  |  |  |                             const pathToRoot = someNotePath.split("/").reverse(); | 
					
						
							| 
									
										
										
										
											2017-11-19 18:16:50 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-23 12:19:15 -05:00
										 |  |  |                             for (const noteId of pathToRoot) { | 
					
						
							|  |  |  |                                 effectivePath.push(noteId); | 
					
						
							|  |  |  |                             } | 
					
						
							| 
									
										
										
										
											2017-11-30 00:02:32 -05:00
										 |  |  |                         } | 
					
						
							| 
									
										
										
										
											2017-11-19 11:28:46 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-30 00:02:32 -05:00
										 |  |  |                         break; | 
					
						
							| 
									
										
										
										
											2017-11-19 11:28:46 -05:00
										 |  |  |                     } | 
					
						
							|  |  |  |                     else { | 
					
						
							| 
									
										
										
										
											2017-12-01 22:28:22 -05:00
										 |  |  |                         messaging.logError("No parents, can't activate node."); | 
					
						
							| 
									
										
										
										
											2017-11-19 11:28:46 -05:00
										 |  |  |                         return; | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2017-11-19 08:47:22 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-03 17:46:56 -05:00
										 |  |  |             if (parentNoteId === 'root') { | 
					
						
							|  |  |  |                 break; | 
					
						
							| 
									
										
										
										
											2017-11-19 08:47:22 -05:00
										 |  |  |             } | 
					
						
							|  |  |  |             else { | 
					
						
							| 
									
										
										
										
											2017-12-03 17:46:56 -05:00
										 |  |  |                 effectivePath.push(parentNoteId); | 
					
						
							|  |  |  |                 childNoteId = parentNoteId; | 
					
						
							| 
									
										
										
										
											2017-11-19 08:47:22 -05:00
										 |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2017-12-03 17:46:56 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return effectivePath.reverse(); | 
					
						
							| 
									
										
										
										
											2017-11-19 08:47:22 -05:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-24 23:00:12 -04:00
										 |  |  |     async function showParentList(noteId, node) { | 
					
						
							| 
									
										
										
										
											2017-12-23 11:02:38 -05:00
										 |  |  |         assertArguments(noteId, node); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-24 23:00:12 -04:00
										 |  |  |         const note = treeCache.getNote(noteId); | 
					
						
							|  |  |  |         const parents = await note.getParentNotes(); | 
					
						
							| 
									
										
										
										
											2017-11-21 20:04:06 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-24 23:00:12 -04:00
										 |  |  |         if (!parents.length) { | 
					
						
							| 
									
										
										
										
											2017-12-06 19:53:23 -05:00
										 |  |  |             throwError("Can't find parents for noteId=" + noteId); | 
					
						
							| 
									
										
										
										
											2017-11-22 23:16:54 -05:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-21 20:04:06 -05:00
										 |  |  |         if (parents.length <= 1) { | 
					
						
							| 
									
										
										
										
											2018-02-14 23:31:20 -05:00
										 |  |  |             $parentList.hide(); | 
					
						
							| 
									
										
										
										
											2017-11-21 20:04:06 -05:00
										 |  |  |         } | 
					
						
							|  |  |  |         else { | 
					
						
							| 
									
										
										
										
											2018-02-14 23:31:20 -05:00
										 |  |  |             $parentList.show(); | 
					
						
							|  |  |  |             $parentListList.empty(); | 
					
						
							| 
									
										
										
										
											2017-11-21 20:04:06 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-24 23:00:12 -04:00
										 |  |  |             for (const parentNote of parents) { | 
					
						
							|  |  |  |                 const parentNotePath = await getSomeNotePath(parentNote); | 
					
						
							| 
									
										
										
										
											2017-12-06 20:11:45 -05:00
										 |  |  |                 // this is to avoid having root notes leading '/'
 | 
					
						
							|  |  |  |                 const notePath = parentNotePath ? (parentNotePath + '/' + noteId) : noteId; | 
					
						
							| 
									
										
										
										
											2017-11-21 20:04:06 -05:00
										 |  |  |                 const title = getNotePathTitle(notePath); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 let item; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-24 23:00:12 -04:00
										 |  |  |                 if (node.getParent().data.noteId === parentNote.noteId) { | 
					
						
							| 
									
										
										
										
											2017-11-21 20:04:06 -05:00
										 |  |  |                     item = $("<span/>").attr("title", "Current note").append(title); | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |                 else { | 
					
						
							|  |  |  |                     item = link.createNoteLink(notePath, title); | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-14 23:31:20 -05:00
										 |  |  |                 $parentListList.append($("<li/>").append(item)); | 
					
						
							| 
									
										
										
										
											2017-11-21 20:04:06 -05:00
										 |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     function getNotePathTitle(notePath) { | 
					
						
							| 
									
										
										
										
											2017-12-23 11:02:38 -05:00
										 |  |  |         assertArguments(notePath); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-21 20:04:06 -05:00
										 |  |  |         const titlePath = []; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-29 22:03:03 -05:00
										 |  |  |         let parentNoteId = 'root'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         for (const noteId of notePath.split('/')) { | 
					
						
							|  |  |  |             titlePath.push(getNoteTitle(noteId, parentNoteId)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             parentNoteId = noteId; | 
					
						
							| 
									
										
										
										
											2017-11-21 20:04:06 -05:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return titlePath.join(' / '); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-24 23:00:12 -04:00
										 |  |  |     async function getSomeNotePath(note) { | 
					
						
							|  |  |  |         assertArguments(note); | 
					
						
							| 
									
										
										
										
											2017-12-23 11:02:38 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-21 20:04:06 -05:00
										 |  |  |         const path = []; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-24 23:00:12 -04:00
										 |  |  |         let cur = note; | 
					
						
							| 
									
										
										
										
											2017-11-21 20:04:06 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-24 23:00:12 -04:00
										 |  |  |         while (cur.noteId !== 'root') { | 
					
						
							|  |  |  |             path.push(cur.noteId); | 
					
						
							| 
									
										
										
										
											2017-11-21 20:04:06 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-24 23:00:12 -04:00
										 |  |  |             const parents = await cur.getParentNotes(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if (!parents.length) { | 
					
						
							| 
									
										
										
										
											2017-12-19 21:40:48 -05:00
										 |  |  |                 throwError("Can't find parents for " + cur); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-24 23:00:12 -04:00
										 |  |  |             cur = parents[0]; | 
					
						
							| 
									
										
										
										
											2017-11-21 20:04:06 -05:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return path.reverse().join('/'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-24 21:39:15 -04:00
										 |  |  |     async function setExpandedToServer(branchId, isExpanded) { | 
					
						
							|  |  |  |         assertArguments(branchId); | 
					
						
							| 
									
										
										
										
											2017-12-23 11:02:38 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-18 17:05:50 -05:00
										 |  |  |         const expandedNum = isExpanded ? 1 : 0; | 
					
						
							| 
									
										
										
										
											2017-11-04 19:28:49 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-24 21:39:15 -04:00
										 |  |  |         await server.put('tree/' + branchId + '/expanded/' + expandedNum); | 
					
						
							| 
									
										
										
										
											2017-11-04 19:28:49 -04:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-19 18:16:50 -05:00
										 |  |  |     function setCurrentNotePathToHash(node) { | 
					
						
							| 
									
										
										
										
											2017-12-23 11:02:38 -05:00
										 |  |  |         assertArguments(node); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-19 18:16:50 -05:00
										 |  |  |         const currentNotePath = treeUtils.getNotePath(node); | 
					
						
							| 
									
										
										
										
											2018-03-24 21:39:15 -04:00
										 |  |  |         const currentBranchId = node.data.branchId; | 
					
						
							| 
									
										
										
										
											2017-11-19 18:16:50 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |         document.location.hash = currentNotePath; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-24 21:39:15 -04:00
										 |  |  |         recentNotes.addRecentNote(currentBranchId, currentNotePath); | 
					
						
							| 
									
										
										
										
											2017-11-19 18:16:50 -05:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-14 21:39:21 -05:00
										 |  |  |     function getSelectedNodes(stopOnParents = false) { | 
					
						
							|  |  |  |         return getTree().getSelectedNodes(stopOnParents); | 
					
						
							| 
									
										
										
										
											2018-01-01 17:59:59 -05:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     function clearSelectedNodes() { | 
					
						
							|  |  |  |         for (const selectedNode of getSelectedNodes()) { | 
					
						
							|  |  |  |             selectedNode.setSelected(false); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-01 18:53:52 -05:00
										 |  |  |         const currentNode = getCurrentNode(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (currentNode) { | 
					
						
							|  |  |  |             currentNode.setSelected(true); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2018-01-01 17:59:59 -05:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-24 21:39:15 -04:00
										 |  |  |     function initFancyTree(branch) { | 
					
						
							|  |  |  |         assertArguments(branch); | 
					
						
							| 
									
										
										
										
											2017-12-23 11:02:38 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-04 19:28:49 -04:00
										 |  |  |         const keybindings = { | 
					
						
							|  |  |  |             "del": node => { | 
					
						
							| 
									
										
										
										
											2018-01-14 21:39:21 -05:00
										 |  |  |                 treeChanges.deleteNodes(getSelectedNodes(true)); | 
					
						
							| 
									
										
										
										
											2017-11-04 19:28:49 -04:00
										 |  |  |             }, | 
					
						
							| 
									
										
										
										
											2018-01-01 17:59:59 -05:00
										 |  |  |             "ctrl+up": node => { | 
					
						
							| 
									
										
										
										
											2017-11-04 19:28:49 -04:00
										 |  |  |                 const beforeNode = node.getPrevSibling(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 if (beforeNode !== null) { | 
					
						
							| 
									
										
										
										
											2018-01-01 18:29:06 -05:00
										 |  |  |                     treeChanges.moveBeforeNode([node], beforeNode); | 
					
						
							| 
									
										
										
										
											2017-11-04 19:28:49 -04:00
										 |  |  |                 } | 
					
						
							| 
									
										
										
										
											2018-01-01 18:29:06 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |                 return false; | 
					
						
							| 
									
										
										
										
											2017-11-04 19:28:49 -04:00
										 |  |  |             }, | 
					
						
							| 
									
										
										
										
											2018-01-01 17:59:59 -05:00
										 |  |  |             "ctrl+down": node => { | 
					
						
							| 
									
										
										
										
											2017-11-04 19:28:49 -04:00
										 |  |  |                 let afterNode = node.getNextSibling(); | 
					
						
							|  |  |  |                 if (afterNode !== null) { | 
					
						
							| 
									
										
										
										
											2018-01-01 18:29:06 -05:00
										 |  |  |                     treeChanges.moveAfterNode([node], afterNode); | 
					
						
							| 
									
										
										
										
											2017-11-04 19:28:49 -04:00
										 |  |  |                 } | 
					
						
							| 
									
										
										
										
											2018-01-01 18:29:06 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |                 return false; | 
					
						
							| 
									
										
										
										
											2017-11-04 19:28:49 -04:00
										 |  |  |             }, | 
					
						
							| 
									
										
										
										
											2018-01-01 17:59:59 -05:00
										 |  |  |             "ctrl+left": node => { | 
					
						
							| 
									
										
										
										
											2017-11-28 15:17:11 -05:00
										 |  |  |                 treeChanges.moveNodeUpInHierarchy(node); | 
					
						
							| 
									
										
										
										
											2018-01-01 18:29:06 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |                 return false; | 
					
						
							| 
									
										
										
										
											2017-11-04 19:28:49 -04:00
										 |  |  |             }, | 
					
						
							| 
									
										
										
										
											2018-01-01 17:59:59 -05:00
										 |  |  |             "ctrl+right": node => { | 
					
						
							| 
									
										
										
										
											2017-11-04 19:28:49 -04:00
										 |  |  |                 let toNode = node.getPrevSibling(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 if (toNode !== null) { | 
					
						
							| 
									
										
										
										
											2018-01-01 18:29:06 -05:00
										 |  |  |                     treeChanges.moveToNode([node], toNode); | 
					
						
							| 
									
										
										
										
											2017-11-04 19:28:49 -04:00
										 |  |  |                 } | 
					
						
							| 
									
										
										
										
											2018-01-01 18:29:06 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |                 return false; | 
					
						
							| 
									
										
										
										
											2017-11-26 23:10:23 -05:00
										 |  |  |             }, | 
					
						
							| 
									
										
										
										
											2018-01-01 17:59:59 -05:00
										 |  |  |             "shift+up": node => { | 
					
						
							|  |  |  |                 node.navigate($.ui.keyCode.UP, true).then(() => { | 
					
						
							|  |  |  |                     const currentNode = getCurrentNode(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                     if (currentNode.isSelected()) { | 
					
						
							|  |  |  |                         node.setSelected(false); | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                     currentNode.setSelected(true); | 
					
						
							|  |  |  |                 }); | 
					
						
							| 
									
										
										
										
											2018-01-01 18:29:06 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |                 return false; | 
					
						
							| 
									
										
										
										
											2018-01-01 17:59:59 -05:00
										 |  |  |             }, | 
					
						
							|  |  |  |             "shift+down": node => { | 
					
						
							|  |  |  |                 node.navigate($.ui.keyCode.DOWN, true).then(() => { | 
					
						
							|  |  |  |                     const currentNode = getCurrentNode(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                     if (currentNode.isSelected()) { | 
					
						
							|  |  |  |                         node.setSelected(false); | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                     currentNode.setSelected(true); | 
					
						
							|  |  |  |                 }); | 
					
						
							| 
									
										
										
										
											2018-01-01 18:29:06 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |                 return false; | 
					
						
							| 
									
										
										
										
											2018-01-01 17:59:59 -05:00
										 |  |  |             }, | 
					
						
							| 
									
										
										
										
											2017-11-26 23:10:23 -05:00
										 |  |  |             "f2": node => { | 
					
						
							| 
									
										
										
										
											2017-11-28 10:17:30 -05:00
										 |  |  |                 editTreePrefix.showDialog(node); | 
					
						
							| 
									
										
										
										
											2017-12-24 14:01:20 -05:00
										 |  |  |             }, | 
					
						
							| 
									
										
										
										
											2017-12-26 10:00:08 -05:00
										 |  |  |             "alt+-": node => { | 
					
						
							|  |  |  |                 collapseTree(node); | 
					
						
							|  |  |  |             }, | 
					
						
							| 
									
										
										
										
											2018-01-13 23:03:17 -05:00
										 |  |  |             "alt+s": node => { | 
					
						
							| 
									
										
										
										
											2018-01-28 19:30:14 -05:00
										 |  |  |                 sortAlphabetically(node.data.noteId); | 
					
						
							| 
									
										
										
										
											2018-01-13 23:03:17 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |                 return false; | 
					
						
							|  |  |  |             }, | 
					
						
							| 
									
										
										
										
											2018-01-01 18:11:23 -05:00
										 |  |  |             "ctrl+a": node => { | 
					
						
							|  |  |  |                 for (const child of node.getParent().getChildren()) { | 
					
						
							|  |  |  |                     child.setSelected(true); | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 return false; | 
					
						
							|  |  |  |             }, | 
					
						
							| 
									
										
										
										
											2018-01-01 17:59:59 -05:00
										 |  |  |             "ctrl+c": () => { | 
					
						
							|  |  |  |                 contextMenu.copy(getSelectedNodes()); | 
					
						
							| 
									
										
										
										
											2017-12-27 21:12:54 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |                 return false; | 
					
						
							|  |  |  |             }, | 
					
						
							| 
									
										
										
										
											2018-01-01 17:59:59 -05:00
										 |  |  |             "ctrl+x": () => { | 
					
						
							|  |  |  |                 contextMenu.cut(getSelectedNodes()); | 
					
						
							| 
									
										
										
										
											2017-12-27 21:12:54 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |                 return false; | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |             "ctrl+v": node => { | 
					
						
							|  |  |  |                 contextMenu.pasteInto(node); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 return false; | 
					
						
							|  |  |  |             }, | 
					
						
							| 
									
										
										
										
											2017-12-28 22:57:35 -05:00
										 |  |  |             "return": node => { | 
					
						
							| 
									
										
										
										
											2018-01-22 22:14:03 -05:00
										 |  |  |                 noteEditor.focus(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 return false; | 
					
						
							| 
									
										
										
										
											2017-12-28 22:57:35 -05:00
										 |  |  |             }, | 
					
						
							| 
									
										
										
										
											2018-01-03 22:49:53 -05:00
										 |  |  |             "backspace": node => { | 
					
						
							|  |  |  |                 if (!isTopLevelNode(node)) { | 
					
						
							|  |  |  |                     node.getParent().setActive().then(() => clearSelectedNodes()); | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             }, | 
					
						
							| 
									
										
										
										
											2017-12-24 14:01:20 -05:00
										 |  |  |             // code below shouldn't be necessary normally, however there's some problem with interaction with context menu plugin
 | 
					
						
							|  |  |  |             // after opening context menu, standard shortcuts don't work, but they are detected here
 | 
					
						
							|  |  |  |             // so we essentially takeover the standard handling with our implementation.
 | 
					
						
							|  |  |  |             "left": node => { | 
					
						
							| 
									
										
										
										
											2018-01-01 17:59:59 -05:00
										 |  |  |                 node.navigate($.ui.keyCode.LEFT, true).then(() => clearSelectedNodes()); | 
					
						
							| 
									
										
										
										
											2017-12-25 21:47:32 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |                 return false; | 
					
						
							| 
									
										
										
										
											2017-12-24 14:01:20 -05:00
										 |  |  |             }, | 
					
						
							|  |  |  |             "right": node => { | 
					
						
							| 
									
										
										
										
											2018-01-01 17:59:59 -05:00
										 |  |  |                 node.navigate($.ui.keyCode.RIGHT, true).then(() => clearSelectedNodes()); | 
					
						
							| 
									
										
										
										
											2017-12-25 21:47:32 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |                 return false; | 
					
						
							| 
									
										
										
										
											2017-12-24 14:01:20 -05:00
										 |  |  |             }, | 
					
						
							|  |  |  |             "up": node => { | 
					
						
							| 
									
										
										
										
											2018-01-01 17:59:59 -05:00
										 |  |  |                 node.navigate($.ui.keyCode.UP, true).then(() => clearSelectedNodes()); | 
					
						
							| 
									
										
										
										
											2017-12-25 21:47:32 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |                 return false; | 
					
						
							| 
									
										
										
										
											2017-12-24 14:01:20 -05:00
										 |  |  |             }, | 
					
						
							|  |  |  |             "down": node => { | 
					
						
							| 
									
										
										
										
											2018-01-01 17:59:59 -05:00
										 |  |  |                 node.navigate($.ui.keyCode.DOWN, true).then(() => clearSelectedNodes()); | 
					
						
							| 
									
										
										
										
											2017-12-25 21:47:32 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |                 return false; | 
					
						
							| 
									
										
										
										
											2017-11-04 19:28:49 -04:00
										 |  |  |             } | 
					
						
							|  |  |  |         }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-14 23:31:20 -05:00
										 |  |  |         $tree.fancytree({ | 
					
						
							| 
									
										
										
										
											2017-11-04 19:28:49 -04:00
										 |  |  |             autoScroll: true, | 
					
						
							| 
									
										
										
										
											2017-12-24 14:01:20 -05:00
										 |  |  |             keyboard: false, // we takover keyboard handling in the hotkeys plugin
 | 
					
						
							| 
									
										
										
										
											2017-11-22 19:40:06 -05:00
										 |  |  |             extensions: ["hotkeys", "filter", "dnd", "clones"], | 
					
						
							| 
									
										
										
										
											2018-03-24 21:39:15 -04:00
										 |  |  |             source: branch, | 
					
						
							| 
									
										
										
										
											2017-11-04 19:28:49 -04:00
										 |  |  |             scrollParent: $("#tree"), | 
					
						
							| 
									
										
										
										
											2018-01-01 17:59:59 -05:00
										 |  |  |             click: (event, data) => { | 
					
						
							|  |  |  |                 const targetType = data.targetType; | 
					
						
							|  |  |  |                 const node = data.node; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 if (targetType === 'title' || targetType === 'icon') { | 
					
						
							|  |  |  |                     if (!event.ctrlKey) { | 
					
						
							| 
									
										
										
										
											2018-01-03 22:54:13 -05:00
										 |  |  |                         node.setActive(); | 
					
						
							|  |  |  |                         node.setSelected(true); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-01 17:59:59 -05:00
										 |  |  |                         clearSelectedNodes(); | 
					
						
							|  |  |  |                     } | 
					
						
							| 
									
										
										
										
											2018-01-03 22:54:13 -05:00
										 |  |  |                     else { | 
					
						
							|  |  |  |                         node.setSelected(!node.isSelected()); | 
					
						
							|  |  |  |                     } | 
					
						
							| 
									
										
										
										
											2018-01-01 17:59:59 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |                     return false; | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             }, | 
					
						
							| 
									
										
										
										
											2017-11-04 19:28:49 -04:00
										 |  |  |             activate: (event, data) => { | 
					
						
							|  |  |  |                 const node = data.node.data; | 
					
						
							| 
									
										
										
										
											2017-11-18 17:05:50 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-19 18:16:50 -05:00
										 |  |  |                 setCurrentNotePathToHash(data.node); | 
					
						
							| 
									
										
										
										
											2017-11-18 17:05:50 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-28 19:30:14 -05:00
										 |  |  |                 noteEditor.switchToNote(node.noteId); | 
					
						
							| 
									
										
										
										
											2017-11-21 20:04:06 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-28 19:30:14 -05:00
										 |  |  |                 showParentList(node.noteId, data.node); | 
					
						
							| 
									
										
										
										
											2017-11-04 19:28:49 -04:00
										 |  |  |             }, | 
					
						
							|  |  |  |             expand: (event, data) => { | 
					
						
							| 
									
										
										
										
											2018-03-24 21:39:15 -04:00
										 |  |  |                 setExpandedToServer(data.node.data.branchId, true); | 
					
						
							| 
									
										
										
										
											2017-11-04 19:28:49 -04:00
										 |  |  |             }, | 
					
						
							|  |  |  |             collapse: (event, data) => { | 
					
						
							| 
									
										
										
										
											2018-03-24 21:39:15 -04:00
										 |  |  |                 setExpandedToServer(data.node.data.branchId, false); | 
					
						
							| 
									
										
										
										
											2017-11-04 19:28:49 -04:00
										 |  |  |             }, | 
					
						
							|  |  |  |             init: (event, data) => { | 
					
						
							| 
									
										
										
										
											2017-12-15 21:36:21 -05:00
										 |  |  |                 const noteId = treeUtils.getNoteIdFromNotePath(startNotePath); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-24 20:41:27 -04:00
										 |  |  |                 if (noteMap[noteId] === undefined) { | 
					
						
							| 
									
										
										
										
											2017-12-15 21:36:21 -05:00
										 |  |  |                     // note doesn't exist so don't try to activate it
 | 
					
						
							|  |  |  |                     startNotePath = null; | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-06 23:15:53 -05:00
										 |  |  |                 if (startNotePath) { | 
					
						
							|  |  |  |                     activateNode(startNotePath); | 
					
						
							| 
									
										
										
										
											2017-12-21 22:00:44 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |                     // looks like this this doesn't work when triggered immediatelly after activating node
 | 
					
						
							|  |  |  |                     // so waiting a second helps
 | 
					
						
							|  |  |  |                     setTimeout(scrollToCurrentNote, 1000); | 
					
						
							| 
									
										
										
										
											2017-11-19 08:47:22 -05:00
										 |  |  |                 } | 
					
						
							| 
									
										
										
										
											2017-11-04 19:28:49 -04:00
										 |  |  |             }, | 
					
						
							|  |  |  |             hotkeys: { | 
					
						
							|  |  |  |                 keydown: keybindings | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |             filter: { | 
					
						
							|  |  |  |                 autoApply: true,   // Re-apply last filter if lazy data is loaded
 | 
					
						
							|  |  |  |                 autoExpand: true, // Expand all branches that contain matches while filtered
 | 
					
						
							|  |  |  |                 counter: false,     // Show a badge with number of matching child nodes near parent icons
 | 
					
						
							|  |  |  |                 fuzzy: false,      // Match single characters in order, e.g. 'fb' will match 'FooBar'
 | 
					
						
							|  |  |  |                 hideExpandedCounter: true,  // Hide counter badge if parent is expanded
 | 
					
						
							|  |  |  |                 hideExpanders: false,       // Hide expanders if all child nodes are hidden by filter
 | 
					
						
							|  |  |  |                 highlight: true,   // Highlight matches by wrapping inside <mark> tags
 | 
					
						
							|  |  |  |                 leavesOnly: false, // Match end nodes only
 | 
					
						
							|  |  |  |                 nodata: true,      // Display a 'no data' status node if result is empty
 | 
					
						
							|  |  |  |                 mode: "hide"       // Grayout unmatched nodes (pass "hide" to remove unmatched node instead)
 | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |             dnd: dragAndDropSetup, | 
					
						
							| 
									
										
										
										
											2018-03-24 20:41:27 -04:00
										 |  |  |             lazyLoad: async function(event, data){ | 
					
						
							| 
									
										
										
										
											2018-03-12 23:14:09 -04:00
										 |  |  |                 const noteId = data.node.data.noteId; | 
					
						
							|  |  |  |                 const note = getNote(noteId); | 
					
						
							| 
									
										
										
										
											2017-11-17 21:31:54 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-12 23:14:09 -04:00
										 |  |  |                 if (note.type === 'search') { | 
					
						
							|  |  |  |                     data.result = loadSearchNote(noteId); | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |                 else { | 
					
						
							| 
									
										
										
										
											2018-03-24 21:39:15 -04:00
										 |  |  |                     data.result = await prepareBranchInner(note); | 
					
						
							| 
									
										
										
										
											2018-03-12 23:14:09 -04:00
										 |  |  |                 } | 
					
						
							| 
									
										
										
										
											2017-11-22 19:40:06 -05:00
										 |  |  |             }, | 
					
						
							|  |  |  |             clones: { | 
					
						
							|  |  |  |                 highlightActiveClones: true | 
					
						
							| 
									
										
										
										
											2017-11-04 19:28:49 -04:00
										 |  |  |             } | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-14 23:31:20 -05:00
										 |  |  |         $tree.contextmenu(contextMenu.contextMenuSettings); | 
					
						
							| 
									
										
										
										
											2017-11-04 19:28:49 -04:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-12 23:27:21 -04:00
										 |  |  |     async function loadSearchNote(searchNoteId) { | 
					
						
							|  |  |  |         const note = await server.get('notes/' + searchNoteId); | 
					
						
							| 
									
										
										
										
											2018-03-12 23:14:09 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |         const json = JSON.parse(note.detail.content); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-23 23:08:29 -04:00
										 |  |  |         const noteIds = await server.get('search/' + encodeURIComponent(json.searchString)); | 
					
						
							| 
									
										
										
										
											2018-03-12 23:14:09 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-12 23:27:21 -04:00
										 |  |  |         for (const noteId of noteIds) { | 
					
						
							| 
									
										
										
										
											2018-03-24 21:39:15 -04:00
										 |  |  |             const branchId = "virt" + randomString(10); | 
					
						
							| 
									
										
										
										
											2018-03-12 23:27:21 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-24 21:39:15 -04:00
										 |  |  |             branchMap[branchId] = { | 
					
						
							|  |  |  |                 branchId: branchId, | 
					
						
							| 
									
										
										
										
											2018-03-12 23:27:21 -04:00
										 |  |  |                 noteId: noteId, | 
					
						
							|  |  |  |                 parentNoteId: searchNoteId, | 
					
						
							|  |  |  |                 prefix: '', | 
					
						
							|  |  |  |                 virtual: true | 
					
						
							|  |  |  |             }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-24 21:39:15 -04:00
										 |  |  |             setParentChildRelation(branchId, searchNoteId, noteId); | 
					
						
							| 
									
										
										
										
											2018-03-12 23:27:21 -04:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-24 21:39:15 -04:00
										 |  |  |         return await prepareBranchInner(searchNoteId); | 
					
						
							| 
									
										
										
										
											2018-03-12 23:14:09 -04:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-22 19:58:56 -05:00
										 |  |  |     function getTree() { | 
					
						
							| 
									
										
										
										
											2018-02-14 23:31:20 -05:00
										 |  |  |         return $tree.fancytree('getTree'); | 
					
						
							| 
									
										
										
										
											2017-11-22 19:58:56 -05:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-05 09:52:28 -05:00
										 |  |  |     async function reload() { | 
					
						
							| 
									
										
										
										
											2017-11-18 17:05:50 -05:00
										 |  |  |         const notes = await loadTree(); | 
					
						
							| 
									
										
										
										
											2017-11-05 09:52:28 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |         // this will also reload the note content
 | 
					
						
							| 
									
										
										
										
											2017-11-22 19:58:56 -05:00
										 |  |  |         await getTree().reload(notes); | 
					
						
							| 
									
										
										
										
											2017-11-05 09:52:28 -05:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-19 19:31:02 -05:00
										 |  |  |     function getNotePathFromAddress() { | 
					
						
							|  |  |  |         return document.location.hash.substr(1); // strip initial #
 | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-12 23:53:00 -05:00
										 |  |  |     async function loadTree() { | 
					
						
							|  |  |  |         const resp = await server.get('tree'); | 
					
						
							|  |  |  |         startNotePath = resp.start_note_path; | 
					
						
							| 
									
										
										
										
											2018-02-24 21:23:04 -05:00
										 |  |  |         instanceName = resp.instanceName; | 
					
						
							| 
									
										
										
										
											2017-11-04 19:28:49 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-12 23:53:00 -05:00
										 |  |  |         if (document.location.hash) { | 
					
						
							|  |  |  |             startNotePath = getNotePathFromAddress(); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2017-11-04 19:28:49 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-24 21:39:15 -04:00
										 |  |  |         return await prepareBranch(resp.notes, resp.branches); | 
					
						
							| 
									
										
										
										
											2017-11-04 19:28:49 -04:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-24 21:39:15 -04:00
										 |  |  |     $(() => loadTree().then(branch => initFancyTree(branch))); | 
					
						
							| 
									
										
										
										
											2017-11-04 19:28:49 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-26 10:00:08 -05:00
										 |  |  |     function collapseTree(node = null) { | 
					
						
							|  |  |  |         if (!node) { | 
					
						
							| 
									
										
										
										
											2018-02-14 23:31:20 -05:00
										 |  |  |             node = $tree.fancytree("getRootNode"); | 
					
						
							| 
									
										
										
										
											2017-12-26 10:00:08 -05:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         node.setExpanded(false); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         node.visit(node => node.setExpanded(false)); | 
					
						
							| 
									
										
										
										
											2017-11-04 19:28:49 -04:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-26 11:00:04 -05:00
										 |  |  |     $(document).bind('keydown', 'alt+c', () => collapseTree()); // don't use shortened form since collapseTree() accepts argument
 | 
					
						
							| 
									
										
										
										
											2017-11-04 19:28:49 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     function scrollToCurrentNote() { | 
					
						
							| 
									
										
										
										
											2017-12-21 22:00:44 -05:00
										 |  |  |         const node = getCurrentNode(); | 
					
						
							| 
									
										
										
										
											2017-11-04 19:28:49 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if (node) { | 
					
						
							|  |  |  |             node.makeVisible({scrollIntoView: true}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             node.setFocus(); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-24 21:39:15 -04:00
										 |  |  |     function setBranchBackgroundBasedOnProtectedStatus(noteId) { | 
					
						
							| 
									
										
										
										
											2018-01-28 19:30:14 -05:00
										 |  |  |         getNodesByNoteId(noteId).map(node => node.toggleClass("protected", !!node.data.isProtected)); | 
					
						
							| 
									
										
										
										
											2017-12-25 09:30:37 -05:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     function setProtected(noteId, isProtected) { | 
					
						
							| 
									
										
										
										
											2018-01-28 19:30:14 -05:00
										 |  |  |         getNodesByNoteId(noteId).map(node => node.data.isProtected = isProtected); | 
					
						
							| 
									
										
										
										
											2017-12-25 09:30:37 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-24 21:39:15 -04:00
										 |  |  |         setBranchBackgroundBasedOnProtectedStatus(noteId); | 
					
						
							| 
									
										
										
										
											2017-11-18 17:05:50 -05:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-24 23:00:12 -04:00
										 |  |  |     async function getAutocompleteItems(parentNoteId, notePath, titlePath) { | 
					
						
							| 
									
										
										
										
											2017-11-19 19:39:39 -05:00
										 |  |  |         if (!parentNoteId) { | 
					
						
							|  |  |  |             parentNoteId = 'root'; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-24 23:00:12 -04:00
										 |  |  |         const parentNote = treeCache.getNote(parentNoteId); | 
					
						
							|  |  |  |         const childNotes = await parentNote.getChildNotes(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (!childNotes.length) { | 
					
						
							| 
									
										
										
										
											2017-11-19 19:39:39 -05:00
										 |  |  |             return []; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (!notePath) { | 
					
						
							|  |  |  |             notePath = ''; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (!titlePath) { | 
					
						
							|  |  |  |             titlePath = ''; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-24 22:44:45 -05:00
										 |  |  |         // https://github.com/zadam/trilium/issues/46
 | 
					
						
							|  |  |  |         // unfortunately not easy to implement because we don't have an easy access to note's isProtected property
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-19 19:39:39 -05:00
										 |  |  |         const autocompleteItems = []; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-24 23:00:12 -04:00
										 |  |  |         for (const childNote of childNotes) { | 
					
						
							|  |  |  |             if (childNote.hideInAutocomplete) { | 
					
						
							| 
									
										
										
										
											2018-02-13 22:30:33 -05:00
										 |  |  |                 continue; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-24 23:00:12 -04:00
										 |  |  |             const childNotePath = (notePath ? (notePath + '/') : '') + childNote.noteId; | 
					
						
							|  |  |  |             const childTitlePath = (titlePath ? (titlePath + ' / ') : '') + getNoteTitle(childNote.noteId, parentNoteId); | 
					
						
							| 
									
										
										
										
											2017-11-19 19:39:39 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |             autocompleteItems.push({ | 
					
						
							| 
									
										
										
										
											2017-11-19 20:36:13 -05:00
										 |  |  |                 value: childTitlePath + ' (' + childNotePath + ')', | 
					
						
							| 
									
										
										
										
											2017-11-19 19:39:39 -05:00
										 |  |  |                 label: childTitlePath | 
					
						
							|  |  |  |             }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-24 23:00:12 -04:00
										 |  |  |             const childItems = await getAutocompleteItems(childNote.noteId, childNotePath, childTitlePath); | 
					
						
							| 
									
										
										
										
											2017-11-19 19:39:39 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |             for (const childItem of childItems) { | 
					
						
							|  |  |  |                 autocompleteItems.push(childItem); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return autocompleteItems; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-28 19:38:33 -05:00
										 |  |  |     function setNoteTitle(noteId, title) { | 
					
						
							| 
									
										
										
										
											2017-12-23 11:02:38 -05:00
										 |  |  |         assertArguments(noteId); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-12 20:00:19 -04:00
										 |  |  |         getNote(noteId).title = title; | 
					
						
							| 
									
										
										
										
											2017-11-22 19:58:56 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-12 23:14:09 -04:00
										 |  |  |         getNodesByNoteId(noteId).map(clone => setNodeTitleWithPrefix(clone)); | 
					
						
							| 
									
										
										
										
											2017-11-22 19:58:56 -05:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-23 19:40:47 -05:00
										 |  |  |     async function createNewTopLevelNote() { | 
					
						
							| 
									
										
										
										
											2018-02-14 23:31:20 -05:00
										 |  |  |         const rootNode = $tree.fancytree("getRootNode"); | 
					
						
							| 
									
										
										
										
											2017-11-22 23:16:54 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-23 19:40:47 -05:00
										 |  |  |         await createNote(rootNode, "root", "into"); | 
					
						
							| 
									
										
										
										
											2017-11-22 23:16:54 -05:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     async function createNote(node, parentNoteId, target, isProtected) { | 
					
						
							| 
									
										
										
										
											2017-12-23 11:02:38 -05:00
										 |  |  |         assertArguments(node, parentNoteId, target); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-22 23:16:54 -05:00
										 |  |  |         // if isProtected isn't available (user didn't enter password yet), then note is created as unencrypted
 | 
					
						
							|  |  |  |         // but this is quite weird since user doesn't see WHERE the note is being created so it shouldn't occur often
 | 
					
						
							|  |  |  |         if (!isProtected || !protected_session.isProtectedSessionAvailable()) { | 
					
						
							|  |  |  |             isProtected = false; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         const newNoteName = "new note"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-28 20:52:38 -05:00
										 |  |  |         const result = await server.post('notes/' + parentNoteId + '/children', { | 
					
						
							| 
									
										
										
										
											2018-01-28 19:30:14 -05:00
										 |  |  |             title: newNoteName, | 
					
						
							| 
									
										
										
										
											2017-11-28 20:52:38 -05:00
										 |  |  |             target: target, | 
					
						
							| 
									
										
										
										
											2018-03-24 21:39:15 -04:00
										 |  |  |             target_branchId: node.data.branchId, | 
					
						
							| 
									
										
										
										
											2018-01-28 19:30:14 -05:00
										 |  |  |             isProtected: isProtected | 
					
						
							| 
									
										
										
										
											2017-11-22 23:16:54 -05:00
										 |  |  |         }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-24 21:39:15 -04:00
										 |  |  |         setParentChildRelation(result.branchId, parentNoteId, result.noteId); | 
					
						
							| 
									
										
										
										
											2018-01-28 10:37:43 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-24 21:39:15 -04:00
										 |  |  |         branchMap[result.branchId] = result; | 
					
						
							| 
									
										
										
										
											2018-01-28 10:37:43 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-24 20:41:27 -04:00
										 |  |  |         noteMap[result.noteId] = { | 
					
						
							| 
									
										
										
										
											2018-03-12 23:14:09 -04:00
										 |  |  |             noteId: result.noteId, | 
					
						
							| 
									
										
										
										
											2018-03-12 20:00:19 -04:00
										 |  |  |             title: result.title, | 
					
						
							|  |  |  |             isProtected: result.isProtected, | 
					
						
							|  |  |  |             type: result.type, | 
					
						
							|  |  |  |             mime: result.mime | 
					
						
							|  |  |  |         }; | 
					
						
							| 
									
										
										
										
											2018-01-28 10:37:43 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |         noteEditor.newNoteCreated(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-22 23:16:54 -05:00
										 |  |  |         const newNode = { | 
					
						
							|  |  |  |             title: newNoteName, | 
					
						
							| 
									
										
										
										
											2018-01-28 19:30:14 -05:00
										 |  |  |             noteId: result.noteId, | 
					
						
							|  |  |  |             parentNoteId: parentNoteId, | 
					
						
							|  |  |  |             refKey: result.noteId, | 
					
						
							| 
									
										
										
										
											2018-03-24 21:39:15 -04:00
										 |  |  |             branchId: result.branchId, | 
					
						
							| 
									
										
										
										
											2018-01-28 19:30:14 -05:00
										 |  |  |             isProtected: isProtected, | 
					
						
							| 
									
										
										
										
											2018-01-28 10:37:43 -05:00
										 |  |  |             extraClasses: getExtraClasses(result.note) | 
					
						
							| 
									
										
										
										
											2017-11-22 23:16:54 -05:00
										 |  |  |         }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (target === 'after') { | 
					
						
							| 
									
										
										
										
											2018-02-12 23:53:00 -05:00
										 |  |  |             await node.appendSibling(newNode).setActive(true); | 
					
						
							| 
									
										
										
										
											2017-11-22 23:16:54 -05:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2018-01-16 23:22:13 -05:00
										 |  |  |         else if (target === 'into') { | 
					
						
							|  |  |  |             if (!node.getChildren() && node.isFolder()) { | 
					
						
							|  |  |  |                 await node.setExpanded(); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             else { | 
					
						
							|  |  |  |                 node.addChildren(newNode); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-12 23:53:00 -05:00
										 |  |  |             await node.getLastChild().setActive(true); | 
					
						
							| 
									
										
										
										
											2017-11-22 23:16:54 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |             node.folder = true; | 
					
						
							|  |  |  |             node.renderTitle(); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2018-01-16 23:22:13 -05:00
										 |  |  |         else { | 
					
						
							|  |  |  |             throwError("Unrecognized target: " + target); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2017-11-22 23:16:54 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-13 23:25:28 -05:00
										 |  |  |         clearSelectedNodes(); // to unmark previously active node
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-22 23:16:54 -05:00
										 |  |  |         showMessage("Created!"); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-13 17:00:40 -05:00
										 |  |  |     async function sortAlphabetically(noteId) { | 
					
						
							|  |  |  |         await server.put('notes/' + noteId + '/sort'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         await reload(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-24 23:00:12 -04:00
										 |  |  |     async function noteExists(noteId) { | 
					
						
							|  |  |  |         return !!treeCache.getNote(noteId); | 
					
						
							| 
									
										
										
										
											2018-02-12 23:53:00 -05:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-24 21:23:04 -05:00
										 |  |  |     function getInstanceName() { | 
					
						
							|  |  |  |         return instanceName; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-24 21:39:15 -04:00
										 |  |  |     function getBranch(branchId) { | 
					
						
							|  |  |  |         return branchMap[branchId]; | 
					
						
							| 
									
										
										
										
											2018-03-13 19:31:07 -04:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-18 23:41:13 -05:00
										 |  |  |     $(document).bind('keydown', 'ctrl+o', e => { | 
					
						
							|  |  |  |         const node = getCurrentNode(); | 
					
						
							| 
									
										
										
										
											2018-01-28 19:30:14 -05:00
										 |  |  |         const parentNoteId = node.data.parentNoteId; | 
					
						
							| 
									
										
										
										
											2017-12-18 23:41:13 -05:00
										 |  |  |         const isProtected = treeUtils.getParentProtectedStatus(node); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         createNote(node, parentNoteId, 'after', isProtected); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         e.preventDefault(); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $(document).bind('keydown', 'ctrl+p', e => { | 
					
						
							| 
									
										
										
										
											2017-12-17 16:40:38 -05:00
										 |  |  |         const node = getCurrentNode(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-28 19:30:14 -05:00
										 |  |  |         createNote(node, node.data.noteId, 'into', node.data.isProtected); | 
					
						
							| 
									
										
										
										
											2017-12-18 23:41:13 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |         e.preventDefault(); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $(document).bind('keydown', 'ctrl+del', e => { | 
					
						
							|  |  |  |         const node = getCurrentNode(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-14 21:39:21 -05:00
										 |  |  |         treeChanges.deleteNodes([node]); | 
					
						
							| 
									
										
										
										
											2017-12-18 23:41:13 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |         e.preventDefault(); | 
					
						
							| 
									
										
										
										
											2017-12-17 16:40:38 -05:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-17 16:56:30 -05:00
										 |  |  |     $(document).bind('keydown', 'ctrl+.', scrollToCurrentNote); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-19 19:31:02 -05:00
										 |  |  |     $(window).bind('hashchange', function() { | 
					
						
							|  |  |  |         const notePath = getNotePathFromAddress(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-01 18:53:52 -05:00
										 |  |  |         if (getCurrentNotePath() !== notePath) { | 
					
						
							|  |  |  |             console.log("Switching to " + notePath + " because of hash change"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             activateNode(notePath); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2017-12-19 19:31:02 -05:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-19 19:54:55 -05:00
										 |  |  |     if (isElectron()) { | 
					
						
							|  |  |  |         $(document).bind('keydown', 'alt+left', e => { | 
					
						
							|  |  |  |             window.history.back(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             e.preventDefault(); | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $(document).bind('keydown', 'alt+right', e => { | 
					
						
							|  |  |  |             window.history.forward(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             e.preventDefault(); | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-24 00:54:50 -04:00
										 |  |  |     $createTopLevelNoteButton.click(createNewTopLevelNote); | 
					
						
							|  |  |  |     $collapseTreeButton.click(collapseTree); | 
					
						
							|  |  |  |     $scrollToCurrentNoteButton.click(scrollToCurrentNote); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-04 19:28:49 -04:00
										 |  |  |     return { | 
					
						
							| 
									
										
										
										
											2017-11-05 09:52:28 -05:00
										 |  |  |         reload, | 
					
						
							| 
									
										
										
										
											2017-11-04 19:28:49 -04:00
										 |  |  |         collapseTree, | 
					
						
							|  |  |  |         scrollToCurrentNote, | 
					
						
							| 
									
										
										
										
											2018-03-24 21:39:15 -04:00
										 |  |  |         setBranchBackgroundBasedOnProtectedStatus, | 
					
						
							| 
									
										
										
										
											2017-12-25 09:30:37 -05:00
										 |  |  |         setProtected, | 
					
						
							| 
									
										
										
										
											2017-11-18 17:05:50 -05:00
										 |  |  |         getCurrentNode, | 
					
						
							| 
									
										
										
										
											2018-01-15 20:54:22 -05:00
										 |  |  |         expandToNote, | 
					
						
							| 
									
										
										
										
											2017-11-19 12:06:48 -05:00
										 |  |  |         activateNode, | 
					
						
							|  |  |  |         getCurrentNotePath, | 
					
						
							| 
									
										
										
										
											2017-11-19 18:16:50 -05:00
										 |  |  |         getNoteTitle, | 
					
						
							| 
									
										
										
										
											2017-11-19 19:39:39 -05:00
										 |  |  |         setCurrentNotePathToHash, | 
					
						
							| 
									
										
										
										
											2017-11-22 19:58:56 -05:00
										 |  |  |         getAutocompleteItems, | 
					
						
							| 
									
										
										
										
											2017-11-28 19:38:33 -05:00
										 |  |  |         setNoteTitle, | 
					
						
							| 
									
										
										
										
											2017-11-22 23:16:54 -05:00
										 |  |  |         createNewTopLevelNote, | 
					
						
							| 
									
										
										
										
											2017-11-28 10:17:30 -05:00
										 |  |  |         createNote, | 
					
						
							|  |  |  |         setPrefix, | 
					
						
							| 
									
										
										
										
											2017-12-17 16:28:13 -05:00
										 |  |  |         getNotePathTitle, | 
					
						
							|  |  |  |         removeParentChildRelation, | 
					
						
							| 
									
										
										
										
											2018-01-01 17:59:59 -05:00
										 |  |  |         setParentChildRelation, | 
					
						
							| 
									
										
										
										
											2018-01-13 17:00:40 -05:00
										 |  |  |         getSelectedNodes, | 
					
						
							| 
									
										
										
										
											2018-02-12 23:53:00 -05:00
										 |  |  |         sortAlphabetically, | 
					
						
							| 
									
										
										
										
											2018-02-24 21:23:04 -05:00
										 |  |  |         noteExists, | 
					
						
							| 
									
										
										
										
											2018-03-12 23:14:09 -04:00
										 |  |  |         getInstanceName, | 
					
						
							| 
									
										
										
										
											2018-03-24 21:39:15 -04:00
										 |  |  |         getBranch, | 
					
						
							| 
									
										
										
										
											2018-03-13 19:31:07 -04:00
										 |  |  |         getNote | 
					
						
							| 
									
										
										
										
											2017-11-04 19:28:49 -04:00
										 |  |  |     }; | 
					
						
							|  |  |  | })(); |