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

iuliana 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 334bed6  make spec-editor sections re-orderable
     new a40e81f  Merge pull request #218 from 
ahgittin/composer-spec-editor-sections-configurable
334bed6 is described below

commit 334bed6ca23787d5352bc3f9ed1a23117801cc29
Author: Alex Heneveld <[email protected]>
AuthorDate: Wed Jun 9 23:11:03 2021 +0100

    make spec-editor sections re-orderable
    
    remove placeholder for "requirements" section wanted by downstream apps
---
 .../spec-editor/spec-editor.directive.js           | 30 ++++++++++------------
 .../app/components/spec-editor/spec-editor.spec.js | 22 +++++++++++++---
 .../spec-editor/spec-editor.template.html          | 23 +++++++++++------
 3 files changed, 47 insertions(+), 28 deletions(-)

diff --git 
a/ui-modules/blueprint-composer/app/components/spec-editor/spec-editor.directive.js
 
b/ui-modules/blueprint-composer/app/components/spec-editor/spec-editor.directive.js
index 0104696..d0fa93f 100644
--- 
a/ui-modules/blueprint-composer/app/components/spec-editor/spec-editor.directive.js
+++ 
b/ui-modules/blueprint-composer/app/components/spec-editor/spec-editor.directive.js
@@ -30,6 +30,7 @@ import template from './spec-editor.template.html';
 import {graphicalState} from '../../views/main/graphical/graphical.state';
 import {SENSITIVE_FIELD_REGEX} from 
'brooklyn-ui-utils/sensitive-field/sensitive-field';
 import {computeQuickFixesForIssue} from '../quick-fix/quick-fix';
+import scriptTagDecorator from 
'brooklyn-ui-utils/script-tag-non-overwrite/script-tag-non-overwrite';
 
 const MODULE_NAME = 'brooklyn.components.spec-editor';
 const ANY_MEMBERSPEC_REGEX = /(^.*[m,M]ember[s,S]pec$)/;
@@ -39,12 +40,9 @@ const SUBSECTION = {
     PARAMETERS: 'parameters'
 }
 
-export const SUBSECTION_TEMPLATE_URL = {
-    REQUIREMENTS: 
'blueprint-composer/component/spec-editor/section-requirements.html',
-    OTHERS: 'blueprint-composer/component/spec-editor/section-others.html'
-};
+export const SUBSECTION_TEMPLATE_OTHERS_URL = 
'blueprint-composer/component/spec-editor/section-others.html';
 
-angular.module(MODULE_NAME, [onEnter, autoGrow, blurOnEnter, 
brooklynDslEditor, brooklynDslViewer])
+angular.module(MODULE_NAME, [onEnter, autoGrow, blurOnEnter, 
brooklynDslEditor, brooklynDslViewer, scriptTagDecorator])
     .directive('specEditor', ['$rootScope', '$templateCache', '$injector', 
'$sanitize', '$filter', '$log', '$sce', '$timeout', '$document', '$state', 
'$compile', 'blueprintService', 'composerOverrides', 'mdHelper', 
specEditorDirective])
     .filter('specEditorConfig', specEditorConfigFilter)
     .filter('specEditorType', specEditorTypeFilter)
