mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 18:36:30 +01:00 
			
		
		
		
	add the ability to sort notes by folders first, closes #2649
This commit is contained in:
		| @@ -9,8 +9,9 @@ let parentNoteId = null; | |||||||
| $form.on('submit', async () => { | $form.on('submit', async () => { | ||||||
|     const sortBy = $form.find("input[name='sort-by']:checked").val(); |     const sortBy = $form.find("input[name='sort-by']:checked").val(); | ||||||
|     const sortDirection = $form.find("input[name='sort-direction']:checked").val(); |     const sortDirection = $form.find("input[name='sort-direction']:checked").val(); | ||||||
|  |     const foldersFirst = $form.find("input[name='sort-folders-first']").is(":checked"); | ||||||
|  |  | ||||||
|     await server.put(`notes/${parentNoteId}/sort-children`, {sortBy, sortDirection}); |     await server.put(`notes/${parentNoteId}/sort-children`, {sortBy, sortDirection, foldersFirst}); | ||||||
|  |  | ||||||
|     utils.closeActiveDialog(); |     utils.closeActiveDialog(); | ||||||
| }); | }); | ||||||
|   | |||||||
| @@ -76,8 +76,6 @@ function findHeadingElementByIndex(parent, headingIndex) { | |||||||
|         // heading level. If a heading node is found, decrement the headingIndex |         // heading level. If a heading node is found, decrement the headingIndex | ||||||
|         // until zero is reached |         // until zero is reached | ||||||
|  |  | ||||||
|         console.log(child.tagName, headingIndex); |  | ||||||
|  |  | ||||||
|         if (child.tagName.match(/H\d+/i) !== null) { |         if (child.tagName.match(/H\d+/i) !== null) { | ||||||
|             if (headingIndex === 0) { |             if (headingIndex === 0) { | ||||||
|                 headingElement = child; |                 headingElement = child; | ||||||
|   | |||||||
| @@ -94,13 +94,13 @@ function undeleteNote(req) { | |||||||
|  |  | ||||||
| function sortChildNotes(req) { | function sortChildNotes(req) { | ||||||
|     const noteId = req.params.noteId; |     const noteId = req.params.noteId; | ||||||
|     const {sortBy, sortDirection} = req.body; |     const {sortBy, sortDirection, foldersFirst} = req.body; | ||||||
|  |  | ||||||
|     log.info(`Sorting '${noteId}' children with ${sortBy} ${sortDirection}`); |     log.info(`Sorting '${noteId}' children with ${sortBy} ${sortDirection}, foldersFirst=${foldersFirst}`); | ||||||
|  |  | ||||||
|     const reverse = sortDirection === 'desc'; |     const reverse = sortDirection === 'desc'; | ||||||
|  |  | ||||||
|     treeService.sortNotes(noteId, sortBy, reverse); |     treeService.sortNotes(noteId, sortBy, reverse, foldersFirst); | ||||||
| } | } | ||||||
|  |  | ||||||
| function protectNote(req) { | function protectNote(req) { | ||||||
|   | |||||||
| @@ -50,6 +50,17 @@ | |||||||
|                             descending |                             descending | ||||||
|                         </label> |                         </label> | ||||||
|                     </div> |                     </div> | ||||||
|  |  | ||||||
|  |                     <br /> | ||||||
|  |  | ||||||
|  |                     <h5>Folders</h5> | ||||||
|  |  | ||||||
|  |                     <div class="form-check"> | ||||||
|  |                         <input class="form-check-input" type="checkbox" name="sort-folders-first" value="1" id="sort-folders-first"> | ||||||
|  |                         <label class="form-check-label" for="sort-folders-first"> | ||||||
|  |                             sort folders at the top | ||||||
|  |                         </label> | ||||||
|  |                     </div> | ||||||
|                 </div> |                 </div> | ||||||
|                 <div class="modal-footer"> |                 <div class="modal-footer"> | ||||||
|                     <button type="submit" class="btn btn-primary">Sort <kbd>enter</kbd></button> |                     <button type="submit" class="btn btn-primary">Sort <kbd>enter</kbd></button> | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user