mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
improvements to search, fixing issue #1
This commit is contained in:
parent
31a69a96c0
commit
7ea23586fe
@ -200,7 +200,7 @@ const noteTree = (function() {
|
|||||||
return noteList;
|
return noteList;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function activateNode(notePath) {
|
async function expandToNote(notePath, expandOpts) {
|
||||||
assertArguments(notePath);
|
assertArguments(notePath);
|
||||||
|
|
||||||
const runPath = getRunPath(notePath);
|
const runPath = getRunPath(notePath);
|
||||||
@ -213,14 +213,22 @@ const noteTree = (function() {
|
|||||||
const node = getNodesByNoteId(childNoteId).find(node => node.data.parent_note_id === parentNoteId);
|
const node = getNodesByNoteId(childNoteId).find(node => node.data.parent_note_id === parentNoteId);
|
||||||
|
|
||||||
if (childNoteId === noteId) {
|
if (childNoteId === noteId) {
|
||||||
await node.setActive();
|
return node;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
await node.setExpanded();
|
await node.setExpanded(true, expandOpts);
|
||||||
}
|
}
|
||||||
|
|
||||||
parentNoteId = childNoteId;
|
parentNoteId = childNoteId;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function activateNode(notePath) {
|
||||||
|
assertArguments(notePath);
|
||||||
|
|
||||||
|
const node = await expandToNote(notePath);
|
||||||
|
|
||||||
|
await node.setActive();
|
||||||
|
|
||||||
clearSelectedNodes();
|
clearSelectedNodes();
|
||||||
}
|
}
|
||||||
@ -841,6 +849,7 @@ const noteTree = (function() {
|
|||||||
setNoteTreeBackgroundBasedOnProtectedStatus,
|
setNoteTreeBackgroundBasedOnProtectedStatus,
|
||||||
setProtected,
|
setProtected,
|
||||||
getCurrentNode,
|
getCurrentNode,
|
||||||
|
expandToNote,
|
||||||
activateNode,
|
activateNode,
|
||||||
getCurrentNotePath,
|
getCurrentNotePath,
|
||||||
getNoteTitle,
|
getNoteTitle,
|
||||||
|
@ -30,7 +30,7 @@ const searchTree = (function() {
|
|||||||
return treeEl.fancytree('getTree');
|
return treeEl.fancytree('getTree');
|
||||||
}
|
}
|
||||||
|
|
||||||
searchInputEl.keyup(e => {
|
searchInputEl.keyup(async e => {
|
||||||
const searchText = searchInputEl.val();
|
const searchText = searchInputEl.val();
|
||||||
|
|
||||||
if (e && e.which === $.ui.keyCode.ESCAPE || $.trim(searchText) === "") {
|
if (e && e.which === $.ui.keyCode.ESCAPE || $.trim(searchText) === "") {
|
||||||
@ -39,12 +39,14 @@ const searchTree = (function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (e && e.which === $.ui.keyCode.ENTER) {
|
if (e && e.which === $.ui.keyCode.ENTER) {
|
||||||
server.get('notes?search=' + searchText).then(resp => {
|
const noteIds = await server.get('notes?search=' + encodeURIComponent(searchText));
|
||||||
// Pass a string to perform case insensitive matching
|
|
||||||
getTree().filterBranches(node => {
|
for (const noteId of noteIds) {
|
||||||
return resp.includes(node.data.note_id);
|
await noteTree.expandToNote(noteId, {noAnimation: true, noEvents: true});
|
||||||
});
|
}
|
||||||
});
|
|
||||||
|
// Pass a string to perform case insensitive matching
|
||||||
|
getTree().filterBranches(node => noteIds.includes(node.data.note_id));
|
||||||
}
|
}
|
||||||
}).focus();
|
}).focus();
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ const auth = require('../../services/auth');
|
|||||||
const sql = require('../../services/sql');
|
const sql = require('../../services/sql');
|
||||||
const notes = require('../../services/notes');
|
const notes = require('../../services/notes');
|
||||||
const log = require('../../services/log');
|
const log = require('../../services/log');
|
||||||
|
const utils = require('../../services/utils');
|
||||||
const protected_session = require('../../services/protected_session');
|
const protected_session = require('../../services/protected_session');
|
||||||
const data_encryption = require('../../services/data_encryption');
|
const data_encryption = require('../../services/data_encryption');
|
||||||
const tree = require('../../services/tree');
|
const tree = require('../../services/tree');
|
||||||
@ -59,17 +60,13 @@ router.put('/:noteId', auth.checkApiAuth, wrap(async (req, res, next) => {
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
router.get('/', auth.checkApiAuth, wrap(async (req, res, next) => {
|
router.get('/', auth.checkApiAuth, wrap(async (req, res, next) => {
|
||||||
const search = '%' + req.query.search + '%';
|
const search = '%' + utils.sanitizeSql(req.query.search) + '%';
|
||||||
|
|
||||||
const result = await sql.getAll("SELECT note_id FROM notes WHERE note_title LIKE ? OR note_text LIKE ?", [search, search]);
|
// searching in protected notes is pointless because of encryption
|
||||||
|
const noteIds = await sql.getFirstColumn(`SELECT note_id FROM notes
|
||||||
|
WHERE is_deleted = 0 AND is_protected = 0 AND (note_title LIKE ? OR note_text LIKE ?)`, [search, search]);
|
||||||
|
|
||||||
const noteIdList = [];
|
res.send(noteIds);
|
||||||
|
|
||||||
for (const res of result) {
|
|
||||||
noteIdList.push(res.note_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
res.send(noteIdList);
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
router.put('/:noteId/sort', auth.checkApiAuth, wrap(async (req, res, next) => {
|
router.put('/:noteId/sort', auth.checkApiAuth, wrap(async (req, res, next) => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user