From eaed7ec86ff4cfc5a64b8c7aa961dab3f8636c91 Mon Sep 17 00:00:00 2001 From: zadam Date: Thu, 26 Nov 2020 23:00:27 +0100 Subject: [PATCH] improvements in search UI --- package-lock.json | 40 ++-- package.json | 2 +- .../layouts/desktop_extra_window_layout.js | 2 +- .../app/layouts/desktop_main_window_layout.js | 6 +- src/public/app/services/tree_cache.js | 9 + .../attribute_detail.js | 20 +- .../attribute_editor.js | 20 +- .../owned_attribute_list.js | 2 +- .../promoted_attributes.js | 10 +- .../app/widgets/inherited_attribute_list.js | 2 +- src/public/app/widgets/note_detail.js | 4 +- src/public/app/widgets/note_list.js | 39 +++- src/public/app/widgets/search_definition.js | 126 ++++++++++++ .../app/widgets/type_widgets/deleted.js | 1 + .../app/widgets/type_widgets/editable_code.js | 1 + .../app/widgets/type_widgets/editable_text.js | 3 +- src/public/app/widgets/type_widgets/empty.js | 1 + src/public/app/widgets/type_widgets/file.js | 1 + src/public/app/widgets/type_widgets/image.js | 1 + src/public/app/widgets/type_widgets/none.js | 11 ++ .../widgets/type_widgets/protected_session.js | 1 + .../widgets/type_widgets/read_only_code.js | 1 + .../widgets/type_widgets/read_only_text.js | 1 + .../app/widgets/type_widgets/relation_map.js | 1 + src/public/app/widgets/type_widgets/render.js | 1 + src/public/app/widgets/type_widgets/search.js | 183 ------------------ src/routes/api/search.js | 14 +- 27 files changed, 251 insertions(+), 252 deletions(-) rename src/public/app/widgets/{ => attribute_widgets}/attribute_detail.js (97%) rename src/public/app/widgets/{ => attribute_widgets}/attribute_editor.js (96%) rename src/public/app/widgets/{ => attribute_widgets}/owned_attribute_list.js (97%) rename src/public/app/widgets/{ => attribute_widgets}/promoted_attributes.js (97%) create mode 100644 src/public/app/widgets/search_definition.js create mode 100644 src/public/app/widgets/type_widgets/none.js delete mode 100644 src/public/app/widgets/type_widgets/search.js diff --git a/package-lock.json b/package-lock.json index b64a575eb..857c1c619 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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 } } } diff --git a/package.json b/package.json index 42815b78c..de37763eb 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/src/public/app/layouts/desktop_extra_window_layout.js b/src/public/app/layouts/desktop_extra_window_layout.js index b14cd7d1e..c3394512c 100644 --- a/src/public/app/layouts/desktop_extra_window_layout.js +++ b/src/public/app/layouts/desktop_extra_window_layout.js @@ -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) { diff --git a/src/public/app/layouts/desktop_main_window_layout.js b/src/public/app/layouts/desktop_main_window_layout.js index 82c2541b6..7dced63fc 100644 --- a/src/public/app/layouts/desktop_main_window_layout.js +++ b/src/public/app/layouts/desktop_main_window_layout.js @@ -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 = ` - + + +
+
`; 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(); + } + } } diff --git a/src/public/app/widgets/search_definition.js b/src/public/app/widgets/search_definition.js new file mode 100644 index 000000000..1b9dce804 --- /dev/null +++ b/src/public/app/widgets/search_definition.js @@ -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 = ` +
+ + +
+ + + + + + + + + + +
Search string: + +
Limit search to subtree: +
+ +
+
+ +
+
+
`; + +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() + }); + } +} diff --git a/src/public/app/widgets/type_widgets/deleted.js b/src/public/app/widgets/type_widgets/deleted.js index 56e7d0f21..e488a835a 100644 --- a/src/public/app/widgets/type_widgets/deleted.js +++ b/src/public/app/widgets/type_widgets/deleted.js @@ -14,5 +14,6 @@ export default class DeletedTypeWidget extends TypeWidget { doRender() { this.$widget = $(TPL); + this.contentSized(); } } diff --git a/src/public/app/widgets/type_widgets/editable_code.js b/src/public/app/widgets/type_widgets/editable_code.js index 1fad7661f..37d19333b 100644 --- a/src/public/app/widgets/type_widgets/editable_code.js +++ b/src/public/app/widgets/type_widgets/editable_code.js @@ -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'); diff --git a/src/public/app/widgets/type_widgets/editable_text.js b/src/public/app/widgets/type_widgets/editable_text.js index 12999e336..f35cb3f90 100644 --- a/src/public/app/widgets/type_widgets/editable_text.js +++ b/src/public/app/widgets/type_widgets/editable_text.js @@ -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; } @@ -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(); diff --git a/src/public/app/widgets/type_widgets/empty.js b/src/public/app/widgets/type_widgets/empty.js index 51d838a72..0508d99fe 100644 --- a/src/public/app/widgets/type_widgets/empty.js +++ b/src/public/app/widgets/type_widgets/empty.js @@ -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 }) diff --git a/src/public/app/widgets/type_widgets/file.js b/src/public/app/widgets/type_widgets/file.js index fbf17e1f3..053545868 100644 --- a/src/public/app/widgets/type_widgets/file.js +++ b/src/public/app/widgets/type_widgets/file.js @@ -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"); diff --git a/src/public/app/widgets/type_widgets/image.js b/src/public/app/widgets/type_widgets/image.js index c369536eb..5c4634432 100644 --- a/src/public/app/widgets/type_widgets/image.js +++ b/src/public/app/widgets/type_widgets/image.js @@ -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"); diff --git a/src/public/app/widgets/type_widgets/none.js b/src/public/app/widgets/type_widgets/none.js new file mode 100644 index 000000000..3b795cc4f --- /dev/null +++ b/src/public/app/widgets/type_widgets/none.js @@ -0,0 +1,11 @@ +import TypeWidget from "./type_widget.js"; + +const TPL = `
`; + +export default class NoneTypeWidget extends TypeWidget { + static getType() { return "none"; } + + doRender() { + this.$widget = $(TPL); + } +} diff --git a/src/public/app/widgets/type_widgets/protected_session.js b/src/public/app/widgets/type_widgets/protected_session.js index 70617406d..53315d317 100644 --- a/src/public/app/widgets/type_widgets/protected_session.js +++ b/src/public/app/widgets/type_widgets/protected_session.js @@ -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"); diff --git a/src/public/app/widgets/type_widgets/read_only_code.js b/src/public/app/widgets/type_widgets/read_only_code.js index 746205d97..afe6d4580 100644 --- a/src/public/app/widgets/type_widgets/read_only_code.js +++ b/src/public/app/widgets/type_widgets/read_only_code.js @@ -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', () => { diff --git a/src/public/app/widgets/type_widgets/read_only_text.js b/src/public/app/widgets/type_widgets/read_only_text.js index e3a5c925d..365ae78fd 100644 --- a/src/public/app/widgets/type_widgets/read_only_text.js +++ b/src/public/app/widgets/type_widgets/read_only_text.js @@ -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'); diff --git a/src/public/app/widgets/type_widgets/relation_map.js b/src/public/app/widgets/type_widgets/relation_map.js index fad261b10..b4ab69372 100644 --- a/src/public/app/widgets/type_widgets/relation_map.js +++ b/src/public/app/widgets/type_widgets/relation_map.js @@ -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"); diff --git a/src/public/app/widgets/type_widgets/render.js b/src/public/app/widgets/type_widgets/render.js index 58bb6532c..78484b5b5 100644 --- a/src/public/app/widgets/type_widgets/render.js +++ b/src/public/app/widgets/type_widgets/render.js @@ -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'); } diff --git a/src/public/app/widgets/type_widgets/search.js b/src/public/app/widgets/type_widgets/search.js deleted file mode 100644 index babe20363..000000000 --- a/src/public/app/widgets/type_widgets/search.js +++ /dev/null @@ -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 = ` -`; - -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() - }); - } -} diff --git a/src/routes/api/search.js b/src/routes/api/search.js index 201c7bbbf..4032ffc44 100644 --- a/src/routes/api/search.js +++ b/src/routes/api/search.js @@ -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); } }