mirror of
				https://github.com/zadam/trilium.git
				synced 2025-11-04 05:28:59 +01:00 
			
		
		
		
	recent notes now don't display current note, unification of autocomplete source handling
This commit is contained in:
		
							parent
							
								
									e39d1d08ac
								
							
						
					
					
						commit
						385d97a9b3
					
				@ -2,8 +2,8 @@ import cloningService from '../services/cloning.js';
 | 
				
			|||||||
import linkService from '../services/link.js';
 | 
					import linkService from '../services/link.js';
 | 
				
			||||||
import noteDetailService from '../services/note_detail.js';
 | 
					import noteDetailService from '../services/note_detail.js';
 | 
				
			||||||
import treeUtils from '../services/tree_utils.js';
 | 
					import treeUtils from '../services/tree_utils.js';
 | 
				
			||||||
import server from "../services/server.js";
 | 
					 | 
				
			||||||
import noteDetailText from "../services/note_detail_text.js";
 | 
					import noteDetailText from "../services/note_detail_text.js";
 | 
				
			||||||
 | 
					import noteAutocompleteService from "../services/note_autocomplete.js";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const $dialog = $("#add-link-dialog");
 | 
					const $dialog = $("#add-link-dialog");
 | 
				
			||||||
const $form = $("#add-link-form");
 | 
					const $form = $("#add-link-form");
 | 
				
			||||||
