fixing search for dropdown fields, and error on loading board

This commit is contained in:
Ignatz 2018-06-14 12:41:16 +02:00
parent 259614b647
commit 571f55f904
2 changed files with 116 additions and 100 deletions

View file

@ -145,6 +145,22 @@ class AdvancedFilter {
return found._id; return found._id;
} }
_fieldValueToId(field, value)
{
const found = CustomFields.findOne({ 'name': field });
if (found.settings.dropdownItems && found.settings.dropdownItems.length > 0)
{
for (let i = 0; i < found.settings.dropdownItems.length; i++)
{
if (found.settings.dropdownItems[i].name === value)
{
return found.settings.dropdownItems[i]._id;
}
}
}
return value;
}
_arrayToSelector(commands) { _arrayToSelector(commands) {
try { try {
//let changed = false; //let changed = false;
@ -163,27 +179,27 @@ class AdvancedFilter {
if (commands[i].cmd) { if (commands[i].cmd) {
switch (commands[i].cmd) { switch (commands[i].cmd) {
case '(': case '(':
{ {
level++; level++;
if (start === -1) start = i; if (start === -1) start = i;
continue; continue;
} }
case ')': case ')':
{ {
level--; level--;
commands.splice(i, 1);
i--;
continue;
}
default:
{
if (level > 0) {
subcommands.push(commands[i]);
commands.splice(i, 1); commands.splice(i, 1);
i--; i--;
continue; continue;
} }
} default:
{
if (level > 0) {
subcommands.push(commands[i]);
commands.splice(i, 1);
i--;
continue;
}
}
} }
} }
} }
@ -205,86 +221,86 @@ class AdvancedFilter {
case '=': case '=':
case '==': case '==':
case '===': case '===':
{ {
const field = commands[i - 1].cmd; const field = commands[i - 1].cmd;
const str = commands[i + 1].cmd; const str = commands[i + 1].cmd;
commands[i] = { 'customFields._id': this._fieldNameToId(field), 'customFields.value': str }; commands[i] = { 'customFields._id': this._fieldNameToId(field), 'customFields.value': this._fieldValueToId(str) };
commands.splice(i - 1, 1); commands.splice(i - 1, 1);
commands.splice(i, 1); commands.splice(i, 1);
//changed = true; //changed = true;
i--; i--;
break; break;
} }
case '!=': case '!=':
case '!==': case '!==':
{ {
const field = commands[i - 1].cmd; const field = commands[i - 1].cmd;
const str = commands[i + 1].cmd; const str = commands[i + 1].cmd;
commands[i] = { 'customFields._id': this._fieldNameToId(field), 'customFields.value': { $not: str } }; commands[i] = { 'customFields._id': this._fieldNameToId(field), 'customFields.value': { $not: this._fieldValueToId(str) } };
commands.splice(i - 1, 1); commands.splice(i - 1, 1);
commands.splice(i, 1); commands.splice(i, 1);
//changed = true; //changed = true;
i--; i--;
break; break;
} }
case '>': case '>':
case 'gt': case 'gt':
case 'Gt': case 'Gt':
case 'GT': case 'GT':
{ {
const field = commands[i - 1].cmd; const field = commands[i - 1].cmd;
const str = commands[i + 1].cmd; const str = commands[i + 1].cmd;
commands[i] = { 'customFields._id': this._fieldNameToId(field), 'customFields.value': { $gt: str } }; commands[i] = { 'customFields._id': this._fieldNameToId(field), 'customFields.value': { $gt: str } };
commands.splice(i - 1, 1); commands.splice(i - 1, 1);
commands.splice(i, 1); commands.splice(i, 1);
//changed = true; //changed = true;
i--; i--;
break; break;
} }
case '>=': case '>=':
case '>==': case '>==':
case 'gte': case 'gte':
case 'Gte': case 'Gte':
case 'GTE': case 'GTE':
{ {
const field = commands[i - 1].cmd; const field = commands[i - 1].cmd;
const str = commands[i + 1].cmd; const str = commands[i + 1].cmd;
commands[i] = { 'customFields._id': this._fieldNameToId(field), 'customFields.value': { $gte: str } }; commands[i] = { 'customFields._id': this._fieldNameToId(field), 'customFields.value': { $gte: str } };
commands.splice(i - 1, 1); commands.splice(i - 1, 1);
commands.splice(i, 1); commands.splice(i, 1);
//changed = true; //changed = true;
i--; i--;
break; break;
} }
case '<': case '<':
case 'lt': case 'lt':
case 'Lt': case 'Lt':
case 'LT': case 'LT':
{ {
const field = commands[i - 1].cmd; const field = commands[i - 1].cmd;
const str = commands[i + 1].cmd; const str = commands[i + 1].cmd;
commands[i] = { 'customFields._id': this._fieldNameToId(field), 'customFields.value': { $lt: str } }; commands[i] = { 'customFields._id': this._fieldNameToId(field), 'customFields.value': { $lt: str } };
commands.splice(i - 1, 1); commands.splice(i - 1, 1);
commands.splice(i, 1); commands.splice(i, 1);
//changed = true; //changed = true;
i--; i--;
break; break;
} }
case '<=': case '<=':
case '<==': case '<==':
case 'lte': case 'lte':
case 'Lte': case 'Lte':
case 'LTE': case 'LTE':
{ {
const field = commands[i - 1].cmd; const field = commands[i - 1].cmd;
const str = commands[i + 1].cmd; const str = commands[i + 1].cmd;
commands[i] = { 'customFields._id': this._fieldNameToId(field), 'customFields.value': { $lte: str } }; commands[i] = { 'customFields._id': this._fieldNameToId(field), 'customFields.value': { $lte: str } };
commands.splice(i - 1, 1); commands.splice(i - 1, 1);
commands.splice(i, 1); commands.splice(i, 1);
//changed = true; //changed = true;
i--; i--;
break; break;
} }
} }
} }
@ -300,44 +316,44 @@ class AdvancedFilter {
case 'OR': case 'OR':
case '|': case '|':
case '||': case '||':
{ {
const op1 = commands[i - 1]; const op1 = commands[i - 1];
const op2 = commands[i + 1]; const op2 = commands[i + 1];
commands[i] = { $or: [op1, op2] }; commands[i] = { $or: [op1, op2] };
commands.splice(i - 1, 1); commands.splice(i - 1, 1);
commands.splice(i, 1); commands.splice(i, 1);
//changed = true; //changed = true;
i--; i--;
break; break;
} }
case 'and': case 'and':
case 'And': case 'And':
case 'AND': case 'AND':
case '&': case '&':
case '&&': case '&&':
{ {
const op1 = commands[i - 1]; const op1 = commands[i - 1];
const op2 = commands[i + 1]; const op2 = commands[i + 1];
commands[i] = { $and: [op1, op2] }; commands[i] = { $and: [op1, op2] };
commands.splice(i - 1, 1); commands.splice(i - 1, 1);
commands.splice(i, 1); commands.splice(i, 1);
//changed = true; //changed = true;
i--; i--;
break; break;
} }
case 'not': case 'not':
case 'Not': case 'Not':
case 'NOT': case 'NOT':
case '!': case '!':
{ {
const op1 = commands[i + 1]; const op1 = commands[i + 1];
commands[i] = { $not: op1 }; commands[i] = { $not: op1 };
commands.splice(i + 1, 1); commands.splice(i + 1, 1);
//changed = true; //changed = true;
i--; i--;
break; break;
} }
} }
} }

View file

@ -230,16 +230,16 @@ Cards.helpers({
// match right definition to each field // match right definition to each field
if (!this.customFields) return []; if (!this.customFields) return [];
return this.customFields.map((customField) => { return this.customFields.map((customField) => {
var definition = definitions.find((definition) => { const definition = definitions.find((definition) => {
return definition._id === customField._id; return definition._id === customField._id;
}); });
//search for "True Value" which is for DropDowns other then the Value (which is the id) //search for "True Value" which is for DropDowns other then the Value (which is the id)
var trueValue = customField.value; let trueValue = customField.value;
if (definition.settings.dropdownItems.length > 0) if (definition.settings.dropdownItems && definition.settings.dropdownItems.length > 0)
{ {
for (var i = 0; i < definition.settings.dropdownItems.length;i++) for (let i = 0; i < definition.settings.dropdownItems.length; i++)
{ {
if (definition.settings.dropdownItems[i]._id == customField.value) if (definition.settings.dropdownItems[i]._id === customField.value)
{ {
trueValue = definition.settings.dropdownItems[i].name; trueValue = definition.settings.dropdownItems[i].name;
} }