search definition refactoring

This commit is contained in:
zadam 2021-01-26 10:42:55 +01:00
parent 8b0a1e546d
commit 898c941333
7 changed files with 38 additions and 46 deletions

View File

@ -200,28 +200,6 @@ export default class SearchDefinitionWidget extends TabAwareWidget {
this.refresh(); 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 => { this.$widget.on('click', '[data-action-conf-del]', async event => {
const attributeId = $(event.target).closest('[data-attribute-id]').attr('data-attribute-id'); 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}); this.triggerEvent('searchRefreshed', {tabId: this.tabContext.tabId});
} }
async refreshSearchDefinitionCommand() {
await this.refresh();
}
async refreshWithNote(note) { async refreshWithNote(note) {
this.$component.show(); this.$component.show();

View File

@ -24,7 +24,7 @@ export default class AbstractSearchOption extends Component {
try { try {
const $rendered = this.doRender(); const $rendered = this.doRender();
$rendered.attr('data-attribute-id', this.attribute.attributeId); $rendered.find('.search-option-del').on('click', () => this.deleteOption())
return $rendered; return $rendered;
} }
@ -36,4 +36,20 @@ export default class AbstractSearchOption extends Component {
// to be overriden // to be overriden
doRender() {} 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}`);
}
}
}
} }

View File

@ -3,29 +3,15 @@ import noteAutocompleteService from "../../services/note_autocomplete.js";
const TPL = ` const TPL = `
<tr> <tr>
<td>Search string:</td> <td title="Matched notes must be within subtree of given note.">
Ancestor: </td>
<td> <td>
<input type="text" class="form-control search-string"> <div class="input-group">
<input class="ancestor form-control" placeholder="search for note by its name">
</div>
</td> </td>
<td> <td>
<div class="dropdown"> <span class="bx bx-x icon-action search-option-del"></span>
<button class="btn btn-secondary dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
?
</button>
<div class="dropdown-menu dropdown-menu-right p-4" style="width: 500px;">
<strong>Search tips</strong> - also see <button class="btn btn-sm" type="button" data-help-page="Search">complete help on search</button>
<p>
<ul>
<li>Just enter any text for full text search</li>
<li><code>#abc</code> - returns notes with label abc</li>
<li><code>#year = 2019</code> - matches notes with label <code>year</code> having value <code>2019</code></li>
<li><code>#rock #pop</code> - matches notes which have both <code>rock</code> and <code>pop</code> labels</li>
<li><code>#rock or #pop</code> - only one of the labels must be present</li>
<li><code>#year &lt;= 2000</code> - numerical comparison (also &gt;, &gt;=, &lt;).</li>
<li><code>note.dateCreated >= MONTH-1</code> - notes created in the last month</li>
</ul>
</p>
</div>
</td> </td>
</tr>`; </tr>`;

View File

@ -8,7 +8,7 @@ const TPL = `
Fast search Fast search
</td> </td>
<td> <td>
<span class="bx bx-x icon-action" data-search-option-del="fastSearch"></span> <span class="bx bx-x icon-action search-option-del"></span>
</td> </td>
</tr>`; </tr>`;

View File

@ -8,7 +8,7 @@ const TPL = `
Include archived notes Include archived notes
</td> </td>
<td> <td>
<span class="bx bx-x icon-action" data-search-option-del="includeArchivedNotes"></span> <span class="bx bx-x icon-action search-option-del"></span>
</td> </td>
</tr>`; </tr>`;

View File

@ -24,7 +24,7 @@ const TPL = `
</select> </select>
</td> </td>
<td> <td>
<span class="bx bx-x icon-action" data-search-option-del="orderBy"></span> <span class="bx bx-x icon-action search-option-del"></span>
</td> </td>
</tr>`; </tr>`;
@ -58,4 +58,10 @@ export default class OrderBy extends AbstractSearchOption {
return $option; return $option;
} }
async deleteOption() {
await this.deleteAttribute('label', 'orderDirection');
await super.deleteOption();
}
} }

View File

@ -28,6 +28,8 @@ const TPL = `
</ul> </ul>
</p> </p>
</div> </div>
<span class="bx bx-x icon-action search-option-del"></span>
</td> </td>
</tr>`; </tr>`;