diff --git a/client/app/assets/css/redash.css b/client/app/assets/css/redash.css index 9f01e388..a04e41be 100644 --- a/client/app/assets/css/redash.css +++ b/client/app/assets/css/redash.css @@ -415,6 +415,16 @@ counter-renderer counter-name { background-color: white; } +.schema-control { + display: flex; + padding: 5px 0; +} + +.schema-control .form-control { + height: 30px; + margin-right: 5px; +} + .schema-browser { height: calc(100% - 45px); overflow-y: auto; diff --git a/client/app/pages/queries/query.html b/client/app/pages/queries/query.html index b93999e4..439a34f6 100644 --- a/client/app/pages/queries/query.html +++ b/client/app/pages/queries/query.html @@ -85,6 +85,7 @@
diff --git a/client/app/pages/queries/schema-browser.html b/client/app/pages/queries/schema-browser.html index 2a9b6d45..65905cd9 100644 --- a/client/app/pages/queries/schema-browser.html +++ b/client/app/pages/queries/schema-browser.html @@ -1,6 +1,11 @@
-
+
+
diff --git a/client/app/pages/queries/schema-browser.js b/client/app/pages/queries/schema-browser.js index 604c114d..ece96de5 100644 --- a/client/app/pages/queries/schema-browser.js +++ b/client/app/pages/queries/schema-browser.js @@ -20,6 +20,7 @@ function SchemaBrowserCtrl($scope) { const SchemaBrowser = { bindings: { schema: '<', + onRefresh: '&', }, controller: SchemaBrowserCtrl, template, diff --git a/client/app/pages/queries/view.js b/client/app/pages/queries/view.js index 3c1dc568..369be50f 100644 --- a/client/app/pages/queries/view.js +++ b/client/app/pages/queries/view.js @@ -43,26 +43,31 @@ function QueryViewCtrl($scope, Events, $route, $routeParams, $http, $location, $ return dataSourceId; } - function updateSchema() { - $scope.hasSchema = false; - $scope.editorSize = 'col-md-12'; - DataSource.getSchema({ id: $scope.query.data_source_id }, (data) => { - if (data && data.length > 0) { + function toggleSchemaBrowser(hasSchema) { + $scope.hasSchema = hasSchema; + $scope.editorSize = hasSchema ? 'col-md-9' : 'col-md-12'; + } + + function getSchema(refresh = undefined) { + DataSource.getSchema({ id: $scope.query.data_source_id, refresh }, (data) => { + const hasSchema = data && (data.length > 0); + if (hasSchema) { $scope.schema = data; data.forEach((table) => { table.collapsed = true; }); - - $scope.editorSize = 'col-md-9'; - $scope.hasSchema = true; - } else { - $scope.schema = undefined; - $scope.hasSchema = false; - $scope.editorSize = 'col-md-12'; } + toggleSchemaBrowser(hasSchema); }); } + function updateSchema() { + toggleSchemaBrowser(false); + getSchema(); + } + + $scope.refreshSchema = () => getSchema(true); + function updateDataSources(dataSources) { // Filter out data sources the user can't query (or used by current query): $scope.dataSources = dataSources.filter(dataSource => diff --git a/client/app/services/data-source.js b/client/app/services/data-source.js index d7a9cbc8..b6d42379 100644 --- a/client/app/services/data-source.js +++ b/client/app/services/data-source.js @@ -3,7 +3,7 @@ function DataSource($resource) { get: { method: 'GET', cache: false, isArray: false }, query: { method: 'GET', cache: false, isArray: true }, test: { method: 'POST', cache: false, isArray: false, url: 'api/data_sources/:id/test' }, - getSchema: { method: 'GET', cache: true, isArray: true, url: 'api/data_sources/:id/schema' }, + getSchema: { method: 'GET', cache: false, isArray: true, url: 'api/data_sources/:id/schema' }, }; const DataSourceResource = $resource('api/data_sources/:id', { id: '@id' }, actions);