mirror of
https://github.com/valitydev/redash.git
synced 2024-11-08 09:53:59 +00:00
Merge pull request #83 from EverythingMe/viz
Visualization Followups + workers bugfix
This commit is contained in:
commit
42a0659012
@ -153,12 +153,12 @@ class Manager(object):
|
||||
def start_workers(self, workers_count, connection_string):
|
||||
if self.workers:
|
||||
return self.workers
|
||||
|
||||
if settings.CONNECTION_ADAPTER == "mysql":
|
||||
import query_runner_mysql
|
||||
|
||||
if getattr(settings, 'CONNECTION_ADAPTER', None) == "mysql":
|
||||
import query_runner_mysql
|
||||
runner = query_runner_mysql.mysql(connection_string)
|
||||
else:
|
||||
import query_runner
|
||||
import query_runner
|
||||
runner = query_runner.redshift(connection_string)
|
||||
|
||||
redis_connection_params = self.redis_connection.connection_pool.connection_kwargs
|
||||
|
@ -51,6 +51,12 @@ class Query(models.Model):
|
||||
app_label = 'redash'
|
||||
db_table = 'queries'
|
||||
|
||||
def create_default_visualizations(self):
|
||||
table_visualization = Visualization(query=self, name="Table",
|
||||
description=self.description,
|
||||
type="TABLE", options="{}")
|
||||
table_visualization.save()
|
||||
|
||||
def to_dict(self, with_result=True, with_stats=False,
|
||||
with_visualizations=False):
|
||||
d = {
|
||||
|
@ -17,36 +17,51 @@ from data.models import *
|
||||
# ALTER TABLE widgets ADD COLUMN "visualization_id" integer REFERENCES "visualizations" ("id") DEFERRABLE INITIALLY DEFERRED;
|
||||
|
||||
if __name__ == '__main__':
|
||||
print 'migrating Widgets -> Visualizations ...'
|
||||
|
||||
default_options = {"series": {"type": "bar"}}
|
||||
|
||||
# create 'table' visualization for all queries
|
||||
print 'creating TABLE visualizations ...'
|
||||
for query in Query.objects.all():
|
||||
vis = Visualization(query=query, name="Table",
|
||||
description=query.description,
|
||||
type="TABLE", options="{}")
|
||||
vis.save()
|
||||
|
||||
|
||||
# create 'cohort' visualization for all queries named with 'cohort'
|
||||
print 'creating COHORT visualizations ...'
|
||||
for query in Query.objects.filter(name__icontains="cohort"):
|
||||
vis = Visualization(query=query, name=query.name,
|
||||
vis = Visualization(query=query, name="Cohort",
|
||||
description=query.description,
|
||||
type="COHORT", options="{}")
|
||||
vis.save()
|
||||
|
||||
|
||||
# create visualization for every widget (unless it already exists)
|
||||
print 'migrating Widgets -> Visualizations ...'
|
||||
for widget in Widget.objects.all():
|
||||
print 'processing widget %d' % widget.id
|
||||
print 'processing widget %d:' % widget.id,
|
||||
query = widget.query
|
||||
vis_type = widget.type.upper()
|
||||
|
||||
vis = query.visualizations.filter(type=vis_type)
|
||||
if vis:
|
||||
print 'found'
|
||||
print 'visualization exists'
|
||||
widget.visualization = vis[0]
|
||||
widget.save()
|
||||
|
||||
else:
|
||||
vis_name = widget.type.title()
|
||||
|
||||
options = json.loads(widget.options)
|
||||
vis_options = {"series": options} if options else default_options
|
||||
vis_options = json.dumps(vis_options)
|
||||
|
||||
vis = Visualization(query=query, name=query.name,
|
||||
description=query.description,
|
||||
type=vis_type, options=vis_options)
|
||||
vis = Visualization(query=query, name=vis_name,
|
||||
description=query.description,
|
||||
type=vis_type, options=vis_options)
|
||||
|
||||
print 'created visualization %s' % vis_type
|
||||
vis.save()
|
||||
widget.visualization = vis
|
||||
widget.save()
|
@ -215,6 +215,7 @@ class QueriesHandler(BaseAuthenticatedHandler):
|
||||
query_def['user'] = self.current_user
|
||||
query = data.models.Query(**query_def)
|
||||
query.save()
|
||||
query.create_default_visualizations()
|
||||
|
||||
self.write_json(query.to_dict(with_result=False))
|
||||
|
||||
|
@ -59,8 +59,7 @@
|
||||
scope.advancedMode = false;
|
||||
scope.visTypes = {
|
||||
'Chart': Visualization.prototype.TYPES.CHART,
|
||||
'Cohort': Visualization.prototype.TYPES.COHORT,
|
||||
'Table': Visualization.prototype.TYPES.GRID
|
||||
'Cohort': Visualization.prototype.TYPES.COHORT
|
||||
};
|
||||
scope.seriesTypes = {
|
||||
'Line': Visualization.prototype.SERIES_TYPES.LINE,
|
||||
@ -77,7 +76,7 @@
|
||||
scope.vis = {
|
||||
'query_id': q.id,
|
||||
'type': Visualization.prototype.TYPES.CHART,
|
||||
'name': q.name,
|
||||
'name': '',
|
||||
'description': q.description,
|
||||
'options': newOptions()
|
||||
};
|
||||
@ -99,6 +98,14 @@
|
||||
};
|
||||
}
|
||||
|
||||
scope.$watch('vis.type', function(type) {
|
||||
// if not edited by user, set name to match type
|
||||
if (type && scope.vis && !scope.visForm.name.$dirty) {
|
||||
// poor man's titlecase
|
||||
scope.vis.name = scope.vis.type[0] + scope.vis.type.slice(1).toLowerCase();
|
||||
}
|
||||
});
|
||||
|
||||
scope.toggleAdvancedMode = function() {
|
||||
scope.advancedMode = !scope.advancedMode;
|
||||
};
|
||||
@ -244,10 +251,6 @@
|
||||
|
||||
reset();
|
||||
|
||||
$scope.toggleView = function(viewName) {
|
||||
$scope.currentView = ($scope.currentView == viewName) ? '' : viewName;
|
||||
};
|
||||
|
||||
$scope.loadVisualizations = function() {
|
||||
if (!$scope.queryId) {
|
||||
return;
|
||||
|
@ -9,7 +9,6 @@ renderers.directive('visualizationRenderer', function() {
|
||||
},
|
||||
template: '<div ng-switch on="visualization.type">' +
|
||||
'<chart-renderer ng-switch-when="CHART" options="visualization.options" query-result="queryResult"></chart-renderer>' +
|
||||
'<grid-renderer ng-switch-when="GRID" options="visualization.options" query-result="queryResult"></grid-renderer>' +
|
||||
'<cohort-renderer ng-switch-when="COHORT" options="visualization.options" query-result="queryResult"></cohort-renderer>' +
|
||||
'</div>',
|
||||
replace: false
|
||||
|
@ -290,7 +290,7 @@
|
||||
TYPES: {
|
||||
'CHART': 'CHART',
|
||||
'COHORT': 'COHORT',
|
||||
'GRID': 'GRID'
|
||||
'TABLE': 'TABLE'
|
||||
},
|
||||
SERIES_TYPES: {
|
||||
'LINE': 'line',
|
||||
|
@ -1,12 +1,7 @@
|
||||
<form role="form" name="visForm" ng-submit="submit()">
|
||||
<div class="form-group">
|
||||
<label class="control-label">Name</label>
|
||||
<input type="text" class="form-control" ng-model="vis.name" placeholder="{{query.name}}">
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="control-label">Description</label>
|
||||
<textarea class="form-control" ng-model="vis.description" placeholder="{{query.description}}"></textarea>
|
||||
<input name="name" type="text" class="form-control" ng-model="vis.name" placeholder="{{vis.type}}">
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
@ -19,11 +14,6 @@
|
||||
<select required ng-model="vis.options.series.type" ng-options="value as key for (key, value) in seriesTypes" class="form-control"></select>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<a class="link" ng-click="toggleAdvancedMode()">Advanced</a>
|
||||
<textarea json-text class="form-control" rows="5" ng-model="vis.options" ng-show="advancedMode"></textarea>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<button type="submit" class="btn btn-primary">Save</button>
|
||||
</div>
|
||||
|
@ -23,13 +23,6 @@
|
||||
<select ng-model="selectedVis" ng-options="vis as vis.name group by vis.type for vis in query.visualizations" class="form-control"></select>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<a ng-click="toggleView('addNew')" class="link">+ Add New</a>
|
||||
<div class="well" ng-show="currentView=='addNew'">
|
||||
<edit-visulatization-form query="query"></edit-visulatization-form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="">Widget Size</label>
|
||||
<select class="form-control" ng-model="widgetSize" ng-options="c.value as c.name for c in widgetSizes"></select>
|
||||
|
@ -54,7 +54,8 @@
|
||||
<ul class="nav nav-tabs">
|
||||
<rd-tab id="table" name="Table"></rd-tab>
|
||||
<rd-tab id="pivot" name="Pivot Table"></rd-tab>
|
||||
<rd-tab id="{{vis.id}}" name="{{vis.name}}" ng-repeat="vis in query.visualizations">
|
||||
<!-- hide the table visualization -->
|
||||
<rd-tab id="{{vis.id}}" name="{{vis.name}}" ng-hide="vis.type=='TABLE'" ng-repeat="vis in query.visualizations">
|
||||
<span class="remove" ng-click="deleteVisualization($event, vis)"> ×</span>
|
||||
</rd-tab>
|
||||
<rd-tab id="add" name="+New" removeable="true"></rd-tab>
|
||||
@ -83,7 +84,7 @@
|
||||
|
||||
<div class="col-lg-12" ng-show="selectedTab == 'add'">
|
||||
<div class="row">
|
||||
<p>
|
||||
<p>
|
||||
<div class="col-lg-6">
|
||||
<edit-visulatization-form vis="newVisualization" query="query"></edit-visulatization-form>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user