improvements in search UI

This commit is contained in:
zadam 2020-11-26 23:00:27 +01:00
parent 02043d9109
commit eaed7ec86f
27 changed files with 251 additions and 252 deletions

40
package-lock.json generated
View file

@ -1808,9 +1808,9 @@
"dev": true
},
"caniuse-lite": {
"version": "1.0.30001159",
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001159.tgz",
"integrity": "sha512-w9Ph56jOsS8RL20K9cLND3u/+5WASWdhC/PPrf+V3/HsM3uHOavWOR1Xzakbv4Puo/srmPHudkmCRWM7Aq+/UA==",
"version": "1.0.30001161",
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001161.tgz",
"integrity": "sha512-JharrCDxOqPLBULF9/SPa6yMcBRTjZARJ6sc3cuKrPfyIk64JN6kuMINWqA99Xc8uElMFcROliwtz0n9pYej+g==",
"dev": true
},
"caseless": {
@ -3212,9 +3212,9 @@
}
},
"electron-to-chromium": {
"version": "1.3.602",
"resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.602.tgz",
"integrity": "sha512-+JbC10U8vpKAqAtrEqORdzaWewRgEj5DY+QQNyP/dxDTshPqqgpjrvt6smewKS/5F3vT5prYgg7/VTxb5FROjw==",
"version": "1.3.607",
"resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.607.tgz",
"integrity": "sha512-h2SYNaBnlplGS0YyXl8oJWokfcNxVjJANQfMCsQefG6OSuAuNIeW+A8yGT/ci+xRoBb3k2zq1FrOvkgoKBol8g==",
"dev": true
},
"electron-window-state": {
@ -3253,9 +3253,9 @@
}
},
"enhanced-resolve": {
"version": "5.3.1",
"resolved": "https://registry.npmjs.org/enhanced-resolve/-/enhanced-resolve-5.3.1.tgz",
"integrity": "sha512-G1XD3MRGrGfNcf6Hg0LVZG7GIKcYkbfHa5QMxt1HDUTdYoXH0JR1xXyg+MaKLF73E9A27uWNVxvFivNRYeUB6w==",
"version": "5.3.2",
"resolved": "https://registry.npmjs.org/enhanced-resolve/-/enhanced-resolve-5.3.2.tgz",
"integrity": "sha512-G28GCrglCAH6+EqMN2D+Q2wCUS1O1vVQJBn8ME2I/Api41YBe4vLWWRBOUbwDH7vwzSZdljxwTRVqnf+sm6XqQ==",
"dev": true,
"requires": {
"graceful-fs": "^4.2.4",
@ -7195,12 +7195,12 @@
},
"dependencies": {
"p-limit": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/p-limit/-/p-limit-3.0.2.tgz",
"integrity": "sha512-iwqZSOoWIW+Ew4kAGUlN16J4M7OB3ysMLSZtnhmqx7njIHFPlxWBX8xo3lVTyFVq6mI/lL9qt2IsN1sHwaxJkg==",
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/p-limit/-/p-limit-3.1.0.tgz",
"integrity": "sha512-TYOanM3wGwNGsZN2cVTYPArw454xnXj5qmWF1bEoAc4+cU/ol7GVh7odevjp1FNHduHc3KZMcFduxU5Xc6uJRQ==",
"dev": true,
"requires": {
"p-try": "^2.0.0"
"yocto-queue": "^0.1.0"
}
}
}
@ -7627,9 +7627,9 @@
"integrity": "sha512-qBIvFLGiBpLjfwmYAaHPXsn+ho5xZnGvyGvsarywGNc8VyQJUMHJ8OBKGGrPER0okBeMDaan4mNBlgBROxuI8w=="
},
"webpack": {
"version": "5.6.0",
"resolved": "https://registry.npmjs.org/webpack/-/webpack-5.6.0.tgz",
"integrity": "sha512-SIeFuBhuheKElRbd84O35UhKc0nxlgSwtzm2ksZ0BVhRJqxVJxEguT/pYhfiR0le/pxTa1VsCp7EOYyTsa6XOA==",
"version": "5.8.0",
"resolved": "https://registry.npmjs.org/webpack/-/webpack-5.8.0.tgz",
"integrity": "sha512-X2yosPiHip3L0TE+ylruzrOqSgEgsdGyBOGFWKYChcwlKChaw9VodZIUovG1oo7s0ss6e3ZxBMn9tXR+nkPThA==",
"dev": true,
"requires": {
"@types/eslint-scope": "^3.7.0",
@ -7652,7 +7652,7 @@
"neo-async": "^2.6.2",
"pkg-dir": "^4.2.0",
"schema-utils": "^3.0.0",
"tapable": "^2.0.0",
"tapable": "^2.1.1",
"terser-webpack-plugin": "^5.0.3",
"watchpack": "^2.0.0",
"webpack-sources": "^2.1.1"
@ -8113,6 +8113,12 @@
"requires": {
"buffer-crc32": "~0.2.3"
}
},
"yocto-queue": {
"version": "0.1.0",
"resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz",
"integrity": "sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==",
"dev": true
}
}
}

