Fix bug in My Cards and Global Search

This commit is contained in:
John R. Supplee 2021-03-31 13:05:39 +02:00
parent db311f677b
commit 392b701956
4 changed files with 24 additions and 20 deletions

View file

@ -96,7 +96,7 @@ class GlobalSearchComponent extends CardSearchPagedComponent {
// eslint-disable-next-line no-console
// console.log('params:', query.getParams());
this.queryParams = query.getParams();
this.queryParams = query.getQueryParams().getParams();
if (query.hasErrors()) {
this.searching.set(false);
@ -106,7 +106,7 @@ class GlobalSearchComponent extends CardSearchPagedComponent {
return;
}
this.runGlobalSearch(query.getParams());
this.runGlobalSearch(query.getQueryParams());
}
searchInstructions() {

View file

@ -99,13 +99,14 @@ export class CardSearchPagedComponent extends BlazeComponent {
}
}
runGlobalSearch(params) {
runGlobalSearch(queryParams) {
this.searching.set(true);
this.stopSubscription();
this.subscriptionHandle = Meteor.subscribe(
'globalSearch',
this.sessionId,
params,
queryParams.params,
queryParams.text,
this.subscriptionCallbacks,
);
}

View file

@ -45,12 +45,15 @@ import moment from 'moment';
export class QueryParams {
text = '';
constructor(params = {}) {
constructor(params = {}, text = '') {
this.params = params;
this.text = text;
}
hasOperator(operator) {
return this.params[operator];
return (
this.params[operator] !== undefined && this.params[operator].length > 0
);
}
addPredicate(operator, predicate) {
@ -189,8 +192,8 @@ export class Query {
return this._errors.errorMessages();
}
getParams() {
return this.queryParams.getParams();
getQueryParams() {
return this.queryParams;
}
addPredicate(operator, predicate) {

View file

@ -80,14 +80,15 @@ Meteor.publish('myCards', function(sessionId) {
// return buildQuery(sessionId, queryParams);
// });
Meteor.publish('globalSearch', function(sessionId, params) {
Meteor.publish('globalSearch', function(sessionId, params, text) {
check(sessionId, String);
check(params, Object);
check(text, String);
// eslint-disable-next-line no-console
// console.log('queryParams:', params);
return findCards(sessionId, buildQuery(new QueryParams(params)));
return findCards(sessionId, buildQuery(new QueryParams(params, text)));
});
function buildSelector(queryParams) {
@ -97,6 +98,9 @@ function buildSelector(queryParams) {
let selector = {};
// eslint-disable-next-line no-console
// console.log('queryParams:', queryParams);
if (queryParams.selector) {
selector = queryParams.selector;
} else {
@ -249,17 +253,13 @@ function buildSelector(queryParams) {
queryUsers[OPERATOR_MEMBER] = [];
if (queryParams.hasOperator(OPERATOR_USER)) {
queryParams.getPredicates(OPERATOR_USER).forEach(query => {
const users = Users.find({
username: query,
});
if (users.count()) {
users.forEach(user => {
queryUsers[OPERATOR_MEMBER].push(user._id);
queryUsers[OPERATOR_ASSIGNEE].push(user._id);
});
queryParams.getPredicates(OPERATOR_USER).forEach(username => {
const user = Users.findOne({ username });
if (user) {
queryUsers[OPERATOR_MEMBER].push(user._id);
queryUsers[OPERATOR_ASSIGNEE].push(user._id);
} else {
errors.addNotFound(OPERATOR_USER, query);
errors.addNotFound(OPERATOR_USER, username);
}
});
}