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 68a694993741dbf00b9b3d13a7328dc7ed92b504 Author: Mykola Mandra <[email protected]> AuthorDate: Mon May 31 13:14:26 2021 +0100 Create constants for DSL target; use subsection parameter in dsl.edit instead of isConfig Signed-off-by: Mykola Mandra <[email protected]> --- .../app/components/dsl-editor/dsl-editor.js | 8 ++--- .../app/components/util/model/dsl.model.js | 35 +++++++++++++++------- .../app/components/util/model/dsl.model.spec.js | 8 ++--- .../main/graphical/edit/dsl/edit.dsl.controller.js | 2 +- 4 files changed, 33 insertions(+), 20 deletions(-) diff --git a/ui-modules/blueprint-composer/app/components/dsl-editor/dsl-editor.js b/ui-modules/blueprint-composer/app/components/dsl-editor/dsl-editor.js index 3b0cd20..5bbd0ee 100644 --- a/ui-modules/blueprint-composer/app/components/dsl-editor/dsl-editor.js +++ b/ui-modules/blueprint-composer/app/components/dsl-editor/dsl-editor.js @@ -18,7 +18,7 @@ */ import angular from 'angular'; import angularSanitize from 'angular-sanitize'; -import {Dsl, DslParser, KIND} from '../util/model/dsl.model'; +import {Dsl, DslParser, KIND, TARGET} from '../util/model/dsl.model'; import template from './dsl-editor.template.html'; import brAutoFocus from 'brooklyn-ui-utils/autofocus/autofocus'; import brUtils from 'brooklyn-ui-utils/utils/general'; @@ -354,10 +354,10 @@ export function dslEditorDirective($rootScope, $filter, $log, brUtilsGeneral, bl function getScopedDsl(entity, targetEntity, state) { if (entity === targetEntity) { - return new Dsl(KIND.TARGET, 'self'); + return new Dsl(KIND.TARGET, TARGET.SELF); } if (entity.parent === targetEntity) { - return new Dsl(KIND.TARGET, 'parent'); + return new Dsl(KIND.TARGET, TARGET.PARENT); } if (!targetEntity.hasId()) { @@ -372,7 +372,7 @@ export function dslEditorDirective($rootScope, $filter, $log, brUtilsGeneral, bl } function isSelfDsl(dsl) { - return dsl && dsl.kind === KIND.TARGET && dsl.name === 'self'; + return dsl && dsl.kind === KIND.TARGET && dsl.name === TARGET.SELF; } } diff --git a/ui-modules/blueprint-composer/app/components/util/model/dsl.model.js b/ui-modules/blueprint-composer/app/components/util/model/dsl.model.js index 0caa5e4..27d4fb6 100644 --- a/ui-modules/blueprint-composer/app/components/util/model/dsl.model.js +++ b/ui-modules/blueprint-composer/app/components/util/model/dsl.model.js @@ -20,7 +20,20 @@ import {Entity} from './entity.model'; const FUNCTION_PREFIX = '$brooklyn:'; -const TARGETS = [ 'self', 'parent', 'child', 'sibling', 'descendant', 'ancestor', 'root', 'scopeRoot', 'entity', 'component', ]; +export const TARGET = { + SELF: 'self', + ROOT: 'root', + CHILD: 'child', + ENTITY: 'entity', + PARENT: 'parent', + SIBLING: 'sibling', + ANCESTOR: 'ancestor', + SCOPEROOT: 'scopeRoot', + COMPONENT: 'component', + DESCENDANT: 'descendant' +} + +const TARGETS = Object.values(TARGET); const UTILITIES = [ 'literal', 'formatString', 'urlEncode', 'regexReplacement' ]; @@ -585,20 +598,20 @@ export class Dsl { let curr = entity; while (dsl.kind === KIND.TARGET) { switch (dsl.name) { - case 'self': + case TARGET.SELF: break; - case 'parent': + case TARGET.PARENT: if (!curr.parent) { this.issues.push('The entity with ID <code>' + curr.id + '</code> does not have a parent'); } curr = curr.parent; break; - case 'child': - case 'sibling': - case 'descendant': - case 'ancestor': - case 'entity': - case 'component': // component can have 1 or 2 params + case TARGET.CHILD: + case TARGET.SIBLING: + case TARGET.DESCENDANT: + case TARGET.ANCESTOR: + case TARGET.ENTITY: + case TARGET.COMPONENT: // component can have 1 or 2 params let name = dsl.params[dsl.params.length - 1].name; let resolvedEntity = entityResolver(name); if (resolvedEntity === null) { @@ -606,8 +619,8 @@ export class Dsl { } curr = resolvedEntity; break; - case 'root': - case 'scopeRoot': + case TARGET.ROOT: + case TARGET.SCOPEROOT: curr = this.resolveRoot(curr); break; } diff --git a/ui-modules/blueprint-composer/app/components/util/model/dsl.model.spec.js b/ui-modules/blueprint-composer/app/components/util/model/dsl.model.spec.js index 836322b..83c621d 100644 --- a/ui-modules/blueprint-composer/app/components/util/model/dsl.model.spec.js +++ b/ui-modules/blueprint-composer/app/components/util/model/dsl.model.spec.js @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -import {Dsl, KIND, DslParser, Tokenizer, DslError} from './dsl.model'; +import {Dsl, KIND, DslParser, Tokenizer, DslError, TARGET} from './dsl.model'; import {Entity} from './entity.model'; describe('Dsl Component Model', ()=>{ @@ -159,7 +159,7 @@ describe('Dsl Component Model', ()=>{ expect(dsl2.generate()).toEqual('10.2'); // target function without parameters - let dsl3 = new Dsl(KIND.TARGET, 'self'); + let dsl3 = new Dsl(KIND.TARGET, TARGET.SELF); expect(dsl3.generateParams()).toEqual(''); expect(dsl3.toString()).toEqual('$brooklyn:self()'); expect(dsl3.generate()).toEqual('self()'); @@ -175,8 +175,8 @@ describe('Dsl Component Model', ()=>{ expect(dsl3.toString()).toEqual('$brooklyn:self().attributeWhenReady("http.port")'); // chained target functions and methods: parent().sibling(...).attributeWhenReady(...) - let dsl4 = new Dsl(KIND.TARGET, 'parent'); - let sib1 = new Dsl(KIND.TARGET, 'sibling'); + let dsl4 = new Dsl(KIND.TARGET, TARGET.PARENT); + let sib1 = new Dsl(KIND.TARGET, TARGET.SIBLING); let par2 = new Dsl(KIND.STRING, 'rootNode'); sib1.param(par2); dsl4.chain(sib1); diff --git a/ui-modules/blueprint-composer/app/views/main/graphical/edit/dsl/edit.dsl.controller.js b/ui-modules/blueprint-composer/app/views/main/graphical/edit/dsl/edit.dsl.controller.js index c29e8d4..c09af70 100644 --- a/ui-modules/blueprint-composer/app/views/main/graphical/edit/dsl/edit.dsl.controller.js +++ b/ui-modules/blueprint-composer/app/views/main/graphical/edit/dsl/edit.dsl.controller.js @@ -128,7 +128,7 @@ export const graphicalEditDslState = { value: '', squash: true }, - isConfig: true // This flag identifies whether DSL edit is for configuration or something else. Configuration is a default. + subsection: '' // This parameter specifies what subsection DSL edit is for. Configuration subsection is default. }, template: template, controller: ['$scope', '$state', '$stateParams', 'objectCache', 'state', EditDslController],
