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

View File

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