Add support for Buefy datepicker in grid filters
This commit is contained in:
parent
0f0b32d797
commit
d5d04b7dac
|
@ -973,6 +973,7 @@ class Grid(object):
|
||||||
'verb_labels': filtr.verb_labels,
|
'verb_labels': filtr.verb_labels,
|
||||||
'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,
|
||||||
}
|
}
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
|
@ -52,6 +52,7 @@ class FilterValueRenderer(object):
|
||||||
"""
|
"""
|
||||||
Base class for all filter renderers.
|
Base class for all filter renderers.
|
||||||
"""
|
"""
|
||||||
|
data_type = 'string'
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
|
@ -75,6 +76,8 @@ class NumericValueRenderer(FilterValueRenderer):
|
||||||
"""
|
"""
|
||||||
Input renderer for numeric values.
|
Input renderer for numeric values.
|
||||||
"""
|
"""
|
||||||
|
# TODO
|
||||||
|
# data_type = 'number'
|
||||||
|
|
||||||
def render(self, value=None, **kwargs):
|
def render(self, value=None, **kwargs):
|
||||||
kwargs.setdefault('step', '0.001')
|
kwargs.setdefault('step', '0.001')
|
||||||
|
@ -85,6 +88,7 @@ class DateValueRenderer(FilterValueRenderer):
|
||||||
"""
|
"""
|
||||||
Input renderer for date values.
|
Input renderer for date values.
|
||||||
"""
|
"""
|
||||||
|
data_type = 'date'
|
||||||
|
|
||||||
def render(self, value=None, **kwargs):
|
def render(self, value=None, **kwargs):
|
||||||
kwargs['data-datepicker'] = 'true'
|
kwargs['data-datepicker'] = 'true'
|
||||||
|
@ -143,6 +147,7 @@ class GridFilter(object):
|
||||||
'is_me', 'is_not_me']
|
'is_me', 'is_not_me']
|
||||||
|
|
||||||
value_renderer_factory = DefaultValueRenderer
|
value_renderer_factory = DefaultValueRenderer
|
||||||
|
data_type = 'string' # default, but will be set from value renderer
|
||||||
|
|
||||||
def __init__(self, key, label=None, verbs=None, value_enum=None, value_renderer=None,
|
def __init__(self, key, label=None, verbs=None, value_enum=None, value_renderer=None,
|
||||||
default_active=False, default_verb=None, default_value=None,
|
default_active=False, default_verb=None, default_value=None,
|
||||||
|
@ -189,6 +194,7 @@ class GridFilter(object):
|
||||||
renderer = renderer()
|
renderer = renderer()
|
||||||
renderer.filter = self
|
renderer.filter = self
|
||||||
self.value_renderer = renderer
|
self.value_renderer = renderer
|
||||||
|
self.data_type = renderer.data_type
|
||||||
|
|
||||||
def filter(self, data, verb=None, value=UNSPECIFIED):
|
def filter(self, data, verb=None, value=UNSPECIFIED):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -11,7 +11,8 @@ const TailboneDatepicker = {
|
||||||
'icon="calendar-alt"',
|
'icon="calendar-alt"',
|
||||||
':date-formatter="formatDate"',
|
':date-formatter="formatDate"',
|
||||||
':date-parser="parseDate"',
|
':date-parser="parseDate"',
|
||||||
':value="rawValue ? parseDate(rawValue) : null"',
|
':value="value ? parseDate(value) : null"',
|
||||||
|
'@input="dateChanged"',
|
||||||
'>',
|
'>',
|
||||||
'</b-datepicker>'
|
'</b-datepicker>'
|
||||||
].join(' '),
|
].join(' '),
|
||||||
|
@ -19,7 +20,7 @@ const TailboneDatepicker = {
|
||||||
props: {
|
props: {
|
||||||
name: String,
|
name: String,
|
||||||
id: String,
|
id: String,
|
||||||
rawValue: String
|
value: String
|
||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
|
@ -39,6 +40,11 @@ const TailboneDatepicker = {
|
||||||
// note, this assumes classic YYYY-MM-DD (i.e. ISO?) format
|
// note, this assumes classic YYYY-MM-DD (i.e. ISO?) format
|
||||||
var parts = date.split('-')
|
var parts = date.split('-')
|
||||||
return new Date(parts[0], parseInt(parts[1]) - 1, parts[2])
|
return new Date(parts[0], parseInt(parts[1]) - 1, parts[2])
|
||||||
|
},
|
||||||
|
|
||||||
|
dateChanged(date) {
|
||||||
|
this.value = this.formatDate(date)
|
||||||
|
this.$emit('input', this.value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,7 @@
|
||||||
${field.start_mapping()}
|
${field.start_mapping()}
|
||||||
<tailbone-datepicker name="date"
|
<tailbone-datepicker name="date"
|
||||||
id="${oid}"
|
id="${oid}"
|
||||||
raw-value="${cstruct}">
|
value="${cstruct}">
|
||||||
</tailbone-datepicker>
|
</tailbone-datepicker>
|
||||||
${field.end_mapping()}
|
${field.end_mapping()}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -28,7 +28,16 @@
|
||||||
</option>
|
</option>
|
||||||
</b-select>
|
</b-select>
|
||||||
|
|
||||||
<b-input v-model="filter.value"
|
## only one of the following "value input" elements will be rendered
|
||||||
|
|
||||||
|
<tailbone-datepicker v-if="filter.data_type == 'date'"
|
||||||
|
v-model="filter.value"
|
||||||
|
v-show="! (filter.valueless_verbs && filter.valueless_verbs.includes(filter.verb))"
|
||||||
|
ref="valueInput">
|
||||||
|
</tailbone-datepicker>
|
||||||
|
|
||||||
|
<b-input v-if="filter.data_type == 'string'"
|
||||||
|
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))"
|
||||||
ref="valueInput">
|
ref="valueInput">
|
||||||
</b-input>
|
</b-input>
|
||||||
|
|
Loading…
Reference in a new issue