mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 18:36:30 +01:00 
			
		
		
		
	#129, recent notes are now visible in the jump to dialog
This commit is contained in:
		| @@ -5,8 +5,6 @@ import searchNotesService from '../services/search_notes.js'; | |||||||
|  |  | ||||||
| const $dialog = $("#jump-to-note-dialog"); | const $dialog = $("#jump-to-note-dialog"); | ||||||
| const $autoComplete = $("#jump-to-note-autocomplete"); | const $autoComplete = $("#jump-to-note-autocomplete"); | ||||||
| const $form = $("#jump-to-note-form"); |  | ||||||
| const $jumpToNoteButton = $("#jump-to-note-button"); |  | ||||||
| const $showInFullTextButton = $("#show-in-full-text-button"); | const $showInFullTextButton = $("#show-in-full-text-button"); | ||||||
|  |  | ||||||
| async function showDialog() { | async function showDialog() { | ||||||
| @@ -34,25 +32,22 @@ async function showDialog() { | |||||||
|             } |             } | ||||||
|         }, |         }, | ||||||
|         focus: function(event, ui) { |         focus: function(event, ui) { | ||||||
|             return $(ui.item).val() !== 'No results'; |             event.preventDefault(); | ||||||
|         }, |         }, | ||||||
|         minLength: 2 |         minLength: 0, | ||||||
|  |         autoFocus: true, | ||||||
|  |         select: function (event, ui) { | ||||||
|  |             if (ui.item.value === 'No results') { | ||||||
|  |                 return false; | ||||||
|  |             } | ||||||
|  |  | ||||||
|  |             treeService.activateNode(ui.item.value); | ||||||
|  |  | ||||||
|  |             $dialog.dialog('close'); | ||||||
|  |         } | ||||||
|     }); |     }); | ||||||
| } |  | ||||||
|  |  | ||||||
| function getSelectedNotePath() { |     $autoComplete.autocomplete("search", ""); | ||||||
|     const val = $autoComplete.val(); |  | ||||||
|     return linkService.getNodePathFromLabel(val); |  | ||||||
| } |  | ||||||
|  |  | ||||||
| function goToNote() { |  | ||||||
|     const notePath = getSelectedNotePath(); |  | ||||||
|  |  | ||||||
|     if (notePath) { |  | ||||||
|         treeService.activateNode(notePath); |  | ||||||
|  |  | ||||||
|         $dialog.dialog('close'); |  | ||||||
|     } |  | ||||||
| } | } | ||||||
|  |  | ||||||
| function showInFullText(e) { | function showInFullText(e) { | ||||||
| @@ -69,14 +64,6 @@ function showInFullText(e) { | |||||||
|     $dialog.dialog('close'); |     $dialog.dialog('close'); | ||||||
| } | } | ||||||
|  |  | ||||||
| $form.submit(() => { |  | ||||||
|     goToNote(); |  | ||||||
|  |  | ||||||
|     return false; |  | ||||||
| }); |  | ||||||
|  |  | ||||||
| $jumpToNoteButton.click(goToNote); |  | ||||||
|  |  | ||||||
| $showInFullTextButton.click(showInFullText); | $showInFullTextButton.click(showInFullText); | ||||||
|  |  | ||||||
| $dialog.bind('keydown', 'ctrl+return', showInFullText); | $dialog.bind('keydown', 'ctrl+return', showInFullText); | ||||||
|   | |||||||
| @@ -1,20 +1,50 @@ | |||||||
| "use strict"; | "use strict"; | ||||||
|  |  | ||||||
| const noteCacheService = require('../../services/note_cache'); | const noteCacheService = require('../../services/note_cache'); | ||||||
|  | const repository = require('../../services/repository'); | ||||||
|  |  | ||||||
| async function getAutocomplete(req) { | async function getAutocomplete(req) { | ||||||
|     const query = req.query.query; |     const query = req.query.query; | ||||||
|  |  | ||||||
|     const results = noteCacheService.findNotes(query); |     let results; | ||||||
|  |  | ||||||
|  |     if (query.trim().length === 0) { | ||||||
|  |         results = await getRecentNotes(); | ||||||
|  |     } | ||||||
|  |     else { | ||||||
|  |         results = noteCacheService.findNotes(query); | ||||||
|  |     } | ||||||
|  |  | ||||||
|     return results.map(res => { |     return results.map(res => { | ||||||
|         return { |         return { | ||||||
|             value: res.title + ' (' + res.path + ')', |             value: res.path, | ||||||
|             label: res.title |             label: res.title | ||||||
|         } |         } | ||||||
|     }); |     }); | ||||||
| } | } | ||||||
|  |  | ||||||
|  | async function getRecentNotes() { | ||||||
|  |     const recentNotes = await repository.getEntities(` | ||||||
|  |       SELECT  | ||||||
|  |         recent_notes.*  | ||||||
|  |       FROM  | ||||||
|  |         recent_notes | ||||||
|  |         JOIN branches USING(branchId) | ||||||
|  |       WHERE | ||||||
|  |         recent_notes.isDeleted = 0 | ||||||
|  |         AND branches.isDeleted = 0 | ||||||
|  |       ORDER BY  | ||||||
|  |         dateCreated DESC | ||||||
|  |       LIMIT 200`); | ||||||
|  |  | ||||||
|  |     return recentNotes.map(rn => { | ||||||
|  |         return { | ||||||
|  |             path: rn.notePath, | ||||||
|  |             title: noteCacheService.getNoteTitleForPath(rn.notePath.split('/')) | ||||||
|  |         }; | ||||||
|  |     }); | ||||||
|  | } | ||||||
|  |  | ||||||
| module.exports = { | module.exports = { | ||||||
|     getAutocomplete |     getAutocomplete | ||||||
| }; | }; | ||||||
| @@ -302,18 +302,12 @@ | |||||||
|     </div> |     </div> | ||||||
|  |  | ||||||
|     <div id="jump-to-note-dialog" title="Jump to note" style="display: none;"> |     <div id="jump-to-note-dialog" title="Jump to note" style="display: none;"> | ||||||
|       <form id="jump-to-note-form"> |       <div class="form-group"> | ||||||
|         <div class="form-group"> |         <label for="jump-to-note-autocomplete">Note</label> | ||||||
|           <label for="jump-to-note-autocomplete">Note</label> |         <input id="jump-to-note-autocomplete" placeholder="search for note by its name" style="width: 100%;"> | ||||||
|           <input id="jump-to-note-autocomplete" placeholder="search for note by its name" style="width: 100%;"> |       </div> | ||||||
|         </div> |  | ||||||
|  |  | ||||||
|         <div style="display: flex; justify-content: space-between;"> |       <button id="show-in-full-text-button" class="btn btn-sm">Search in full text <kbd>ctrl+enter</kbd></button> | ||||||
|           <button id="jump-to-note-button" class="btn btn-sm btn-primary">Jump <kbd>enter</kbd></button> |  | ||||||
|  |  | ||||||
|           <button id="show-in-full-text-button" class="btn btn-sm">Search in full text <kbd>ctrl+enter</kbd></button> |  | ||||||
|         </div> |  | ||||||
|       </form> |  | ||||||
|     </div> |     </div> | ||||||
|  |  | ||||||
|     <div id="protected-session-password-dialog" title="Protected session" style="display: none;"> |     <div id="protected-session-password-dialog" title="Protected session" style="display: none;"> | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user