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


The following commit(s) were added to refs/heads/master by this push:
     new d166640  fix critical bugs in yaml routing
     new 1b071b7  Merge branch 'master' of https://github.com/apache/brooklyn-ui
d166640 is described below

commit d166640c587b01a1835751abff5fdd02d56f08be
Author: Alex Heneveld <[email protected]>
AuthorDate: Thu Feb 11 20:22:06 2021 +0000

    fix critical bugs in yaml routing
    
    improve yaml auto-detect and passing of format where available
    
    make overrides a provider that is better accessible elsewhere,
    with option to override auto-detection
    
    minor fixes where location or other items are not strings or json maps
---
 .../providers/blueprint-service.provider.js        | 22 +++++-----
 .../providers/composer-overrides.provider.js       | 36 +++++++++++++++++
 ui-modules/blueprint-composer/app/index.js         | 22 ++++------
 .../app/views/main/graphical/graphical.state.js    |  2 +-
 .../app/views/main/main.controller.js              |  9 +++--
 .../app/views/main/yaml/yaml.state.js              | 47 +++++++++++++++++-----
 .../app/views/main/main.controller.js              |  2 +-
 ui-modules/utils/quick-launch/quick-launch.js      |  6 ++-
 8 files changed, 104 insertions(+), 42 deletions(-)

diff --git 
a/ui-modules/blueprint-composer/app/components/providers/blueprint-service.provider.js
 
