mirror of
https://github.com/wekan/wekan.git
synced 2025-12-20 09:20:12 +01:00
Fixes for duration predicates
This commit is contained in:
parent
43f40c4085
commit
a3229ea965
2 changed files with 77 additions and 38 deletions
|
|
@ -118,10 +118,7 @@ BlazeComponent.extendComponent({
|
||||||
// console.log('session data:', sessionData);
|
// console.log('session data:', sessionData);
|
||||||
const projection = sessionData.getProjection();
|
const projection = sessionData.getProjection();
|
||||||
projection.skip = 0;
|
projection.skip = 0;
|
||||||
const cards = Cards.find(
|
const cards = Cards.find({ _id: { $in: sessionData.cards } }, projection);
|
||||||
{ _id: { $in: sessionData.cards } },
|
|
||||||
projection,
|
|
||||||
);
|
|
||||||
this.queryErrors = sessionData.errors;
|
this.queryErrors = sessionData.errors;
|
||||||
if (this.queryErrors.length) {
|
if (this.queryErrors.length) {
|
||||||
this.hasQueryErrors.set(true);
|
this.hasQueryErrors.set(true);
|
||||||
|
|
@ -314,25 +311,65 @@ BlazeComponent.extendComponent({
|
||||||
}
|
}
|
||||||
// eslint-disable-next-line no-prototype-builtins
|
// eslint-disable-next-line no-prototype-builtins
|
||||||
if (operatorMap.hasOwnProperty(op)) {
|
if (operatorMap.hasOwnProperty(op)) {
|
||||||
|
const operator = operatorMap[op];
|
||||||
let value = m.groups.value;
|
let value = m.groups.value;
|
||||||
if (operatorMap[op] === 'labels') {
|
if (operator === 'labels') {
|
||||||
if (value in this.colorMap) {
|
if (value in this.colorMap) {
|
||||||
value = this.colorMap[value];
|
value = this.colorMap[value];
|
||||||
// console.log('found color:', value);
|
// console.log('found color:', value);
|
||||||
}
|
}
|
||||||
} else if (
|
} else if (['dueAt', 'createdAt', 'modifiedAt'].includes(operator)) {
|
||||||
['dueAt', 'createdAt', 'modifiedAt'].includes(operatorMap[op])
|
|
||||||
) {
|
|
||||||
let days = parseInt(value, 10);
|
let days = parseInt(value, 10);
|
||||||
let duration = null;
|
let duration = null;
|
||||||
if (isNaN(days)) {
|
if (isNaN(days)) {
|
||||||
|
// duration was specified as text
|
||||||
if (predicateTranslations.durations[value]) {
|
if (predicateTranslations.durations[value]) {
|
||||||
duration = predicateTranslations.durations[value];
|
duration = predicateTranslations.durations[value];
|
||||||
value = moment();
|
let date = null;
|
||||||
} else if (predicateTranslations.due[value] === 'overdue') {
|
switch (duration) {
|
||||||
value = moment();
|
case 'week':
|
||||||
duration = 'days';
|
let week = moment().week();
|
||||||
days = 0;
|
if (week === 52) {
|
||||||
|
date = moment(1, 'W');
|
||||||
|
date.set('year', date.year() + 1);
|
||||||
|
} else {
|
||||||
|
date = moment(week + 1, 'W');
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'month':
|
||||||
|
let month = moment().month();
|
||||||
|
// .month() is zero indexed
|
||||||
|
if (month === 11) {
|
||||||
|
date = moment(1, 'M');
|
||||||
|
date.set('year', date.year() + 1);
|
||||||
|
} else {
|
||||||
|
date = moment(month + 2, 'M');
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'quarter':
|
||||||
|
let quarter = moment().quarter();
|
||||||
|
if (quarter === 4) {
|
||||||
|
date = moment(1, 'Q');
|
||||||
|
date.set('year', date.year() + 1);
|
||||||
|
} else {
|
||||||
|
date = moment(quarter + 1, 'Q');
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'year':
|
||||||
|
date = moment(moment().year() + 1, 'YYYY');
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (date) {
|
||||||
|
value = {
|
||||||
|
operator: '$lt',
|
||||||
|
value: date.format(),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
} else if (operator === 'dueAt' && value === 'overdue') {
|
||||||
|
value = {
|
||||||
|
operator: '$lt',
|
||||||
|
value: moment().format(),
|
||||||
|
};
|
||||||
} else {
|
} else {
|
||||||
this.parsingErrors.push({
|
this.parsingErrors.push({
|
||||||
tag: 'operator-number-expected',
|
tag: 'operator-number-expected',
|
||||||
|
|
@ -341,18 +378,23 @@ BlazeComponent.extendComponent({
|
||||||
value = null;
|
value = null;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
value = moment();
|
if (operator === 'dueAt') {
|
||||||
}
|
value = {
|
||||||
if (value) {
|
operator: '$lte',
|
||||||
if (operatorMap[op] === 'dueAt') {
|
value: moment()
|
||||||
value = value.add(days, duration ? duration : 'days').format();
|
.add(days, duration ? duration : 'days')
|
||||||
|
.format(),
|
||||||
|
};
|
||||||
} else {
|
} else {
|
||||||
value = value
|
value = {
|
||||||
|
operator: '$gte',
|
||||||
|
value: moment()
|
||||||
.subtract(days, duration ? duration : 'days')
|
.subtract(days, duration ? duration : 'days')
|
||||||
.format();
|
.format(),
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (operatorMap[op] === 'sort') {
|
} else if (operator === 'sort') {
|
||||||
let negated = false;
|
let negated = false;
|
||||||
const m = value.match(reNegatedOperator);
|
const m = value.match(reNegatedOperator);
|
||||||
if (m) {
|
if (m) {
|
||||||
|
|
@ -370,7 +412,7 @@ BlazeComponent.extendComponent({
|
||||||
order: negated ? 'des' : 'asc',
|
order: negated ? 'des' : 'asc',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
} else if (operatorMap[op] === 'status') {
|
} else if (operator === 'status') {
|
||||||
if (!predicateTranslations.status[value]) {
|
if (!predicateTranslations.status[value]) {
|
||||||
this.parsingErrors.push({
|
this.parsingErrors.push({
|
||||||
tag: 'operator-status-invalid',
|
tag: 'operator-status-invalid',
|
||||||
|
|
@ -379,7 +421,7 @@ BlazeComponent.extendComponent({
|
||||||
} else {
|
} else {
|
||||||
value = predicateTranslations.status[value];
|
value = predicateTranslations.status[value];
|
||||||
}
|
}
|
||||||
} else if (operatorMap[op] === 'has') {
|
} else if (operator === 'has') {
|
||||||
if (!predicateTranslations.has[value]) {
|
if (!predicateTranslations.has[value]) {
|
||||||
this.parsingErrors.push({
|
this.parsingErrors.push({
|
||||||
tag: 'operator-has-invalid',
|
tag: 'operator-has-invalid',
|
||||||
|
|
@ -389,10 +431,10 @@ BlazeComponent.extendComponent({
|
||||||
value = predicateTranslations.has[value];
|
value = predicateTranslations.has[value];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (Array.isArray(params[operatorMap[op]])) {
|
if (Array.isArray(params[operator])) {
|
||||||
params[operatorMap[op]].push(value);
|
params[operator].push(value);
|
||||||
} else {
|
} else {
|
||||||
params[operatorMap[op]] = value;
|
params[operator] = value;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this.parsingErrors.push({
|
this.parsingErrors.push({
|
||||||
|
|
|
||||||
|
|
@ -395,17 +395,14 @@ Meteor.publish('globalSearch', function(sessionId, queryParams) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (queryParams.dueAt !== null) {
|
['dueAt', 'createdAt', 'modifiedAt'].forEach(field => {
|
||||||
selector.dueAt = { $lte: new Date(queryParams.dueAt) };
|
if (queryParams[field]) {
|
||||||
}
|
selector[field] = {};
|
||||||
|
selector[field][queryParams[field]['operator']] = new Date(
|
||||||
if (queryParams.createdAt !== null) {
|
queryParams[field]['value'],
|
||||||
selector.createdAt = { $gte: new Date(queryParams.createdAt) };
|
);
|
||||||
}
|
|
||||||
|
|
||||||
if (queryParams.modifiedAt !== null) {
|
|
||||||
selector.modifiedAt = { $gte: new Date(queryParams.modifiedAt) };
|
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
const queryMembers = [];
|
const queryMembers = [];
|
||||||
const queryAssignees = [];
|
const queryAssignees = [];
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue