if yaml is supplied, preserve it where possible
eg if yaml mode is requested, or the yaml has errors and can't be parsed, then the user switches to yaml mode
diff --git a/ui-modules/blueprint-composer/app/views/main/main.controller.js b/ui-modules/blueprint-composer/app/views/main/main.controller.js
index 886b4a1..fc1ac1a 100644
--- a/ui-modules/blueprint-composer/app/views/main/main.controller.js
+++ b/ui-modules/blueprint-composer/app/views/main/main.controller.js
@@ -131,9 +131,28 @@
yaml = edit.type.plan.data;
}
+
+ vm.isGraphicalMode = () => {
+ return $state.includes(graphicalState.name);
+ };
+ vm.isYamlMode = () => {
+ return $state.includes(yamlState.name);
+ };
if (yaml) {
- blueprintService.setFromYaml(yaml);
+ if (vm.isYamlMode()) {
+ // don't set blueprint; yaml mode will take from "initial yaml"
+ blueprintService.reset();
+ $scope.initialYaml = yaml;
+ } else {
+ try {
+ blueprintService.setFromYaml(yaml);
+ } catch (e) {
+ console.warn("YAML supplied for editing is not valid for a blueprint. It will be ignored unless opened in the YAML editor:", e);
+ blueprintService.reset();
+ $scope.initialYaml = yaml;
+ }
+ }
} else {
blueprintService.reset();
}
@@ -147,10 +166,6 @@
deployApplication();
};
- vm.isGraphicalMode = () => {
- return $state.includes(graphicalState.name);
- };
-
vm.getAllActions = () => {
return actionService.getActions();
}
diff --git a/ui-modules/blueprint-composer/app/views/main/yaml/yaml.state.js b/ui-modules/blueprint-composer/app/views/main/yaml/yaml.state.js
index bfd47f2..f9390ae 100644
--- a/ui-modules/blueprint-composer/app/views/main/yaml/yaml.state.js
+++ b/ui-modules/blueprint-composer/app/views/main/yaml/yaml.state.js
@@ -39,6 +39,11 @@
brSnackbar.create(`Cannot load blueprint: ${ex.message}`);
vm.yaml = '';
}
+ if ($scope.initialYaml && !vm.yaml) {
+ // either yaml was supplied and yaml mode requested, skipping blueprint setup,
+ // or the yaml was invalid, an error logged, and this was recorded
+ vm.yaml = $scope.initialYaml;
+ }
if (!CodeMirror.lint.hasOwnProperty('yaml-composer')) {
CodeMirror.registerGlobalHelper('lint', 'yaml-composer', mode => mode.name === 'yaml', (text, options, cm) => {