View file

@ -86,7 +86,7 @@
"jsdoc": "3.6.6",
"lorem-ipsum": "2.0.3",
"rcedit": "2.2.0",
"webpack": "5.6.0",
"webpack": "5.8.0",
"webpack-cli": "4.2.0"
},
"optionalDependencies": {

View file

@ -9,7 +9,7 @@ import RunScriptButtonsWidget from "../widgets/run_script_buttons.js";
import NoteTypeWidget from "../widgets/note_type.js";
import NoteActionsWidget from "../widgets/note_actions.js";
import NoteDetailWidget from "../widgets/note_detail.js";
import OwnedAttributeListWidget from "../widgets/owned_attribute_list.js";
import OwnedAttributeListWidget from "../widgets/attribute_widgets/owned_attribute_list.js";
export default class DesktopExtraWindowLayout {
constructor(customWidgets) {

View file

@ -11,7 +11,7 @@ import NoteTreeWidget from "../widgets/note_tree.js";
import TabCachingWidget from "../widgets/tab_caching_widget.js";
import NotePathsWidget from "../widgets/note_paths.js";
import NoteTitleWidget from "../widgets/note_title.js";
import OwnedAttributeListWidget from "../widgets/owned_attribute_list.js";
import OwnedAttributeListWidget from "../widgets/attribute_widgets/owned_attribute_list.js";
import RunScriptButtonsWidget from "../widgets/run_script_buttons.js";
import NoteTypeWidget from "../widgets/note_type.js";
import NoteActionsWidget from "../widgets/note_actions.js";
@ -25,9 +25,10 @@ import WhatLinksHereWidget from "../widgets/collapsible_widgets/what_links_here.
import SidePaneToggles from "../widgets/side_pane_toggles.js";
import EditedNotesWidget from "../widgets/collapsible_widgets/edited_notes.js";
import CollapsibleSectionContainer from "../widgets/collapsible_section_container.js";
import PromotedAttributesWidget from "../widgets/promoted_attributes.js";
import PromotedAttributesWidget from "../widgets/attribute_widgets/promoted_attributes.js";
import InheritedAttributesWidget from "../widgets/inherited_attribute_list.js";
import NoteListWidget from "../widgets/note_list.js";
import SearchDefinitionWidget from "../widgets/search_definition.js";
const RIGHT_PANE_CSS = `
<style>
@ -159,6 +160,7 @@ export default class DesktopMainWindowLayout {
)
.child(
new TabCachingWidget(() => new CollapsibleSectionContainer()
.child(new SearchDefinitionWidget())
.child(new PromotedAttributesWidget())
.child(new OwnedAttributeListWidget())
.child(new InheritedAttributesWidget())

View file

@ -2,6 +2,7 @@ import Branch from "../entities/branch.js";
import NoteShort from "../entities/note_short.js";
import Attribute from "../entities/attribute.js";
import server from "./server.js";
import appContext from "./app_context.js";
import NoteComplement from "../entities/note_complement.js";
/**
@ -192,8 +193,12 @@ class TreeCache {
await this.loadParents(resp, true);
this.addResp(resp);
const searchNoteIds = [];
for (const note of resp.notes) {
if (note.type === 'search') {
searchNoteIds.push(note.noteId);
const searchResultNoteIds = await server.get('search-note/' + note.noteId);
if (!Array.isArray(searchResultNoteIds)) {
@ -227,6 +232,10 @@ class TreeCache {
});
}
}
if (searchNoteIds.length > 0) {
appContext.triggerEvent('searchResultsUpdated', {searchNoteIds});
}
}
/** @return {NoteShort[]} */

View file

@ -1,13 +1,13 @@
import server from "../services/server.js";
import treeCache from "../services/tree_cache.js";
import treeService from "../services/tree.js";
import linkService from "../services/link.js";
import attributeAutocompleteService from "../services/attribute_autocomplete.js";
import noteAutocompleteService from "../services/note_autocomplete.js";
import promotedAttributeDefinitionParser from '../services/promoted_attribute_definition_parser.js';
import TabAwareWidget from "./tab_aware_widget.js";
import SpacedUpdate from "../services/spaced_update.js";
import utils from "../services/utils.js";
import server from "../../services/server.js";
import treeCache from "../../services/tree_cache.js";
import treeService from "../../services/tree.js";
import linkService from "../../services/link.js";
import attributeAutocompleteService from "../../services/attribute_autocomplete.js";
import noteAutocompleteService from "../../services/note_autocomplete.js";
import promotedAttributeDefinitionParser from '../../services/promoted_attribute_definition_parser.js';
import TabAwareWidget from "../tab_aware_widget.js";
import SpacedUpdate from "../../services/spaced_update.js";
import utils from "../../services/utils.js";
const TPL = `
<div class="attr-detail">

View file

@ -1,13 +1,13 @@
import TabAwareWidget from "./tab_aware_widget.js";
import noteAutocompleteService from "../services/note_autocomplete.js";
import server from "../services/server.js";
import contextMenuService from "../services/context_menu.js";
import attributesParser from "../services/attribute_parser.js";
import libraryLoader from "../services/library_loader.js";
import treeCache from "../services/tree_cache.js";
import attributeRenderer from "../services/attribute_renderer.js";
import noteCreateService from "../services/note_create.js";
import treeService from "../services/tree.js";
import TabAwareWidget from "../tab_aware_widget.js";
import noteAutocompleteService from "../../services/note_autocomplete.js";
import server from "../../services/server.js";
import contextMenuService from "../../services/context_menu.js";
import attributesParser from "../../services/attribute_parser.js";
import libraryLoader from "../../services/library_loader.js";
import treeCache from "../../services/tree_cache.js";
import attributeRenderer from "../../services/attribute_renderer.js";
import noteCreateService from "../../services/note_create.js";
import treeService from "../../services/tree.js";
const HELP_TEXT = `
<p>To add label, just type e.g. <code>#rock</code> or if you want to add also value then e.g. <code>#year = 2020</code></p>

View file

@ -1,4 +1,4 @@
import TabAwareWidget from "./tab_aware_widget.js";
import TabAwareWidget from "../tab_aware_widget.js";
import AttributeDetailWidget from "./attribute_detail.js";
import AttributeEditorWidget from "./attribute_editor.js";

View file

@ -1,8 +1,8 @@
import server from "../services/server.js";
import ws from "../services/ws.js";
import treeService from "../services/tree.js";
import noteAutocompleteService from "../services/note_autocomplete.js";
import TabAwareWidget from "./tab_aware_widget.js";
import server from "../../services/server.js";
import ws from "../../services/ws.js";
import treeService from "../../services/tree.js";
import noteAutocompleteService from "../../services/note_autocomplete.js";
import TabAwareWidget from "../tab_aware_widget.js";
const TPL = `
<div>

View file

@ -1,5 +1,5 @@
import TabAwareWidget from "./tab_aware_widget.js";
import AttributeDetailWidget from "./attribute_detail.js";
import AttributeDetailWidget from "./attribute_widgets/attribute_detail.js";
import attributeRenderer from "../services/attribute_renderer.js";
const TPL = `

View file

@ -9,7 +9,6 @@ import EditableTextTypeWidget from "./type_widgets/editable_text.js";
import EditableCodeTypeWidget from "./type_widgets/editable_code.js";
import FileTypeWidget from "./type_widgets/file.js";
import ImageTypeWidget from "./type_widgets/image.js";
import SearchTypeWidget from "./type_widgets/search.js";
import RenderTypeWidget from "./type_widgets/render.js";
import RelationMapTypeWidget from "./type_widgets/relation_map.js";
import ProtectedSessionTypeWidget from "./type_widgets/protected_session.js";
@ -20,6 +19,7 @@ import noteCreateService from "../services/note_create.js";
import DeletedTypeWidget from "./type_widgets/deleted.js";
import ReadOnlyTextTypeWidget from "./type_widgets/read_only_text.js";
import ReadOnlyCodeTypeWidget from "./type_widgets/read_only_code.js";
import NoneTypeWidget from "./type_widgets/none.js";
const TPL = `
<div class="note-detail">
@ -43,7 +43,7 @@ const typeWidgetClasses = {
'read-only-code': ReadOnlyCodeTypeWidget,
'file': FileTypeWidget,
'image': ImageTypeWidget,
'search': SearchTypeWidget,
'search': NoneTypeWidget,
'render': RenderTypeWidget,
'relation-map': RelationMapTypeWidget,
'protected-session': ProtectedSessionTypeWidget,

View file

@ -1,20 +1,25 @@
import TabAwareWidget from "./tab_aware_widget.js";
import NoteListRenderer from "../services/note_list_renderer.js";
import utils from "../services/utils.js";
const TPL = `
<div class="note-list-widget">
<style>
.note-list-widget {
flex-grow: 100000;
padding: 0 10px 10px 10px;
}
</style>
<style>
.note-list-widget {
flex-grow: 100000;
flex-shrink: 100000;
min-height: 0;
padding: 0 10px 10px 10px;
}
</style>
<div class="note-list-widget-content">
</div>
</div>`;
export default class NoteListWidget extends TabAwareWidget {
isEnabled() {
return super.isEnabled() && !this.tabContext.autoBookDisabled && (
return super.isEnabled() && (
['book', 'search'].includes(this.note.type)
|| (this.note.type === 'text' && this.note.hasChildren())
);
@ -22,13 +27,23 @@ export default class NoteListWidget extends TabAwareWidget {
doRender() {
this.$widget = $(TPL);
this.$content = this.$widget.find('.note-list-widget-content');
this.contentSized();
}
async refreshWithNote(note) {
// this.tabContext.autoBookDisabled;
//
// const noteComplement = await this.tabContext.getNoteComplement();
//
// if (utils.isHtmlEmpty(noteComplement.content)) {
//
// }
//
const noteListRenderer = new NoteListRenderer(note, note.getChildNoteIds());
this.$widget.empty().append(await noteListRenderer.renderList());
this.$content.empty().append(await noteListRenderer.renderList());
}
autoBookDisabledEvent({tabContext}) {
@ -36,4 +51,10 @@ export default class NoteListWidget extends TabAwareWidget {
this.refresh();
}
}
searchResultsUpdatedEvent({searchNoteIds}) {
if (searchNoteIds.includes(this.noteId)) {
this.refresh();
}
}
}

View file

@ -0,0 +1,126 @@
import TypeWidget from "./type_widgets/type_widget.js";
import noteAutocompleteService from "../services/note_autocomplete.js";
import SpacedUpdate from "../services/spaced_update.js";
import server from "../services/server.js";
import toastService from "../services/toast.js";
import NoteListRenderer from "../services/note_list_renderer.js";
import TabAwareWidget from "./tab_aware_widget.js";
import treeCache from "../services/tree_cache.js";
const TPL = `
<div class="search-definition-widget">
<style>
.note-detail-search {
padding: 7px;
height: 100%;
display: flex;
flex-direction: column;
}
.search-setting-table {
width: 100%;
border-collapse: separate;
border-spacing: 10px;
}
.attribute-list hr {
height: 1px;
border-color: var(--main-border-color);
position: relative;
top: 4px;
margin-top: 5px;
margin-bottom: 0;
}
</style>
<div class="search-settings">
<table class="search-setting-table">
<tr>
<td>Search string:</td>
<td colspan="3">
<input type="text" class="form-control search-string">
</td>
</tr>
<tr>
<td>Limit search to subtree:</td>
<td>
<div class="input-group">
<input class="limit-search-to-subtree form-control" placeholder="search for note by its name">
</div>
</td>
<td colspan="2" style="padding-top: 9px;">
<label title="By choosing to take into acount also note content, search can be slightly slower">
<input class="search-within-note-content" value="1" type="checkbox" checked>
Search also within note content
</label>
</td>
</tr>
</table>
</div>
</div>`;
export default class SearchDefinitionWidget extends TabAwareWidget {
static getType() { return "search"; }
renderTitle(note) {
return {
show: note.type === 'search',
activate: true,
$title: 'Search'
};
}
doRender() {
this.$widget = $(TPL);
this.contentSized();
this.$searchString = this.$widget.find(".search-string");
this.$searchString.on('input', () => this.spacedUpdate.scheduleUpdate());
this.$component = this.$widget.find('.search-definition-widget');
this.$settingsArea = this.$widget.find('.search-settings');
this.spacedUpdate = new SpacedUpdate(() => this.updateSearch(), 2000);
this.$limitSearchToSubtree = this.$widget.find('.limit-search-to-subtree');
noteAutocompleteService.initNoteAutocomplete(this.$limitSearchToSubtree);
this.$limitSearchToSubtree.on('autocomplete:closed', e => {
this.spacedUpdate.scheduleUpdate();
});
this.$searchWithinNoteContent = this.$widget.find('.search-within-note-content');
this.$searchWithinNoteContent.on('change', () => {
this.spacedUpdate.scheduleUpdate();
});
}
async updateSearch() {
const searchString = this.$searchString.val();
const subNoteId = this.$limitSearchToSubtree.getSelectedNoteId();
const includeNoteContent = this.$searchWithinNoteContent.is(":checked");
await server.put(`notes/${this.noteId}/attributes`, [
{ type: 'label', name: 'searchString', value: searchString },
{ type: 'label', name: 'includeNoteContent', value: includeNoteContent ? 'true' : 'false' },
subNoteId ? { type: 'label', name: 'subTreeNoteId', value: subNoteId } : undefined,
].filter(it => !!it));
await treeCache.reloadNotes([this.noteId]);
}
async doRefresh(note) {
this.$component.show();
this.$searchString.val(this.note.getLabelValue('searchString'));
this.$searchWithinNoteContent.prop('checked', this.note.getLabelValue('includeNoteContent') === 'true');
this.$limitSearchToSubtree.val(this.note.getLabelValue('subTreeNoteId'));
}
getContent() {
return JSON.stringify({
searchString: this.$searchString.val()
});
}
}

View file

@ -14,5 +14,6 @@ export default class DeletedTypeWidget extends TypeWidget {
doRender() {
this.$widget = $(TPL);
this.contentSized();
}
}

View file

@ -74,6 +74,7 @@ export default class EditableCodeTypeWidget extends TypeWidget {
doRender() {
this.$widget = $(TPL);
this.contentSized();
this.$editor = this.$widget.find('.note-detail-code-editor');
this.$sqlConsoleArea = this.$widget.find('.sql-console-area');
this.$sqlConsoleTableSchemas = this.$widget.find('.sql-console-table-schemas');

View file

@ -61,7 +61,7 @@ const TPL = `
border: 0 !important;
box-shadow: none !important;
/* This is because with empty content height of editor is 0 and it's impossible to click into it */
min-height: 500px;
min-height: 300px;
}
</style>
@ -74,6 +74,7 @@ export default class EditableTextTypeWidget extends AbstractTextTypeWidget {
doRender() {
this.$widget = $(TPL);
this.contentSized();
this.$editor = this.$widget.find('.note-detail-editable-text-editor');
this.initialized = this.initEditor();

View file

@ -19,6 +19,7 @@ export default class EmptyTypeWidget extends TypeWidget {
// FIXME: this might be optimized - cleaned up after use since it's always used only for new tab
this.$widget = $(TPL);
this.contentSized();
this.$autoComplete = this.$widget.find(".note-autocomplete");
noteAutocompleteService.initNoteAutocomplete(this.$autoComplete, { hideGoToSelectedNoteButton: true })

View file

@ -63,6 +63,7 @@ export default class FileTypeWidget extends TypeWidget {
doRender() {
this.$widget = $(TPL);
this.contentSized();
this.$fileNoteId = this.$widget.find(".file-note-id");
this.$fileName = this.$widget.find(".file-filename");
this.$fileType = this.$widget.find(".file-filetype");

View file

@ -55,6 +55,7 @@ class ImageTypeWidget extends TypeWidget {
doRender() {
this.$widget = $(TPL);
this.contentSized();
this.$imageWrapper = this.$widget.find('.note-detail-image-wrapper');
this.$imageView = this.$widget.find('.note-detail-image-view');
this.$copyToClipboardButton = this.$widget.find(".image-copy-to-clipboard");

View file

@ -0,0 +1,11 @@
import TypeWidget from "./type_widget.js";
const TPL = `<div class="note-detail-none note-detail-printable"></div>`;
export default class NoneTypeWidget extends TypeWidget {
static getType() { return "none"; }
doRender() {
this.$widget = $(TPL);
}
}

View file

@ -25,6 +25,7 @@ export default class ProtectedSessionTypeWidget extends TypeWidget {
doRender() {
this.$widget = $(TPL);
this.contentSized();
this.$passwordForm = this.$widget.find(".protected-session-password-form");
this.$passwordInput = this.$widget.find(".protected-session-password");

View file

@ -32,6 +32,7 @@ export default class ReadOnlyCodeTypeWidget extends TypeWidget {
doRender() {
this.$widget = $(TPL);
this.contentSized();
this.$content = this.$widget.find('.note-detail-read-only-code-content');
this.$widget.find('a.edit-note').on('click', () => {

View file

@ -50,6 +50,7 @@ export default class ReadOnlyTextTypeWidget extends AbstractTextTypeWidget {
doRender() {
this.$widget = $(TPL);
this.contentSized();
this.$content = this.$widget.find('.note-detail-readonly-text-content');

View file

@ -98,6 +98,7 @@ export default class RelationMapTypeWidget extends TypeWidget {
doRender() {
this.$widget = $(TPL);
this.contentSized();
this.$relationMapContainer = this.$widget.find(".relation-map-container");
this.$createChildNote = this.$widget.find(".relation-map-create-child-note");
this.$zoomInButton = this.$widget.find(".relation-map-zoom-in");

View file

@ -23,6 +23,7 @@ export default class RenderTypeWidget extends TypeWidget {
doRender() {
this.$widget = $(TPL);
this.contentSized();
this.$noteDetailRenderHelp = this.$widget.find('.note-detail-render-help');
this.$noteDetailRenderContent = this.$widget.find('.note-detail-render-content');
}

View file

@ -1,183 +0,0 @@
import TypeWidget from "./type_widget.js";
import noteAutocompleteService from "../../services/note_autocomplete.js";
import SpacedUpdate from "../../services/spaced_update.js";
import server from "../../services/server.js";
import toastService from "../../services/toast.js";
import NoteListRenderer from "../../services/note_list_renderer.js";
const TPL = `
<div class="note-detail-search note-detail-printable">
<style>
.note-detail-search {
padding: 7px;
height: 100%;
display: flex;
flex-direction: column;
}
.search-setting-table {
width: 100%;
border-collapse: separate;
border-spacing: 10px;
}
.search-setting-expander {
display: flex;
flex-direction: row;
color: var(--muted-text-color);
font-size: 90%;
margin: 3px 0 3px 0;
}
.attribute-list hr {
height: 1px;
border-color: var(--main-border-color);
position: relative;
top: 4px;
margin-top: 5px;
margin-bottom: 0;
}
.search-setting-expander-text {
padding-left: 20px;
padding-right: 20px;
white-space: nowrap;
}
.search-setting-expander:hover {
cursor: pointer;
}
.search-setting-expander:hover hr {
border-color: var(--main-text-color);
}
.search-setting-expander:hover .search-setting-expander-text {
color: var(--main-text-color);
}
.note-result-wrapper {
height: 100%;
overflow: auto;
}
</style>
<div class="area-expander">
<hr class="w-100">
<div class="area-expander-text">Search settings</div>
<hr class="w-100">
</div>
<div class="search-settings">
<table class="search-setting-table">
<tr>
<td>Search string:</td>
<td colspan="3">
<input type="text" class="form-control search-string">
</td>
</tr>
<tr>
<td>Limit search to subtree:</td>
<td>
<div class="input-group">
<input class="limit-search-to-subtree form-control" placeholder="search for note by its name">
</div>
</td>
<td colspan="2" style="padding-top: 9px;">
<label title="By choosing to take into acount also note content, search can be slightly slower">
<input class="search-within-note-content" value="1" type="checkbox" checked>
Search also within note content
</label>
</td>
</tr>
</table>
<hr class="w-100 search-setting-empty-expander" style="margin-bottom: 10px;">
</div>
<div class="note-result-wrapper"></div>
</div>`;
export default class SearchTypeWidget extends TypeWidget {
static getType() { return "search"; }
doRender() {
this.$widget = $(TPL);
this.$searchString = this.$widget.find(".search-string");
this.$searchString.on('input', () => this.spacedUpdate.scheduleUpdate());
this.$component = this.$widget.find('.note-detail-search');
this.$settingsArea = this.$widget.find('.search-settings');
this.spacedUpdate = new SpacedUpdate(() => this.updateSearch(), 2000);
this.$limitSearchToSubtree = this.$widget.find('.limit-search-to-subtree');
noteAutocompleteService.initNoteAutocomplete(this.$limitSearchToSubtree);
this.$limitSearchToSubtree.on('autocomplete:closed', e => {
this.spacedUpdate.scheduleUpdate();
});
this.$searchWithinNoteContent = this.$widget.find('.search-within-note-content');
this.$searchWithinNoteContent.on('change', () => {
this.spacedUpdate.scheduleUpdate();
});
this.$settingExpander = this.$widget.find('.area-expander');
this.$settingExpander.on('click', async () => {
const collapse = this.$settingsArea.is(":visible");
if (collapse) {
this.$settingsArea.slideUp(200);
} else {
this.$settingsArea.slideDown(200);
}
});
this.$noteResultWrapper = this.$widget.find('.note-result-wrapper');
}
async updateSearch() {
const searchString = this.$searchString.val();
const subNoteId = this.$limitSearchToSubtree.getSelectedNoteId();
const includeNoteContent = this.$searchWithinNoteContent.is(":checked");
const response = await server.get(`search/${encodeURIComponent(searchString)}?includeNoteContent=${includeNoteContent}&excludeArchived=true&fuzzyAttributeSearch=false`);
if (!response.success) {
toastService.showError("Search failed: " + response.message, 10000);
// even in this case we'll show the results
}
const resultNoteIds = response.results.map(res => res.notePathArray[res.notePathArray.length - 1]);
const noteListRenderer = new NoteListRenderer(this.note, resultNoteIds);
this.$noteResultWrapper.empty().append(await noteListRenderer.renderList());
}
async doRefresh(note) {
this.$component.show();
// try {
// const noteComplement = await this.tabContext.getNoteComplement();
// const json = JSON.parse(noteComplement.content);
//
// this.$searchString.val(json.searchString);
// }
// catch (e) {
// console.log(e);
// this.$searchString.val('');
// }
}
getContent() {
return JSON.stringify({
searchString: this.$searchString.val()
});
}
}

View file

@ -46,27 +46,23 @@ async function searchFromNote(req) {
return [400, `Note ${req.params.noteId} is not search note.`]
}
const json = note.getJsonContent();
if (!json || !json.searchString) {
return [];
}
const searchString = note.getLabelValue('searchString');
let searchResultNoteIds;
try {
if (json.searchString.startsWith('=')) {
const relationName = json.searchString.substr(1).trim();
if (searchString.startsWith('=')) {
const relationName = searchString.substr(1).trim();
searchResultNoteIds = await searchFromRelation(note, relationName);
} else {
const searchContext = new SearchContext({
includeNoteContent: true,
includeNoteContent: note.getLabelValue('includeNoteContent') === 'true',
excludeArchived: true,
fuzzyAttributeSearch: false
});
searchResultNoteIds = searchService.findNotesWithQuery(json.searchString, searchContext)
searchResultNoteIds = searchService.findNotesWithQuery(searchString, searchContext)
.map(sr => sr.noteId);
}
}