Simplify inconsistent silence update behavior

The old silence update behavior resulted in duplicated silences after
e.g. updating a typo in a silence comment. I have to admit that I don't
understand the idea behind the old logic, but I couldn't see a use case
for creating a second silence when clicking on "Edit". The new behavior
is very simple and will simply always delete an existing silence and
replace it with the updated behavior.

Fixes #188.
This commit is contained in:
Tobias Schmidt 2016-09-01 16:12:05 -04:00
parent 9729d2db16
commit 7385ac95fa

View File

@ -417,20 +417,12 @@ angular.module('am.controllers').controller('SilenceCreateCtrl', function($scope
};
$scope.create = function() {
var now = new Date;
// Go through conditions that go against immutability of historic silences.
var createNew = !angular.equals(origSilence.matchers, $scope.silence.matchers);
createNew = createNew || $scope.silence.elapsed;
createNew = createNew || ($scope.silence.active && (origSilence.startsAt == $scope.silence.startsAt || origSilence.endsAt == $scope.silence.endsAt));
if (createNew) {
if (origSilence.id) {
$scope.silence.id = undefined;
}
Silence.create($scope.silence, function(data) {
// If the modifications require creating a new silence,
// we expire/delete the old one.
if (createNew && origSilence.id && !$scope.silence.elapsed) {
if (origSilence.id) {
Silence.delete({id: origSilence.id},
function(data) {
// Only trigger reload after after old silence was deleted.