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 @@ -
+