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