Skip to content

Commit

Permalink
Merge pull request #2178 from spadgett/edit-yaml-warning
Browse files Browse the repository at this point in the history
Merged by openshift-bot
  • Loading branch information
OpenShift Bot committed Sep 27, 2017
2 parents d8d6ca4 + 0a67e51 commit 0177053
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 24 deletions.
14 changes: 8 additions & 6 deletions app/scripts/controllers/edit/yaml.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,6 @@ angular.module('openshiftConsole')
$window.history.back();
};

$scope.$watch('updated.resource', function(current, previous) {
if (current !== previous) {
$scope.modified = true;
}
});

var watches = [];
ProjectsService
.get($routeParams.project)
Expand All @@ -75,6 +69,14 @@ angular.module('openshiftConsole')

// Modify a copy of the resource.
_.set($scope, 'updated.resource', angular.copy(result));
$scope.$watch('updated.resource', function(updated, previous) {
// Skip the initial $watch callback when we first add the listener.
if (updated === previous) {
return;
}

$scope.modified = true;
});

// TODO: Update the BreadcrumbsService to handle types without browse pages.
// $scope.breadcrumbs = BreadcrumbsService.getBreadcrumbs({
Expand Down
17 changes: 14 additions & 3 deletions app/scripts/directives/uiAceYaml.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,18 @@
});
};

var updated = function() {
var updated = function(current, previous) {
var resource;
// Check for errors, then check for warnings.
try {
ctrl.resource = parseYAML(false);
resource = parseYAML(false);
setValid(true);

// Only update `ctrl.resource` if the value has changed.
if (current !== previous) {
ctrl.resource = resource;
}

// Check for warnings.
try {
parseYAML(true);
Expand All @@ -86,6 +93,7 @@
setAnnotation(e, 'error');
setValid(false);
}

};

$scope.$watch(function() {
Expand All @@ -106,7 +114,6 @@
}
};

ctrl.aceChanged = updated;
ctrl.aceLoaded = function(editor) {
// Keep a reference to use later in event callbacks.
aceEditor = editor;
Expand All @@ -117,6 +124,10 @@
editor.setDragDelay = 0;
};

$scope.$watch(function() {
return ctrl.model;
}, updated);

ctrl.gotoLine = function(line) {
aceEditor.gotoLine(line);
};
Expand Down
1 change: 0 additions & 1 deletion app/views/directives/ui-ace-yaml.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
mode: 'yaml',
theme: 'eclipse',
onLoad: $ctrl.aceLoaded,
onChange: $ctrl.aceChanged,
rendererOptions: {
showPrintMargin: false
}
Expand Down
27 changes: 14 additions & 13 deletions dist/scripts/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -7650,11 +7650,7 @@ title: "Edit YAML"
} ];
var m = function() {
e.modified = !1, a.returnURL ? n.url(a.returnURL) : r.history.back();
};
e.$watch("updated.resource", function(t, n) {
t !== n && (e.modified = !0);
});
var f = [];
}, f = [];
d.get(a.project).then(_.spread(function(n, r) {
var s = {
resource: o.kindToResource(a.kind),
Expand All @@ -7664,7 +7660,9 @@ i.canI(s, "update", a.project) ? (c.get(s, e.name, r, {
errorNotification: !1
}).then(function(n) {
var i = n;
_.set(e, "updated.resource", angular.copy(n));
_.set(e, "updated.resource", angular.copy(n)), e.$watch("updated.resource", function(t, n) {
t !== n && (e.modified = !0);
});
var l = function(e) {
return _.get(e, "metadata.resourceVersion");
};
Expand Down Expand Up @@ -14140,9 +14138,16 @@ e !== t && (n.model = e);
n.resource && (n.model = jsyaml.safeDump(n.resource, {
sortKeys: !0
}));
}, n.aceChanged = function() {
}, n.aceLoaded = function(e) {
t = e;
var n = e.getSession();
n.setOption("tabSize", 2), n.setOption("useSoftTabs", !0), e.setDragDelay = 0;
}, e.$watch(function() {
return n.model;
}, function(e, t) {
var s;
try {
n.resource = a(!1), i(!0);
s = a(!1), i(!0), e !== t && (n.resource = s);
try {
a(!0), r();
} catch (e) {
Expand All @@ -14151,11 +14156,7 @@ o(e, "warning");
} catch (e) {
o(e, "error"), i(!1);
}
}, n.aceLoaded = function(e) {
t = e;
var n = e.getSession();
n.setOption("tabSize", 2), n.setOption("useSoftTabs", !0), e.setDragDelay = 0;
}, n.gotoLine = function(e) {
}), n.gotoLine = function(e) {
t.gotoLine(e);
};
} ],
Expand Down
1 change: 0 additions & 1 deletion dist/scripts/templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -9167,7 +9167,6 @@ angular.module('openshiftConsoleTemplates', []).run(['$templateCache', function(
" mode: 'yaml',\n" +
" theme: 'eclipse',\n" +
" onLoad: $ctrl.aceLoaded,\n" +
" onChange: $ctrl.aceChanged,\n" +
" rendererOptions: {\n" +
" showPrintMargin: false\n" +
" }\n" +
Expand Down

0 comments on commit 0177053

Please sign in to comment.