Skip to content

Commit

Permalink
feat: open node on click
Browse files Browse the repository at this point in the history
  • Loading branch information
haidaraM committed Jan 9, 2022
1 parent 21c3f9a commit 0c14809
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
13 changes: 11 additions & 2 deletions ansibleplaybookgrapher/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def __init__(self, node_name: str, node_id: str, raw_object=None):
:param node_name: The name of the node
:param node_id: An identifier for this node
:param raw_object: The raw ansible object matching this node in the graph. Will be None if there is no match on
:param raw_object: The raw ansible object matching this node in the graph. Will be None if there is no match on
Ansible side
"""
self.name = node_name
Expand Down Expand Up @@ -237,8 +237,17 @@ class TaskNode(Node):
A task node. Can be pre_task, task or post_task
"""

def __init__(self, node_name: str, node_id: str = None, raw_object=None):
def __init__(self, node_name: str, node_id: str = None, raw_object=None, path: str = None):
"""
:param node_name:
:param node_id:
:param raw_object:
:param path: The path on the filesystem where the task is located. It should be something like
${absolute_path_to_the_file}:${task_line_number}
"""
super().__init__(node_name, node_id or generate_id("task_"), raw_object)
self.path = path


class RoleNode(CompositeTasksNode):
Expand Down
5 changes: 3 additions & 2 deletions ansibleplaybookgrapher/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,9 @@ def _add_task(self, task: Task, task_vars: Dict, node_type: str, parent_node: Co
task_name = clean_name(self.template(task.get_name(), task_vars))
edge_label = convert_when_to_str(task.when)

edge_node = EdgeNode(parent_node, TaskNode(task_name, generate_id(f"{node_type}_"), raw_object=task),
edge_label)
edge_node = EdgeNode(source=parent_node, node_name=edge_label,
destination=TaskNode(task_name, generate_id(f"{node_type}_"), raw_object=task,
path=task.get_path()))
parent_node.add_node(target_composition=f"{node_type}s", node=edge_node)

return True
Expand Down
2 changes: 1 addition & 1 deletion ansibleplaybookgrapher/renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def render_node(self, graph: Digraph, edge: EdgeNode, color: str, node_counter:
else:
edge_label = f"{node_counter} {edge.name}"
graph.node(destination_node.id, label=node_label_prefix + destination_node.name, shape=shape,
id=destination_node.id, tooltip=destination_node.name, color=color)
id=destination_node.id, tooltip=destination_node.name, color=color, URL=destination_node.path)
graph.edge(source_node.id, destination_node.id, label=edge_label, color=color, fontcolor=color, id=edge.id,
tooltip=edge_label, labeltooltip=edge_label)

Expand Down

0 comments on commit 0c14809

Please sign in to comment.