mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 03:29:02 +01:00 
			
		
		
		
	have paths in "note paths" widget also sorted by priority
This commit is contained in:
		
							parent
							
								
									9bac2a4819
								
							
						
					
					
						commit
						7df8c940b6
					
				| @ -2,6 +2,7 @@ import server from '../services/server.js'; | |||||||
| import noteAttributeCache from "../services/note_attribute_cache.js"; | import noteAttributeCache from "../services/note_attribute_cache.js"; | ||||||
| import ws from "../services/ws.js"; | import ws from "../services/ws.js"; | ||||||
| import options from "../services/options.js"; | import options from "../services/options.js"; | ||||||
|  | import treeCache from "../services/tree_cache.js"; | ||||||
| 
 | 
 | ||||||
| const LABEL = 'label'; | const LABEL = 'label'; | ||||||
| const RELATION = 'relation'; | const RELATION = 'relation'; | ||||||
| @ -279,6 +280,29 @@ class NoteShort { | |||||||
|         return paths; |         return paths; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     getSortedNotePaths(hoistedNotePath = 'root') { | ||||||
|  |         const notePaths = this.getAllNotePaths().map(path => ({ | ||||||
|  |             notePath: path, | ||||||
|  |             isInHoistedSubTree: path.includes(hoistedNotePath), | ||||||
|  |             isArchived: path.find(noteId => treeCache.notes[noteId].hasLabel('archived')), | ||||||
|  |             isSearch: path.find(noteId => treeCache.notes[noteId].type === 'search') | ||||||
|  |         })); | ||||||
|  | 
 | ||||||
|  |         notePaths.sort((a, b) => { | ||||||
|  |             if (a.isInHoistedSubTree !== b.isInHoistedSubTree) { | ||||||
|  |                 return a.isInHoistedSubTree ? -1 : 1; | ||||||
|  |             } else if (a.isSearch !== b.isSearch) { | ||||||
|  |                 return a.isSearch ? 1 : -1; | ||||||
|  |             } else if (a.isArchived !== b.isArchived) { | ||||||
|  |                 return a.isArchived ? 1 : -1; | ||||||
|  |             } else { | ||||||
|  |                 return a.notePath.length - b.notePath.length; | ||||||
|  |             } | ||||||
|  |         }); | ||||||
|  | 
 | ||||||
|  |         return notePaths.map(rec => rec.notePath); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     __filterAttrs(attributes, type, name) { |     __filterAttrs(attributes, type, name) { | ||||||
|         if (!type && !name) { |         if (!type && !name) { | ||||||
|             return attributes; |             return attributes; | ||||||
|  | |||||||
| @ -99,24 +99,7 @@ async function resolveNotePathToSegments(notePath, hoistedNoteId = 'root', logEr | |||||||
| function getSomeNotePathSegments(note, hoistedNotePath = 'root') { | function getSomeNotePathSegments(note, hoistedNotePath = 'root') { | ||||||
|     utils.assertArguments(note); |     utils.assertArguments(note); | ||||||
| 
 | 
 | ||||||
|     const notePaths = note.getAllNotePaths().map(path => ({ |     const notePaths = note.getSortedNotePaths(hoistedNotePath); | ||||||
|         notePath: path, |  | ||||||
|         isInHoistedSubTree: path.includes(hoistedNotePath), |  | ||||||
|         isArchived: path.find(noteId => treeCache.notes[noteId].hasLabel('archived')), |  | ||||||
|         isSearch: path.find(noteId => treeCache.notes[noteId].type === 'search') |  | ||||||
|     })); |  | ||||||
| 
 |  | ||||||
|     notePaths.sort((a, b) => { |  | ||||||
|         if (a.isInHoistedSubTree !== b.isInHoistedSubTree) { |  | ||||||
|             return a.isInHoistedSubTree ? -1 : 1; |  | ||||||
|         } else if (a.isSearch !== b.isSearch) { |  | ||||||
|             return a.isSearch ? 1 : -1; |  | ||||||
|         } else if (a.isArchived !== b.isArchived) { |  | ||||||
|             return a.isArchived ? 1 : -1; |  | ||||||
|         } else { |  | ||||||
|             return a.notePath.length - b.notePath.length; |  | ||||||
|         } |  | ||||||
|     }); |  | ||||||
| 
 | 
 | ||||||
|     return notePaths[0].notePath; |     return notePaths[0].notePath; | ||||||
| } | } | ||||||
|  | |||||||
| @ -47,16 +47,10 @@ export default class NotePathsWidget extends TabAwareWidget { | |||||||
|             return; |             return; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         const pathSegments = treeService.parseNotePath(this.notePath); |         for (const notePath of this.note.getSortedNotePaths(this.hoistedNoteId)) { | ||||||
|         const activeNoteParentNoteId = pathSegments[pathSegments.length - 2]; // we know this is not root so there must be a parent
 |             const notePathStr = notePath.join('/'); | ||||||
| 
 | console.log(notePathStr, this.notePath, notePathStr === this.notePath); | ||||||
|         for (const parentNote of this.note.getParentNotes()) { |             await this.addPath(notePathStr, notePathStr === this.notePath); | ||||||
|             const parentNotePath = treeService.getSomeNotePath(parentNote); |  | ||||||
|             // this is to avoid having root notes leading '/'
 |  | ||||||
|             const notePath = parentNotePath ? (parentNotePath + '/' + this.noteId) : this.noteId; |  | ||||||
|             const isCurrent = activeNoteParentNoteId === parentNote.noteId; |  | ||||||
| 
 |  | ||||||
|             await this.addPath(notePath, isCurrent); |  | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         const cloneLink = $("<div>") |         const cloneLink = $("<div>") | ||||||
| @ -96,4 +90,10 @@ export default class NotePathsWidget extends TabAwareWidget { | |||||||
|             this.refresh(); |             this.refresh(); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  | 
 | ||||||
|  |     async refresh() { | ||||||
|  |         await super.refresh(); | ||||||
|  | 
 | ||||||
|  |         this.$widget.find('.dropdown-toggle').dropdown('hide'); | ||||||
|  |     } | ||||||
| } | } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 zadam
						zadam