diff --git a/pkg/api/api.go b/pkg/api/api.go index c516b7c2225..f5b7b69bea3 100644 --- a/pkg/api/api.go +++ b/pkg/api/api.go @@ -27,6 +27,7 @@ func Register(r *macaron.Macaron) { r.Get("/profile/", reqSignedIn, Index) r.Get("/org/", reqSignedIn, Index) r.Get("/datasources/", reqSignedIn, Index) + r.Get("/datasources/edit/*", reqSignedIn, Index) r.Get("/org/users/", reqSignedIn, Index) r.Get("/org/apikeys/", reqSignedIn, Index) r.Get("/dashboard/import/", reqSignedIn, Index) @@ -75,6 +76,7 @@ func Register(r *macaron.Macaron) { r.Combo("/").Get(GetDataSources).Put(AddDataSource).Post(UpdateDataSource) r.Delete("/:id", DeleteDataSource) r.Get("/:id", GetDataSourceById) + r.Get("/plugins", GetDataSourcePlugins) }, reqAccountAdmin) r.Get("/frontend/settings/", GetFrontendSettings) diff --git a/pkg/api/dataproxy.go b/pkg/api/dataproxy.go index 7aaf029c05c..3be991068cc 100644 --- a/pkg/api/dataproxy.go +++ b/pkg/api/dataproxy.go @@ -21,12 +21,12 @@ func NewReverseProxy(ds *m.DataSource, proxyPath string) *httputil.ReverseProxy reqQueryVals := req.URL.Query() - if ds.Type == m.DS_INFLUXDB { + if ds.Type == m.DS_INFLUXDB_08 { req.URL.Path = util.JoinUrlFragments(target.Path, "db/"+ds.Database+"/"+proxyPath) reqQueryVals.Add("u", ds.User) reqQueryVals.Add("p", ds.Password) req.URL.RawQuery = reqQueryVals.Encode() - } else if ds.Type == m.DS_INFLUXDB_08 { + } else if ds.Type == m.DS_INFLUXDB { req.URL.Path = util.JoinUrlFragments(target.Path, proxyPath) reqQueryVals.Add("db", ds.Database) reqQueryVals.Add("u", ds.User) diff --git a/pkg/api/datasources.go b/pkg/api/datasources.go index f4f406504e7..9dfa698769c 100644 --- a/pkg/api/datasources.go +++ b/pkg/api/datasources.go @@ -5,6 +5,7 @@ import ( "github.com/grafana/grafana/pkg/bus" "github.com/grafana/grafana/pkg/middleware" m "github.com/grafana/grafana/pkg/models" + "github.com/grafana/grafana/pkg/plugins" ) func GetDataSources(c *middleware.Context) { @@ -118,3 +119,7 @@ func UpdateDataSource(c *middleware.Context) { c.JsonOK("Datasource updated") } + +func GetDataSourcePlugins(c *middleware.Context) { + c.JSON(200, plugins.DataSources) +} diff --git a/src/app/app.js b/src/app/app.js index 3d61b8baf77..029e477d1c1 100644 --- a/src/app/app.js +++ b/src/app/app.js @@ -15,7 +15,7 @@ define([ 'extend-jquery', 'bindonce', ], -function (angular, $, _, appLevelRequire, config) { +function (angular, $, _, appLevelRequire) { "use strict"; diff --git a/src/app/features/org/datasourceEditCtrl.js b/src/app/features/org/datasourceEditCtrl.js index 0ecf0f9d3d8..db09d632d4a 100644 --- a/src/app/features/org/datasourceEditCtrl.js +++ b/src/app/features/org/datasourceEditCtrl.js @@ -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); diff --git a/src/app/features/org/partials/datasourceEdit.html b/src/app/features/org/partials/datasourceEdit.html index 0809d5958aa..b0f30c214b3 100644 --- a/src/app/features/org/partials/datasourceEdit.html +++ b/src/app/features/org/partials/datasourceEdit.html @@ -19,7 +19,7 @@