diff --git a/rd_ui/app/index.html b/rd_ui/app/index.html index e6c1b096..64e476d3 100644 --- a/rd_ui/app/index.html +++ b/rd_ui/app/index.html @@ -127,7 +127,8 @@ - + + diff --git a/rd_ui/app/scripts/controllers/query_view.js b/rd_ui/app/scripts/controllers/query_view.js index 51e47d96..801873b3 100644 --- a/rd_ui/app/scripts/controllers/query_view.js +++ b/rd_ui/app/scripts/controllers/query_view.js @@ -23,16 +23,7 @@ $scope.queryExecuting = lock; }; - $scope.formatQuery = function () { - $scope.editorOptions.readOnly = 'nocursor'; - $http.post('/api/queries/format', { - 'query': $scope.query.query - }).success(function (response) { - $scope.query.query = response; - $scope.editorOptions.readOnly = false; - }) - } $scope.duplicateQuery = function () { var oldId = $scope.query.id; @@ -53,42 +44,6 @@ $scope.queryResult.cancelExecution(); }; - $scope.editorOptions = { - mode: 'text/x-sql', - lineWrapping: true, - lineNumbers: true, - readOnly: false, - matchBrackets: true, - autoCloseBrackets: true - }; - - $scope.refreshOptions = [ - { - value: -1, - name: 'No Refresh' - }, - { - value: 60, - name: 'Every minute' - }, - ] - - _.each(_.range(1, 13), function (i) { - $scope.refreshOptions.push({ - value: i * 3600, - name: 'Every ' + i + 'h' - }); - }) - - $scope.refreshOptions.push({ - value: 24 * 3600, - name: 'Every 24h' - }); - $scope.refreshOptions.push({ - value: 7 * 24 * 3600, - name: 'Once a week' - }); - $scope.$watch('queryResult && queryResult.getError()', function (newError, oldError) { if (newError == undefined) { return; diff --git a/rd_ui/app/scripts/directives.js b/rd_ui/app/scripts/directives/directives.js similarity index 100% rename from rd_ui/app/scripts/directives.js rename to rd_ui/app/scripts/directives/directives.js diff --git a/rd_ui/app/scripts/directives/query_directives.js b/rd_ui/app/scripts/directives/query_directives.js new file mode 100644 index 00000000..631b54ba --- /dev/null +++ b/rd_ui/app/scripts/directives/query_directives.js @@ -0,0 +1,102 @@ +(function() { + 'use strict' + function queryEditor() { + return { + restrict: 'E', + scope: { + 'query': '=', + 'lock': '=' + }, + template: '', + link: function($scope) { + $scope.editorOptions = { + mode: 'text/x-sql', + lineWrapping: true, + lineNumbers: true, + readOnly: false, + matchBrackets: true, + autoCloseBrackets: true + }; + + $scope.$watch('lock', function(locked) { + $scope.editorOptions.readOnly = locked ? 'nocursor' : false; + }); + } + } + } + + function queryFormatter($http) { + return { + restrict: 'E', + scope: { + 'query': '=', + 'lock': '=' + }, + template: '', + link: function($scope) { + $scope.formatQuery = function formatQuery() { + $scope.lock = true; + $http.post('/api/queries/format', { + 'query': $scope.query.query + }).success(function (response) { + $scope.query.query = response; + }).finally(function () { + $scope.lock = false; + }); + }; + } + } + } + + function queryRefreshSelect() { + return { + restrict: 'E', + template: '\ + ', + link: function($scope) { + $scope.refreshOptions = [ + { + value: -1, + name: 'No Refresh' + }, + { + value: 60, + name: 'Every minute' + }, + ] + + _.each(_.range(1, 13), function (i) { + $scope.refreshOptions.push({ + value: i * 3600, + name: 'Every ' + i + 'h' + }); + }) + + $scope.refreshOptions.push({ + value: 24 * 3600, + name: 'Every 24h' + }); + $scope.refreshOptions.push({ + value: 7 * 24 * 3600, + name: 'Once a week' + }); + } + + } + } + + angular.module('redash.directives') + .directive('queryRefreshSelect', queryRefreshSelect) + .directive('queryEditor', queryEditor) + .directive('queryFormatter', ['$http', queryFormatter]); +})(); \ No newline at end of file diff --git a/rd_ui/app/views/query.html b/rd_ui/app/views/query.html index d8d4df81..01c55615 100644 --- a/rd_ui/app/views/query.html +++ b/rd_ui/app/views/query.html @@ -60,7 +60,7 @@ - + - - - - - - -

- - - -

- -

-
- - - - -
-
-

- - Last update - - - -

-

- - Created By - {{query.user.name}} - You -

-

- - Runtime - {{queryResult.getRuntime() | durationHumanize}} - Running… -

-

- - Rows {{queryResult.getData().length}} -

-

- - Refresh Interval - -

- -

- - Data Source - -

- -
- -

- - - Download Dataset - -

-
- -
- -
- Executing query… - -
-
- Query in queue… - -
-
Error running query: {{queryResult.getError()}}
- - -
-
-
- -
-
-
-
-
- - -
- - - -
- - -
- -
- - -
-
-
-
-
-
-