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: |
-
+
+
+
|
-
-
-
+
|
`;
diff --git a/src/public/app/widgets/search_options/fast_search.js b/src/public/app/widgets/search_options/fast_search.js
index 17873c18e..f57160117 100644
--- a/src/public/app/widgets/search_options/fast_search.js
+++ b/src/public/app/widgets/search_options/fast_search.js
@@ -8,7 +8,7 @@ const TPL = `
Fast search
-
+
|
`;
diff --git a/src/public/app/widgets/search_options/include_archived_notes.js b/src/public/app/widgets/search_options/include_archived_notes.js
index a4704f674..746aae56b 100644
--- a/src/public/app/widgets/search_options/include_archived_notes.js
+++ b/src/public/app/widgets/search_options/include_archived_notes.js
@@ -8,7 +8,7 @@ const TPL = `
Include archived notes
-
+
|
`;
diff --git a/src/public/app/widgets/search_options/order_by.js b/src/public/app/widgets/search_options/order_by.js
index 525227ab7..06b1fe9c0 100644
--- a/src/public/app/widgets/search_options/order_by.js
+++ b/src/public/app/widgets/search_options/order_by.js
@@ -24,7 +24,7 @@ const TPL = `
-
+
|
`;
@@ -58,4 +58,10 @@ export default class OrderBy extends AbstractSearchOption {
return $option;
}
+
+ async deleteOption() {
+ await this.deleteAttribute('label', 'orderDirection');
+
+ await super.deleteOption();
+ }
}
diff --git a/src/public/app/widgets/search_options/search_string.js b/src/public/app/widgets/search_options/search_string.js
index b43075a36..df4f5d119 100644
--- a/src/public/app/widgets/search_options/search_string.js
+++ b/src/public/app/widgets/search_options/search_string.js
@@ -28,6 +28,8 @@ const TPL = `
+
+
`;