diff --git a/src/app/controllers/pro/datasourcesCtrl.js b/src/app/controllers/pro/datasourcesCtrl.js index 6750015a639..431dd487388 100644 --- a/src/app/controllers/pro/datasourcesCtrl.js +++ b/src/app/controllers/pro/datasourcesCtrl.js @@ -17,17 +17,62 @@ function (angular) { }; $scope.init = function() { + $scope.reset(); + $scope.editor = {index: 0}; + $scope.datasources = []; + $scope.getDatasources(); + + $scope.$watch('editor.index', function(newVal) { + if (newVal !== 2) { + $scope.reset(); + } + }); + }; + + $scope.reset = function() { $scope.current = angular.copy(defaults); + $scope.currentIsNew = true; + }; + + $scope.edit = function(ds) { + $scope.current = ds; + $scope.currentIsNew = false; + $scope.editor.index = 2; + }; + + $scope.cancel = function() { + $scope.reset(); + $scope.editor.index = 0; + }; + + $scope.getDatasources = function() { + backendSrv.get('/api/admin/datasources/list').then(function(results) { + $scope.datasources = results; + }); + }; + + $scope.remove = function(ds) { + backendSrv.delete('/api/admin/datasources/' + ds.id).then(function() { + $scope.getDatasources(); + }); + }; + + $scope.update = function() { + backendSrv.post('/api/admin/datasources', $scope.current).then(function() { + $scope.editor.index = 0; + $scope.getDatasources(); + }); }; - $scope.addDatasource = function() { + $scope.add = function() { if (!$scope.editForm.$valid) { return; } - backendSrv.post('/api/admin/datasources/add', $scope.current) - .then(function(result) { - console.log('add datasource result', result); + backendSrv.put('/api/admin/datasources', $scope.current) + .then(function() { + $scope.editor.index = 0; + $scope.getDatasources(); }); }; diff --git a/src/app/partials/pro/datasources.html b/src/app/partials/pro/datasources.html index 71aa1c536d3..2aff611db7c 100644 --- a/src/app/partials/pro/datasources.html +++ b/src/app/partials/pro/datasources.html @@ -1,4 +1,4 @@ -
+
@@ -7,43 +7,81 @@
- Add data source + Data sources
+ +
+
+
+
+
-
-
-
- - -
-
- - +
+
+
+ No datasources defined +
+ + + + + + + +
+   + {{ds.name}} + + {{ds.url}} + + + + Edit + + + + + +
-
-
- - +
+
+
+ + +
+
+ + +
-
- - + +
+
+ + +
+
+ + +
-
- - + - + +
diff --git a/src/app/services/pro/backendSrv.js b/src/app/services/pro/backendSrv.js index b2a38de5e53..28d32317778 100644 --- a/src/app/services/pro/backendSrv.js +++ b/src/app/services/pro/backendSrv.js @@ -13,6 +13,10 @@ function (angular, _) { return this.request({ method: 'GET', url: url }); }; + this.delete = function(url) { + return this.request({ method: 'DELETE', url: url }); + }; + this.post = function(url, data) { return this.request({ method: 'POST', url: url, data: data }); };