From 907bf4ffdcb98e2344e1b908272d5836236804aa Mon Sep 17 00:00:00 2001 From: "John R. Supplee" Date: Sun, 24 Jan 2021 02:32:37 +0200 Subject: [PATCH] Pass found cards in sessionData cursor --- client/components/main/globalSearch.jade | 4 +- client/components/main/globalSearch.js | 55 ++++------------ i18n/en.i18n.json | 1 + models/cardComments.js | 9 ++- models/cards.js | 58 ++++++++++++++++- models/usersessiondata.js | 8 +++ server/publications/cards.js | 82 +++++++++++++++--------- 7 files changed, 137 insertions(+), 80 deletions(-) diff --git a/client/components/main/globalSearch.jade b/client/components/main/globalSearch.jade index 3dac5c9ef..0ffb1a807 100644 --- a/client/components/main/globalSearch.jade +++ b/client/components/main/globalSearch.jade @@ -28,9 +28,9 @@ template(name="globalSearch") .global-search-results-list-wrapper if hasQueryErrors.get div - each msg in errorMessages + each msg in queryErrors span.global-search-error-messages - | {{_ msg.tag msg.value }} + = msg else h1 = resultsHeading.get diff --git a/client/components/main/globalSearch.js b/client/components/main/globalSearch.js index 796a2562d..eeb5e2fc0 100644 --- a/client/components/main/globalSearch.js +++ b/client/components/main/globalSearch.js @@ -98,21 +98,26 @@ BlazeComponent.extendComponent({ // eslint-disable-next-line no-console // console.log('getting results'); if (this.queryParams) { - const results = Cards.globalSearch(this.queryParams); - this.queryErrors = results.errors; + const sessionData = SessionData.findOne({ userId: Meteor.userId() }); + const cards = Cards.find({ _id: { $in: sessionData.cards } }); + this.queryErrors = sessionData.errorMessages; // eslint-disable-next-line no-console // 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); return null; } - if (results.cards) { - const sessionData = SessionData.findOne({ userId: Meteor.userId() }); + if (cards) { this.totalHits = sessionData.totalHits; - this.resultsCount = results.cards.count(); + this.resultsCount = cards.count(); this.resultsHeading.set(this.getResultsHeading()); - return results.cards; + return cards; } } this.resultsCount = 0; @@ -122,43 +127,9 @@ BlazeComponent.extendComponent({ errorMessages() { 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) { this.parsingErrors.forEach(err => { - messages.push(err); + messages.push(TAPi18n.__(err.tag, err.value)); }); } diff --git a/i18n/en.i18n.json b/i18n/en.i18n.json index 2079395be..3ab491ebb 100644 --- a/i18n/en.i18n.json +++ b/i18n/en.i18n.json @@ -900,6 +900,7 @@ "operator-created": "created", "operator-modified": "modified", "operator-sort": "sort", + "operator-comment": "comment", "operator-unknown-error": "%s is not an operator", "operator-number-expected": "operator __operator__ expected a number, got '__value__'", "operator-sort-invalid": "sort of '%s' is invalid", diff --git a/models/cardComments.js b/models/cardComments.js index ecfbc7516..fe49b9161 100644 --- a/models/cardComments.js +++ b/models/cardComments.js @@ -112,7 +112,7 @@ function commentCreation(userId, doc) { CardComments.textSearch = (userId, textArray) => { const selector = { - boardId: { $in: Boards.userBoardIds() }, + boardId: { $in: Boards.userBoardIds(userId) }, $and: [], }; @@ -121,9 +121,12 @@ CardComments.textSearch = (userId, textArray) => { } // 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) { diff --git a/models/cards.js b/models/cards.js index 3457e5fc9..88f0b0942 100644 --- a/models/cards.js +++ b/models/cards.js @@ -1882,6 +1882,12 @@ Cards.globalSearch = queryParams => { assignees: [], is: [], }; + + this.colorMap = {}; + for (const color of Boards.simpleSchema()._schema['labels.$.color'] + .allowedValues) { + this.colorMap[TAPi18n.__(`color-${color}`)] = color; + } } hasErrors() { @@ -1892,6 +1898,41 @@ Cards.globalSearch = queryParams => { } 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 = { @@ -1956,6 +1997,14 @@ Cards.globalSearch = queryParams => { 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) { selector.dueAt = { $lte: new Date(queryParams.dueAt) }; } @@ -2089,6 +2138,13 @@ Cards.globalSearch = queryParams => { { title: regex }, { description: 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); // eslint-disable-next-line no-console - //console.log('count:', cards.count()); + console.log('count:', cards.count()); return { cards, errors }; }; diff --git a/models/usersessiondata.js b/models/usersessiondata.js index e93cde2bd..7053667fe 100644 --- a/models/usersessiondata.js +++ b/models/usersessiondata.js @@ -39,6 +39,14 @@ SessionData.attachSchema( type: Number, optional: true, }, + cards: { + type: [String], + optional: true, + }, + errorMessages: { + type: [String], + optional: true, + }, createdAt: { /** * creation date of the team diff --git a/server/publications/cards.js b/server/publications/cards.js index 6d5223c50..36156481a 100644 --- a/server/publications/cards.js +++ b/server/publications/cards.js @@ -179,53 +179,71 @@ Meteor.publish('globalSearch', function(queryParams) { // eslint-disable-next-line no-console // console.log('queryParams:', queryParams); - const cards = Cards.globalSearch(queryParams).cards; + const results = Cards.globalSearch(queryParams); + const cards = results.cards; - if (!cards) { - return []; + const update = { + $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( - { userId: this.userId }, - { - $set: { - totalHits: cards.count(), - lastHit: cards.count() > 50 ? 50 : cards.count(), - }, - }, - ); + SessionData.upsert({ userId: this.userId }, update); const boards = []; const swimlanes = []; const lists = []; const users = [this.userId]; - cards.forEach(card => { - if (card.boardId) boards.push(card.boardId); - if (card.swimlaneId) swimlanes.push(card.swimlaneId); - if (card.listId) lists.push(card.listId); - if (card.members) { - card.members.forEach(userId => { - users.push(userId); - }); - } - if (card.assignees) { - card.assignees.forEach(userId => { - users.push(userId); - }); - } - }); + if (cards) { + cards.forEach(card => { + if (card.boardId) boards.push(card.boardId); + if (card.swimlaneId) swimlanes.push(card.swimlaneId); + if (card.listId) lists.push(card.listId); + if (card.members) { + card.members.forEach(userId => { + users.push(userId); + }); + } + if (card.assignees) { + card.assignees.forEach(userId => { + users.push(userId); + }); + } + }); + } + const fields = { + _id: 1, + title: 1, + archived: 1, + }; // eslint-disable-next-line no-console // console.log('users:', users); - return [ - cards, - Boards.find({ _id: { $in: boards } }), - Swimlanes.find({ _id: { $in: swimlanes } }), - Lists.find({ _id: { $in: lists } }), + const cursors = [ + Boards.find({ _id: { $in: boards } }, { fields }), + Swimlanes.find({ _id: { $in: swimlanes } }, { fields }), + Lists.find({ _id: { $in: lists } }, { fields }), Users.find({ _id: { $in: users } }, { fields: Users.safeFields }), SessionData.find({ userId: this.userId }), ]; + + if (cards) { + cursors.push(cards); + } + + return cursors; }); Meteor.publish('brokenCards', function() {