@@ -128,6 +126,17 @@ export function specEditorDirective($rootScope, 
$templateCache, $injector, $sani
         scope.REPLACED_DSL_ENTITYSPEC = REPLACED_DSL_ENTITYSPEC;
         scope.parameters = [];
         scope.config = {};
+
+        scope.sections = [
+            'blueprint-composer/component/spec-editor/section-header.html',
+            'blueprint-composer/component/spec-editor/section-parameters.html',
+            
'blueprint-composer/component/spec-editor/section-entity-config.html',
+            'blueprint-composer/component/spec-editor/section-locations.html',
+            'blueprint-composer/component/spec-editor/section-policies.html',
+            'blueprint-composer/component/spec-editor/section-enrichers.html',
+            SUBSECTION_TEMPLATE_OTHERS_URL,
+        ];
+
         specEditor.descriptionVisible = false;
         specEditor.paramTypes = PARAM_TYPES;
 
@@ -1279,21 +1288,10 @@ export function specEditorTypeFilter() {
 }
 
 /**
- * @returns {string} The HTML template placeholder for a subsection with a 
specified ID.
- */
-function getSubsectionPlaceholder(id) {
-    return `<script type="text/ng-template" id="${id}" 
defer-to-preexisting-id="true">
-                 <!-- Subsection placeholder -->
-            </script>`;
-}
-
-/**
  * Configures $templateCache for this directive.
  *
  * @param $templateCache The template cache to configure.
  */
 function templateCache($templateCache) {
     $templateCache.put(TEMPLATE_URL, template);
-    $templateCache.put(SUBSECTION_TEMPLATE_URL.REQUIREMENTS, 
getSubsectionPlaceholder(SUBSECTION_TEMPLATE_URL.REQUIREMENTS));
-    $templateCache.put(SUBSECTION_TEMPLATE_URL.OTHERS, 
getSubsectionPlaceholder(SUBSECTION_TEMPLATE_URL.OTHERS));
 }
diff --git 
a/ui-modules/blueprint-composer/app/components/spec-editor/spec-editor.spec.js 
b/ui-modules/blueprint-composer/app/components/spec-editor/spec-editor.spec.js
index dbc70f4..38b4d86 100644
--- 
a/ui-modules/blueprint-composer/app/components/spec-editor/spec-editor.spec.js
+++ 
b/ui-modules/blueprint-composer/app/components/spec-editor/spec-editor.spec.js
@@ -17,7 +17,7 @@
  * under the License.
  */
 
-import SpecEditor, {SUBSECTION_TEMPLATE_URL} from './spec-editor.directive';
+import SpecEditor, {SUBSECTION_TEMPLATE_OTHERS_URL} from 
'./spec-editor.directive';
 import {iconGeneratorProvider} from 
'brooklyn-ui-utils/icon-generator/icon-generator';
 import {locationApiProvider} from 
'brooklyn-ui-utils/providers/location-api.provider';
 import {catalogApiProvider} from 
'brooklyn-ui-utils/providers/catalog-api.provider';
@@ -66,10 +66,10 @@ describe('Spec Editor', () => {
         // Dependencies of the spec-editor.
         $provide.provider('blueprintService', blueprintServiceProvider);
         $provide.provider('$state', {$get: () => {return {}}}); // Produces 
'Object {}'.
-        $provide.provider('composerOverrides', {$get: () => {return {}}}); // 
Produces 'Object {}'.
         $provide.factory('mdHelper', mdHelperFactory);
 
         // Configuration dependency.
+        //$provide.provider('composerOverrides', {$get: () => {return {}}}); 
// Produces 'Object {}'.
         $provide.provider('composerOverrides', {
             $get: () => {
                 return {
@@ -157,10 +157,24 @@ describe('Spec Editor', () => {
     it('Creates custom subsections', () => {
 
         // Prepare templates for custom accordions.
-        $templateCache.put(SUBSECTION_TEMPLATE_URL.REQUIREMENTS, 
'<br-collapsible><heading>Requirements</heading></br-collapsible>');
-        $templateCache.put(SUBSECTION_TEMPLATE_URL.OTHERS, 
'<br-collapsible><heading>Other</heading></br-collapsible>');
+
+        // one at the end can be added by overriding this (requires 
scriptTagDecorator on spec-editor directive, which it is)
+        $templateCache.put(SUBSECTION_TEMPLATE_OTHERS_URL, 
'<br-collapsible><heading>Other</heading></br-collapsible>');
+        // a custom one can be inserted in the middle
+        $templateCache.put('custom-reqs', 
'<br-collapsible><heading>Requirements</heading></br-collapsible>');
+        // a dummy one has no impact
         $templateCache.put('dummy-template.html', 
'<br-collapsible><heading>Dummy</heading></br-collapsible>');
+
         element = $compile('<spec-editor 
model="testModel"></spec-editor>')($rootScope);
+        $templateCache.put(SUBSECTION_TEMPLATE_OTHERS_URL, 
'<br-collapsible><heading>Other</heading></br-collapsible>');
+
+        $rootScope.$digest();
+
+        _scope = element.isolateScope();
+        let index = _scope.sections.findIndex(k => 
k.indexOf("entity-config")>=0) + 1;
+        if (index<=0) index = _scope.sections.length;
+        _scope.sections.splice(index, 0, 'custom-reqs');
+
         $rootScope.$digest();
 
         let accordions = element.find('br-collapsible');
diff --git 
a/ui-modules/blueprint-composer/app/components/spec-editor/spec-editor.template.html
 
b/ui-modules/blueprint-composer/app/components/spec-editor/spec-editor.template.html
index b59dfb7..55a4b69 100644
--- 
a/ui-modules/blueprint-composer/app/components/spec-editor/spec-editor.template.html
+++ 
b/ui-modules/blueprint-composer/app/components/spec-editor/spec-editor.template.html
@@ -16,7 +16,13 @@
   specific language governing permissions and limitations
   under the License.
 -->
+
+
+<ng-include ng-repeat="section in sections" src="section"></ng-include>
+
+
 <!-- ENTITY TYPE -->
+<script type="text/ng-template" 
id="blueprint-composer/component/spec-editor/section-header.html" 
defer-to-preexisting-id="true">
 <section class="spec-type container-fluid panel-group">
   <div class="panel">
     <div class="spec-type-header">
@@ -67,8 +73,10 @@
         <md-if-multiline ng-show="specEditor.descriptionVisible" 
data="modelDescription"></md-if-multiline>
     </div>
 </br-collapsible>
+</script>
 
 <!-- ENTITY PARAMETERS -->
+<script type="text/ng-template" 
id="blueprint-composer/component/spec-editor/section-parameters.html" 
defer-to-preexisting-id="true">
 <br-collapsible state="state.parameters.open" ng-if="!model.parent">  <!-- the 
ng-if is needed to make state update?! -->
     <heading>
         Parameters
@@ -277,8 +285,10 @@
 
     </div>
 </br-collapsible>
+</script>
 
 <!-- ENTITY CONFIGURATION -->
+<script type="text/ng-template" 
id="blueprint-composer/component/spec-editor/section-entity-config.html" 
defer-to-preexisting-id="true">
 <br-collapsible ng-if="true" state="state.config.open">  <!-- the ng-if is 
needed to make state update?! -->
     <heading>
         Configuration
@@ -578,12 +588,9 @@
         
     </div>
 </br-collapsible>
-
-<!-- Placeholder for REQUIREMENTS section, URL (src) must match with 
SUBSECTION_TEMPLATE_URL.REQUIREMENTS -->
-<ng-include 
src="'blueprint-composer/component/spec-editor/section-requirements.html'"></ng-include>
+</script>
 
 <!-- ENTITY LOCATION -->
-<ng-include 
src="'blueprint-composer/component/spec-editor/section-locations.html'"></ng-include>
 <script type="text/ng-template" 
id="blueprint-composer/component/spec-editor/section-locations.html" 
defer-to-preexisting-id="true">
   <br-collapsible ng-if="[FAMILIES.ENTITY, 
FAMILIES.SPEC].indexOf(model.family) > -1" state="state.location.open">
     <heading>
@@ -618,7 +625,6 @@
 </script>
 
 <!-- ENTITY POLICIES -->
-<ng-include 
src="'blueprint-composer/component/spec-editor/section-policies.html'"></ng-include>
 <script type="text/ng-template" 
id="blueprint-composer/component/spec-editor/section-policies.html" 
defer-to-preexisting-id="true">
   <br-collapsible ng-if="[FAMILIES.ENTITY, 
FAMILIES.SPEC].indexOf(model.family) > -1" state="state.policy.open">
     <heading>
@@ -654,7 +660,6 @@
 </script>
 
 <!-- ENTITY ENRICHERS -->
-<ng-include 
src="'blueprint-composer/component/spec-editor/section-enrichers.html'"></ng-include>
 <script type="text/ng-template" 
id="blueprint-composer/component/spec-editor/section-enrichers.html" 
defer-to-preexisting-id="true">
   <br-collapsible ng-if="[FAMILIES.ENTITY, 
FAMILIES.SPEC].indexOf(model.family) > -1" state="state.enricher.open">
     <heading>
@@ -689,8 +694,10 @@
   </br-collapsible>
 </script>
 
-<!-- Placeholder for other sections, URL (src) must match with 
SUBSECTION_TEMPLATE_URL.OTHERS -->
-<ng-include 
src="'blueprint-composer/component/spec-editor/section-others.html'"></ng-include>
+<!-- OTHERS (downstream customizations) -->
+<script type="text/ng-template" 
id="blueprint-composer/component/spec-editor/section-others.html" 
defer-to-preexisting-id="true">
+    <!-- Placeholder for other sections. -->
+</script>
 
 <!-- PARAMETER INFO TEMPLATE :: START -->
 <script type="text/ng-template" 
id="blueprint-composer/component/spec-editor/parameter-info.html" 
defer-to-preexisting-id="true">

Reply via email to