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 Sep 23, 2021
1 parent fd45aed commit a3a862c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
9 changes: 8 additions & 1 deletion ansibleplaybookgrapher/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,14 @@ class TaskNode(Node):
A task node. Can be pre_task, task or post_task
"""

def __init__(self, node_name: str, node_id: str = None):
def __init__(self, node_name: str, node_id: str = None, task_filepath: str = None):
"""
:param node_name:
:param node_id:
:param task_filepath: 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_"))


Expand Down
2 changes: 1 addition & 1 deletion ansibleplaybookgrapher/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def _add_task(self, task: Task, task_vars: Dict, node_type: str, parent_node: Co

task_name = clean_name(f"[{node_type}] " + self.template(task.get_name(), task_vars))

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

return True
Expand Down
9 changes: 7 additions & 2 deletions ansibleplaybookgrapher/renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from ansible.utils.display import Display
from graphviz import Digraph

from ansibleplaybookgrapher.graph import PlaybookNode, EdgeNode, Node, PlayNode, RoleNode
from ansibleplaybookgrapher.graph import PlaybookNode, EdgeNode, Node, PlayNode, RoleNode, TaskNode
from ansibleplaybookgrapher.utils import clean_name, get_play_colors


Expand Down Expand Up @@ -56,8 +56,13 @@ def _add_task(self, graph: GraphvizCustomDigraph, parent_node: Node, edge: EdgeN
:return:
"""
destination_node = edge.destination
node_filepath = None
if isinstance(destination_node, TaskNode):
# Task nodes have the path the file they are located
node_filepath, _ = destination_node.task_filepath.split(":")

graph.node(destination_node.id, label=destination_node.name, shape=shape, id=destination_node.id,
tooltip=destination_node.name)
tooltip=destination_node.name, URL=node_filepath)
edge_label = f"{task_counter} {edge.name}"
graph.edge(parent_node.id, destination_node.id, label=edge_label, color=color, fontcolor=color, style="bold",
id=edge.id, tooltip=edge_label, labeltooltip=edge_label)
Expand Down

0 comments on commit a3a862c

Please sign in to comment.