| 
									
										
										
										
											2020-01-18 19:46:30 +01:00
										 |  |  | import TabAwareWidget from "./tab_aware_widget.js"; | 
					
						
							|  |  |  | import treeService from "../services/tree.js"; | 
					
						
							|  |  |  | import linkService from "../services/link.js"; | 
					
						
							| 
									
										
										
										
											2020-04-08 20:38:50 +02:00
										 |  |  | import hoistedNoteService from "../services/hoisted_note.js"; | 
					
						
							| 
									
										
										
										
											2020-01-18 19:46:30 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | const TPL = `
 | 
					
						
							| 
									
										
										
										
											2021-02-13 22:47:06 +01:00
										 |  |  | <div class="dropdown note-paths-widget"> | 
					
						
							| 
									
										
										
										
											2020-01-18 19:46:30 +01:00
										 |  |  |     <style> | 
					
						
							| 
									
										
										
										
											2020-04-07 22:53:03 +02:00
										 |  |  |     .note-path-list-button { | 
					
						
							| 
									
										
										
										
											2021-02-13 22:47:06 +01:00
										 |  |  |         font-size: 120% !important; | 
					
						
							| 
									
										
										
										
											2020-04-07 22:53:03 +02:00
										 |  |  |     } | 
					
						
							|  |  |  |      | 
					
						
							|  |  |  |     .note-path-list-button::after { | 
					
						
							|  |  |  |         display: none !important; // disabling the standard caret
 | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |      | 
					
						
							| 
									
										
										
										
											2020-09-15 22:46:51 +02:00
										 |  |  |     .note-path-list { | 
					
						
							|  |  |  |         max-height: 600px; | 
					
						
							|  |  |  |         overflow-y: auto; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-03-08 00:07:00 +01:00
										 |  |  |      | 
					
						
							|  |  |  |     .note-path-list .current { | 
					
						
							|  |  |  |         text-decoration: underline; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-01-18 19:46:30 +01:00
										 |  |  |     </style> | 
					
						
							| 
									
										
										
										
											2021-02-13 22:47:06 +01:00
										 |  |  |      | 
					
						
							|  |  |  |     <button class="btn dropdown-toggle note-path-list-button bx bx-collection" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" title="Note paths"></button> | 
					
						
							|  |  |  |     <ul class="note-path-list dropdown-menu dropdown-menu-right" aria-labelledby="note-path-list-button"> | 
					
						
							|  |  |  |     </ul> | 
					
						
							| 
									
										
										
										
											2020-01-18 19:46:30 +01:00
										 |  |  | </div>`; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export default class NotePathsWidget extends TabAwareWidget { | 
					
						
							|  |  |  |     doRender() { | 
					
						
							|  |  |  |         this.$widget = $(TPL); | 
					
						
							| 
									
										
										
										
											2020-08-26 16:50:16 +02:00
										 |  |  |         this.overflowing(); | 
					
						
							| 
									
										
										
										
											2020-01-18 19:46:30 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-13 22:47:06 +01:00
										 |  |  |         this.$notePathList = this.$widget.find(".note-path-list"); | 
					
						
							|  |  |  |         this.$widget.on('show.bs.dropdown', () => this.renderDropdown()); | 
					
						
							| 
									
										
										
										
											2020-02-03 21:16:33 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-01-18 19:46:30 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-03 21:16:33 +01:00
										 |  |  |     async renderDropdown() { | 
					
						
							|  |  |  |         this.$notePathList.empty(); | 
					
						
							| 
									
										
										
										
											2020-04-08 10:13:11 +02:00
										 |  |  |         this.$notePathList.append( | 
					
						
							|  |  |  |             $("<div>") | 
					
						
							|  |  |  |                 .addClass("dropdown-header") | 
					
						
							|  |  |  |                 .text('This note is placed into the following paths:') | 
					
						
							|  |  |  |         ); | 
					
						
							| 
									
										
										
										
											2020-01-18 19:46:30 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-03 21:16:33 +01:00
										 |  |  |         if (this.noteId === 'root') { | 
					
						
							| 
									
										
										
										
											2020-01-18 19:46:30 +01:00
										 |  |  |             await this.addPath('root', true); | 
					
						
							| 
									
										
										
										
											2020-02-03 21:16:33 +01:00
										 |  |  |             return; | 
					
						
							| 
									
										
										
										
											2020-01-18 19:46:30 +01:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-08 00:04:43 +01:00
										 |  |  |         for (const notePath of this.note.getSortedNotePaths(this.hoistedNoteId)) { | 
					
						
							|  |  |  |             const notePathStr = notePath.join('/'); | 
					
						
							|  |  |  | console.log(notePathStr, this.notePath, notePathStr === this.notePath); | 
					
						
							|  |  |  |             await this.addPath(notePathStr, notePathStr === this.notePath); | 
					
						
							| 
									
										
										
										
											2020-02-03 21:16:33 +01:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-01-18 19:46:30 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-03 21:16:33 +01:00
										 |  |  |         const cloneLink = $("<div>") | 
					
						
							| 
									
										
										
										
											2020-04-08 10:13:11 +02:00
										 |  |  |             .addClass("dropdown-header") | 
					
						
							| 
									
										
										
										
											2020-02-03 21:16:33 +01:00
										 |  |  |             .append( | 
					
						
							|  |  |  |                 $('<button class="btn btn-sm">') | 
					
						
							|  |  |  |                     .text('Clone note to new location...') | 
					
						
							|  |  |  |                     .on('click', () => import("../dialogs/clone_to.js").then(d => d.showDialog([this.noteId]))) | 
					
						
							|  |  |  |             ); | 
					
						
							| 
									
										
										
										
											2020-01-18 19:46:30 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-03 21:16:33 +01:00
										 |  |  |         this.$notePathList.append(cloneLink); | 
					
						
							| 
									
										
										
										
											2020-01-18 19:46:30 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     async addPath(notePath, isCurrent) { | 
					
						
							| 
									
										
										
										
											2020-01-25 09:56:08 +01:00
										 |  |  |         const title = await treeService.getNotePathTitle(notePath); | 
					
						
							| 
									
										
										
										
											2020-01-18 19:46:30 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-27 20:44:58 +01:00
										 |  |  |         const $noteLink = await linkService.createNoteLink(notePath, {title}); | 
					
						
							| 
									
										
										
										
											2020-01-18 19:46:30 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-27 20:44:58 +01:00
										 |  |  |         $noteLink | 
					
						
							| 
									
										
										
										
											2020-01-18 19:46:30 +01:00
										 |  |  |             .addClass("dropdown-item"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-27 20:44:58 +01:00
										 |  |  |         $noteLink | 
					
						
							| 
									
										
										
										
											2020-02-03 21:16:33 +01:00
										 |  |  |             .find('a') | 
					
						
							|  |  |  |             .addClass("no-tooltip-preview"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-18 19:46:30 +01:00
										 |  |  |         if (isCurrent) { | 
					
						
							| 
									
										
										
										
											2021-01-27 20:44:58 +01:00
										 |  |  |             $noteLink.addClass("current"); | 
					
						
							| 
									
										
										
										
											2020-01-18 19:46:30 +01:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-27 20:44:58 +01:00
										 |  |  |         this.$notePathList.append($noteLink); | 
					
						
							| 
									
										
										
										
											2020-01-18 19:46:30 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-02-17 22:47:50 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     entitiesReloadedEvent({loadResults}) { | 
					
						
							| 
									
										
										
										
											2020-10-21 22:45:49 +02:00
										 |  |  |         if (loadResults.getBranches().find(branch => branch.noteId === this.noteId) | 
					
						
							|  |  |  |             || loadResults.isNoteReloaded(this.noteId)) { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-17 22:47:50 +01:00
										 |  |  |             this.refresh(); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-03-08 00:04:43 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     async refresh() { | 
					
						
							|  |  |  |         await super.refresh(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         this.$widget.find('.dropdown-toggle').dropdown('hide'); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-05-09 14:25:27 +02:00
										 |  |  | } |