handle type ["integer"] in url and fix inbetween vs ["integer"] filter

This commit is contained in:
j 2023-07-06 11:52:36 +05:30
parent b0c0bd36be
commit b7c201a74f
2 changed files with 32 additions and 19 deletions

View file

@ -683,15 +683,21 @@ Ox.URL = function(options) {
condition.operator = condition.operator.replace('=', '^')
}
}
var key = Ox.getObjectById(self.options.findKeys[state.type], condition.key)
if (
['date', 'enum', 'float', 'integer', 'time', 'year'].indexOf(
Ox.getObjectById(self.options.findKeys[state.type], condition.key).type
) > -1
['date', 'enum', 'float', 'integer', 'time', 'year'].indexOf(key.type) > -1
&& condition.value.indexOf(',') > -1
) {
condition.value = condition.value.split(',').map(function(value) {
return parseValue(decodeValue(value), condition.key, state);
});
} else if (Ox.isArray(key.type) && key.type[0] == "integer" && condition.value.indexOf(',') > -1) {
condition.value = condition.value.split(',').map(function(value) {
return parseValue(decodeValue(value), condition.key, state);
});
if (condition.value.length == 4) {
condition.value = [condition.value.slice(0,2), condition.value.slice(2)]
}
} else {
condition.value = parseValue(decodeValue(condition.value), condition.key, state);
}

View file

@ -355,6 +355,13 @@ Ox.Filter = function(options, self) {
}
}
function isBetweenCondition(condition) {
if (condition.key == "resolution") {
return Ox.isArray(condition.value) && Ox.isArray(condition.value[0])
}
return Ox.isArray(condition.value)
}
function changeConditionOperator(pos, subpos, operator) {
subpos = Ox.isUndefined(subpos) ? -1 : subpos;
Ox.Log('FILTER', 'chCoOp', 'query', self.options.value)
@ -362,7 +369,7 @@ Ox.Filter = function(options, self) {
? self.options.value.conditions[pos]
: self.options.value.conditions[pos].conditions[subpos],
isBetween = operator.indexOf(',') > -1,
wasBetween = Ox.isArray(condition.value),
wasBetween = isBetweenCondition(condition),
wasUselessCondition = isUselessCondition(pos, subpos);
Ox.Log('FILTER', 'chCoOp', 'iB/wB', isBetween, wasBetween)
condition.operator = operator;
@ -577,7 +584,7 @@ Ox.Filter = function(options, self) {
Ox.getObjectById(self.options.findKeys, condition.key).type
)],
overlap: 'right',
value: condition.operator + (Ox.isArray(condition.value) ? ',' : ''),
value: condition.operator + (isBetweenCondition(condition) ? ',' : ''),
width: 128
})
.bindEvent({
@ -593,7 +600,7 @@ Ox.Filter = function(options, self) {
}
function renderConditionValue(condition) {
return (!Ox.isArray(condition.value)
return (!isBetweenCondition(condition)
? renderInput(condition)
: Ox.InputGroup({
inputs: [
@ -699,11 +706,11 @@ Ox.Filter = function(options, self) {
Ox.Log('Form', 'renderInput', condition)
var $input,
findKey = Ox.getObjectById(self.options.findKeys, condition.key),
isArray = Ox.isArray(condition.value),
isBetween = isBetweenCondition(condition),
isHue,
// FIXME: always use 'int'
type = findKey.type == 'integer' ? 'int' : findKey.type,
value = !isArray ? condition.value : condition.value[index],
value = !isBetween ? condition.value : condition.value[index],
formatArgs, formatType, title;
if (type == 'boolean') {
$input = Ox.Select({
@ -720,7 +727,7 @@ Ox.Filter = function(options, self) {
return {id: i, title: v}
}),
value: value,
width: !isArray ? 288 : 128
width: !isBetween ? 288 : 128
});
} else if (type == 'item') {
$input = Ox.Select({
@ -747,8 +754,8 @@ Ox.Filter = function(options, self) {
$input = Ox.Range({
max: isHue ? 360 : 1,
min: 0,
size: !isArray ? 288 : 128, // fixme: should be width!
width: !isArray ? 288 : 128, // have to set this too, for formatting when tuple
size: !isBetween ? 288 : 128, // fixme: should be width!
width: !isBetween ? 288 : 128, // have to set this too, for formatting when tuple
step: isHue ? 1 : 0.01,
thumbSize: 48,
thumbValue: true,
@ -761,7 +768,7 @@ Ox.Filter = function(options, self) {
value: value
});
} else if (formatType == 'date') {
$input = Ox.DateInput(!isArray ? {
$input = Ox.DateInput(!isBetween ? {
value: value,
width: {day: 66, month: 66, year: 140}
} : {
@ -769,7 +776,7 @@ Ox.Filter = function(options, self) {
width: {day: 32, month: 32, year: 48}
});
} else if (formatType == 'duration') {
$input = Ox.TimeInput(!isArray ? {
$input = Ox.TimeInput(!isBetween ? {
seconds: true,
value: value,
width: {hours: 91, minutes: 91, seconds: 90}
@ -796,16 +803,16 @@ Ox.Filter = function(options, self) {
Ox.Input({
id: 'width',
type: 'int',
value: value
value: value[0]
}),
Ox.Input({
id: 'height',
type: 'int',
value: value
value: value[1]
})
],
separators: [{title: 'x', width: 16}],
width: !isArray ? 288 : 128
width: !isBetween ? 288 : 128
})
} else if ([
'currency', 'percent', 'unit', 'value'
@ -816,7 +823,7 @@ Ox.Filter = function(options, self) {
Ox.Input({
type: type,
value: value,
width: !isArray ? 242 : 80
width: !isBetween ? 242 : 80
}),
formatType == 'value' ? Ox.Select({
overlap: 'left',
@ -840,7 +847,7 @@ Ox.Filter = function(options, self) {
split: function(value) {
},
width: !isArray ? 288 : 128
width: !isBetween ? 288 : 128
})
}
} else {
@ -850,7 +857,7 @@ Ox.Filter = function(options, self) {
autocomplete: findKey.autocomplete,
autocompleteSelect: true,
autocompleteSelectSubmit: true,
width: !isArray ? 288 : 128
width: !isBetween ? 288 : 128
});
}
return $input;