Add the possibility to query for a list of string values in segment rules
This commit is contained in:
parent
62e63fbb80
commit
ccb1ba1100
3 changed files with 76 additions and 10 deletions
|
@ -156,7 +156,8 @@ module.exports.get = (id, callback) => {
|
|||
rule.formatted = rule.value.value ? _('Selected') : _('Not selected');
|
||||
break;
|
||||
default:
|
||||
rule.formatted = (rule.value.negate ? '!= ' : '') + (rule.value.value || '');
|
||||
let value = rule.value.value || rule.value.list || '';
|
||||
rule.formatted = (rule.value.negate ? '!= ' : '') + value;
|
||||
}
|
||||
|
||||
return rule;
|
||||
|
@ -491,10 +492,17 @@ module.exports.updateRule = (id, rule, callback) => {
|
|||
};
|
||||
break;
|
||||
default:
|
||||
value = {
|
||||
negate: Number(rule.negate) ? 1 : 0,
|
||||
value: rule.value
|
||||
};
|
||||
if (rule.multiple) {
|
||||
value = {
|
||||
multiple: true,
|
||||
list: rule.list
|
||||
};
|
||||
} else {
|
||||
value = {
|
||||
value: rule.value
|
||||
};
|
||||
}
|
||||
value.negate = Number(rule.negate) ? true : false;
|
||||
}
|
||||
|
||||
let keys = ['value'];
|
||||
|
@ -575,9 +583,21 @@ module.exports.getQuery = (id, prefix, callback) => {
|
|||
segment.rules.forEach(rule => {
|
||||
switch (rule.columnType.type) {
|
||||
case 'string': {
|
||||
let condition = rule.value.negate ? 'NOT LIKE' : 'LIKE';
|
||||
query.push(prefix + '`' + rule.columnType.column + '` ' + condition + ' ?');
|
||||
values.push(rule.value.value);
|
||||
let condition, query_val;
|
||||
if (rule.value.multiple) {
|
||||
condition = rule.value.negate ? 'NOT IN' : 'IN';
|
||||
query_val = [];
|
||||
rule.value.list.split(/\s*,\s*/).forEach(value => {
|
||||
query_val.push('?');
|
||||
values.push(value);
|
||||
});
|
||||
query_val = '(' + query_val.join(',') + ')';
|
||||
} else {
|
||||
condition = rule.value.negate ? 'NOT LIKE' : 'LIKE';
|
||||
query_val = '?';
|
||||
values.push(rule.value.value);
|
||||
}
|
||||
query.push(prefix + '`' + rule.columnType.column + '` ' + condition + ' ' + query_val);
|
||||
break;
|
||||
}
|
||||
case 'boolean':
|
||||
|
|
|
@ -39,11 +39,34 @@
|
|||
|
||||
<div class="form-group">
|
||||
<label for="value" class="col-sm-2 control-label">{{#translate}}Value{{/translate}}</label>
|
||||
<div class="col-sm-10">
|
||||
<div class="col-sm-10 radio">
|
||||
<label>
|
||||
<input type="radio" name="multiple" value="" {{#unless value.multiple}} checked{{/unless}}> {{#translate}}Use single value{{/translate}}
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<div class="col-sm-offset-2 col-sm-10">
|
||||
<input type="text" class="form-control" name="value" id="value" value="{{value.value}}" placeholder="{{#translate}}Value{{/translate}}">
|
||||
<span class="help-block">{{#translate}}Use % for wildcard character, e.g. "%test" to match all values that end with "test"{{/translate}}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<div class="col-sm-offset-2 col-sm-10 radio">
|
||||
<label>
|
||||
<input type="radio" name="multiple" value="1" {{#if value.multiple}} checked{{/if}}> {{#translate}}Use multiple values{{/translate}}
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<div class="col-sm-offset-2 col-sm-10">
|
||||
<input type="text" class="form-control" name="list" id="list" value="{{value.list}}" placeholder="{{#translate}}List of comma separated values{{/translate}}">
|
||||
<span class="help-block">{{#translate}}Use a list of comma separated values, e.g. "test,try,exam" to match either "test", "try" or "exam"{{/translate}}</span>
|
||||
</div>
|
||||
</div>
|
||||
{{/if}}
|
||||
|
||||
{{#if columnTypeNumber}}
|
||||
|
|
|
@ -44,11 +44,34 @@
|
|||
|
||||
<div class="form-group">
|
||||
<label for="value" class="col-sm-2 control-label">{{#translate}}Value{{/translate}}</label>
|
||||
<div class="col-sm-10">
|
||||
<div class="col-sm-10 radio">
|
||||
<label>
|
||||
<input type="radio" name="multiple" value="" {{#unless value.multiple}} checked{{/unless}}> {{#translate}}Use single value{{/translate}}
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<div class="col-sm-offset-2 col-sm-10">
|
||||
<input type="text" class="form-control" name="value" id="value" value="{{value.value}}" placeholder="{{#translate}}Value{{/translate}}">
|
||||
<span class="help-block">{{#translate}}Use % for wildcard character, e.g. "%test" to match all values that end with "test"{{/translate}}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<div class="col-sm-offset-2 col-sm-10 radio">
|
||||
<label>
|
||||
<input type="radio" name="multiple" value="1" {{#if value.multiple}} checked{{/if}}> {{#translate}}Use multiple values{{/translate}}
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<div class="col-sm-offset-2 col-sm-10">
|
||||
<input type="text" class="form-control" name="list" id="list" value="{{value.list}}" placeholder="{{#translate}}List of comma separated values{{/translate}}">
|
||||
<span class="help-block">{{#translate}}Use a list of comma separated values, e.g. "test,try,exam" to match either "test", "try" or "exam"{{/translate}}</span>
|
||||
</div>
|
||||
</div>
|
||||
{{/if}}
|
||||
|
||||
{{#if columnTypeNumber}}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue