mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
@@ -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();
|
||||
|
||||
@@ -43,11 +43,22 @@
|
||||
</div>
|
||||
|
||||
<div ng-include="datasourceMeta.partials.config" ng-if="datasourceMeta.partials.config"></div>
|
||||
<br>
|
||||
<br>
|
||||
<div class="pull-right">
|
||||
<button type="submit" class="btn btn-success" ng-show="isNew" ng-click="add()">Add</button>
|
||||
<button type="submit" class="btn btn-success" ng-show="!isNew" ng-click="update()">Update</button>
|
||||
|
||||
<div ng-if="testing" style="margin-top: 25px">
|
||||
<h5 ng-show="!testing.done">Testing.... <i class="fa fa-spiner fa-spin"></i></h5>
|
||||
<h5 ng-show="testing.done">Test results</h5>
|
||||
<div class="alert-{{testing.status}} alert">
|
||||
<div class="alert-title">{{testing.title}}</div>
|
||||
<div ng-bind='testing.message'></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="pull-right" style="margin-top: 35px">
|
||||
<button type="submit" class="btn btn-success" ng-show="isNew" ng-click="saveChanges()">Add</button>
|
||||
<button type="submit" class="btn btn-success" ng-show="!isNew" ng-click="saveChanges()">Save</button>
|
||||
<button type="submit" class="btn btn-inverse" ng-show="!isNew" ng-click="saveChanges(true)">
|
||||
Test Connection
|
||||
</button>
|
||||
<a class="btn btn-inverse" ng-show="!isNew" href="datasources">Cancel</a>
|
||||
</div>
|
||||
<br>
|
||||
|
||||
Reference in New Issue
Block a user