b/ui-modules/blueprint-composer/app/components/providers/blueprint-service.provider.js
index eec14e5..a798d9c 100644
--- 
a/ui-modules/blueprint-composer/app/components/providers/blueprint-service.provider.js
+++ 
b/ui-modules/blueprint-composer/app/components/providers/blueprint-service.provider.js
@@ -277,16 +277,20 @@ function BlueprintService($log, $q, $sce, paletteApi, 
iconGenerator, dslService)
 
         if (entity.hasLocation()) {
             let type = locationType(entity.location);
-            if (type.startsWith("jclouds:")) {
-                // types eg jclouds:aws-ec2 are low-level, not in the catalog
-                deferred.resolve(populateLocationFromApiSuccess(entity, { 
yamlHere: entity.location }));
+            if (type && type.startsWith) {
+                if (type.startsWith("jclouds:")) {
+                    // types eg jclouds:aws-ec2 are low-level, not in the 
catalog
+                    deferred.resolve(populateLocationFromApiSuccess(entity, { 
yamlHere: entity.location }));
+                } else {
+                    
paletteApi.getLocation(locationType(entity.location)).then((location) => {
+                        let loc = Object.assign({}, location.catalog || 
location, {yamlHere: entity.location});
+                        
deferred.resolve(populateLocationFromApiSuccess(entity, loc));
+                    }).catch(function () {
+                        deferred.resolve(populateLocationFromApiError(entity));
+                    });
+                }
             } else {
-                
paletteApi.getLocation(locationType(entity.location)).then((location)=> {
-                    let loc = Object.assign({}, location.catalog || location, 
{ yamlHere: entity.location });
-                    deferred.resolve(populateLocationFromApiSuccess(entity, 
loc));
-                }).catch(function () {
-                    deferred.resolve(populateLocationFromApiError(entity));
-                });
+                deferred.resolve(entity);
             }
         } else {
             deferred.resolve(entity);
diff --git 
a/ui-modules/blueprint-composer/app/components/providers/composer-overrides.provider.js
 
b/ui-modules/blueprint-composer/app/components/providers/composer-overrides.provider.js
new file mode 100644
index 0000000..124daf0
--- /dev/null
+++ 
b/ui-modules/blueprint-composer/app/components/providers/composer-overrides.provider.js
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+import angular from 'angular';
+
+const MODULE_NAME = 'brooklyn.composer.service.composer-overrides-service';
+
+angular.module(MODULE_NAME, [])
+    .provider('composerOverrides', composerOverridesProvider);
+
+export default MODULE_NAME;
+
+function composerOverridesProvider() {
+    // callers can do angular.config(['composerOverridesProvider', function 
(provider) { provider.add({ ... }) })
+    // to set various configuration. to see what configuration is supported, 
grep for composerOverrides in this project.
+    var result = {};
+    return {
+        $get: () => result,
+        add: (props) => angular.extend(result, props),
+    };
+}
diff --git a/ui-modules/blueprint-composer/app/index.js 
b/ui-modules/blueprint-composer/app/index.js
index 5afb6b8..e45c07f 100755
--- a/ui-modules/blueprint-composer/app/index.js
+++ b/ui-modules/blueprint-composer/app/index.js
@@ -57,6 +57,7 @@ import dslService from 
"./components/providers/dsl-service.provider";
 import paletteDragAndDropService from 
"./components/providers/palette-dragndrop.provider";
 import actionService from "./components/providers/action-service.provider";
 import tabService from "./components/providers/tab-service.provider";
+import composerOverrides from 
"./components/providers/composer-overrides.provider";
 import {mainState} from "./views/main/main.controller";
 import {yamlAutodetectState, yamlCampState, yamlState} from 
"./views/main/yaml/yaml.state";
 import {graphicalState} from "./views/main/graphical/graphical.state";
@@ -80,13 +81,12 @@ angular.module('brooklynBlueprintComposer', [ngAnimate, 
ngResource, ngCookies, n
     brServerStatus, brAutoFocus, brIconGenerator, brInterstitialSpinner, 
brooklynModuleLinks, brooklynUserManagement,
     brYamlEditor, brUtils, brSpecEditor, brooklynCatalogSaver, brooklynApi, 
bottomSheet, stackViewer, brDragndrop,
     customActionDirective, customConfigSuggestionDropdown, paletteApiProvider, 
paletteServiceProvider, blueprintLoaderApiProvider,
-    breadcrumbs, catalogSelector, designer, objectCache, entityFilters, 
locationFilter, actionService, tabService, blueprintService,
+    breadcrumbs, catalogSelector, designer, objectCache, entityFilters, 
locationFilter, actionService, tabService, composerOverrides, blueprintService,
     dslService, paletteDragAndDropService, recentlyUsedService, 
scriptTagDecorator, brandAngularJs])
-    .provider('composerOverrides', composerOverridesProvider)
     .filter('dslParamLabel', ['$filter', dslParamLabelFilter])
     .config(['$urlRouterProvider', '$stateProvider', '$logProvider', 
'$compileProvider', applicationConfig])
     .config(['actionServiceProvider', actionConfig])
-    .config(['tabServiceProvider', tabConfig])
+    .config(['tabServiceProvider', 'composerOverridesProvider', tabConfig])
     .config(['paletteServiceProvider', paletteConfig])
     .run(['$rootScope', '$state', 'brSnackbar', errorHandler])
     .run(['$http', httpConfig]);
@@ -110,22 +110,12 @@ function applicationConfig($urlRouterProvider, 
$stateProvider, $logProvider, $co
         .state(graphicalEditDslState);
 }
 
-function composerOverridesProvider() {
-    // callers can do angular.config(['composerOverridesProvider', function 
(provider) { provider.add({ ... }) })
-    // to set various configuration. to see what configuration is supported, 
grep for composerOverrides in this project.
-    var result = {};
-    return {
-        $get: () => result,
-        add: (props) => angular.extend(result, props),
-    };
-}
-
 function actionConfig(actionServiceProvider) {
     actionServiceProvider.addAction("deploy", {html: '<button class="btn 
btn-outline btn-success" ng-click="vm.deployApplication()" 
ng-disabled="vm.deploying">Deploy</button>'});
     actionServiceProvider.addAction("add", {html: '<catalog-saver 
config="vm.saveToCatalogConfig"></catalog-saver>'});
 }
 
-function tabConfig(tabServiceProvider) {
+function tabConfig(tabServiceProvider, composerOverridesProvider) {
     tabServiceProvider.addTab('graphical', {
         title: 'Graphical Designer',
         icon: 'fa-object-group',
@@ -134,8 +124,10 @@ function tabConfig(tabServiceProvider) {
     tabServiceProvider.addTab('yaml', {
         title: 'YAML Editor',
         icon: 'fa-pencil',
-        stateKey: 'main.yaml',
+        stateKey: 'main.yaml_camp',
     });
+
+    (composerOverridesProvider.$get().tabServiceProviderCustomization || 
(()=>{}))(tabServiceProvider);
 }
 
 function paletteConfig(paletteServiceProvider) {
diff --git 
a/ui-modules/blueprint-composer/app/views/main/graphical/graphical.state.js 
b/ui-modules/blueprint-composer/app/views/main/graphical/graphical.state.js
index ffb9616..0e7e0b2 100644
--- a/ui-modules/blueprint-composer/app/views/main/graphical/graphical.state.js
+++ b/ui-modules/blueprint-composer/app/views/main/graphical/graphical.state.js
@@ -24,7 +24,7 @@ import template from './graphical.state.html';
 
 export const graphicalState = {
     name: 'main.graphical',
-    url: 'graphical',
+    url: '/graphical',
     templateProvider: function(composerOverrides) {
         return composerOverrides.paletteGraphicalStateTemplate || template;
     },
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 7e08c30..0af26ad 100644
--- a/ui-modules/blueprint-composer/app/views/main/main.controller.js
+++ b/ui-modules/blueprint-composer/app/views/main/main.controller.js
@@ -56,7 +56,7 @@ const layers = [
 ];
 const layerCacheKey = 'blueprint-composer.layers';
 
-export function MainController($scope, $element, $log, $state, $stateParams, 
brBrandInfo, blueprintService, actionService, tabService, catalogApi, 
applicationApi, brSnackbar, brBottomSheet, edit, yaml, composerOverrides) {
+export function MainController($scope, $element, $log, $state, $stateParams, 
brBrandInfo, blueprintService, actionService, tabService, catalogApi, 
applicationApi, brSnackbar, brBottomSheet, composerOverrides, edit, yaml) {
     $scope.$emit(HIDE_INTERSTITIAL_SPINNER_EVENT);
     let vm = this;
 
@@ -130,6 +130,7 @@ export function MainController($scope, $element, $log, 
$state, $stateParams, brB
         }
         
         yaml = edit.type.plan.data;
+        $scope.initialYamlFormat = edit.type.plan.format;
     }
 
     vm.isTabActive = stateKey => {
@@ -140,6 +141,8 @@ export function MainController($scope, $element, $log, 
$state, $stateParams, brB
     }
 
     if (yaml) {
+        $scope.initialYamlFormat = $stateParams.format;
+
         if (vm.isYamlMode()) {
             // don't set blueprint; yaml mode will take from "initial yaml" 
             blueprintService.reset();
@@ -278,10 +281,10 @@ export function MainController($scope, $element, $log, 
$state, $stateParams, brB
 
 export const mainState = {
     name: 'main',
-    url: 
'/?bundleSymbolicName&bundleVersion&typeSymbolicName&typeVersion&yaml',
+    url: 
'?bundleSymbolicName&bundleVersion&typeSymbolicName&typeVersion&yaml&format',
     abstract: true,
     template: template,
-    controller: ['$scope', '$element', '$log', '$state', '$stateParams', 
'brBrandInfo', 'blueprintService', 'actionService', 'tabService', 'catalogApi', 
'applicationApi', 'brSnackbar', 'brBottomSheet', 'edit', 'yaml', 
'composerOverrides', MainController],
+    controller: ['$scope', '$element', '$log', '$state', '$stateParams', 
'brBrandInfo', 'blueprintService', 'actionService', 'tabService', 'catalogApi', 
'applicationApi', 'brSnackbar', 'brBottomSheet', 'composerOverrides', 'edit', 
'yaml', MainController],
     controllerAs: 'vm',
     resolve: {
         edit: ['$stateParams', 'blueprintLoaderApi', ($stateParams, 
blueprintLoaderApi) => blueprintLoaderApi.loadBlueprint($stateParams)],
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 d1b3a25..e4e3606 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
@@ -21,28 +21,53 @@ import {YAMLException} from 'js-yaml';
 
 
 export const yamlAutodetectState = {
-    // TODO make this do auto-detect
     name: 'main.yaml',
-    url: 'yaml',
-    template: '<br-yaml-editor value="vm.yaml" 
type="blueprint"></br-yaml-editor>',
-    controller: ['$scope', '$rootScope', '$timeout', 'blueprintService', 
'brSnackbar', yamlStateController],
+    url: '/yaml',
+    controller: ['$scope', '$state', '$timeout', 'blueprintService', 
'brSnackbar', 'composerOverrides', yamlStateController],
     controllerAs: 'vm',
-    data: {
-        label: 'YAML Editor'
-    }
 }
 export const yamlCampState = {
-    name: 'main.yaml.camp',
-    url: 'camp',
+    name: 'main.yaml_camp',
+    url: '/yaml/camp',
     template: '<br-yaml-editor value="vm.yaml" 
type="blueprint"></br-yaml-editor>',
-    controller: ['$scope', '$rootScope', '$timeout', 'blueprintService', 
'brSnackbar', yamlStateController],
+    controller: ['$scope', 'blueprintService', 'brSnackbar', 
yamlCampStateController],
     controllerAs: 'vm',
     data: {
         label: 'YAML Editor'
     }
 };
 
-function yamlStateController($scope, $rootScope, $timeout, blueprintService, 
brSnackbar) {
+function yamlStateController($scope, $state, $timeout, blueprintService, 
brSnackbar, composerOverrides) {
+    let vm = this;
+
+    try {
+        vm.yaml = blueprintService.getAsYaml();
+    } catch (ex) {
+        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;
+    }
+
+    $timeout(() => $state.go( getYamlStateNameForBlueprint($scope, vm.yaml, 
composerOverrides) ));
+}
+
+export function getYamlStateNameForBlueprint($scope, yaml, composerOverrides) {
+    if ($scope.initialYamlFormat == "brooklyn-camp") return yamlCampState.name;
+
+    let state = (composerOverrides.getYamlStateNameForBlueprint || (() => 
null))($scope, yaml, composerOverrides);
+    if (state) return state;
+
+    if ($scope.initialYamlFormat && 
$scope.initialYamlFormat.indexOf("camp")>=0) return yamlCampState.name;
+    if (yaml && yaml.indexOf("services:")>=0) return yamlCampState.name;
+
+    return composerOverrides.yamlDefaultStateName || yamlCampState.name;
+}
+
+function yamlCampStateController($scope, blueprintService, brSnackbar) {
     let vm = this;
 
     try {
diff --git a/ui-modules/blueprint-importer/app/views/main/main.controller.js 
b/ui-modules/blueprint-importer/app/views/main/main.controller.js
index b92b644..959ca2c 100644
--- a/ui-modules/blueprint-importer/app/views/main/main.controller.js
+++ b/ui-modules/blueprint-importer/app/views/main/main.controller.js
@@ -123,7 +123,7 @@ function bottomSheetController($log, brBrandInfo, 
brBottomSheetInstance, catalog
                         type: item.symbolicName + ':' + item.version
                     }]
                 };
-                return '/brooklyn-ui-blueprint-composer/#!/graphical?yaml=' + 
JSON.stringify(yaml);
+                return 
'/brooklyn-ui-blueprint-composer/#!/graphical?format=brooklyn-camp&yaml=' + 
JSON.stringify(yaml);
             default:
                 return;
         }
diff --git a/ui-modules/utils/quick-launch/quick-launch.js 
b/ui-modules/utils/quick-launch/quick-launch.js
index 26fa8ca..7f32f2c 100644
--- a/ui-modules/utils/quick-launch/quick-launch.js
+++ b/ui-modules/utils/quick-launch/quick-launch.js
@@ -264,9 +264,9 @@ export function quickLaunchDirective() {
                 }
                 
                 // prefer to use the actual yaml input, but if it's not 
possible
-                let tryMergeByConcatenate = 
+                let tryMergeByConcatenate =
                     Object.keys(newApp).length ?
-                        (yaml.safeDump(newApp) + "\n" + ((validate && 
cannotUsePlanText) ? yaml.safeDump(result) : planText))
+                        (yaml.safeDump(newApp, {skipInvalid: true}) + "\n" + 
((validate && cannotUsePlanText) ? yaml.safeDump(result) : planText))
                         : planText;
                 if (validate) {
                     // don't think there's any way we'd wind up with invalid 
yaml but check to be sure
@@ -288,10 +288,12 @@ export function quickLaunchDirective() {
         function openComposer() {
             try {
               window.location.href = 
'/brooklyn-ui-blueprint-composer/#!/graphical?'+
+                ($scope.app.plan.format ? 
'format='+encodeURIComponent($scope.app.plan.format)+'&' : '')+
                 'yaml='+encodeURIComponent(buildComposerYaml(true));
             } catch (error) {
               console.warn("Opening composer in YAML text editor mode because 
we cannot generate a model for this configuration:", error);
               window.location.href = 
'/brooklyn-ui-blueprint-composer/#!/yaml?'+
+                ($scope.app.plan.format ? 
'format='+encodeURIComponent($scope.app.plan.format)+'&' : '')+
                 'yaml='+encodeURIComponent(
                     "# This plan may have items which require attention so is 
being opened in YAML text editor mode.\n"+
                     "# The YAML was autogenerated by merging the plan with any 
values provided in UI, but issues were\n"+

Reply via email to