From 898c941333255fd4fae8f1973782040e559f4e1f Mon Sep 17 00:00:00 2001 From: zadam Date: Tue, 26 Jan 2021 10:42:55 +0100 Subject: [PATCH] search definition refactoring --- src/public/app/widgets/search_definition.js | 26 +++---------------- .../search_options/abstract_search_option.js | 18 ++++++++++++- .../app/widgets/search_options/ancestor.js | 26 +++++-------------- .../app/widgets/search_options/fast_search.js | 2 +- .../search_options/include_archived_notes.js | 2 +- .../app/widgets/search_options/order_by.js | 8 +++++- .../widgets/search_options/search_string.js | 2 ++ 7 files changed, 38 insertions(+), 46 deletions(-) diff --git a/src/public/app/widgets/search_definition.js b/src/public/app/widgets/search_definition.js index f470259a7..36e821a8f 100644 --- a/src/public/app/widgets/search_definition.js +++ b/src/public/app/widgets/search_definition.js @@ -200,28 +200,6 @@ export default class SearchDefinitionWidget extends TabAwareWidget { this.refresh(); }); - this.$widget.on('click', '[data-search-option-del]', async event => { - async function deleteAttr(note, attrName) { - for (const attr of note.getOwnedAttributes()) { - if (attr.name === attrName) { - await server.remove(`notes/${note.noteId}/attributes/${attr.attributeId}`); - } - } - } - - const searchOption = $(event.target).attr('data-search-option-del'); - - await deleteAttr(this.note, searchOption); - - if (searchOption === 'orderBy') { - await deleteAttr(this.note, 'orderDirection'); - } - - await ws.waitForMaxKnownEntityChangeId(); - - this.refresh(); - }); - this.$widget.on('click', '[data-action-conf-del]', async event => { const attributeId = $(event.target).closest('[data-attribute-id]').attr('data-attribute-id'); @@ -248,6 +226,10 @@ export default class SearchDefinitionWidget extends TabAwareWidget { this.triggerEvent('searchRefreshed', {tabId: this.tabContext.tabId}); } + async refreshSearchDefinitionCommand() { + await this.refresh(); + } + async refreshWithNote(note) { this.$component.show(); diff --git a/src/public/app/widgets/search_options/abstract_search_option.js b/src/public/app/widgets/search_options/abstract_search_option.js index 35825a1b3..0d6069d84 100644 --- a/src/public/app/widgets/search_options/abstract_search_option.js +++ b/src/public/app/widgets/search_options/abstract_search_option.js @@ -24,7 +24,7 @@ export default class AbstractSearchOption extends Component { try { const $rendered = this.doRender(); - $rendered.attr('data-attribute-id', this.attribute.attributeId); + $rendered.find('.search-option-del').on('click', () => this.deleteOption()) return $rendered; } @@ -36,4 +36,20 @@ export default class AbstractSearchOption extends Component { // to be overriden doRender() {} + + async deleteOption() { + await this.deleteAttribute(this.constructor.attributeType, this.constructor.optionName); + + await ws.waitForMaxKnownEntityChangeId(); + + await this.triggerCommand('refreshSearchDefinition'); + } + + async deleteAttribute(type, name) { + for (const attr of this.note.getOwnedAttributes()) { + if (attr.type === type && attr.name === name) { + await server.remove(`notes/${this.note.noteId}/attributes/${attr.attributeId}`); + } + } + } } diff --git a/src/public/app/widgets/search_options/ancestor.js b/src/public/app/widgets/search_options/ancestor.js index b10350d1c..ff8071fde 100644 --- a/src/public/app/widgets/search_options/ancestor.js +++ b/src/public/app/widgets/search_options/ancestor.js @@ -3,29 +3,15 @@ import noteAutocompleteService from "../../services/note_autocomplete.js"; const TPL = ` - Search string: + + Ancestor: - +
+ +
- + + `;