@ -55,24 +55,7 @@ async function showDialog() {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    await $autoComplete.autocomplete({
 | 
					    await $autoComplete.autocomplete({
 | 
				
			||||||
        source: async function(request, response) {
 | 
					        source: noteAutocompleteService.autocompleteSource,
 | 
				
			||||||
            const result = await server.get('autocomplete?query=' + encodeURIComponent(request.term));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            if (result.length > 0) {
 | 
					 | 
				
			||||||
                response(result.map(row => {
 | 
					 | 
				
			||||||
                    return {
 | 
					 | 
				
			||||||
                        label: row.label,
 | 
					 | 
				
			||||||
                        value: row.label + ' (' + row.value + ')'
 | 
					 | 
				
			||||||
                    }
 | 
					 | 
				
			||||||
                }));
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            else {
 | 
					 | 
				
			||||||
                response([{
 | 
					 | 
				
			||||||
                    label: "No results",
 | 
					 | 
				
			||||||
                    value: "No results"
 | 
					 | 
				
			||||||
                }]);
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        },
 | 
					 | 
				
			||||||
        minLength: 0,
 | 
					        minLength: 0,
 | 
				
			||||||
        change: async (event, ui) => {
 | 
					        change: async (event, ui) => {
 | 
				
			||||||
            if (!ui.item) {
 | 
					            if (!ui.item) {
 | 
				
			||||||
 | 
				
			|||||||
@ -1,6 +1,7 @@
 | 
				
			|||||||
import treeService from '../services/tree.js';
 | 
					import treeService from '../services/tree.js';
 | 
				
			||||||
import server from '../services/server.js';
 | 
					 | 
				
			||||||
import searchNotesService from '../services/search_notes.js';
 | 
					import searchNotesService from '../services/search_notes.js';
 | 
				
			||||||
 | 
					import noteautocompleteService from '../services/note_autocomplete.js';
 | 
				
			||||||
 | 
					import linkService from "../services/link.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");
 | 
				
			||||||
@ -19,22 +20,8 @@ async function showDialog() {
 | 
				
			|||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    await $autoComplete.autocomplete({
 | 
					    await $autoComplete.autocomplete({
 | 
				
			||||||
        source: async function(request, response) {
 | 
					        source: noteautocompleteService.autocompleteSource,
 | 
				
			||||||
            const result = await server.get('autocomplete?query=' + encodeURIComponent(request.term));
 | 
					        focus: event => event.preventDefault(),
 | 
				
			||||||
 | 
					 | 
				
			||||||
            if (result.length > 0) {
 | 
					 | 
				
			||||||
                response(result);
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            else {
 | 
					 | 
				
			||||||
                response([{
 | 
					 | 
				
			||||||
                    label: "No results",
 | 
					 | 
				
			||||||
                    value: "No results"
 | 
					 | 
				
			||||||
                }]);
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        },
 | 
					 | 
				
			||||||
        focus: function(event, ui) {
 | 
					 | 
				
			||||||
            event.preventDefault();
 | 
					 | 
				
			||||||
        },
 | 
					 | 
				
			||||||
        minLength: 0,
 | 
					        minLength: 0,
 | 
				
			||||||
        autoFocus: true,
 | 
					        autoFocus: true,
 | 
				
			||||||
        select: function (event, ui) {
 | 
					        select: function (event, ui) {
 | 
				
			||||||
@ -42,7 +29,9 @@ async function showDialog() {
 | 
				
			|||||||
                return false;
 | 
					                return false;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            treeService.activateNode(ui.item.value);
 | 
					            const notePath = linkService.getNotePathFromLabel(ui.item.value);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            treeService.activateNode(notePath);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            $dialog.dialog('close');
 | 
					            $dialog.dialog('close');
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
				
			|||||||
@ -1,4 +1,26 @@
 | 
				
			|||||||
import server from "./server.js";
 | 
					import server from "./server.js";
 | 
				
			||||||
 | 
					import noteDetailService from "./note_detail.js";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					async function autocompleteSource(request, response) {
 | 
				
			||||||
 | 
					    const result = await server.get('autocomplete'
 | 
				
			||||||
 | 
					        + '?query=' + encodeURIComponent(request.term)
 | 
				
			||||||
 | 
					        + '¤tNoteId=' + noteDetailService.getCurrentNoteId());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (result.length > 0) {
 | 
				
			||||||
 | 
					        response(result.map(row => {
 | 
				
			||||||
 | 
					            return {
 | 
				
			||||||
 | 
					                label: row.label,
 | 
				
			||||||
 | 
					                value: row.label + ' (' + row.value + ')'
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }));
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    else {
 | 
				
			||||||
 | 
					        response([{
 | 
				
			||||||
 | 
					            label: "No results",
 | 
				
			||||||
 | 
					            value: "No results"
 | 
				
			||||||
 | 
					        }]);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
async function initNoteAutocomplete($el) {
 | 
					async function initNoteAutocomplete($el) {
 | 
				
			||||||
    if (!$el.hasClass("ui-autocomplete-input")) {
 | 
					    if (!$el.hasClass("ui-autocomplete-input")) {
 | 
				
			||||||
@ -12,24 +34,7 @@ async function initNoteAutocomplete($el) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        await $el.autocomplete({
 | 
					        await $el.autocomplete({
 | 
				
			||||||
            appendTo: $el.parent().parent(),
 | 
					            appendTo: $el.parent().parent(),
 | 
				
			||||||
            source: async function (request, response) {
 | 
					            source: autocompleteSource,
 | 
				
			||||||
                const result = await server.get('autocomplete?query=' + encodeURIComponent(request.term));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                if (result.length > 0) {
 | 
					 | 
				
			||||||
                    response(result.map(row => {
 | 
					 | 
				
			||||||
                        return {
 | 
					 | 
				
			||||||
                            label: row.label,
 | 
					 | 
				
			||||||
                            value: row.label + ' (' + row.value + ')'
 | 
					 | 
				
			||||||
                        }
 | 
					 | 
				
			||||||
                    }));
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
                else {
 | 
					 | 
				
			||||||
                    response([{
 | 
					 | 
				
			||||||
                        label: "No results",
 | 
					 | 
				
			||||||
                        value: "No results"
 | 
					 | 
				
			||||||
                    }]);
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
            },
 | 
					 | 
				
			||||||
            minLength: 0,
 | 
					            minLength: 0,
 | 
				
			||||||
            change: function (event, ui) {
 | 
					            change: function (event, ui) {
 | 
				
			||||||
                $el.trigger("change");
 | 
					                $el.trigger("change");
 | 
				
			||||||
@ -50,5 +55,6 @@ ko.bindingHandlers.noteAutocomplete = {
 | 
				
			|||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default {
 | 
					export default {
 | 
				
			||||||
    initNoteAutocomplete
 | 
					    initNoteAutocomplete,
 | 
				
			||||||
 | 
					    autocompleteSource
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -5,11 +5,12 @@ const repository = require('../../services/repository');
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
async function getAutocomplete(req) {
 | 
					async function getAutocomplete(req) {
 | 
				
			||||||
    const query = req.query.query;
 | 
					    const query = req.query.query;
 | 
				
			||||||
 | 
					    const currentNoteId = req.query.currentNoteId || 'none';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let results;
 | 
					    let results;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (query.trim().length === 0) {
 | 
					    if (query.trim().length === 0) {
 | 
				
			||||||
        results = await getRecentNotes();
 | 
					        results = await getRecentNotes(currentNoteId);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    else {
 | 
					    else {
 | 
				
			||||||
        results = noteCacheService.findNotes(query);
 | 
					        results = noteCacheService.findNotes(query);
 | 
				
			||||||
@ -23,7 +24,7 @@ async function getAutocomplete(req) {
 | 
				
			|||||||
    });
 | 
					    });
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
async function getRecentNotes() {
 | 
					async function getRecentNotes(currentNoteId) {
 | 
				
			||||||
    const recentNotes = await repository.getEntities(`
 | 
					    const recentNotes = await repository.getEntities(`
 | 
				
			||||||
      SELECT 
 | 
					      SELECT 
 | 
				
			||||||
        recent_notes.* 
 | 
					        recent_notes.* 
 | 
				
			||||||
@ -33,9 +34,10 @@ async function getRecentNotes() {
 | 
				
			|||||||
      WHERE
 | 
					      WHERE
 | 
				
			||||||
        recent_notes.isDeleted = 0
 | 
					        recent_notes.isDeleted = 0
 | 
				
			||||||
        AND branches.isDeleted = 0
 | 
					        AND branches.isDeleted = 0
 | 
				
			||||||
 | 
					        AND branches.noteId != ?
 | 
				
			||||||
      ORDER BY 
 | 
					      ORDER BY 
 | 
				
			||||||
        dateCreated DESC
 | 
					        dateCreated DESC
 | 
				
			||||||
      LIMIT 200`);
 | 
					      LIMIT 200`, [currentNoteId]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return recentNotes.map(rn => {
 | 
					    return recentNotes.map(rn => {
 | 
				
			||||||
        return {
 | 
					        return {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user