search note fixes

This commit is contained in:
azivner 2018-06-04 23:21:45 -04:00
parent 5a1938c078
commit bd913a63a8
5 changed files with 25 additions and 11 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 388 B

View File

@ -114,13 +114,14 @@ const contextMenuOptions = {
// Modify menu entries depending on node status
$tree.contextmenu("enableEntry", "insertNoteHere", isNotRoot && parentNote.type !== 'search');
$tree.contextmenu("enableEntry", "insertChildNote", note.type !== 'search');
$tree.contextmenu("enableEntry", "delete", isNotRoot);
$tree.contextmenu("enableEntry", "delete", isNotRoot && parentNote.type !== 'search');
$tree.contextmenu("enableEntry", "copy", isNotRoot);
$tree.contextmenu("enableEntry", "cut", isNotRoot);
$tree.contextmenu("enableEntry", "pasteAfter", clipboardIds.length > 0 && isNotRoot && parentNote.type !== 'search');
$tree.contextmenu("enableEntry", "pasteInto", clipboardIds.length > 0 && note.type !== 'search');
$tree.contextmenu("enableEntry", "importBranch", note.type !== 'search');
$tree.contextmenu("enableEntry", "exportBranch", note.type !== 'search');
$tree.contextmenu("enableEntry", "editBranchPrefix", parentNote.type !== 'search');
// Activate node on right-click
node.setActive();

View File

@ -74,14 +74,14 @@ async function prepareRealBranch(parentNote) {
async function prepareSearchBranch(note) {
const fullNote = await noteDetailService.loadNote(note.noteId);
const noteIds = await server.get('search/' + encodeURIComponent(fullNote.jsonContent.searchString));
const results = await server.get('search/' + encodeURIComponent(fullNote.jsonContent.searchString));
for (const noteId of noteIds) {
for (const result of results) {
const branch = new Branch(treeCache, {
branchId: "virt" + utils.randomString(10),
noteId: noteId,
noteId: result.noteId,
parentNoteId: note.noteId,
prefix: '',
prefix: result.prefix,
virtual: true
});

View File

@ -8,6 +8,7 @@ const utils = require('./utils');
let noteTitles;
let protectedNoteTitles;
let noteIds;
let childParentToBranchId = {};
const childToParent = {};
const hideInAutocomplete = {};
@ -20,11 +21,12 @@ async function load() {
prefixes = await sql.getMap(`SELECT noteId || '-' || parentNoteId, prefix FROM branches WHERE prefix IS NOT NULL AND prefix != ''`);
const relations = await sql.getRows(`SELECT noteId, parentNoteId FROM branches WHERE isDeleted = 0`);
const relations = await sql.getRows(`SELECT branchId, noteId, parentNoteId FROM branches WHERE isDeleted = 0`);
for (const rel of relations) {
childToParent[rel.noteId] = childToParent[rel.noteId] || [];
childToParent[rel.noteId].push(rel.parentNoteId);
childParentToBranchId[`${rel.noteId}-${rel.parentNoteId}`] = rel.branchId;
}
const hiddenLabels = await sql.getColumn(`SELECT noteId FROM labels WHERE isDeleted = 0 AND name = 'hideInAutocomplete'`);
@ -91,11 +93,15 @@ function search(noteId, tokens, path, results) {
if (retPath) {
const noteTitle = getNoteTitleForPath(retPath);
const thisNoteId = retPath[retPath.length - 1];
const thisParentNoteId = retPath[retPath.length - 2];
results.push({
noteId: noteId,
noteId: thisNoteId,
branchId: childParentToBranchId[`${thisNoteId}-${thisParentNoteId}`],
title: noteTitle,
path: retPath.join('/')
path: retPath.join('/'),
prefix: prefixes[`${thisNoteId}-${thisParentNoteId}`]
});
}
@ -230,6 +236,7 @@ eventService.subscribe(eventService.ENTITY_CHANGED, async ({entityName, entityId
if (branch.isDeleted) {
delete prefixes[branch.noteId + '-' + branch.parentNoteId];
delete childParentToBranchId[branch.noteId + '-' + branch.parentNoteId];
}
else {
if (branch.prefix) {
@ -238,6 +245,7 @@ eventService.subscribe(eventService.ENTITY_CHANGED, async ({entityName, entityId
childToParent[branch.noteId] = childToParent[branch.noteId] || [];
childToParent[branch.noteId].push(branch.parentNoteId);
childParentToBranchId[branch.noteId + '-' + branch.parentNoteId] = branch.branchId;
}
}
else if (entityName === 'labels') {

View File

@ -77,7 +77,12 @@
<div style="display: flex; align-items: center;">
<input name="search-text" placeholder="Search text, labels" style="flex-grow: 100; margin-left: 5px; margin-right: 5px;" autocomplete="off">
<button id="do-search-button" class="btn btn-sm" title="Search">Search</button>
<button id="save-search-button" class="btn btn-sm" title="Save search">Save</button>
&nbsp;
<button id="save-search-button" class="btn btn-sm" title="Save search" style="padding: 4px;">
<img src="/images/icons/save.png" alt="Save search"/>
</button>
</div>
</div>
@ -115,10 +120,10 @@
<div class="btn-group btn-group-xs">
<button type="button" class="btn" id="protect-button" title="Protected note can be viewed and edited only after entering password">
<img src="images/icons/shield.png"/>
<img src="/images/icons/shield.png"/>
</button>
<button type="button" class="btn" id="unprotect-button" title="Not protected note can be viewed without entering password">
<img src="images/icons/shield-off.png"/>
<img src="/images/icons/shield-off.png"/>
</button>
</div>
</div>