algairim commented on a change in pull request #209: URL: https://github.com/apache/brooklyn-ui/pull/209#discussion_r643382426
########## File path: ui-modules/app-inspector/app/components/entity-tree/entity-tree.directive.js ########## @@ -141,55 +134,106 @@ export function entityTreeDirective() { } /** - * Extends entity tree with 'host_for/hosted_on' view mode. Moves entities (creates copies) if their host is - * not a parent and labels them to display under 'host_for/hosted_on' view mode only. + * Extends entity tree with other view modes. Moves entities (creates copies) if their host is + * not a parent and labels them to display under other view modes only. * * @param {Array.<Object>} entities The entity tree converted to array. * @param {Array.<Object>} relationships The relationships of entities. */ - function addHostForHostedOnView(entities, relationships) { + function addOtherViews(entities, relationships) { + let otherViews = Array.from($scope.viewModes).filter(r => r !== VIEW_PARENT_CHILD); + otherViews.forEach(view => { - // Look through all entities found in the entity tree - entities.forEach(entity => { + // Get 'OTHER_PARENT' and 'OTHER_CHILD' identifiers. + const {OTHER_PARENT, OTHER_CHILD} = getRelationshipViewIdentifiers(view); + + // Phase 1. Look through all entities found in the entity tree: process entity with 'OTHER_PARENT' + // roles and entities without roles. + entities.forEach(entity => { + + // Get relationship roles for an entity. + const {parentRole, childRole} = getRelationshipRoles(relationships, entity.id, OTHER_PARENT, OTHER_CHILD); + + if (parentRole) { - // Check if entity has 'host_for/hosted_on' relationship. - let relationship = relationships.find(r => r.id === entity.id); - if (relationship && relationship.name === RELATIONSHIP_HOST_FOR) { - - // Label every 'host_for' entity to display and highlight in 'host_for/hosted_on' view mode. - displayEntityInView(entity, VIEW_HOST_FOR_HOSTED_ON); - highlightEntityInView(entity, VIEW_HOST_FOR_HOSTED_ON); - - // Look for 'hosted_on' entities under 'host_for', flip of move them and label to display in - // 'host_for/hosted_on' view mode respectively. - relationship.targets.forEach(target => { - let relatedEntity = entities.find(e => e.id === target); - if (relatedEntity) { - highlightEntityInView(relatedEntity, VIEW_HOST_FOR_HOSTED_ON); - displayParentsInView(entities, relatedEntity.parentId, VIEW_HOST_FOR_HOSTED_ON); - - // Re-arrange the tree if related 'hosted_on' entity is not a child of 'host_for'. - if (relatedEntity.parentId !== entity.id) { - - if (relatedEntity.id === entity.parentId) { - // 4.1. Flip 'hosted_on' parent with a 'host_for' child. - flipParentAndChild(relatedEntity, entity, entities, VIEW_HOST_FOR_HOSTED_ON); - } else { - // 4.2. Move 'hosted_on' entity to a new 'host_for' parent. - moveEntityToParent(relatedEntity, entity, entities, VIEW_HOST_FOR_HOSTED_ON); + // Label every 'OTHER_PARENT' entity to display and highlight in 'OTHER_PARENT/OTHER_CHILD' + // view mode, only if it does not play the role of 'OTHER_CHILD' at the same time. + if (!childRole) { + displayEntityInView(entity, view); + highlightEntityInView(entity, view); + } + + // Look for 'OTHER_CHILD' entities under 'OTHER_PARENT', flip or move them and label to display in + // 'OTHER_PARENT/OTHER_CHILD' view mode respectively. + parentRole.targets.forEach(target => { + let relatedEntity = findEntity(entities, target); + if (relatedEntity) { + highlightEntityInView(relatedEntity, view); + displayParentsInView(entities, relatedEntity.parentId, view); + + // Re-arrange the tree if related 'OTHER_CHILD' entity is not a child of 'OTHER_PARENT'. + if (relatedEntity.parentId !== entity.id) { + + if (relatedEntity.id === entity.parentId) { + // 4.1. Flip 'OTHER_CHILD' parent with a 'OTHER_PARENT' child. + flipParentAndChild(relatedEntity, entity, entities, view); + } else { + // 4.2. Move 'OTHER_CHILD' entity to a new 'OTHER_PARENT' parent. + moveEntityToParent(relatedEntity, entity, entities, view); + } } } - } - }); - } else if (!relationship || relationship.name !== RELATIONSHIP_HOSTED_ON) { + }); + } else if (!parentRole && !childRole) { - // Display original position for any other entity under 'host_for/hosted_on' view. Do no highlight - // entities that are required to be displayed but do not belong to this view. - displayEntityInView(entity, VIEW_HOST_FOR_HOSTED_ON); - } + // Display original position for any other entity under 'OTHER_PARENT/OTHER_CHILD' view. Do + // no highlight entities that are required to be displayed but do not belong to this view. + displayEntityInView(entity, view); + } + }); + + // Phase 2. Look through all entities found again and process entities that play both roles: + // 'OTHER_PARENT' and 'OTHER_CHILD'. Review comment: New phase to cover edge case when entity plays role of parent and child in the view. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org