From a1f67e830d8f1d6d29790e5c3ea2c71c548c654d Mon Sep 17 00:00:00 2001 From: zadam Date: Tue, 26 Jan 2021 22:22:17 +0100 Subject: [PATCH] search script UI --- src/public/app/services/date_notes.js | 4 +- src/public/app/services/tree_cache.js | 2 +- .../search_actions/abstract_search_action.js | 3 + .../widgets/search_actions/execute_script.js | 4 ++ src/public/app/widgets/search_definition.js | 21 +++++- .../search_options/abstract_search_option.js | 3 + .../app/widgets/search_options/ancestor.js | 10 ++- .../widgets/search_options/search_script.js | 70 +++++++++++++++++++ .../widgets/search_options/search_string.js | 4 +- src/public/stylesheets/style.css | 2 +- src/routes/api/search.js | 52 ++++++-------- src/routes/routes.js | 9 ++- src/services/log.js | 4 +- 13 files changed, 139 insertions(+), 49 deletions(-) create mode 100644 src/public/app/widgets/search_options/search_script.js diff --git a/src/public/app/services/date_notes.js b/src/public/app/services/date_notes.js index d46d81dd4..30a734a44 100644 --- a/src/public/app/services/date_notes.js +++ b/src/public/app/services/date_notes.js @@ -47,8 +47,8 @@ async function createSearchNote(opts = {}) { const note = await server.post('search-note'); const attrsToUpdate = [ - opts.ancestor ? { type: 'relation', name: 'ancestor', value: opts.ancestorNoteId } : undefined, - { type: 'label', name: 'searchString', value: opts.searchString } + opts.ancestorNoteId ? { type: 'relation', name: 'ancestor', value: opts.ancestorNoteId } : undefined, + { type: 'label', name: 'searchString', value: opts.searchStringe } ].filter(attr => !!attr); if (attrsToUpdate.length > 0) { diff --git a/src/public/app/services/tree_cache.js b/src/public/app/services/tree_cache.js index 6e2e67dd3..d9661437e 100644 --- a/src/public/app/services/tree_cache.js +++ b/src/public/app/services/tree_cache.js @@ -167,7 +167,7 @@ class TreeCache { for (const note of resp.notes) { if (note.type === 'search') { const searchResultNoteIds = await server.get('search-note/' + note.noteId); - +console.log("searchResultNoteIds", searchResultNoteIds); if (!Array.isArray(searchResultNoteIds)) { throw new Error(`Search note ${note.noteId} failed: ${searchResultNoteIds}`); } diff --git a/src/public/app/widgets/search_actions/abstract_search_action.js b/src/public/app/widgets/search_actions/abstract_search_action.js index 3a9f771ee..28d3133a8 100644 --- a/src/public/app/widgets/search_actions/abstract_search_action.js +++ b/src/public/app/widgets/search_actions/abstract_search_action.js @@ -1,6 +1,7 @@ import server from "../../services/server.js"; import ws from "../../services/ws.js"; import Component from "../component.js"; +import utils from "../../services/utils.js"; export default class AbstractSearchAction extends Component { constructor(attribute, actionDef) { @@ -18,6 +19,8 @@ export default class AbstractSearchAction extends Component { .on('click', () => this.deleteAction()) .attr('title', 'Remove this search action'); + utils.initHelpDropdown($rendered); + return $rendered; } catch (e) { diff --git a/src/public/app/widgets/search_actions/execute_script.js b/src/public/app/widgets/search_actions/execute_script.js index 1bd24ec42..16ea0a9b9 100644 --- a/src/public/app/widgets/search_actions/execute_script.js +++ b/src/public/app/widgets/search_actions/execute_script.js @@ -21,6 +21,10 @@ const TPL = ` For example to append a string to a note's title, use this small script:
note.title = note.title + ' - suffix';
+ + More complex example would be deleting all matched note's attributes: + +
for (const attr of note.getOwnedAttributes) { attr.isDeleted = true; attr.save(); }
diff --git a/src/public/app/widgets/search_definition.js b/src/public/app/widgets/search_definition.js index 431640128..8e49a8bdc 100644 --- a/src/public/app/widgets/search_definition.js +++ b/src/public/app/widgets/search_definition.js @@ -1,4 +1,3 @@ -import noteAutocompleteService from "../services/note_autocomplete.js"; import server from "../services/server.js"; import TabAwareWidget from "./tab_aware_widget.js"; import treeCache from "../services/tree_cache.js"; @@ -18,12 +17,13 @@ import FastSearch from "./search_options/fast_search.js"; import Ancestor from "./search_options/ancestor.js"; import IncludeArchivedNotes from "./search_options/include_archived_notes.js"; import OrderBy from "./search_options/order_by.js"; +import SearchScript from "./search_options/search_script.js"; const TPL = `
@@ -75,6 +79,11 @@ const TPL = ` search string + +