Show query's data source.

This commit is contained in:
Arik Fraimovich
2014-03-19 11:22:51 +02:00
parent b6dbc3356d
commit 8ae41c0b6a
3 changed files with 22 additions and 6 deletions

View File

@@ -1,12 +1,14 @@
(function () {
'use strict';
var QueryViewCtrl = function ($scope, $window, $route, $http, $location, growl, notifications, Query, Visualization) {
var QueryViewCtrl = function ($scope, $window, $route, $http, $location, growl, notifications, Query, Visualization, DataSource) {
var DEFAULT_TAB = 'table';
var pristineHash = "";
var leavingPageText = "You will lose your changes if you leave";
var route = $route.current;
$scope.dataSources = DataSource.get();
$scope.dirty = undefined;
$scope.isNewQuery = false;
$scope.isOwner = false;
@@ -278,6 +280,7 @@
'notifications',
'Query',
'Visualization',
'DataSource',
QueryViewCtrl
]);

View File

@@ -284,10 +284,10 @@
return queryResult;
}
QueryResult.get = function (query, ttl) {
QueryResult.get = function (data_source_id, query, ttl) {
var queryResult = new QueryResult();
QueryResultResource.post({'query': query, 'ttl': ttl}, function (response) {
QueryResultResource.post({'data_source_id': data_source_id, 'query': query, 'ttl': ttl}, function (response) {
queryResult.update(response);
if ('job' in response) {
@@ -301,7 +301,7 @@
return QueryResult;
};
var Query = function ($resource, QueryResult) {
var Query = function ($resource, QueryResult, DataSource) {
var Query = $resource('/api/queries/:id', {id: '@id'});
Query.prototype.getQueryResult = function(ttl) {
@@ -316,7 +316,7 @@
} else if (this.latest_query_data_id && ttl != 0) {
queryResult = QueryResult.getById(this.latest_query_data_id);
} else {
queryResult = QueryResult.get(this.query, ttl);
queryResult = QueryResult.get(this.data_source_id, this.query, ttl);
}
return queryResult;
@@ -329,7 +329,14 @@
return Query;
};
var DataSource = function($resource) {
var DataSourceResource = $resource('/api/data_sources/:id', {id: '@id'}, {'get': {'method': 'GET', 'cache': true, 'isArray': true}});
return DataSourceResource;
}
angular.module('redash.services', [])
.factory('QueryResult', ['$resource', '$timeout', QueryResult])
.factory('Query', ['$resource', 'QueryResult', Query])
.factory('Query', ['$resource', 'QueryResult', 'DataSource', Query])
.factory('DataSource', ['$resource', DataSource]);
})();

View File

@@ -112,6 +112,12 @@
<select ng-disabled="!isOwner" ng-model="query.ttl" ng-change="saveQuery()" ng-options="c.value as c.name for c in refreshOptions"></select>
</p>
<p>
<span class="glyphicon glyphicon-hdd"></span>
<span class="text-muted">Data Source</span>
<select ng-disabled="!isOwner" ng-model="query.data_source_id" ng-options="ds.id as ds.name for ds in dataSources"></select>
</p>
<hr>
<p>