Move global search to cards model

* add some explanation of the operators
This commit is contained in:
John R. Supplee 2021-01-12 00:48:43 +02:00
parent bbcb236a46
commit 34000ad159
4 changed files with 149 additions and 105 deletions

View file

@ -12,33 +12,42 @@ template(name="globalSearch")
.wrapper
form.js-search-query-form
input(type="text" name="searchQuery" placeholder="{{_ 'search-example'}}" autofocus dir="auto")
if searching.get
+spinner
else if hasResults.get
.global-search-dueat-list-wrapper
h1 Results
each card in results
.global-search-card-wrapper
a.minicard-wrapper.card-title(href=card.absoluteUrl)
+minicard(card)
ul.global-search-context-list
li.global-search-context(title="{{_ 'board'}}")
+viewer
= card.getBoard.title
li.global-search-context.global-search-context-separator
= ' '
| {{_ 'context-separator'}}
= ' '
li.global-search-context(title="{{_ 'swimlane'}}")
+viewer
= card.getSwimlane.title
li.global-search-context
= ' '
| {{_ 'context-separator'}}
= ' '
li.global-search-context(title="{{_ 'list'}}")
+viewer
= card.getList.title
if searching.get
+spinner
else if hasResults.get
.global-search-dueat-list-wrapper
h1 Results
each card in results
.global-search-card-wrapper
a.minicard-wrapper.card-title(href=card.absoluteUrl)
+minicard(card)
//= card.title
ul.global-search-context-list
li.global-search-context(title="{{_ 'board'}}")
+viewer
= card.getBoard.title
li.global-search-context.global-search-context-separator
= ' '
| {{_ 'context-separator'}}
= ' '
li.global-search-context(title="{{_ 'swimlane'}}")
+viewer
= card.getSwimlane.title
li.global-search-context
= ' '
| {{_ 'context-separator'}}
= ' '
li.global-search-context(title="{{_ 'list'}}")
+viewer
= card.getList.title
else
h2 Search Operators
+viewer
= '* `@`username\n'
= '* `#`label\n'
= '* `board:`<name> or `board:`"<name>"\n'
= '* `swimlane:`<name> or `swimlane:`"<name>"\n'
= '* `list:`<name> or `list:`"<name>"\n'
template(name="globalSearchViewChangePopup")
ul.pop-over-list

View file

@ -40,6 +40,7 @@ BlazeComponent.extendComponent({
this.searching = new ReactiveVar(false);
this.hasResults = new ReactiveVar(false);
this.query = new ReactiveVar('');
this.queryParams = null;
// this.autorun(() => {
// const handle = subManager.subscribe('globalSearch');
@ -53,7 +54,10 @@ BlazeComponent.extendComponent({
},
results() {
return Cards.find();
if (this.queryParams) {
return Cards.globalSearch(this.queryParams);
}
return [];
},
events() {
@ -63,6 +67,12 @@ BlazeComponent.extendComponent({
evt.preventDefault();
this.query.set(evt.target.searchQuery.value);
if (!this.query.get()) {
this.searching.set(false);
this.hasResults.set(false);
return;
}
this.searching.set(true);
this.hasResults.set(false);
@ -70,8 +80,8 @@ BlazeComponent.extendComponent({
// eslint-disable-next-line no-console
console.log('query:', query);
const reUser = /^@(?<user>\w+)(\s+|$)/;
const reLabel = /^#(?<label>\w+)(\s+|$)/;
const reUser = /^@(?<user>[\w.:]+)(\s+|$)/;
const reLabel = /^#(?<label>[\w:-]+)(\s+|$)/;
const reOperator1 = /^(?<operator>\w+):(?<value>\w+)(\s+|$)/;
const reOperator2 = /^(?<operator>\w+):(?<quote>["']*)(?<value>.*?)\k<quote>(\s+|$)/;
const reText = /^(?<text>[^:@#\s]+)(\s+|$)/;
@ -148,7 +158,7 @@ BlazeComponent.extendComponent({
}
// eslint-disable-next-line no-console
console.log('selector:', selector);
// console.log('selector:', selector);
// eslint-disable-next-line no-console
console.log('text:', text);
@ -193,13 +203,21 @@ BlazeComponent.extendComponent({
}
selector.text = text;
// eslint-disable-next-line no-console
console.log('selector:', selector);
this.queryParams = selector;
this.autorun(() => {
const handle = subManager.subscribe('globalSearch', selector);
Tracker.nonreactive(() => {
Tracker.autorun(() => {
this.searching.set(!handle.ready());
this.hasResults.set(handle.ready());
// eslint-disable-next-line no-console
console.log('ready:', handle.ready());
if (handle.ready()) {
this.searching.set(false);
this.hasResults.set(true);
}
});
});
});