mirror of
https://github.com/wekan/wekan.git
synced 2025-09-22 01:50:48 +02:00
Global search development
* Add translation tags * Use translation tags for showing result count * Add logic for selecting cards by labels * Readd code for searching card text that was mistakenly deleted
This commit is contained in:
parent
a647768368
commit
25dc779a73
5 changed files with 77 additions and 9 deletions
|
@ -17,8 +17,12 @@ template(name="globalSearch")
|
|||
else if hasResults.get
|
||||
.global-search-dueat-list-wrapper
|
||||
h1
|
||||
= resultsCount.get
|
||||
| Results
|
||||
if $eq resultCount.get 0
|
||||
| {{_ 'no-results' }}
|
||||
else if $eq resultCount.get 1
|
||||
| {{_ 'one-result' }}
|
||||
else
|
||||
| {{_ 'n-results' resultsCount.get }}
|
||||
if queryErrors.get
|
||||
div
|
||||
each msg in errorMessages
|
||||
|
|
|
@ -104,7 +104,7 @@ BlazeComponent.extendComponent({
|
|||
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+|$)/;
|
||||
const reText = /^(?<text>\S+)(\s+|$)/;
|
||||
const reQuotedText = /^(?<quote>["'])(?<text>\w+)\k<quote>(\s+|$)/;
|
||||
const operatorMap = {
|
||||
board: 'boards',
|
||||
|
|
|
@ -868,5 +868,8 @@
|
|||
"board-title-not-found": "Board '%s' not found.",
|
||||
"swimlane-title-not-found": "Swimlane '%s' not found.",
|
||||
"list-title-not-found": "List '%s' not found.",
|
||||
"user-username-not-found": "Username '%s' not found."
|
||||
"user-username-not-found": "Username '%s' not found.",
|
||||
"globalSearch-title": "Search All Boards",
|
||||
"one-results": "One Result",
|
||||
"n-results": "%s Results"
|
||||
}
|
||||
|
|
|
@ -1208,18 +1208,21 @@ function boardRemover(userId, doc) {
|
|||
);
|
||||
}
|
||||
|
||||
Boards.userSearch = (userId, includeArchived = false, selector = {}) => {
|
||||
Boards.userSearch = (
|
||||
userId,
|
||||
selector = {},
|
||||
projection = {},
|
||||
includeArchived = false,
|
||||
) => {
|
||||
if (!includeArchived) {
|
||||
selector = {
|
||||
archived: false,
|
||||
};
|
||||
selector.archived = false;
|
||||
}
|
||||
selector.$or = [
|
||||
{ permission: 'public' },
|
||||
{ members: { $elemMatch: { userId, isActive: true } } },
|
||||
];
|
||||
|
||||
return Boards.find(selector);
|
||||
return Boards.find(selector, projection);
|
||||
};
|
||||
|
||||
Boards.userBoards = (userId, includeArchived = false, selector = {}) => {
|
||||
|
|
|
@ -1827,6 +1827,63 @@ Cards.globalSearch = queryParams => {
|
|||
];
|
||||
}
|
||||
|
||||
if (queryParams.labels.length) {
|
||||
queryParams.labels.forEach(label => {
|
||||
const queryLabels = [];
|
||||
|
||||
let boards = Boards.userSearch(userId, {
|
||||
labels: { $elemMatch: { color: label.toLowerCase() } },
|
||||
});
|
||||
|
||||
if (boards.count()) {
|
||||
boards.forEach(board => {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('board:', board);
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('board.labels:', board.labels);
|
||||
board.labels
|
||||
.filter(boardLabel => {
|
||||
return boardLabel.color === label.toLowerCase();
|
||||
})
|
||||
.forEach(boardLabel => {
|
||||
queryLabels.push(boardLabel._id);
|
||||
});
|
||||
});
|
||||
} else {
|
||||
const reLabel = new RegExp(label, 'i');
|
||||
boards = Boards.userSearch(userId, {
|
||||
labels: { $elemMatch: { name: reLabel } },
|
||||
});
|
||||
|
||||
if (boards.count()) {
|
||||
boards.forEach(board => {
|
||||
board.labels
|
||||
.filter(boardLabel => {
|
||||
return boardLabel.name.match(reLabel);
|
||||
})
|
||||
.forEach(boardLabel => {
|
||||
queryLabels.push(boardLabel._id);
|
||||
});
|
||||
});
|
||||
} else {
|
||||
errors.notFound.labels.push({ tag: 'label', value: label });
|
||||
}
|
||||
}
|
||||
|
||||
selector.labelIds = { $in: queryLabels };
|
||||
});
|
||||
}
|
||||
|
||||
if (queryParams.text) {
|
||||
const regex = new RegExp(queryParams.text, 'i');
|
||||
|
||||
selector.$or = [
|
||||
{ title: regex },
|
||||
{ description: regex },
|
||||
{ customFields: { $elemMatch: { value: regex } } },
|
||||
];
|
||||
}
|
||||
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('selector:', selector);
|
||||
const cards = Cards.find(selector, {
|
||||
|
@ -1843,6 +1900,7 @@ Cards.globalSearch = queryParams => {
|
|||
assignees: 1,
|
||||
colors: 1,
|
||||
dueAt: 1,
|
||||
labelIds: 1,
|
||||
},
|
||||
limit: 50,
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue