Improve silence form

This commit is contained in:
Fabian Reinartz 2015-11-06 14:14:46 +01:00
parent e681d8619d
commit 8b327b1d8e
2 changed files with 29 additions and 23 deletions

View File

@ -209,7 +209,7 @@ angular.module('am.controllers').controller('AlertsCtrl',
$scope.route = data.data; $scope.route = data.data;
}, },
function(data) { function(data) {
$scope.error = data.data;
} }
); );
} }
@ -235,23 +235,31 @@ angular.module('am.controllers').controller('SilencesCtrl',
}; };
$scope.delete = function(sil) { $scope.delete = function(sil) {
Silence.delete({ Silence.delete({id: sil.id},
id: sil.id function(data) {
}) $scope.refresh();
$scope.refresh() },
function(data) {
$scope.error = data.data;
});
}; };
$scope.$on('silence-created', function(evt) {
$scope.refresh();
});
$scope.refresh(); $scope.refresh();
} }
); );
angular.module('am.controllers').controller('SilenceCreateCtrl', angular.module('am.controllers').controller('SilenceCreateCtrl',
function($scope, Silence) { function($scope, $rootScope, Silence) {
$scope.create = function() { $scope.create = function() {
Silence.create($scope.silence, Silence.create($scope.silence,
function(data) { function(data) {
$scope.refresh(); $rootScope.$broadcast('silence-created');
$scope.reset();
}, },
function(data) { function(data) {
$scope.error = data.data; $scope.error = data.data;
@ -264,9 +272,11 @@ angular.module('am.controllers').controller('SilenceCreateCtrl',
$scope.addMatcher = function() { $scope.addMatcher = function() {
$scope.silence.matchers.push({}); $scope.silence.matchers.push({});
}; };
$scope.delMatcher = function(i) { $scope.delMatcher = function(i) {
$scope.silence.matchers.splice(i, 1); $scope.silence.matchers.splice(i, 1);
}; };
$scope.reset = function() { $scope.reset = function() {
var now = new Date(); var now = new Date();
var end = new Date(); var end = new Date();
@ -278,17 +288,15 @@ angular.module('am.controllers').controller('SilenceCreateCtrl',
now.setSeconds(0); now.setSeconds(0);
end.setSeconds(0); end.setSeconds(0);
end.setHours(end.getHours() + 2) end.setHours(end.getHours() + 4)
$scope.silence.startsAt = now; $scope.silence = {
$scope.silence.endsAt = end; startsAt: now,
endsAt: end,
$scope.silence.comment = ""; comment: "",
$scope.silence.createdBy = ""; createdBy: "",
matchers: [{}, {}]
if (!$scope.silence.matchers) { };
$scope.silence.matchers = [{}, {}];
}
}; };
$scope.reset(); $scope.reset();

View File

@ -21,12 +21,10 @@
<column cols="2"> <column cols="2">
<input class="input-small" type="text" placeholder="value" ng-model="m.value"> <input class="input-small" type="text" placeholder="value" ng-model="m.value">
</column> </column>
<column>
<label class="checkbox is-regex"><input type="checkbox" ng-model="m.isRegex"> /re/</label>
</column>
<column> <column>
<div class="btn-group"> <div class="btn-group">
<button type="primary" small><label class="checkbox is-regex"><input type="checkbox" ng-model="m.isRegex"> regex</label></button>
<button type="secondary" ng-hide="silence.matchers.length <= 1" ng-click="delMatcher($index)" small>-</button> <button type="secondary" ng-hide="silence.matchers.length <= 1" ng-click="delMatcher($index)" small>-</button>
<button type="secondary" ng-click="addMatcher()" small>+</button> <button type="secondary" ng-click="addMatcher()" small>+</button>
</div> </div>
@ -36,7 +34,7 @@
<row> <row>
<column cols="2"> <column cols="2">
<label>Creator</label> <label>Creator</label>
<input ng-model="silence.createdBy" type="email"> <input ng-model="silence.createdBy" type="email" required>
</column> </column>
<column cols="4"> <column cols="4">
<label>Comment</label> <label>Comment</label>
@ -49,7 +47,7 @@
<div ng-show="error != null"><span class="error">{{ error }}</span></div> <div ng-show="error != null"><span class="error">{{ error }}</span></div>
<div class="btn-group"> <div class="btn-group">
<button type="primary" ng-disabled="silence.matchers.length == 0" ng-click="create()" small>Create</button> <button type="primary" ng-disabled="silence.matchers.length == 0" ng-click="create()" upper>Create</button>
<button type="seconday" ng-click="reset()" small>Reset</button> <button type="seconday" ng-click="reset()" upper>Reset</button>
</div> </div>
</form> </form>