You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by he...@apache.org on 2019/11/18 15:29:27 UTC

[brooklyn-ui] 02/06: better handling for edge conditions

This is an automated email from the ASF dual-hosted git repository.

heneveld pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/brooklyn-ui.git

commit 19b5d7671e3eb9aceeddda84a4bb511b88124ad1
Author: Alex Heneveld <al...@cloudsoftcorp.com>
AuthorDate: Mon Nov 18 13:44:41 2019 +0000

    better handling for edge conditions
---
 ui-modules/utils/quick-launch/quick-launch.js | 37 +++++++++++++++++----------
 1 file changed, 24 insertions(+), 13 deletions(-)

diff --git a/ui-modules/utils/quick-launch/quick-launch.js b/ui-modules/utils/quick-launch/quick-launch.js
index 4d53cc3..e4b1a67 100644
--- a/ui-modules/utils/quick-launch/quick-launch.js
+++ b/ui-modules/utils/quick-launch/quick-launch.js
@@ -64,9 +64,15 @@ export function quickLaunchDirective() {
 
         $scope.$watch('app', () => {
             $scope.clearError();
-            $scope.appHasWizard = !checkForLocationTags($scope.app.plan.data);
-            $scope.yamlViewDisplayed = !$scope.appHasWizard;
             $scope.editorYaml = $scope.app.plan.data;
+            var parsedPlan = null;
+            try {
+                parsedPlan = yaml.safeLoad($scope.editorYaml);
+            } catch (e) { /* ignore, it's an unparseable template */ }
+            // enable wizard if it's parseble and doesn't specify a location
+            // (if it's not parseable, or it specifies a location, then the YAML view is displayed)
+            $scope.appHasWizard = parsedPlan!=null && !checkForLocationTags(parsedPlan);
+            $scope.yamlViewDisplayed = !$scope.appHasWizard;
             $scope.entityToDeploy = {
                 type: $scope.app.symbolicName
             };
@@ -172,16 +178,21 @@ export function quickLaunchDirective() {
         }
 
         function buildComposerYaml() {
-            let newApp = {
-                name: $scope.model.name || $scope.app.displayName,
-            };
-            if ($scope.model.location) {
-                newApp.location = $scope.model.location;
-            }
-            if ($scope.entityToDeploy[BROOKLYN_CONFIG]) {
-                newApp[BROOKLYN_CONFIG] = $scope.entityToDeploy[BROOKLYN_CONFIG]
+            if ($scope.yamlViewDisplayed) {
+                return angular.copy($scope.editorYaml);
+            } else {
+                let newApp = {
+                    name: $scope.model.name || $scope.app.displayName,
+                };
+                if ($scope.model.location) {
+                    newApp.location = $scope.model.location;
+                }
+                if ($scope.entityToDeploy[BROOKLYN_CONFIG]) {
+                    newApp[BROOKLYN_CONFIG] = $scope.entityToDeploy[BROOKLYN_CONFIG]
+                }
+                // TODO if plan data has config in the root (unlikely) this will have errors
+                return yaml.safeDump(newApp) + "\n" + $scope.app.plan.data;
             }
-            return yaml.safeDump(newApp) + "\n" + $scope.app.plan.data;
         }
 
         function showEditor() {
@@ -203,8 +214,8 @@ export function quickLaunchDirective() {
         }
     }
 
-    function checkForLocationTags(planYaml) {
-        return reduceFunction(false, yaml.safeLoad(planYaml));
+    function checkForLocationTags(parsedPlan) {
+        return reduceFunction(false, parsedPlan);
 
         function reduceFunction(locationFound, entity) {
             if (entity.hasOwnProperty('location') || entity.hasOwnProperty('location')) {