This commit is contained in:
humancopy 2020-08-07 18:59:07 -03:00 committed by GitHub
commit 9b1bba0b6e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 76 additions and 10 deletions

View file

@ -156,7 +156,8 @@ module.exports.get = (id, callback) => {
rule.formatted = rule.value.value ? _('Selected') : _('Not selected'); rule.formatted = rule.value.value ? _('Selected') : _('Not selected');
break; break;
default: 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; return rule;
@ -491,10 +492,17 @@ module.exports.updateRule = (id, rule, callback) => {
}; };
break; break;
default: default:
value = { if (rule.multiple) {
negate: Number(rule.negate) ? 1 : 0, value = {
value: rule.value multiple: true,
}; list: rule.list
};
} else {
value = {
value: rule.value
};
}
value.negate = Number(rule.negate) ? true : false;
} }
let keys = ['value']; let keys = ['value'];
@ -575,9 +583,21 @@ module.exports.getQuery = (id, prefix, callback) => {
segment.rules.forEach(rule => { segment.rules.forEach(rule => {
switch (rule.columnType.type) { switch (rule.columnType.type) {
case 'string': { case 'string': {
let condition = rule.value.negate ? 'NOT LIKE' : 'LIKE'; let condition, query_val;
query.push(prefix + '`' + rule.columnType.column + '` ' + condition + ' ?'); if (rule.value.multiple) {
values.push(rule.value.value); 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; break;
} }
case 'boolean': case 'boolean':

View file

@ -39,11 +39,34 @@
<div class="form-group"> <div class="form-group">
<label for="value" class="col-sm-2 control-label">{{#translate}}Value{{/translate}}</label> <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}}"> <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> <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> </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}}
{{#if columnTypeNumber}} {{#if columnTypeNumber}}

View file

@ -44,11 +44,34 @@
<div class="form-group"> <div class="form-group">
<label for="value" class="col-sm-2 control-label">{{#translate}}Value{{/translate}}</label> <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}}"> <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> <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> </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}}
{{#if columnTypeNumber}} {{#if columnTypeNumber}}