Pass found cards in sessionData cursor

This commit is contained in:
John R. Supplee 2021-01-24 02:32:37 +02:00
parent dd163b9923
commit 907bf4ffdc
7 changed files with 137 additions and 80 deletions

View file

@ -28,9 +28,9 @@ template(name="globalSearch")
.global-search-results-list-wrapper .global-search-results-list-wrapper
if hasQueryErrors.get if hasQueryErrors.get
div div
each msg in errorMessages each msg in queryErrors
span.global-search-error-messages span.global-search-error-messages
| {{_ msg.tag msg.value }} = msg
else else
h1 h1
= resultsHeading.get = resultsHeading.get

View file

@ -98,21 +98,26 @@ BlazeComponent.extendComponent({
// eslint-disable-next-line no-console // eslint-disable-next-line no-console
// console.log('getting results'); // console.log('getting results');
if (this.queryParams) { if (this.queryParams) {
const results = Cards.globalSearch(this.queryParams); const sessionData = SessionData.findOne({ userId: Meteor.userId() });
this.queryErrors = results.errors; const cards = Cards.find({ _id: { $in: sessionData.cards } });
this.queryErrors = sessionData.errorMessages;
// eslint-disable-next-line no-console // eslint-disable-next-line no-console
// console.log('errors:', this.queryErrors); // console.log('errors:', this.queryErrors);
if (this.errorMessages().length) { if (this.parsingErrors.length) {
this.queryErrors = this.errorMessages();
this.hasQueryErrors.set(true);
return null;
}
if (this.queryErrors.length) {
this.hasQueryErrors.set(true); this.hasQueryErrors.set(true);
return null; return null;
} }
if (results.cards) { if (cards) {
const sessionData = SessionData.findOne({ userId: Meteor.userId() });
this.totalHits = sessionData.totalHits; this.totalHits = sessionData.totalHits;
this.resultsCount = results.cards.count(); this.resultsCount = cards.count();
this.resultsHeading.set(this.getResultsHeading()); this.resultsHeading.set(this.getResultsHeading());
return results.cards; return cards;
} }
} }
this.resultsCount = 0; this.resultsCount = 0;
@ -122,43 +127,9 @@ BlazeComponent.extendComponent({
errorMessages() { errorMessages() {
const messages = []; const messages = [];
if (this.queryErrors) {
this.queryErrors.notFound.boards.forEach(board => {
messages.push({ tag: 'board-title-not-found', value: board });
});
this.queryErrors.notFound.swimlanes.forEach(swim => {
messages.push({ tag: 'swimlane-title-not-found', value: swim });
});
this.queryErrors.notFound.lists.forEach(list => {
messages.push({ tag: 'list-title-not-found', value: list });
});
this.queryErrors.notFound.labels.forEach(label => {
const color = Object.entries(this.colorMap)
.filter(value => value[1] === label)
.map(value => value[0]);
if (color.length) {
messages.push({
tag: 'label-color-not-found',
value: color[0],
});
} else {
messages.push({ tag: 'label-not-found', value: label });
}
});
this.queryErrors.notFound.users.forEach(user => {
messages.push({ tag: 'user-username-not-found', value: user });
});
this.queryErrors.notFound.members.forEach(user => {
messages.push({ tag: 'user-username-not-found', value: user });
});
this.queryErrors.notFound.assignees.forEach(user => {
messages.push({ tag: 'user-username-not-found', value: user });
});
}
if (this.parsingErrors.length) { if (this.parsingErrors.length) {
this.parsingErrors.forEach(err => { this.parsingErrors.forEach(err => {
messages.push(err); messages.push(TAPi18n.__(err.tag, err.value));
}); });
} }

View file

@ -900,6 +900,7 @@
"operator-created": "created", "operator-created": "created",
"operator-modified": "modified", "operator-modified": "modified",
"operator-sort": "sort", "operator-sort": "sort",
"operator-comment": "comment",
"operator-unknown-error": "%s is not an operator", "operator-unknown-error": "%s is not an operator",
"operator-number-expected": "operator __operator__ expected a number, got '__value__'", "operator-number-expected": "operator __operator__ expected a number, got '__value__'",
"operator-sort-invalid": "sort of '%s' is invalid", "operator-sort-invalid": "sort of '%s' is invalid",

View file

@ -112,7 +112,7 @@ function commentCreation(userId, doc) {
CardComments.textSearch = (userId, textArray) => { CardComments.textSearch = (userId, textArray) => {
const selector = { const selector = {
boardId: { $in: Boards.userBoardIds() }, boardId: { $in: Boards.userBoardIds(userId) },
$and: [], $and: [],
}; };
@ -121,9 +121,12 @@ CardComments.textSearch = (userId, textArray) => {
} }
// eslint-disable-next-line no-console // eslint-disable-next-line no-console
console.log(textArray); console.log('cardComments selector:', selector);
return CardComments.find(selector); const comments = CardComments.find(selector);
// eslint-disable-next-line no-console
console.log('count:', comments.count());
return comments;
}; };
if (Meteor.isServer) { if (Meteor.isServer) {

View file

@ -1882,6 +1882,12 @@ Cards.globalSearch = queryParams => {
assignees: [], assignees: [],
is: [], is: [],
}; };
this.colorMap = {};
for (const color of Boards.simpleSchema()._schema['labels.$.color']
.allowedValues) {
this.colorMap[TAPi18n.__(`color-${color}`)] = color;
}
} }
hasErrors() { hasErrors() {
@ -1892,6 +1898,41 @@ Cards.globalSearch = queryParams => {
} }
return false; return false;
} }
errorMessages() {
const messages = [];
this.notFound.boards.forEach(board => {
messages.push(TAPi18n.__('board-title-not-found', board));
});
this.notFound.swimlanes.forEach(swim => {
messages.push(TAPi18n.__('swimlane-title-not-found', swim));
});
this.notFound.lists.forEach(list => {
messages.push(TAPi18n.__('list-title-not-found', list));
});
this.notFound.labels.forEach(label => {
const color = Object.entries(this.colorMap)
.filter(value => value[1] === label)
.map(value => value[0]);
if (color.length) {
messages.push(TAPi18n.__('label-color-not-found', color[0]));
} else {
messages.push(TAPi18n.__('label-not-found', label));
}
});
this.notFound.users.forEach(user => {
messages.push(TAPi18n.__('user-username-not-found', user));
});
this.notFound.members.forEach(user => {
messages.push(TAPi18n.__('user-username-not-found', user));
});
this.notFound.assignees.forEach(user => {
messages.push(TAPi18n.__('user-username-not-found', user));
});
return messages;
}
})(); })();
const selector = { const selector = {
@ -1956,6 +1997,14 @@ Cards.globalSearch = queryParams => {
selector.listId.$in = queryLists; selector.listId.$in = queryLists;
} }
if (queryParams.comments.length) {
selector._id = {
$in: CardComments.textSearch(userId, queryParams.comments).map(com => {
return com.cardId;
}),
};
}
if (queryParams.dueAt !== null) { if (queryParams.dueAt !== null) {
selector.dueAt = { $lte: new Date(queryParams.dueAt) }; selector.dueAt = { $lte: new Date(queryParams.dueAt) };
} }
@ -2089,6 +2138,13 @@ Cards.globalSearch = queryParams => {
{ title: regex }, { title: regex },
{ description: regex }, { description: regex },
{ customFields: { $elemMatch: { value: regex } } }, { customFields: { $elemMatch: { value: regex } } },
{
_id: {
$in: CardComments.textSearch(userId, [queryParams.text]).map(
com => com.cardId,
),
},
},
]; ];
} }
@ -2153,7 +2209,7 @@ Cards.globalSearch = queryParams => {
const cards = Cards.find(selector, projection); const cards = Cards.find(selector, projection);
// eslint-disable-next-line no-console // eslint-disable-next-line no-console
//console.log('count:', cards.count()); console.log('count:', cards.count());
return { cards, errors }; return { cards, errors };
}; };

View file

@ -39,6 +39,14 @@ SessionData.attachSchema(
type: Number, type: Number,
optional: true, optional: true,
}, },
cards: {
type: [String],
optional: true,
},
errorMessages: {
type: [String],
optional: true,
},
createdAt: { createdAt: {
/** /**
* creation date of the team * creation date of the team

View file

@ -179,53 +179,71 @@ Meteor.publish('globalSearch', function(queryParams) {
// eslint-disable-next-line no-console // eslint-disable-next-line no-console
// console.log('queryParams:', queryParams); // console.log('queryParams:', queryParams);
const cards = Cards.globalSearch(queryParams).cards; const results = Cards.globalSearch(queryParams);
const cards = results.cards;
if (!cards) { const update = {
return []; $set: {
totalHits: 0,
lastHit: 0,
cards: [],
errorMessages: results.errors.errorMessages(),
},
};
if (cards) {
update.$set.totalHits = cards.count();
update.$set.lastHit = cards.count() > 50 ? 50 : cards.count();
update.$set.cards = cards.map(card => {
return card._id;
});
} }
SessionData.upsert( SessionData.upsert({ userId: this.userId }, update);
{ userId: this.userId },
{
$set: {
totalHits: cards.count(),
lastHit: cards.count() > 50 ? 50 : cards.count(),
},
},
);
const boards = []; const boards = [];
const swimlanes = []; const swimlanes = [];
const lists = []; const lists = [];
const users = [this.userId]; const users = [this.userId];
cards.forEach(card => { if (cards) {
if (card.boardId) boards.push(card.boardId); cards.forEach(card => {
if (card.swimlaneId) swimlanes.push(card.swimlaneId); if (card.boardId) boards.push(card.boardId);
if (card.listId) lists.push(card.listId); if (card.swimlaneId) swimlanes.push(card.swimlaneId);
if (card.members) { if (card.listId) lists.push(card.listId);
card.members.forEach(userId => { if (card.members) {
users.push(userId); card.members.forEach(userId => {
}); users.push(userId);
} });
if (card.assignees) { }
card.assignees.forEach(userId => { if (card.assignees) {
users.push(userId); card.assignees.forEach(userId => {
}); users.push(userId);
} });
}); }
});
}
const fields = {
_id: 1,
title: 1,
archived: 1,
};
// eslint-disable-next-line no-console // eslint-disable-next-line no-console
// console.log('users:', users); // console.log('users:', users);
return [ const cursors = [
cards, Boards.find({ _id: { $in: boards } }, { fields }),
Boards.find({ _id: { $in: boards } }), Swimlanes.find({ _id: { $in: swimlanes } }, { fields }),
Swimlanes.find({ _id: { $in: swimlanes } }), Lists.find({ _id: { $in: lists } }, { fields }),
Lists.find({ _id: { $in: lists } }),
Users.find({ _id: { $in: users } }, { fields: Users.safeFields }), Users.find({ _id: { $in: users } }, { fields: Users.safeFields }),
SessionData.find({ userId: this.userId }), SessionData.find({ userId: this.userId }),
]; ];
if (cards) {
cursors.push(cards);
}
return cursors;
}); });
Meteor.publish('brokenCards', function() { Meteor.publish('brokenCards', function() {