From c94fb7a62de9307c42d6cd4bb0ae85212aa27441 Mon Sep 17 00:00:00 2001 From: zadam Date: Fri, 19 Feb 2021 22:15:56 +0100 Subject: [PATCH] created a specific widget for search result to add "no results" message --- .../layouts/desktop_extra_window_layout.js | 2 + .../app/layouts/desktop_main_window_layout.js | 2 + src/public/app/services/tree_cache.js | 2 + src/public/app/widgets/note_list.js | 17 +---- src/public/app/widgets/search_result.js | 72 +++++++++++++++++++ 5 files changed, 80 insertions(+), 15 deletions(-) create mode 100644 src/public/app/widgets/search_result.js diff --git a/src/public/app/layouts/desktop_extra_window_layout.js b/src/public/app/layouts/desktop_extra_window_layout.js index aef4df0da..b89b976e4 100644 --- a/src/public/app/layouts/desktop_extra_window_layout.js +++ b/src/public/app/layouts/desktop_extra_window_layout.js @@ -22,6 +22,7 @@ import ImagePropertiesWidget from "../widgets/type_property_widgets/image_proper import NotePropertiesWidget from "../widgets/type_property_widgets/note_properties.js"; import NoteIconWidget from "../widgets/note_icon.js"; import NotePathsWidget from "../widgets/note_paths.js"; +import SearchResultWidget from "../widgets/search_result.js"; export default class DesktopExtraWindowLayout { constructor(customWidgets) { @@ -69,6 +70,7 @@ export default class DesktopExtraWindowLayout { .child(new TabCachingWidget(() => new SqlTableSchemasWidget())) .child(new TabCachingWidget(() => new NoteDetailWidget())) .child(new TabCachingWidget(() => new NoteListWidget())) + .child(new TabCachingWidget(() => new SearchResultWidget())) .child(new TabCachingWidget(() => new SqlResultWidget())) ) .child(...this.customWidgets.get('center-pane')) diff --git a/src/public/app/layouts/desktop_main_window_layout.js b/src/public/app/layouts/desktop_main_window_layout.js index 663a7bfe9..37286d9c2 100644 --- a/src/public/app/layouts/desktop_main_window_layout.js +++ b/src/public/app/layouts/desktop_main_window_layout.js @@ -32,6 +32,7 @@ import FilePropertiesWidget from "../widgets/type_property_widgets/file_properti import ImagePropertiesWidget from "../widgets/type_property_widgets/image_properties.js"; import NotePropertiesWidget from "../widgets/type_property_widgets/note_properties.js"; import NoteIconWidget from "../widgets/note_icon.js"; +import SearchResultWidget from "../widgets/search_result.js"; const RIGHT_PANE_CSS = ` + +
+ No notes have been found for given search parameters. +
+ +
+ Search has not been executed yet. Click on "Search" button above to see the results. +
+ +
+
+`; + +export default class SearchResultWidget extends TabAwareWidget { + isEnabled() { + return super.isEnabled() + && this.note.type === 'search'; + } + + doRender() { + this.$widget = $(TPL); + this.$content = this.$widget.find('.search-result-widget-content'); + this.$noResults = this.$widget.find('.search-no-results'); + this.$notExecutedYet = this.$widget.find('.search-not-executed-yet'); + this.contentSized(); + } + + async refreshWithNote(note) { + this.$content.empty(); + this.$noResults.toggle(note.getChildNoteIds().length === 0 && !!note.searchResultsLoaded); + this.$notExecutedYet.toggle(!note.searchResultsLoaded); + + const noteListRenderer = new NoteListRenderer(this.$content, note, note.getChildNoteIds()); + await noteListRenderer.renderList(); + } + + searchRefreshedEvent({tabId}) { + if (!this.isTab(tabId)) { + return; + } + + this.refresh(); + } + + notesReloadedEvent({noteIds}) { + if (noteIds.includes(this.noteId)) { + this.refresh(); + } + } +}