From 8d2c2202fa8e1c4b8aef5540b02ce5406f5f74e3 Mon Sep 17 00:00:00 2001 From: zadam Date: Fri, 14 Feb 2020 20:18:09 +0100 Subject: [PATCH] refactoring and fixes for saved note --- package-lock.json | 18 ++++---- package.json | 6 +-- src/public/javascripts/desktop.js | 18 ++++++-- .../javascripts/dialogs/jump_to_note.js | 1 - .../javascripts/services/search_notes.js | 42 ------------------- src/public/javascripts/widgets/note_tree.js | 13 +++++- src/public/javascripts/widgets/search_box.js | 13 +++--- .../widgets/type_widgets/search.js | 17 +------- 8 files changed, 45 insertions(+), 83 deletions(-) delete mode 100644 src/public/javascripts/services/search_notes.js diff --git a/package-lock.json b/package-lock.json index f30a28fdd..3c4467292 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2669,9 +2669,9 @@ "integrity": "sha512-7vmuyh5+kuUyJKePhQfRQBhXV5Ce+RnaeeQArKu1EAMpL3WbgMt5WG6uQZpEVvYSSsxMXRKOewtDk9RaTKXRlA==" }, "electron": { - "version": "8.0.0", - "resolved": "https://registry.npmjs.org/electron/-/electron-8.0.0.tgz", - "integrity": "sha512-vBXUKRqTUq0jv1upvISdvScDDH3uCPwXj4eA5BeR3UDbJp2hOhq7eJxwjIQbfLQql98aYz4X6pSlzBnhfyQqHA==", + "version": "9.0.0-beta.1", + "resolved": "https://registry.npmjs.org/electron/-/electron-9.0.0-beta.1.tgz", + "integrity": "sha512-OUqCC/aGYjFb2cA2ta1eBcjBW9yembcwtOQ9jKu75Lk3zTIVPavKLQxkC0LDy1FqTL9/Et8VtBI86EDvnFm3xw==", "dev": true, "requires": { "@electron/get": "^1.0.1", @@ -3790,9 +3790,9 @@ } }, "file-type": { - "version": "14.1.1", - "resolved": "https://registry.npmjs.org/file-type/-/file-type-14.1.1.tgz", - "integrity": "sha512-fGmNwmRgDi3uMDNbJfRRKaOUGN/uzeWRl2Ti9RJdvLpzFMKbl5cBGP3ngHYKiBSbHPB8wzMckP9x9SixJDFftg==", + "version": "14.1.2", + "resolved": "https://registry.npmjs.org/file-type/-/file-type-14.1.2.tgz", + "integrity": "sha512-9NI4+QzDlEPB6OETc/FcJt8i8vNT396VweRwEwLcE07MnorWkZDopNuc+MeoYA7ArbzoK044JbaDExWys8deTQ==", "requires": { "readable-web-to-node-stream": "^2.0.0", "strtok3": "^6.0.0", @@ -6858,9 +6858,9 @@ "integrity": "sha512-0L9FvHG3nfnnmaEQPjT9xhfN4ISk0A8/2j4M37Np4mcDesJjHgEUfgPhdCyZuFI954tjokaIj/A3NdpFNdEh4Q==" }, "node-abi": { - "version": "2.14.0", - "resolved": "https://registry.npmjs.org/node-abi/-/node-abi-2.14.0.tgz", - "integrity": "sha512-y54KGgEOHnRHlGQi7E5UiryRkH8bmksmQLj/9iLAjoje743YS+KaKB/sDYXgqtT0J16JT3c3AYJZNI98aU/kYg==", + "version": "2.15.0", + "resolved": "https://registry.npmjs.org/node-abi/-/node-abi-2.15.0.tgz", + "integrity": "sha512-FeLpTS0F39U7hHZU1srAK4Vx+5AHNVOTP+hxBNQknR/54laTHSFIJkDWDqiquY1LeLUgTfPN7sLPhMubx0PLAg==", "requires": { "semver": "^5.4.1" }, diff --git a/package.json b/package.json index 5a3ad5277..61c17c300 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,7 @@ "electron-window-state": "5.0.3", "express": "4.17.1", "express-session": "1.17.0", - "file-type": "14.1.1", + "file-type": "14.1.2", "fs-extra": "8.1.0", "helmet": "3.21.2", "html": "1.0.0", @@ -53,7 +53,7 @@ "jimp": "0.9.3", "mime-types": "2.1.26", "multer": "1.4.2", - "node-abi": "2.14.0", + "node-abi": "2.15.0", "open": "7.0.2", "portscanner": "2.2.0", "rand-token": "0.4.0", @@ -75,7 +75,7 @@ "ws": "7.2.1" }, "devDependencies": { - "electron": "8.0.0", + "electron": "9.0.0-beta.1", "electron-builder": "22.3.2", "electron-packager": "14.2.1", "electron-rebuild": "1.10.0", diff --git a/src/public/javascripts/desktop.js b/src/public/javascripts/desktop.js index 81cde1ae1..113e095e0 100644 --- a/src/public/javascripts/desktop.js +++ b/src/public/javascripts/desktop.js @@ -5,7 +5,6 @@ import ws from './services/ws.js'; import noteType from './widgets/note_type.js'; import protectedSessionService from './services/protected_session.js'; import protectedSessionHolder from './services/protected_session_holder.js'; -import searchNotesService from './services/search_notes.js'; import FrontendScriptApi from './services/frontend_script_api.js'; import ScriptContext from './services/script_context.js'; import sync from './services/sync.js'; @@ -135,9 +134,22 @@ window.glob.importMarkdownInline = async () => { dialog.importMarkdownInline(); }; -macInit.init(); +window.glob.SEARCH_HELP_TEXT = ` +Search tips - also see +

+

+

`; -searchNotesService.init(); // should be in front of treeService since that one manipulates address bar hash +macInit.init(); appContext.start(); diff --git a/src/public/javascripts/dialogs/jump_to_note.js b/src/public/javascripts/dialogs/jump_to_note.js index 14ad90e11..a420abd95 100644 --- a/src/public/javascripts/dialogs/jump_to_note.js +++ b/src/public/javascripts/dialogs/jump_to_note.js @@ -1,4 +1,3 @@ -import searchNotesService from '../services/search_notes.js'; import noteAutocompleteService from '../services/note_autocomplete.js'; import utils from "../services/utils.js"; import appContext from "../services/app_context.js"; diff --git a/src/public/javascripts/services/search_notes.js b/src/public/javascripts/services/search_notes.js deleted file mode 100644 index 2c001e623..000000000 --- a/src/public/javascripts/services/search_notes.js +++ /dev/null @@ -1,42 +0,0 @@ -import toastService from "./toast.js"; -import appContext from "./app_context.js"; - -const helpText = ` -Search tips - also see -

-

-

`; - -async function refreshSearch() { - // FIXME - const activeNode = appContext.getMainNoteTree().getActiveNode(); - - activeNode.load(true); - activeNode.setExpanded(true); - - toastService.showMessage("Saved search note refreshed."); -} - -function init() { - const hashValue = document.location.hash ? document.location.hash.substr(1) : ""; // strip initial # - - if (hashValue.startsWith("search=")) { - showSearch(); - doSearch(hashValue.substr(7)); - } -} - -export default { - refreshSearch, - init, - getHelpText: () => helpText -}; \ No newline at end of file diff --git a/src/public/javascripts/widgets/note_tree.js b/src/public/javascripts/widgets/note_tree.js index d76a8803b..0decc618d 100644 --- a/src/public/javascripts/widgets/note_tree.js +++ b/src/public/javascripts/widgets/note_tree.js @@ -1,5 +1,4 @@ import hoistedNoteService from "../services/hoisted_note.js"; -import searchNotesService from "../services/search_notes.js"; import treeService from "../services/tree.js"; import utils from "../services/utils.js"; import contextMenuWidget from "../services/context_menu.js"; @@ -12,6 +11,7 @@ import ws from "../services/ws.js"; import TabAwareWidget from "./tab_aware_widget.js"; import server from "../services/server.js"; import noteCreateService from "../services/note_create.js"; +import toastService from "../services/toast.js"; const TPL = `
@@ -41,7 +41,7 @@ export default class NoteTreeWidget extends TabAwareWidget { this.$widget = $(TPL); this.$widget.on("click", ".unhoist-button", hoistedNoteService.unhoist); - this.$widget.on("click", ".refresh-search-button", searchNotesService.refreshSearch); + this.$widget.on("click", ".refresh-search-button", () => this.refreshSearch()); // fancytree doesn't support middle click so this is a way to support it this.$widget.on('mousedown', '.fancytree-title', e => { @@ -438,6 +438,15 @@ export default class NoteTreeWidget extends TabAwareWidget { } } + async refreshSearch() { + const activeNode = this.getActiveNode(); + + activeNode.load(true); + activeNode.setExpanded(true); + + toastService.showMessage("Saved search note refreshed."); + } + async entitiesReloadedListener({loadResults}) { const noteIdsToUpdate = new Set(); const noteIdsToReload = new Set(); diff --git a/src/public/javascripts/widgets/search_box.js b/src/public/javascripts/widgets/search_box.js index 4c94e742a..622afde2a 100644 --- a/src/public/javascripts/widgets/search_box.js +++ b/src/public/javascripts/widgets/search_box.js @@ -1,6 +1,4 @@ import BasicWidget from "./basic_widget.js"; -import searchService from "../services/search_notes.js"; -import treeCache from "../services/tree_cache.js"; import toastService from "../services/toast.js"; import appContext from "../services/app_context.js"; import noteCreateService from "../services/note_create.js"; @@ -109,14 +107,13 @@ export default class SearchBoxWidget extends BasicWidget { } // FIXME - let activeNode = appContext.getMainNoteTree().getActiveNode(); - const parentNote = await treeCache.getNote(activeNode.data.noteId); + let activeNote = appContext.tabManager.getActiveTabNote(); - if (parentNote.type === 'search') { - activeNode = activeNode.getParent(); + if (activeNote.type === 'search') { + activeNote = (await activeNote.getParentNotes())[0]; } - await noteCreateService.createNote(activeNode.data.noteId, { + await noteCreateService.createNote(activeNote.noteId, { type: "search", mime: "application/json", title: searchString, @@ -134,7 +131,7 @@ export default class SearchBoxWidget extends BasicWidget { this.$searchBox.tooltip({ trigger: 'focus', html: true, - title: searchService.getHelpText(), + title: window.glob.SEARCH_HELP_TEXT, placement: 'right', delay: { show: 500, // necessary because sliding out may cause wrong position diff --git a/src/public/javascripts/widgets/type_widgets/search.js b/src/public/javascripts/widgets/type_widgets/search.js index 97fadb559..93e08bfd1 100644 --- a/src/public/javascripts/widgets/type_widgets/search.js +++ b/src/public/javascripts/widgets/type_widgets/search.js @@ -1,4 +1,3 @@ -import searchNotesService from "../../services/search_notes.js"; import TypeWidget from "./type_widget.js"; const TPL = ` @@ -6,11 +5,6 @@ const TPL = `
Search string:     - - -     - -

@@ -26,19 +20,12 @@ export default class SearchTypeWidget extends TypeWidget { this.$searchString = this.$widget.find(".search-string"); this.$component = this.$widget.find('.note-detail-search'); this.$help = this.$widget.find(".note-detail-search-help"); - this.$refreshButton = this.$widget.find('.note-detail-search-refresh-results-button'); - this.$refreshButton.on('click', async () => { - await this.spacedUpdate.updateNowIfNecessary(); - - await searchNotesService.refreshSearch(); - }); - return this.$widget; } async doRefresh(note) { - this.$help.html(searchNotesService.getHelpText()); + this.$help.html(window.glob.SEARCH_HELP_TEXT); this.$component.show(); @@ -53,7 +40,7 @@ export default class SearchTypeWidget extends TypeWidget { this.$searchString.val(''); } - this.$searchString.on('input', () => this.noteChanged()); + this.$searchString.on('input', () => this.spacedUpdate.scheduleUpdate()); } getContent() {