diff --git a/src/public/app/services/date_notes.js b/src/public/app/services/date_notes.js index 5a1a88ca0..f786487d6 100644 --- a/src/public/app/services/date_notes.js +++ b/src/public/app/services/date_notes.js @@ -34,10 +34,18 @@ async function createSqlConsole() { return await treeCache.getNote(note.noteId); } +/** @return {NoteShort} */ +async function createSearchNote() { + const note = await server.post('search-note'); + + return await treeCache.getNote(note.noteId); +} + export default { getTodayNote, getDateNote, getMonthNote, getYearNote, - createSqlConsole -} \ No newline at end of file + createSqlConsole, + createSearchNote +} diff --git a/src/public/app/services/dialog_command_executor.js b/src/public/app/services/dialog_command_executor.js index af57e56af..8f1145a8d 100644 --- a/src/public/app/services/dialog_command_executor.js +++ b/src/public/app/services/dialog_command_executor.js @@ -67,6 +67,15 @@ export default class DialogCommandExecutor extends Component { appContext.triggerCommand('focusOnDetail', {tabId: tabContext.tabId}); } + async searchNotesCommand() { + const searchNote = await dateNoteService.createSearchNote(); + + const tabContext = await appContext.tabManager.openTabWithNote(searchNote.noteId, true); + + appContext.triggerCommand('focusOnDetail', {tabId: tabContext.tabId}); + + } + showBackendLogCommand() { import("../dialogs/backend_log.js").then(d => d.showDialog()); } diff --git a/src/public/app/services/note_list_renderer.js b/src/public/app/services/note_list_renderer.js index 4136a7757..abcd11b55 100644 --- a/src/public/app/services/note_list_renderer.js +++ b/src/public/app/services/note_list_renderer.js @@ -135,12 +135,20 @@ const TPL = ` `; class NoteListRenderer { - constructor(parentNote, notes) { + /* + * We're using noteIds so that it's not necessary to load all notes at once when paging + */ + constructor(parentNote, noteIds) { this.$noteList = $(TPL); this.parentNote = parentNote; - this.notes = notes; + this.noteIds = noteIds; this.page = 1; - this.pageSize = 6; + this.pageSize = parseInt(parentNote.getLabelValue('pageSize')); + + if (!this.pageSize || this.pageSize < 1 || this.pageSize > 10000) { + this.pageSize = 10; + } + this.viewType = parentNote.getLabelValue('viewType'); if (!['list', 'grid'].includes(this.viewType)) { @@ -205,7 +213,8 @@ class NoteListRenderer { const startIdx = (this.page - 1) * this.pageSize; const endIdx = startIdx + this.pageSize; - const pageNotes = this.notes.slice(startIdx, Math.min(endIdx, this.notes.length)); + const pageNoteIds = this.noteIds.slice(startIdx, Math.min(endIdx, this.noteIds.length)); + const pageNotes = await treeCache.getNotes(pageNoteIds); for (const note of pageNotes) { // image is already visible in the parent note so no need to display it separately in the book @@ -213,7 +222,7 @@ class NoteListRenderer { continue; } - const $card = await this.renderNote(note); + const $card = await this.renderNote(note, this.parentNote.hasLabel('expanded')); $container.append($card); } @@ -225,7 +234,7 @@ class NoteListRenderer { renderPager() { const $pager = this.$noteList.find('.note-list-pager').empty(); - const pageCount = Math.ceil(this.notes.length / this.pageSize); + const pageCount = Math.ceil(this.noteIds.length / this.pageSize); $pager.toggle(pageCount > 1); @@ -255,7 +264,8 @@ class NoteListRenderer { } // TODO: we should also render (promoted) attributes - async renderNote(note) { + // FIXME: showing specific path might be necessary because of a match in the patch + async renderNote(note, expand = false) { const notePath = /*this.notePath + '/' + */ note.noteId; const $expander = $(''); @@ -270,7 +280,7 @@ class NoteListRenderer { $expander.on('click', () => this.toggleContent($card, note, !$card.hasClass("expanded"))); - await this.toggleContent($card, note, this.parentNote.hasLabel('expanded')); + await this.toggleContent($card, note, expand); return $card; } diff --git a/src/public/app/widgets/search_box.js b/src/public/app/widgets/search_box.js index d1645f8ff..784b58650 100644 --- a/src/public/app/widgets/search_box.js +++ b/src/public/app/widgets/search_box.js @@ -164,9 +164,9 @@ export default class SearchBoxWidget extends BasicWidget { } } - searchNotesEvent() { - this.toggleSearchEvent(); - } + // searchNotesEvent() { + // this.toggleSearchEvent(); + // } resetSearchEvent() { this.$searchInput.val(""); diff --git a/src/public/app/widgets/type_widgets/search.js b/src/public/app/widgets/type_widgets/search.js index 5ce4d1d94..babe20363 100644 --- a/src/public/app/widgets/type_widgets/search.js +++ b/src/public/app/widgets/type_widgets/search.js @@ -1,11 +1,18 @@ 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 = `