Skip to content

Commit 2496202

Browse files
committed
Merge pull request grafana#3998 from utkarshcmu/ds-conf-box
Added DS deletion confirmation modal
2 parents ac5f7ec + bb77070 commit 2496202

File tree

4 files changed

+57
-40
lines changed

4 files changed

+57
-40
lines changed

public/app/core/routes/routes.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ function setupAngularRoutes($routeProvider, $locationProvider) {
4545
.when('/datasources', {
4646
templateUrl: 'public/app/features/datasources/partials/list.html',
4747
controller : 'DataSourcesCtrl',
48+
controllerAs: 'ctrl',
4849
resolve: loadOrgBundle,
4950
})
5051
.when('/datasources/edit/:id', {

public/app/features/datasources/list_ctrl.js

Lines changed: 0 additions & 36 deletions
This file was deleted.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
///<reference path="../../headers/common.d.ts" />
2+
3+
import angular from 'angular';
4+
import _ from 'lodash';
5+
import coreModule from '../../core/core_module';
6+
7+
export class DataSourcesCtrl {
8+
datasources: any;
9+
10+
/** @ngInject */
11+
constructor(private $scope, private $location, private $http, private backendSrv, private datasourceSrv) {
12+
backendSrv.get('/api/datasources')
13+
.then((result) => {
14+
this.datasources = result;
15+
});
16+
}
17+
18+
removeDataSourceConfirmed(ds) {
19+
20+
this.backendSrv.delete('/api/datasources/' + ds.id)
21+
.then(() => {
22+
this.$scope.appEvent('alert-success', ['Datasource deleted', '']);
23+
}, () => {
24+
this.$scope.appEvent('alert-error', ['Unable to delete datasource', '']);
25+
}).then(() => {
26+
this.backendSrv.get('/api/datasources')
27+
.then((result) => {
28+
this.datasources = result;
29+
});
30+
this.backendSrv.get('/api/frontend/settings')
31+
.then((settings) => {
32+
this.datasourceSrv.init(settings.datasources);
33+
});
34+
});
35+
}
36+
37+
removeDataSource(ds) {
38+
39+
this.$scope.appEvent('confirm-modal', {
40+
title: 'Confirm delete datasource',
41+
text: 'Are you sure you want to delete datasource ' + ds.name + '?',
42+
yesText: "Delete",
43+
icon: "fa-warning",
44+
onConfirm: () => {
45+
this.removeDataSourceConfirmed(ds);
46+
}
47+
});
48+
}
49+
50+
}
51+
52+
coreModule.controller('DataSourcesCtrl', DataSourcesCtrl);

public/app/features/datasources/partials/list.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
<h1>Data sources</h1>
1313
<br>
1414

15-
<div ng-if="datasources.length === 0">
15+
<div ng-if="ctrl.datasources.length === 0">
1616
<em>No data sources defined</em>
1717
</div>
1818

19-
<table class="filter-table" ng-if="datasources.length > 0">
19+
<table class="filter-table" ng-if="ctrl.datasources.length > 0">
2020
<thead>
2121
<tr>
2222
<th><strong>Name</strong></th>
@@ -27,7 +27,7 @@ <h1>Data sources</h1>
2727
</tr>
2828
</thead>
2929
<tbody>
30-
<tr ng-repeat="ds in datasources">
30+
<tr ng-repeat="ds in ctrl.datasources">
3131
<td>
3232
<a href="datasources/edit/{{ds.id}}">
3333
<i class="fa fa-database"></i> &nbsp; {{ds.name}}
@@ -48,7 +48,7 @@ <h1>Data sources</h1>
4848
</a>
4949
</td>
5050
<td class="text-right">
51-
<a ng-click="remove(ds)" class="btn btn-danger btn-mini">
51+
<a ng-click="ctrl.removeDataSource(ds)" class="btn btn-danger btn-mini">
5252
<i class="fa fa-remove"></i>
5353
</a>
5454
</td>

0 commit comments

Comments
 (0)