Skip to content

Commit 0a67e51

Browse files
committed
Bug 1496396 - Don't warn on navigate when YAML isn't changed
Don't prompt the user about unsaved changes on the edit YAML page if the user hasn't made any edits. Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1496396
1 parent d8d6ca4 commit 0a67e51

File tree

5 files changed

+36
-24
lines changed

5 files changed

+36
-24
lines changed

app/scripts/controllers/edit/yaml.js

+8-6
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,6 @@ angular.module('openshiftConsole')
4848
$window.history.back();
4949
};
5050

51-
$scope.$watch('updated.resource', function(current, previous) {
52-
if (current !== previous) {
53-
$scope.modified = true;
54-
}
55-
});
56-
5751
var watches = [];
5852
ProjectsService
5953
.get($routeParams.project)
@@ -75,6 +69,14 @@ angular.module('openshiftConsole')
7569

7670
// Modify a copy of the resource.
7771
_.set($scope, 'updated.resource', angular.copy(result));
72+
$scope.$watch('updated.resource', function(updated, previous) {
73+
// Skip the initial $watch callback when we first add the listener.
74+
if (updated === previous) {
75+
return;
76+
}
77+
78+
$scope.modified = true;
79+
});
7880

7981
// TODO: Update the BreadcrumbsService to handle types without browse pages.
8082
// $scope.breadcrumbs = BreadcrumbsService.getBreadcrumbs({

app/scripts/directives/uiAceYaml.js

+14-3
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,18 @@
7070
});
7171
};
7272

73-
var updated = function() {
73+
var updated = function(current, previous) {
74+
var resource;
7475
// Check for errors, then check for warnings.
7576
try {
76-
ctrl.resource = parseYAML(false);
77+
resource = parseYAML(false);
7778
setValid(true);
79+
80+
// Only update `ctrl.resource` if the value has changed.
81+
if (current !== previous) {
82+
ctrl.resource = resource;
83+
}
84+
7885
// Check for warnings.
7986
try {
8087
parseYAML(true);
@@ -86,6 +93,7 @@
8693
setAnnotation(e, 'error');
8794
setValid(false);
8895
}
96+
8997
};
9098

9199
$scope.$watch(function() {
@@ -106,7 +114,6 @@
106114
}
107115
};
108116

109-
ctrl.aceChanged = updated;
110117
ctrl.aceLoaded = function(editor) {
111118
// Keep a reference to use later in event callbacks.
112119
aceEditor = editor;
@@ -117,6 +124,10 @@
117124
editor.setDragDelay = 0;
118125
};
119126

127+
$scope.$watch(function() {
128+
return ctrl.model;
129+
}, updated);
130+
120131
ctrl.gotoLine = function(line) {
121132
aceEditor.gotoLine(line);
122133
};

app/views/directives/ui-ace-yaml.html

-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
mode: 'yaml',
3232
theme: 'eclipse',
3333
onLoad: $ctrl.aceLoaded,
34-
onChange: $ctrl.aceChanged,
3534
rendererOptions: {
3635
showPrintMargin: false
3736
}

dist/scripts/scripts.js

+14-13
Original file line numberDiff line numberDiff line change
@@ -7650,11 +7650,7 @@ title: "Edit YAML"
76507650
} ];
76517651
var m = function() {
76527652
e.modified = !1, a.returnURL ? n.url(a.returnURL) : r.history.back();
7653-
};
7654-
e.$watch("updated.resource", function(t, n) {
7655-
t !== n && (e.modified = !0);
7656-
});
7657-
var f = [];
7653+
}, f = [];
76587654
d.get(a.project).then(_.spread(function(n, r) {
76597655
var s = {
76607656
resource: o.kindToResource(a.kind),
@@ -7664,7 +7660,9 @@ i.canI(s, "update", a.project) ? (c.get(s, e.name, r, {
76647660
errorNotification: !1
76657661
}).then(function(n) {
76667662
var i = n;
7667-
_.set(e, "updated.resource", angular.copy(n));
7663+
_.set(e, "updated.resource", angular.copy(n)), e.$watch("updated.resource", function(t, n) {
7664+
t !== n && (e.modified = !0);
7665+
});
76687666
var l = function(e) {
76697667
return _.get(e, "metadata.resourceVersion");
76707668
};
@@ -14140,9 +14138,16 @@ e !== t && (n.model = e);
1414014138
n.resource && (n.model = jsyaml.safeDump(n.resource, {
1414114139
sortKeys: !0
1414214140
}));
14143-
}, n.aceChanged = function() {
14141+
}, n.aceLoaded = function(e) {
14142+
t = e;
14143+
var n = e.getSession();
14144+
n.setOption("tabSize", 2), n.setOption("useSoftTabs", !0), e.setDragDelay = 0;
14145+
}, e.$watch(function() {
14146+
return n.model;
14147+
}, function(e, t) {
14148+
var s;
1414414149
try {
14145-
n.resource = a(!1), i(!0);
14150+
s = a(!1), i(!0), e !== t && (n.resource = s);
1414614151
try {
1414714152
a(!0), r();
1414814153
} catch (e) {
@@ -14151,11 +14156,7 @@ o(e, "warning");
1415114156
} catch (e) {
1415214157
o(e, "error"), i(!1);
1415314158
}
14154-
}, n.aceLoaded = function(e) {
14155-
t = e;
14156-
var n = e.getSession();
14157-
n.setOption("tabSize", 2), n.setOption("useSoftTabs", !0), e.setDragDelay = 0;
14158-
}, n.gotoLine = function(e) {
14159+
}), n.gotoLine = function(e) {
1415914160
t.gotoLine(e);
1416014161
};
1416114162
} ],

dist/scripts/templates.js

-1
Original file line numberDiff line numberDiff line change
@@ -9167,7 +9167,6 @@ angular.module('openshiftConsoleTemplates', []).run(['$templateCache', function(
91679167
" mode: 'yaml',\n" +
91689168
" theme: 'eclipse',\n" +
91699169
" onLoad: $ctrl.aceLoaded,\n" +
9170-
" onChange: $ctrl.aceChanged,\n" +
91719170
" rendererOptions: {\n" +
91729171
" showPrintMargin: false\n" +
91739172
" }\n" +

0 commit comments

Comments
 (0)