Skip to content

Commit

Permalink
feat: open node on click
Browse files Browse the repository at this point in the history
Add url
  • Loading branch information
haidaraM committed Sep 19, 2021
1 parent 8f2f564 commit 167d280
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
10 changes: 9 additions & 1 deletion ansibleplaybookgrapher/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,16 @@ class TaskNode(Node):
A task node. Can be pre_task, task or post_task
"""

def __init__(self, node_label: str, node_id: str = None):
def __init__(self, node_label: str, node_id: str = None, task_filepath: str = None):
"""
:param node_label:
: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_label, node_id or generate_id("task_"))
self.task_filepath = task_filepath


class RoleNode(CompositeNode):
Expand Down
3 changes: 2 additions & 1 deletion ansibleplaybookgrapher/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ def _add_task(self, task: Task, loop_counter: int, task_vars: Dict, node_type: s

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

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

return True
Expand Down
15 changes: 11 additions & 4 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 @@ -55,9 +55,16 @@ def _add_task(self, graph: GraphvizCustomDigraph, parent_node: Node, edge: EdgeN
:param shape
:return:
"""
graph.node(edge.destination.id, label=edge.destination.label, shape=shape, id=edge.destination.id,
tooltip=edge.destination.label)
graph.edge(parent_node.id, edge.destination.id, label=edge.label, color=color, fontcolor=color, style="bold",
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.label, shape=shape, id=destination_node.id,
tooltip=destination_node.label, URL=node_filepath)
# Edge from parent to destination
graph.edge(parent_node.id, destination_node.id, label=edge.label, color=color, fontcolor=color, style="bold",
id=edge.id)

def _convert_to_graphviz(self):
Expand Down

0 comments on commit 167d280

Please sign in to comment.