diff --git a/rd_service/server.py b/rd_service/server.py index 75fcbf16b..dbeef29ee 100644 --- a/rd_service/server.py +++ b/rd_service/server.py @@ -269,7 +269,7 @@ class VisualizationHandler(BaseAuthenticatedHandler): vis = data.models.Visualization(**kwargs) vis.save() - self.write_json(vis.to_dict()) + self.write_json(vis.to_dict(with_query=False)) class CsvQueryResultsHandler(BaseAuthenticatedHandler): diff --git a/rd_ui/app/scripts/controllers.js b/rd_ui/app/scripts/controllers.js index 24540519c..725e0bd2a 100644 --- a/rd_ui/app/scripts/controllers.js +++ b/rd_ui/app/scripts/controllers.js @@ -33,12 +33,14 @@ $scope.updateTime = ''; } - var QueryFiddleCtrl = function ($scope, $window, $routeParams, $http, $location, growl, notifications, Query) { + var QueryFiddleCtrl = function ($scope, $window, $location, $routeParams, $http, $location, growl, notifications, Query) { + var DEFAULT_TAB = 'table'; var pristineHash = null; - $scope.dirty = undefined; - var leavingPageText = "You will lose your changes if you leave"; + $scope.dirty = undefined; + $scope.newVisualization = undefined; + $window.onbeforeunload = function(){ if (currentUser.canEdit($scope.query) && $scope.dirty) { return leavingPageText; @@ -72,11 +74,9 @@ $scope.$parent.pageTitle = "Query Fiddle"; - // more tabs added when query loads - $scope.tabs = [{'key': 'table', 'name': 'Table'}, - {'key': 'pivot', 'name': 'Pivot Table'}, - {'key': 'add', 'name': 'New Visualization'}]; - + $scope.$watch(function() {return $location.hash()}, function(hash) { + $scope.selectedTab = hash || DEFAULT_TAB; + }); $scope.lockButton = function (lock) { $scope.queryExecuting = lock; @@ -194,11 +194,6 @@ pristineHash = q.getHash(); $scope.dirty = false; $scope.queryResult = $scope.query.getQueryResult(); - - _.each(q.visualizations, function(vis) { - $scope.tabs.splice(-1, 0, {'key': 'vis' + vis.id, 'name': vis.name}); - }); - }); } else { $scope.query = new Query({query: "", name: "New Query", ttl: -1, user: currentUser.name}); @@ -381,7 +376,7 @@ .controller('DashboardCtrl', ['$scope', '$routeParams', '$http', 'Dashboard', DashboardCtrl]) .controller('WidgetCtrl', ['$scope', '$http', '$location', 'Query', WidgetCtrl]) .controller('QueriesCtrl', ['$scope', '$http', '$location', '$filter', 'Query', QueriesCtrl]) - .controller('QueryFiddleCtrl', ['$scope', '$window', '$routeParams', '$http', '$location', 'growl', 'notifications', 'Query', QueryFiddleCtrl]) + .controller('QueryFiddleCtrl', ['$scope', '$window', '$location', '$routeParams', '$http', '$location', 'growl', 'notifications', 'Query', QueryFiddleCtrl]) .controller('IndexCtrl', ['$scope', 'Dashboard', IndexCtrl]) .controller('MainCtrl', ['$scope', 'Dashboard', 'notifications', MainCtrl]); })(); diff --git a/rd_ui/app/scripts/directives.js b/rd_ui/app/scripts/directives.js index ebe99bdc7..ca0a955ff 100644 --- a/rd_ui/app/scripts/directives.js +++ b/rd_ui/app/scripts/directives.js @@ -3,6 +3,23 @@ var directives = angular.module('redash.directives', []); + directives.directive('rdTab', ['$location', function($location) { + return { + restrict: 'E', + scope: { + 'id': '@', + 'name': '@' + }, + template: '