Add HTML5 flowchart fragment
This commit is contained in:
@@ -231,6 +231,7 @@ def render_html5_editor(
|
||||
{render_html5_symbols(snapshot, q, project_id)}
|
||||
</div>
|
||||
{render_html5_symbol_detail(project_id, None)}
|
||||
{render_html5_flowchart(project_id, None)}
|
||||
{render_html5_project_report(project_id, None)}
|
||||
{render_html5_review(project_id, None)}
|
||||
{render_html5_authoring_preview(project_id, None)}
|
||||
@@ -246,6 +247,48 @@ def render_html5_editor(
|
||||
return _page(f"SFERA HTML5 - {project_id}", content)
|
||||
|
||||
|
||||
def render_html5_flowchart(project_id: str, flowchart: object | None) -> str:
|
||||
if flowchart is None:
|
||||
return f"""
|
||||
<div
|
||||
class="flowchart-panel"
|
||||
data-html5-flowchart
|
||||
hx-get="/html5/projects/{quote(project_id)}/flowchart"
|
||||
hx-trigger="load"
|
||||
hx-swap="outerHTML"
|
||||
>
|
||||
<div class="panel-title">Карта связей</div>
|
||||
<p class="muted padded">Сервер собирает граф проекта.</p>
|
||||
</div>
|
||||
"""
|
||||
nodes = getattr(flowchart, "nodes", []) or []
|
||||
edges = getattr(flowchart, "edges", []) or []
|
||||
mode = str(getattr(flowchart, "mode", "overview"))
|
||||
body = "".join(_flowchart_edge_item(item, nodes) for item in edges[:10])
|
||||
if not body:
|
||||
body = "".join(_flowchart_node_item(item) for item in nodes[:10])
|
||||
if not body:
|
||||
body = '<p class="muted padded">Связи проекта не найдены</p>'
|
||||
return f"""
|
||||
<div
|
||||
class="flowchart-panel"
|
||||
data-html5-flowchart
|
||||
hx-get="/html5/projects/{quote(project_id)}/flowchart"
|
||||
hx-trigger="every 30s"
|
||||
hx-swap="outerHTML"
|
||||
>
|
||||
<div class="panel-title">Карта связей · {escape(mode)}</div>
|
||||
<dl class="report-grid">
|
||||
{_metric("Nodes", len(nodes))}
|
||||
{_metric("Edges", len(edges))}
|
||||
{_metric("Total nodes", getattr(flowchart, "total_nodes", 0))}
|
||||
{_metric("Total edges", getattr(flowchart, "total_edges", 0))}
|
||||
</dl>
|
||||
<div class="compact-list">{body}</div>
|
||||
</div>
|
||||
"""
|
||||
|
||||
|
||||
def render_html5_project_report(project_id: str, report: dict | None) -> str:
|
||||
if report is None:
|
||||
return f"""
|
||||
@@ -1527,6 +1570,19 @@ def _flowchart_edge_item(edge: object, nodes: Iterable[object]) -> str:
|
||||
"""
|
||||
|
||||
|
||||
def _flowchart_node_item(node: object) -> str:
|
||||
name = str(getattr(node, "qualified_name", "") or getattr(node, "label", "") or "node")
|
||||
kind = str(getattr(node, "kind", "") or "NODE")
|
||||
level = getattr(node, "level", 0)
|
||||
count = getattr(node, "count", 1)
|
||||
return f"""
|
||||
<article class="object-context-item" data-html5-flowchart-node="{escape(kind)}">
|
||||
<strong>{escape(name)}</strong>
|
||||
<small>{escape(kind)} · level {escape(str(level))} · count {escape(str(count))}</small>
|
||||
</article>
|
||||
"""
|
||||
|
||||
|
||||
def _authoring_diff_item(line: object) -> str:
|
||||
kind = str(getattr(line, "kind", ""))
|
||||
text = str(getattr(line, "text", ""))
|
||||
|
||||
Reference in New Issue
Block a user