mirror of
https://github.com/apache/superset.git
synced 2024-09-12 16:49:40 -04:00
Cleanup around multiple select fields
This commit is contained in:
parent
08fd4d1258
commit
f4e4c529a0
@ -21,7 +21,7 @@ class BetterBooleanField(BooleanField):
|
|||||||
return widgets.HTMLString(html)
|
return widgets.HTMLString(html)
|
||||||
|
|
||||||
|
|
||||||
class BetterSelectMultipleField(SelectMultipleField):
|
class SelectMultipleSortableField(SelectMultipleField):
|
||||||
"""
|
"""
|
||||||
Works along with select2sortable to preserves the sort order
|
Works along with select2sortable to preserves the sort order
|
||||||
"""
|
"""
|
||||||
@ -37,6 +37,28 @@ class BetterSelectMultipleField(SelectMultipleField):
|
|||||||
yield d.pop(d.keys()[0])
|
yield d.pop(d.keys()[0])
|
||||||
|
|
||||||
|
|
||||||
|
class FreeFormSelect(widgets.Select):
|
||||||
|
def __call__(self, field, **kwargs):
|
||||||
|
kwargs.setdefault('id', field.id)
|
||||||
|
if self.multiple:
|
||||||
|
kwargs['multiple'] = True
|
||||||
|
html = ['<select %s>' % widgets.html_params(name=field.name, **kwargs)]
|
||||||
|
found = False
|
||||||
|
for val, label, selected in field.iter_choices():
|
||||||
|
html.append(self.render_option(val, label, selected))
|
||||||
|
if field.data and val == field.data:
|
||||||
|
found = True
|
||||||
|
if not found:
|
||||||
|
html.insert(1, self.render_option(field.data, field.data, True))
|
||||||
|
html.append('</select>')
|
||||||
|
return widgets.HTMLString(''.join(html))
|
||||||
|
|
||||||
|
class FreeFormSelectField(SelectField):
|
||||||
|
widget = FreeFormSelect()
|
||||||
|
def pre_validate(self, form):
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
class OmgWtForm(Form):
|
class OmgWtForm(Form):
|
||||||
fieldsets = {}
|
fieldsets = {}
|
||||||
css_classes = dict()
|
css_classes = dict()
|
||||||
@ -53,6 +75,12 @@ class OmgWtForm(Form):
|
|||||||
class FormFactory(object):
|
class FormFactory(object):
|
||||||
row_limits = [10, 50, 100, 500, 1000, 5000, 10000, 50000]
|
row_limits = [10, 50, 100, 500, 1000, 5000, 10000, 50000]
|
||||||
series_limits = [0, 5, 10, 25, 50, 100, 500]
|
series_limits = [0, 5, 10, 25, 50, 100, 500]
|
||||||
|
fieltype_class = {
|
||||||
|
SelectField: 'select2',
|
||||||
|
SelectMultipleField: 'select2',
|
||||||
|
FreeFormSelectField: 'select2_freeform',
|
||||||
|
SelectMultipleSortableField: 'select2Sortable',
|
||||||
|
}
|
||||||
|
|
||||||
def __init__(self, viz):
|
def __init__(self, viz):
|
||||||
self.viz = viz
|
self.viz = viz
|
||||||
@ -69,7 +97,7 @@ class FormFactory(object):
|
|||||||
default='table',
|
default='table',
|
||||||
choices=[(k, v.verbose_name) for k, v in viz_types.items()],
|
choices=[(k, v.verbose_name) for k, v in viz_types.items()],
|
||||||
description="The type of visualization to display"),
|
description="The type of visualization to display"),
|
||||||
'metrics': BetterSelectMultipleField(
|
'metrics': SelectMultipleSortableField(
|
||||||
'Metrics', choices=datasource.metrics_combo,
|
'Metrics', choices=datasource.metrics_combo,
|
||||||
default=[default_metric],
|
default=[default_metric],
|
||||||
description="One or many metrics to display"),
|
description="One or many metrics to display"),
|
||||||
@ -81,16 +109,27 @@ class FormFactory(object):
|
|||||||
'Color Metric', choices=datasource.metrics_combo,
|
'Color Metric', choices=datasource.metrics_combo,
|
||||||
default=default_metric,
|
default=default_metric,
|
||||||
description="A metric to use for color"),
|
description="A metric to use for color"),
|
||||||
'groupby': BetterSelectMultipleField(
|
'groupby': SelectMultipleSortableField(
|
||||||
'Group by',
|
'Group by',
|
||||||
choices=self.choicify(datasource.groupby_column_names),
|
choices=self.choicify(datasource.groupby_column_names),
|
||||||
description="One or many fields to group by"),
|
description="One or many fields to group by"),
|
||||||
'columns': SelectMultipleField(
|
'columns': SelectMultipleSortableField(
|
||||||
'Columns',
|
'Columns',
|
||||||
choices=self.choicify(datasource.groupby_column_names),
|
choices=self.choicify(datasource.groupby_column_names),
|
||||||
description="One or many fields to pivot as columns"),
|
description="One or many fields to pivot as columns"),
|
||||||
'granularity': TextField(
|
'granularity': FreeFormSelectField(
|
||||||
'Time Granularity', default="one day",
|
'Time Granularity', default="one day",
|
||||||
|
choices=self.choicify([
|
||||||
|
'all',
|
||||||
|
'5 seconds',
|
||||||
|
'30 seconds',
|
||||||
|
'1 minute',
|
||||||
|
'5 minutes',
|
||||||
|
'1 hour',
|
||||||
|
'6 hour',
|
||||||
|
'1 day',
|
||||||
|
'7 days',
|
||||||
|
]),
|
||||||
description=(
|
description=(
|
||||||
"The time granularity for the visualization. Note that you "
|
"The time granularity for the visualization. Note that you "
|
||||||
"can type and use simple natural language as in '10 seconds', "
|
"can type and use simple natural language as in '10 seconds', "
|
||||||
@ -102,11 +141,29 @@ class FormFactory(object):
|
|||||||
"The time granularity for the visualization. Note that you "
|
"The time granularity for the visualization. Note that you "
|
||||||
"can define arbitrary expression that return a DATETIME "
|
"can define arbitrary expression that return a DATETIME "
|
||||||
"column in the table editor")),
|
"column in the table editor")),
|
||||||
'since': TextField(
|
'since': FreeFormSelectField(
|
||||||
'Since', default="7 days ago", description=(
|
'Since', default="7 days ago",
|
||||||
|
choices=self.choicify([
|
||||||
|
'1 hour ago',
|
||||||
|
'12 hours ago',
|
||||||
|
'1 day ago',
|
||||||
|
'7 days ago',
|
||||||
|
'28 days ago',
|
||||||
|
'90 days ago',
|
||||||
|
'1 year ago'
|
||||||
|
]),
|
||||||
|
description=(
|
||||||
"Timestamp from filter. This supports free form typing and "
|
"Timestamp from filter. This supports free form typing and "
|
||||||
"natural language as in '1 day ago', '28 days' or '3 years'")),
|
"natural language as in '1 day ago', '28 days' or '3 years'")),
|
||||||
'until': TextField('Until', default="now"),
|
'until': FreeFormSelectField('Until', default="now",
|
||||||
|
choices=self.choicify([
|
||||||
|
'now',
|
||||||
|
'1 day ago',
|
||||||
|
'7 days ago',
|
||||||
|
'28 days ago',
|
||||||
|
'90 days ago',
|
||||||
|
'1 year ago'])
|
||||||
|
),
|
||||||
'row_limit':
|
'row_limit':
|
||||||
SelectField(
|
SelectField(
|
||||||
'Row limit',
|
'Row limit',
|
||||||
@ -262,26 +319,15 @@ class FormFactory(object):
|
|||||||
px_form_fields = self.field_dict
|
px_form_fields = self.field_dict
|
||||||
viz = self.viz
|
viz = self.viz
|
||||||
datasource = viz.datasource
|
datasource = viz.datasource
|
||||||
field_css_classes = {k: ['form-control'] for k in px_form_fields.keys()}
|
field_css_classes = {}
|
||||||
select2 = [
|
for name, obj in px_form_fields.iteritems():
|
||||||
'viz_type',
|
field_css_classes[name] = ['form-control']
|
||||||
'viz_type', 'columns', 'pandas_aggfunc',
|
s = self.fieltype_class.get(obj.field_class)
|
||||||
'row_limit', 'rolling_type', 'series',
|
if s:
|
||||||
'entity', 'x', 'y', 'size', 'rotation', 'metric', 'limit',
|
field_css_classes[name] += [s]
|
||||||
'markup_type',]
|
|
||||||
select2Sortable = [
|
|
||||||
'metrics', 'groupby'
|
|
||||||
]
|
|
||||||
field_css_classes['since'] += ['select2_free_since']
|
|
||||||
field_css_classes['until'] += ['select2_free_until']
|
|
||||||
field_css_classes['granularity'] += ['select2_free_granularity']
|
|
||||||
|
|
||||||
for field in ('show_brush', 'show_legend', 'rich_tooltip'):
|
for field in ('show_brush', 'show_legend', 'rich_tooltip'):
|
||||||
field_css_classes[field] += ['input-sm']
|
field_css_classes[field] += ['input-sm']
|
||||||
for field in select2:
|
|
||||||
field_css_classes[field] += ['select2']
|
|
||||||
for field in select2Sortable:
|
|
||||||
field_css_classes[field] += ['select2Sortable']
|
|
||||||
|
|
||||||
class QueryForm(OmgWtForm):
|
class QueryForm(OmgWtForm):
|
||||||
fieldsets = copy(viz.fieldsetizer())
|
fieldsets = copy(viz.fieldsetizer())
|
||||||
|
@ -29,6 +29,7 @@ function initializeDatasourceView() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$(".select2").select2();
|
$(".select2").select2();
|
||||||
|
$(".select2Sortable").select2();
|
||||||
$(".select2Sortable").select2Sortable();
|
$(".select2Sortable").select2Sortable();
|
||||||
$("form").show();
|
$("form").show();
|
||||||
$('[data-toggle="tooltip"]').tooltip({container: 'body'});
|
$('[data-toggle="tooltip"]').tooltip({container: 'body'});
|
||||||
@ -114,45 +115,27 @@ function initializeDatasourceView() {
|
|||||||
}
|
}
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
$(".select2_free_since").select2({
|
$(".select2_freeform").each(function(){
|
||||||
createSearchChoice: create_choices,
|
parent = $(this).parent();
|
||||||
initSelection: initSelectionToValue,
|
var name = $(this).attr('name');
|
||||||
multiple: false,
|
var l = [];
|
||||||
data: list_data([
|
var selected = '';
|
||||||
'1 hour ago',
|
for(var i=0; i<this.options.length; i++) {
|
||||||
'12 hours ago',
|
l.push({id: this.options[i].value, text: this.options[i].text});
|
||||||
'1 day ago',
|
if(this.options[i].selected){
|
||||||
'7 days ago',
|
selected = this.options[i].value;
|
||||||
'28 days ago',
|
}
|
||||||
'90 days ago',
|
}
|
||||||
'1 year ago'])
|
obj = parent.append(
|
||||||
});
|
'<input class="' + $(this).attr('class') + '" name="'+ name +'" type="text" value="' + selected + '">');
|
||||||
$(".select2_free_until").select2({
|
$("input[name='" + name +"']")
|
||||||
createSearchChoice: create_choices,
|
.select2({
|
||||||
initSelection: initSelectionToValue,
|
createSearchChoice: create_choices,
|
||||||
multiple: false,
|
initSelection: initSelectionToValue,
|
||||||
data: list_data([
|
multiple: false,
|
||||||
'now',
|
data: l,
|
||||||
'1 day ago',
|
});
|
||||||
'7 days ago',
|
$(this).remove();
|
||||||
'28 days ago',
|
|
||||||
'90 days ago',
|
|
||||||
'1 year ago'])
|
|
||||||
});
|
|
||||||
$(".select2_free_granularity").select2({
|
|
||||||
createSearchChoice: create_choices,
|
|
||||||
initSelection: initSelectionToValue,
|
|
||||||
multiple: false,
|
|
||||||
data: list_data([
|
|
||||||
'all',
|
|
||||||
'5 seconds',
|
|
||||||
'30 seconds',
|
|
||||||
'1 minute',
|
|
||||||
'5 minutes',
|
|
||||||
'1 hour',
|
|
||||||
'6 hour',
|
|
||||||
'1 day',
|
|
||||||
'7 days'])
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,7 +39,13 @@ function viz_sunburst(data_attribute) {
|
|||||||
.outerRadius(function(d) { return Math.sqrt(d.y + d.dy); });
|
.outerRadius(function(d) { return Math.sqrt(d.y + d.dy); });
|
||||||
|
|
||||||
var ext;
|
var ext;
|
||||||
d3.json(data_attribute.json_endpoint, function(json){
|
d3.json(data_attribute.json_endpoint, function(error, json){
|
||||||
|
|
||||||
|
if (error != null){
|
||||||
|
var err = '<div class="alert alert-danger">' + error.responseText + '</div>';
|
||||||
|
token.html(err);
|
||||||
|
return '';
|
||||||
|
}
|
||||||
var tree = buildHierarchy(json.data);
|
var tree = buildHierarchy(json.data);
|
||||||
createVisualization(tree);
|
createVisualization(tree);
|
||||||
token.select("img.loading").remove();
|
token.select("img.loading").remove();
|
||||||
|
Loading…
Reference in New Issue
Block a user