|
|
@@ -6,8 +6,9 @@ function (angular) {
|
|
|
'use strict';
|
|
|
|
|
|
var module = angular.module('grafana.controllers');
|
|
|
+ var datasourceTypes = [];
|
|
|
|
|
|
- module.controller('DataSourceEditCtrl', function($scope, $http, backendSrv, $routeParams, $location, datasourceSrv) {
|
|
|
+ module.controller('DataSourceEditCtrl', function($scope, $q, backendSrv, $routeParams, $location, datasourceSrv) {
|
|
|
|
|
|
var defaults = {
|
|
|
name: '',
|
|
|
@@ -16,32 +17,44 @@ function (angular) {
|
|
|
access: 'proxy'
|
|
|
};
|
|
|
|
|
|
- $scope.types = [
|
|
|
- { name: 'Graphite', type: 'graphite' },
|
|
|
- { name: 'InfluxDB 0.9.x (Experimental support)', type: 'influxdb' },
|
|
|
- { name: 'InfluxDB 0.8.x', type: 'influxdb_08' },
|
|
|
- { name: 'Elasticsearch', type: 'elasticsearch' },
|
|
|
- { name: 'OpenTSDB', type: 'opentsdb' },
|
|
|
- ];
|
|
|
-
|
|
|
$scope.init = function() {
|
|
|
$scope.isNew = true;
|
|
|
$scope.datasources = [];
|
|
|
|
|
|
- if ($routeParams.id) {
|
|
|
- $scope.isNew = false;
|
|
|
- $scope.getDatasourceById($routeParams.id);
|
|
|
- } else {
|
|
|
- $scope.current = angular.copy(defaults);
|
|
|
+ $scope.loadDatasourceTypes().then(function() {
|
|
|
+ if ($routeParams.id) {
|
|
|
+ $scope.isNew = false;
|
|
|
+ $scope.getDatasourceById($routeParams.id);
|
|
|
+ } else {
|
|
|
+ $scope.current = angular.copy(defaults);
|
|
|
+ $scope.typeChanged();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ };
|
|
|
+
|
|
|
+ $scope.loadDatasourceTypes = function() {
|
|
|
+ if (datasourceTypes.length > 0) {
|
|
|
+ $scope.types = datasourceTypes;
|
|
|
+ return $q.when(null);
|
|
|
}
|
|
|
+
|
|
|
+ return backendSrv.get('/api/datasources/plugins').then(function(plugins) {
|
|
|
+ datasourceTypes = plugins;
|
|
|
+ $scope.types = plugins;
|
|
|
+ });
|
|
|
};
|
|
|
|
|
|
$scope.getDatasourceById = function(id) {
|
|
|
backendSrv.get('/api/datasources/' + id).then(function(ds) {
|
|
|
$scope.current = ds;
|
|
|
+ $scope.typeChanged();
|
|
|
});
|
|
|
};
|
|
|
|
|
|
+ $scope.typeChanged = function() {
|
|
|
+ $scope.datasourceMeta = $scope.types[$scope.current.type];
|
|
|
+ };
|
|
|
+
|
|
|
$scope.updateFrontendSettings = function() {
|
|
|
backendSrv.get('/api/frontend/settings').then(function(settings) {
|
|
|
datasourceSrv.init(settings.datasources);
|