From 42498391ceb245e0253587efb1d0d9fbe2b9ab43 Mon Sep 17 00:00:00 2001 From: Amir Nissim Date: Mon, 30 Dec 2013 14:31:23 +0200 Subject: [PATCH 1/3] Show error notification when saving a query fails (FED #1) --- rd_ui/app/scripts/app.js | 67 +++++++++++++++++++++++++------- rd_ui/app/scripts/controllers.js | 2 + rd_ui/app/styles/redash.css | 1 + 3 files changed, 56 insertions(+), 14 deletions(-) diff --git a/rd_ui/app/scripts/app.js b/rd_ui/app/scripts/app.js index 471cdd4e6e..9835d089b1 100644 --- a/rd_ui/app/scripts/app.js +++ b/rd_ui/app/scripts/app.js @@ -1,19 +1,58 @@ -angular.module('redash', ['redash.directives', 'redash.admin_controllers', 'redash.controllers', 'redash.filters', 'redash.services', - 'redash.renderers', - 'ui.codemirror', 'highchart', 'angular-growl', 'angularMoment', 'ui.bootstrap', 'smartTable.table', 'ngResource']). - config(['$routeProvider', '$locationProvider', '$compileProvider', function ($routeProvider, $locationProvider, $compileProvider) { +angular.module('redash', [ + 'redash.directives', + 'redash.admin_controllers', + 'redash.controllers', + 'redash.filters', + 'redash.services', + 'redash.renderers', + 'ui.codemirror', + 'highchart', + 'angular-growl', + 'angularMoment', + 'ui.bootstrap', + 'smartTable.table', + 'ngResource' +]).config(['$routeProvider', '$locationProvider', '$compileProvider', 'growlProvider', + function($routeProvider, $locationProvider, $compileProvider, growlProvider) { $compileProvider.urlSanitizationWhitelist(/^\s*(https?|http|data):/); - $locationProvider.html5Mode(true); - $routeProvider.when('/dashboard/:dashboardSlug', {templateUrl: '/views/dashboard.html', controller: 'DashboardCtrl'}); - $routeProvider.when('/queries', {templateUrl: '/views/queries.html', controller: 'QueriesCtrl', reloadOnSearch: false}); - $routeProvider.when('/queries/new', {templateUrl: '/views/queryfiddle.html', controller: 'QueryFiddleCtrl', reloadOnSearch: false}); - $routeProvider.when('/queries/:queryId', {templateUrl: '/views/queryfiddle.html', controller: 'QueryFiddleCtrl', reloadOnSearch: false}); - $routeProvider.when('/admin/status', {templateUrl: '/views/admin_status.html', controller: 'AdminStatusCtrl'}); - $routeProvider.when('/', {templateUrl: '/views/index.html', controller: 'IndexCtrl'}); - $routeProvider.otherwise({redirectTo: '/'}); + growlProvider.globalTimeToLive(2000); - Highcharts.setOptions({colors: ["#4572A7", "#AA4643", "#89A54E", "#80699B", "#3D96AE", "#DB843D", "#92A8CD", "#A47D7C", "#B5CA92"]}); - }]); + $routeProvider.when('/dashboard/:dashboardSlug', { + templateUrl: '/views/dashboard.html', + controller: 'DashboardCtrl' + }); + $routeProvider.when('/queries', { + templateUrl: '/views/queries.html', + controller: 'QueriesCtrl', + reloadOnSearch: false + }); + $routeProvider.when('/queries/new', { + templateUrl: '/views/queryfiddle.html', + controller: 'QueryFiddleCtrl', + reloadOnSearch: false + }); + $routeProvider.when('/queries/:queryId', { + templateUrl: '/views/queryfiddle.html', + controller: 'QueryFiddleCtrl', + reloadOnSearch: false + }); + $routeProvider.when('/admin/status', { + templateUrl: '/views/admin_status.html', + controller: 'AdminStatusCtrl' + }); + $routeProvider.when('/', { + templateUrl: '/views/index.html', + controller: 'IndexCtrl' + }); + $routeProvider.otherwise({ + redirectTo: '/' + }); + Highcharts.setOptions({ + colors: ["#4572A7", "#AA4643", "#89A54E", "#80699B", "#3D96AE", + "#DB843D", "#92A8CD", "#A47D7C", "#B5CA92"] + }); + } +]); \ No newline at end of file diff --git a/rd_ui/app/scripts/controllers.js b/rd_ui/app/scripts/controllers.js index 03b5b19dae..393fe7b765 100644 --- a/rd_ui/app/scripts/controllers.js +++ b/rd_ui/app/scripts/controllers.js @@ -68,6 +68,8 @@ $location.path($location.path().replace(oldId, q.id)).replace(); } } + }, function(httpResponse) { + growl.addErrorMessage("Query could not be saved"); }); }; diff --git a/rd_ui/app/styles/redash.css b/rd_ui/app/styles/redash.css index aeb0268c2b..e935e6b33a 100644 --- a/rd_ui/app/styles/redash.css +++ b/rd_ui/app/styles/redash.css @@ -53,6 +53,7 @@ a.navbar-brand { right: 10px; float: right; width: 250px; + z-index: 10000; } .growl-item.ng-enter, From 6d8b256d10d2e3f930ddde6b841220134b98575a Mon Sep 17 00:00:00 2001 From: Amir Nissim Date: Mon, 30 Dec 2013 15:11:49 +0200 Subject: [PATCH 2/3] Show indication when query has unsaved changes (FED #1) --- rd_ui/app/scripts/controllers.js | 5 ++++- rd_ui/app/views/queryfiddle.html | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/rd_ui/app/scripts/controllers.js b/rd_ui/app/scripts/controllers.js index 393fe7b765..2a4989e8ba 100644 --- a/rd_ui/app/scripts/controllers.js +++ b/rd_ui/app/scripts/controllers.js @@ -54,6 +54,8 @@ } delete $scope.query.latest_query_data; $scope.query.$save(function (q) { + $scope.pristineQuery = q.query; + if (duplicate) { growl.addInfoMessage("Query duplicated.", {ttl: 2000}); } else{ @@ -144,7 +146,8 @@ }); if ($routeParams.queryId != undefined) { - $scope.query = Query.get({id: $routeParams.queryId}, function() { + $scope.query = Query.get({id: $routeParams.queryId}, function(q) { + $scope.pristineQuery = q.query; $scope.queryResult = $scope.query.getQueryResult(); }); } else { diff --git a/rd_ui/app/views/queryfiddle.html b/rd_ui/app/views/queryfiddle.html index 4ff57c0d86..2e436f746e 100644 --- a/rd_ui/app/views/queryfiddle.html +++ b/rd_ui/app/views/queryfiddle.html @@ -17,7 +17,9 @@

- +
From 304a14e5a13fbea3c67251bc522a4d5d6b0368ff Mon Sep 17 00:00:00 2001 From: Amir Nissim Date: Mon, 30 Dec 2013 16:34:48 +0200 Subject: [PATCH 3/3] Show confirm box, when trying to leave the page before saving the query (FED #1) --- rd_ui/app/scripts/controllers.js | 30 ++++++++++++++++++++++++++---- rd_ui/app/views/queryfiddle.html | 2 +- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/rd_ui/app/scripts/controllers.js b/rd_ui/app/scripts/controllers.js index 2a4989e8ba..aca4c78625 100644 --- a/rd_ui/app/scripts/controllers.js +++ b/rd_ui/app/scripts/controllers.js @@ -29,7 +29,23 @@ $scope.updateTime = ''; } - var QueryFiddleCtrl = function ($scope, $routeParams, $http, $location, growl, notifications, Query) { + var QueryFiddleCtrl = function ($scope, $window, $routeParams, $http, $location, growl, notifications, Query) { + var leavingPageText = "You will lose your changes if you leave"; + var pristineQuery = null; + + $window.onbeforeunload = function(){ + if ($scope.queryChanged) { + return leavingPageText; + } + } + + $scope.$on('$locationChangeStart', function(event, next, current) { + if($scope.queryChanged && + !confirm(leavingPageText + "\n\nAre you sure you want to leave this page?")) { + event.preventDefault(); + } + }); + $scope.$parent.pageTitle = "Query Fiddle"; $scope.tabs = [{'key': 'table', 'name': 'Table'}, {'key': 'chart', 'name': 'Chart'}, @@ -54,7 +70,8 @@ } delete $scope.query.latest_query_data; $scope.query.$save(function (q) { - $scope.pristineQuery = q.query; + pristineQuery = q.query; + $scope.queryChanged = false; if (duplicate) { growl.addInfoMessage("Query duplicated.", {ttl: 2000}); @@ -147,7 +164,7 @@ if ($routeParams.queryId != undefined) { $scope.query = Query.get({id: $routeParams.queryId}, function(q) { - $scope.pristineQuery = q.query; + pristineQuery = q.query; $scope.queryResult = $scope.query.getQueryResult(); }); } else { @@ -158,6 +175,11 @@ $scope.$watch('query.name', function() { $scope.$parent.pageTitle = $scope.query.name; }); + $scope.$watch('query.query', function(q) { + if (q) { + $scope.queryChanged = (q != pristineQuery); + } + }); $scope.executeQuery = function() { $scope.queryResult = $scope.query.getQueryResult(0); @@ -325,7 +347,7 @@ .controller('DashboardCtrl', ['$scope', '$routeParams', '$http', 'Dashboard', DashboardCtrl]) .controller('WidgetCtrl', ['$scope', '$http', 'Query', WidgetCtrl]) .controller('QueriesCtrl', ['$scope', '$http', '$location', '$filter', 'Query', QueriesCtrl]) - .controller('QueryFiddleCtrl', ['$scope', '$routeParams', '$http', '$location', 'growl', 'notifications', 'Query', QueryFiddleCtrl]) + .controller('QueryFiddleCtrl', ['$scope', '$window', '$routeParams', '$http', '$location', 'growl', 'notifications', 'Query', QueryFiddleCtrl]) .controller('IndexCtrl', ['$scope', 'Dashboard', IndexCtrl]) .controller('MainCtrl', ['$scope', 'Dashboard', 'notifications', MainCtrl]); })(); diff --git a/rd_ui/app/views/queryfiddle.html b/rd_ui/app/views/queryfiddle.html index 2e436f746e..3614ddb1a0 100644 --- a/rd_ui/app/views/queryfiddle.html +++ b/rd_ui/app/views/queryfiddle.html @@ -18,7 +18,7 @@