Add Buefy support for enum grid filters

This commit is contained in:
Lance Edgar 2019-05-21 18:40:08 -05:00
parent ef7b2ddbdd
commit be6a1d916f
3 changed files with 20 additions and 0 deletions

View file

@ -963,6 +963,12 @@ class Grid(object):
valueless = [v for v in filtr.valueless_verbs valueless = [v for v in filtr.valueless_verbs
if v in filtr.verbs] if v in filtr.verbs]
choices = []
choice_labels = {}
if self.enums and filtr.key in self.enums:
choices = list(self.enums[filtr.key])
choice_labels = self.enums[filtr.key]
data[filtr.key] = { data[filtr.key] = {
'key': filtr.key, 'key': filtr.key,
'label': filtr.label, 'label': filtr.label,
@ -974,6 +980,8 @@ class Grid(object):
'verb': filtr.verb or filtr.default_verb or filtr.verbs[0], 'verb': filtr.verb or filtr.default_verb or filtr.verbs[0],
'value': six.text_type(filtr.value) if filtr.value is not None else "", 'value': six.text_type(filtr.value) if filtr.value is not None else "",
'data_type': filtr.data_type, 'data_type': filtr.data_type,
'choices': choices,
'choice_labels': choice_labels,
} }
return data return data

View file

@ -99,6 +99,7 @@ class ChoiceValueRenderer(FilterValueRenderer):
""" """
Renders value input as a dropdown/selectmenu of available choices. Renders value input as a dropdown/selectmenu of available choices.
""" """
data_type = 'choice'
def __init__(self, options): def __init__(self, options):
self.options = options self.options = options

View file

@ -36,6 +36,17 @@
ref="valueInput"> ref="valueInput">
</tailbone-datepicker> </tailbone-datepicker>
<b-select v-if="filter.data_type == 'choice'"
v-model="filter.value"
v-show="! (filter.valueless_verbs && filter.valueless_verbs.includes(filter.verb))"
ref="valueInput">
<option v-for="choice in filter.choices"
:key="choice"
:value="choice">
{{ filter.choice_labels[choice] || choice }}
</option>
</b-select>
<b-input v-if="filter.data_type == 'string'" <b-input v-if="filter.data_type == 'string'"
v-model="filter.value" v-model="filter.value"
v-show="! (filter.valueless_verbs && filter.valueless_verbs.includes(filter.verb))" v-show="! (filter.valueless_verbs && filter.valueless_verbs.includes(filter.verb))"