|
|
@@ -25,7 +25,6 @@ function (angular, config) {
|
|
|
|
|
|
$scope.loadDatasourceTypes().then(function() {
|
|
|
if ($routeParams.id) {
|
|
|
- $scope.isNew = false;
|
|
|
$scope.getDatasourceById($routeParams.id);
|
|
|
} else {
|
|
|
$scope.current = angular.copy(defaults);
|
|
|
@@ -48,6 +47,7 @@ function (angular, config) {
|
|
|
|
|
|
$scope.getDatasourceById = function(id) {
|
|
|
backendSrv.get('/api/datasources/' + id).then(function(ds) {
|
|
|
+ $scope.isNew = false;
|
|
|
$scope.current = ds;
|
|
|
$scope.typeChanged();
|
|
|
});
|
|
|
@@ -65,26 +65,46 @@ function (angular, config) {
|
|
|
});
|
|
|
};
|
|
|
|
|
|
- $scope.update = function() {
|
|
|
- if (!$scope.editForm.$valid) {
|
|
|
- return;
|
|
|
- }
|
|
|
+ $scope.testDatasource = function() {
|
|
|
+ $scope.testing = { done: false };
|
|
|
|
|
|
- backendSrv.post('/api/datasources', $scope.current).then(function() {
|
|
|
- $scope.updateFrontendSettings();
|
|
|
- $location.path("datasources");
|
|
|
+ datasourceSrv.get($scope.current.name).then(function(datasource) {
|
|
|
+ if (!datasource.testDatasource) {
|
|
|
+ $scope.testing.message = 'Data source does not support test connection feature.';
|
|
|
+ $scope.testing.status = 'warning';
|
|
|
+ $scope.testing.title = 'Unknown';
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ return datasource.testDatasource().then(function(result) {
|
|
|
+ $scope.testing.message = result.message;
|
|
|
+ $scope.testing.status = result.status;
|
|
|
+ $scope.testing.title = result.title;
|
|
|
+ });
|
|
|
+ }).finally(function() {
|
|
|
+ $scope.testing.done = true;
|
|
|
});
|
|
|
};
|
|
|
|
|
|
- $scope.add = function() {
|
|
|
+ $scope.saveChanges = function(test) {
|
|
|
if (!$scope.editForm.$valid) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- backendSrv.put('/api/datasources', $scope.current).then(function() {
|
|
|
- $scope.updateFrontendSettings();
|
|
|
- $location.path("datasources");
|
|
|
- });
|
|
|
+ if ($scope.current.id) {
|
|
|
+ return backendSrv.put('/api/datasources/' + $scope.current.id, $scope.current).then(function() {
|
|
|
+ $scope.updateFrontendSettings();
|
|
|
+ if (test) {
|
|
|
+ $scope.testDatasource();
|
|
|
+ } else {
|
|
|
+ $location.path('datasources');
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ return backendSrv.post('/api/datasources', $scope.current).then(function(result) {
|
|
|
+ $scope.updateFrontendSettings();
|
|
|
+ $location.path('datasources/edit/' + result.id);
|
|
|
+ });
|
|
|
+ }
|
|
|
};
|
|
|
|
|
|
$scope.init();
|