algairim commented on a change in pull request #199:
URL: https://github.com/apache/brooklyn-ui/pull/199#discussion_r621310492
##########
File path:
ui-modules/app-inspector/app/components/entity-tree/entity-tree.directive.js
##########
@@ -149,45 +149,99 @@ export function entityTreeDirective() {
* @param {Array.<Object>} relationships The relationships of
entities.
*/
function addHostForHostedOnView(entities, relationships) {
+
+ // Look through all entities found in the entity tree
entities.forEach(entity => {
+
+ // 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 child = entities.find(e => e.id === target);
- if (child) {
- highlightEntityInView(child,
VIEW_HOST_FOR_HOSTED_ON);
- if (child.parentId !== entity.id) { // Move
(copy) child under 'hosted_on' entity.
- let childCopy = Object.assign({}, child);
// Copy entity
-
- // Display in 'host_for/hosted_on' view
only.
- childCopy.viewModes = null;
- displayEntityInView(childCopy,
VIEW_HOST_FOR_HOSTED_ON);
-
- let parent = findEntity(entities,
child.parentId);
- if (parent) {
- childCopy.name += ' (' + parent.name +
')';
- }
+ 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 (!entity.children) {
- entity.children = [childCopy];
+ 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 {
- entity.children.push(childCopy);
+ // 4.2. Move 'hosted_on' entity to a
new 'host_for' parent.
+ moveEntityToParent(relatedEntity,
entity, entities, VIEW_HOST_FOR_HOSTED_ON);
}
}
- displayParentsInView(entities, child.parentId,
VIEW_HOST_FOR_HOSTED_ON);
}
});
} else if (!relationship || relationship.name !==
RELATIONSHIP_HOSTED_ON) {
- // Display original position for any other entity
under 'host_for/hosted_on' view.
+
+ // 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);
- // Spotlight will never be on entities that are
required to be displayed but do not belong to this view.
}
});
}
+ /**
+ * Flips parent entity with its child.
+ *
+ * @param parent The parent entity to flip with its child.
+ * @param child The child entity to flip with its parent.
+ * @param {Array.<Object>} entities The entity tree converted to
array.
+ * @param {string} viewMode The view mode to display copy of the
entity in only.
+ */
+ function flipParentAndChild(parent, child, entities, viewMode) {
+ console.log('Flip parent with a child!', parent, child);
Review comment:
This has been removed in the following commit.
--
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:
[email protected]