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 2021/08/03 15:52:10 UTC
[brooklyn-ui] 02/03: syntax refactoring
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 6d38e6aa2c4728685cca0d22fc613a5992065dc8
Author: John Athanasiou <ja...@users.noreply.github.com>
AuthorDate: Tue Aug 3 14:13:25 2021 +0100
syntax refactoring
---
.../app/components/dsl-editor/dsl-editor.js | 70 +++++++++++-----------
1 file changed, 36 insertions(+), 34 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 9e4812d..cd1bdf4 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
@@ -280,19 +280,19 @@ export function dslEditorDirective($rootScope, $filter, $log, brUtilsGeneral, bl
}
}
- function getEntityConfigPropertyItems (entity, definition, propertyName) {
- return entity.miscData.get(propertyName)
- .filter(item => item !== definition)
+ function entityPropertyParserFor(type, filterFunc=()=>true) {
+ return (entity, propertyName) => entity.miscData.get(propertyName)
+ .filter(filterFunc)
.map(({ name, description }) => ({
id: name,
- type: DSL_KINDS.CONFIG,
+ type,
entity,
name,
description,
}));
- };
+ }
- function uniqueConfigItems(items) {
+ function uniqueItems(items) {
const IDs = new Set();
return items.filter(({ id }) => {
@@ -303,9 +303,11 @@ export function dslEditorDirective($rootScope, $filter, $log, brUtilsGeneral, bl
}
function getConfigItems(entity, definition, nested=false) {
+ const parseAsConfig = entityPropertyParserFor(DSL_KINDS.CONFIG, item=>item !== definition);
+
const result = [
- ...getEntityConfigPropertyItems(entity, definition, 'config'),
- ...getEntityConfigPropertyItems(entity, definition, 'parameters'),
+ ...parseAsConfig(entity, 'config'),
+ ...parseAsConfig(entity, 'parameters'),
];
Object.values(entity.getClusterMemberspecEntities() || {}).forEach(member => {
@@ -318,47 +320,47 @@ export function dslEditorDirective($rootScope, $filter, $log, brUtilsGeneral, bl
return nested
? result
- : uniqueConfigItems(result); // only need to check distinct items once, not in every recursion
+ : uniqueItems(result); // only need to check distinct items once, not in every recursion
}
- function getSensorItems(entity) {
- let sensors = entity.miscData.get('sensors').map(sensor => {
- return {
- id: sensor.name,
- type: DSL_KINDS.SENSOR,
- entity: entity,
- name: sensor.name,
- description: sensor.description
- };
+ function getSensorItems(entity, nested=false) {
+ const parseAsSensors = entityPropertyParserFor(DSL_KINDS.SENSOR);
+
+ const result = parseAsSensors(entity, 'sensors');
+
+ Object.values(entity.getClusterMemberspecEntities() || {}).forEach(member => {
+ result.push(...getSensorItems(member, true));
});
- sensors = Object.values(entity.getClusterMemberspecEntities()).reduce((acc, spec) => {
- return acc.concat(getSensorItems(spec));
- }, sensors);
+ (entity.children || []).forEach(child => {
+ result.push(...getSensorItems(child, true));
+ });
- return entity.children.reduce((acc, child) => {
- return acc.concat(getSensorItems(child));
- }, sensors);
+ return nested
+ ? result
+ : uniqueItems(result);
}
- function getEntityItems(entity, type) {
- let entities = [];
-
- entities.push({
+ function getEntityItems(entity, nested=false) {
+ const result = [{
id: entity._id,
type: DSL_KINDS.ENTITY,
entity: entity,
name: entity.miscData.get('typeName') || $filter('entityName')(entity) || 'New application',
description: entity.description
+ }];
+
+ Object.values(entity.getClusterMemberspecEntities() || {}).forEach(member => {
+ result.push(...getEntityItems(member, true));
});
- entities = Object.values(entity.getClusterMemberspecEntities()).reduce((acc, spec) => {
- return acc.concat(getEntityItems(spec, type));
- }, entities);
+ (entity.children || []).forEach(child => {
+ result.push(...getEntityItems(child, true));
+ });
- return entity.children.reduce((acc, child) => {
- return acc.concat(getEntityItems(child, type));
- }, entities);
+ return nested
+ ? result
+ : uniqueItems(result);
}
function getScopedDsl(entity, targetEntity, state) {