Global search add sort operator

* Add sort operator
* add 'overdue' value to 'due' operator
This commit is contained in:
John R. Supplee 2021-01-22 00:37:16 +02:00
parent 319783b008
commit fc0ee2e41b
3 changed files with 68 additions and 10 deletions

View file

@ -212,6 +212,7 @@ BlazeComponent.extendComponent({
operatorMap[TAPi18n.__('operator-due')] = 'dueAt'; operatorMap[TAPi18n.__('operator-due')] = 'dueAt';
operatorMap[TAPi18n.__('operator-created')] = 'createdAt'; operatorMap[TAPi18n.__('operator-created')] = 'createdAt';
operatorMap[TAPi18n.__('operator-modified')] = 'modifiedAt'; operatorMap[TAPi18n.__('operator-modified')] = 'modifiedAt';
operatorMap[TAPi18n.__('operator-sort')] = 'sort';
// eslint-disable-next-line no-console // eslint-disable-next-line no-console
console.log('operatorMap:', operatorMap); console.log('operatorMap:', operatorMap);
@ -256,12 +257,16 @@ BlazeComponent.extendComponent({
} else if ( } else if (
['dueAt', 'createdAt', 'modifiedAt'].includes(operatorMap[op]) ['dueAt', 'createdAt', 'modifiedAt'].includes(operatorMap[op])
) { ) {
const days = parseInt(value, 10); let days = parseInt(value, 10);
let duration = null;
if (isNaN(days)) { if (isNaN(days)) {
if (['day', 'week', 'month', 'quarter', 'year'].includes(value)) { if (['day', 'week', 'month', 'quarter', 'year'].includes(value)) {
value = moment() duration = value;
.subtract(1, value) value = moment();
.format(); } else if (value === 'overdue') {
value = moment();
duration = 'days';
days = 0;
} else { } else {
this.parsingErrors.push({ this.parsingErrors.push({
tag: 'operator-number-expected', tag: 'operator-number-expected',
@ -270,9 +275,23 @@ BlazeComponent.extendComponent({
value = null; value = null;
} }
} else { } else {
value = moment() value = moment();
.subtract(days, 'days') }
.format(); if (value) {
if (operatorMap[op] === 'dueAt') {
value = value.add(days, duration ? duration : 'days').format();
} else {
value = value
.subtract(days, duration ? duration : 'days')
.format();
}
}
} else if (operatorMap[op] === 'sort') {
if (!['due', 'modified', 'created', 'system'].includes(value)) {
this.parsingErrors.push({
tag: 'operator-sort-invalid',
value,
});
} }
} }
if (Array.isArray(params[operatorMap[op]])) { if (Array.isArray(params[operatorMap[op]])) {

View file

@ -898,8 +898,10 @@
"operator-due": "due", "operator-due": "due",
"operator-created": "created", "operator-created": "created",
"operator-modified": "modified", "operator-modified": "modified",
"operator-sort": "sort",
"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",
"heading-notes": "Notes", "heading-notes": "Notes",
"globalSearch-instructions-heading": "Search Instructions", "globalSearch-instructions-heading": "Search Instructions",
"globalSearch-instructions-description": "Searches can include operators to refine the search. Operators are specified by writing the operator name and value separated by a colon. For example, an operator specification of `list:Blocked` would limit the search to cards that are contained in a list named *Blocked*. If the value contains spaces or special characters it must be enclosed in quotation marks (e.g. `__operator_list__:\"To Review\"`).", "globalSearch-instructions-description": "Searches can include operators to refine the search. Operators are specified by writing the operator name and value separated by a colon. For example, an operator specification of `list:Blocked` would limit the search to cards that are contained in a list named *Blocked*. If the value contains spaces or special characters it must be enclosed in quotation marks (e.g. `__operator_list__:\"To Review\"`).",

View file

@ -1955,7 +1955,7 @@ Cards.globalSearch = queryParams => {
} }
if (queryParams.dueAt !== null) { if (queryParams.dueAt !== null) {
selector.dueAt = { $gte: new Date(queryParams.dueAt) }; selector.dueAt = { $lte: new Date(queryParams.dueAt) };
} }
if (queryParams.createdAt !== null) { if (queryParams.createdAt !== null) {
@ -2092,7 +2092,8 @@ Cards.globalSearch = queryParams => {
// eslint-disable-next-line no-console // eslint-disable-next-line no-console
console.log('selector:', selector); console.log('selector:', selector);
const cards = Cards.find(selector, {
const projection = {
fields: { fields: {
_id: 1, _id: 1,
archived: 1, archived: 1,
@ -2111,7 +2112,43 @@ Cards.globalSearch = queryParams => {
labelIds: 1, labelIds: 1,
}, },
limit: 50, limit: 50,
}); };
if (queryParams.sort === 'due') {
projection.sort = {
dueAt: 1,
boardId: 1,
swimlaneId: 1,
listId: 1,
sort: 1,
};
} else if (queryParams.sort === 'modified') {
projection.sort = {
modifiedAt: -1,
boardId: 1,
swimlaneId: 1,
listId: 1,
sort: 1,
};
} else if (queryParams.sort === 'created') {
projection.sort = {
createdAt: -1,
boardId: 1,
swimlaneId: 1,
listId: 1,
sort: 1,
};
} else if (queryParams.sort === 'system') {
projection.sort = {
boardId: 1,
swimlaneId: 1,
listId: 1,
modifiedAt: 1,
sort: 1,
};
}
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());