Add UI to delete alerts (closes #731)

This commit is contained in:
Arik Fraimovich
2016-06-14 11:55:00 +03:00
parent 2d2fb69b7b
commit 9ad85091ed
2 changed files with 21 additions and 9 deletions

View File

@@ -67,10 +67,12 @@
if ($scope.alertId === "new") {
$scope.alert = new Alert({options: {}});
$scope.canEdit = true;
} else {
$scope.alert = Alert.get({id: $scope.alertId}, function(alert) {
$scope.onQuerySelected(new Query($scope.alert.query));
});
$scope.canEdit = currentUser.canEdit($scope.alert);
}
$scope.ops = ['greater than', 'less than', 'equals'];
@@ -110,6 +112,15 @@
});
};
$scope.delete = function() {
$scope.alert.$delete(function() {
$location.path('/alerts');
growl.addSuccessMessage("Alert deleted.");
}, function() {
growl.addErrorMessage("Failed deleting alert.");
});
}
};
angular.module('redash.directives').directive('alertSubscriptions', ['$q', '$sce', 'AlertSubscription', 'Destination', 'growl', function ($q, $sce, AlertSubscription, Destination, growl) {

View File

@@ -7,10 +7,10 @@
<div class="container">
<div class="row bg-white p-10">
<div class="col-md-8">
<form name="alertForm" ng-submit="saveChanges()" class="form">
<form name="alertForm" class="form">
<div class="form-group">
<label>Query</label>
<ui-select ng-model="alert.query" reset-search-input="false" on-select="onQuerySelected($item)">
<ui-select ng-model="alert.query" reset-search-input="false" on-select="onQuerySelected($item)" ng-disabled="!canEdit">
<ui-select-match placeholder="Search a query by name">{{$select.selected.name}}</ui-select-match>
<ui-select-choices repeat="q in queries"
refresh="searchQueries($select.search)"
@@ -22,7 +22,7 @@
<div class="form-group" ng-show="selectedQuery">
<label>Name</label>
<input type="string" placeholder="{{getDefaultName()}}" class="form-control" ng-model="alert.name">
<input type="string" placeholder="{{getDefaultName()}}" class="form-control" ng-model="alert.name" ng-disabled="!canEdit">
</div>
<div ng-show="queryResult" class="form-horizontal">
@@ -30,7 +30,7 @@
<label class="control-label col-md-2">Value column</label>
<div class="col-md-4">
<select ng-options="name for name in queryResult.getColumnNames()" ng-model="alert.options.column"
class="form-control"></select>
class="form-control" ng-disabled="!canEdit"></select>
</div>
<label class="control-label col-md-2">Value</label>
<div class="col-md-4">
@@ -40,24 +40,25 @@
<div class="form-group">
<label class="control-label col-md-2">Op</label>
<div class="col-md-4">
<select ng-options="name for name in ops" ng-model="alert.options.op" class="form-control"></select>
<select ng-options="name for name in ops" ng-model="alert.options.op" class="form-control" ng-disabled="!canEdit"></select>
</div>
<label class="control-label col-md-2">Reference</label>
<div class="col-md-4">
<input type="number" step="any" class="form-control" ng-model="alert.options.value" placeholder="reference value"
<input type="number" step="any" class="form-control" ng-model="alert.options.value" placeholder="reference value" ng-disabled="!canEdit"
required/>
</div>
</div>
<div class="form-group">
<label class="control-label col-md-2">Rearm seconds</label>
<div class="col-md-4">
<input type="number" class="form-control" ng-model="alert.rearm"/>
<input type="number" class="form-control" ng-model="alert.rearm" ng-disabled="!canEdit"/>
</div>
</div>
</div>
<div class="form-group">
<button class="btn btn-primary" ng-disabled="!alertForm.$valid">Save</button>
<div class="form-group" ng-if="canEdit">
<button class="btn btn-primary" ng-disabled="!alertForm.$valid" ng-click="saveChanges()">Save</button>
<button class="btn btn-danger" ng-if="alert.id" ng-click="delete()">Delete</button>
</div>
</form>
</div>