mirror of
https://github.com/wekan/wekan.git
synced 2025-04-22 04:57:07 -04:00
Pass found cards in sessionData cursor
This commit is contained in:
parent
dd163b9923
commit
907bf4ffdc
7 changed files with 137 additions and 80 deletions
|
@ -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
|
||||
|
|
|
@ -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));
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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 };
|
||||
};
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue