Link HTML5 object selection to flowchart
This commit is contained in:
@@ -247,15 +247,26 @@ def render_html5_editor(
|
|||||||
return _page(f"SFERA HTML5 - {project_id}", content)
|
return _page(f"SFERA HTML5 - {project_id}", content)
|
||||||
|
|
||||||
|
|
||||||
def render_html5_flowchart(project_id: str, flowchart: object | None) -> str:
|
def render_html5_flowchart(
|
||||||
|
project_id: str,
|
||||||
|
flowchart: object | None,
|
||||||
|
*,
|
||||||
|
focus: str | None = None,
|
||||||
|
oob: bool = False,
|
||||||
|
) -> str:
|
||||||
|
hx_url = f"/html5/projects/{quote(project_id)}/flowchart"
|
||||||
|
if focus:
|
||||||
|
hx_url = f"{hx_url}?focus={quote(focus, safe='')}"
|
||||||
|
oob_attr = ' hx-swap-oob="outerHTML"' if oob else ""
|
||||||
if flowchart is None:
|
if flowchart is None:
|
||||||
return f"""
|
return f"""
|
||||||
<div
|
<div
|
||||||
class="flowchart-panel"
|
class="flowchart-panel"
|
||||||
data-html5-flowchart
|
data-html5-flowchart
|
||||||
hx-get="/html5/projects/{quote(project_id)}/flowchart"
|
hx-get="{hx_url}"
|
||||||
hx-trigger="load"
|
hx-trigger="load"
|
||||||
hx-swap="outerHTML"
|
hx-swap="outerHTML"
|
||||||
|
{oob_attr}
|
||||||
>
|
>
|
||||||
<div class="panel-title">Карта связей</div>
|
<div class="panel-title">Карта связей</div>
|
||||||
<p class="muted padded">Сервер собирает граф проекта.</p>
|
<p class="muted padded">Сервер собирает граф проекта.</p>
|
||||||
@@ -273,9 +284,10 @@ def render_html5_flowchart(project_id: str, flowchart: object | None) -> str:
|
|||||||
<div
|
<div
|
||||||
class="flowchart-panel"
|
class="flowchart-panel"
|
||||||
data-html5-flowchart
|
data-html5-flowchart
|
||||||
hx-get="/html5/projects/{quote(project_id)}/flowchart"
|
hx-get="{hx_url}"
|
||||||
hx-trigger="every 30s"
|
hx-trigger="every 30s"
|
||||||
hx-swap="outerHTML"
|
hx-swap="outerHTML"
|
||||||
|
{oob_attr}
|
||||||
>
|
>
|
||||||
<div class="panel-title">Карта связей · {escape(mode)}</div>
|
<div class="panel-title">Карта связей · {escape(mode)}</div>
|
||||||
<dl class="report-grid">
|
<dl class="report-grid">
|
||||||
|
|||||||
@@ -1751,7 +1751,7 @@ async def html5_project_flowchart(
|
|||||||
) -> Response:
|
) -> Response:
|
||||||
flowchart = await project_flowchart(project_id, focus=focus, depth=depth, limit=limit)
|
flowchart = await project_flowchart(project_id, focus=focus, depth=depth, limit=limit)
|
||||||
return Response(
|
return Response(
|
||||||
render_html5_flowchart(project_id, flowchart),
|
render_html5_flowchart(project_id, flowchart, focus=focus),
|
||||||
media_type="text/html; charset=utf-8",
|
media_type="text/html; charset=utf-8",
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -1767,19 +1767,21 @@ async def html5_project_object_context(project_id: str, object_name: str) -> Res
|
|||||||
flowchart = await project_flowchart(project_id, focus=object_name, depth=1, limit=40)
|
flowchart = await project_flowchart(project_id, focus=object_name, depth=1, limit=40)
|
||||||
runtime = _runtime_for_object_context(project_id, impact)
|
runtime = _runtime_for_object_context(project_id, impact)
|
||||||
knowledge = _knowledge_for_object_context(schema, impact, ui)
|
knowledge = _knowledge_for_object_context(schema, impact, ui)
|
||||||
|
object_context = render_html5_object_context(
|
||||||
|
project_id,
|
||||||
|
schema,
|
||||||
|
impact,
|
||||||
|
access,
|
||||||
|
ui,
|
||||||
|
runtime,
|
||||||
|
knowledge,
|
||||||
|
privacy,
|
||||||
|
integrations,
|
||||||
|
flowchart,
|
||||||
|
)
|
||||||
|
flowchart_context = render_html5_flowchart(project_id, flowchart, focus=object_name, oob=True)
|
||||||
return Response(
|
return Response(
|
||||||
render_html5_object_context(
|
object_context + flowchart_context,
|
||||||
project_id,
|
|
||||||
schema,
|
|
||||||
impact,
|
|
||||||
access,
|
|
||||||
ui,
|
|
||||||
runtime,
|
|
||||||
knowledge,
|
|
||||||
privacy,
|
|
||||||
integrations,
|
|
||||||
flowchart,
|
|
||||||
),
|
|
||||||
media_type="text/html; charset=utf-8",
|
media_type="text/html; charset=utf-8",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -325,6 +325,9 @@ def test_html5_object_context_fragment(tmp_path: Path):
|
|||||||
assert "https://api.example.local/orders" in context.text
|
assert "https://api.example.local/orders" in context.text
|
||||||
assert "OUTBOUND" in context.text
|
assert "OUTBOUND" in context.text
|
||||||
assert "data-html5-object-context-item=\"flow-edge\"" in context.text
|
assert "data-html5-object-context-item=\"flow-edge\"" in context.text
|
||||||
|
assert "data-html5-flowchart" in context.text
|
||||||
|
assert 'hx-swap-oob="outerHTML"' in context.text
|
||||||
|
assert "Карта связей · focus" in context.text
|
||||||
assert "1 signals" in context.text
|
assert "1 signals" in context.text
|
||||||
assert "1 errors" in context.text
|
assert "1 errors" in context.text
|
||||||
assert "125.0 ms" in context.text
|
assert "125.0 ms" in context.text
|
||||||
@@ -362,6 +365,7 @@ def test_html5_flowchart_fragment(tmp_path: Path):
|
|||||||
assert flowchart.status_code == 200
|
assert flowchart.status_code == 200
|
||||||
assert "text/html" in flowchart.headers["content-type"]
|
assert "text/html" in flowchart.headers["content-type"]
|
||||||
assert "data-html5-flowchart" in flowchart.text
|
assert "data-html5-flowchart" in flowchart.text
|
||||||
|
assert 'hx-swap-oob="outerHTML"' not in flowchart.text
|
||||||
assert "Карта связей" in flowchart.text
|
assert "Карта связей" in flowchart.text
|
||||||
assert "Nodes" in flowchart.text
|
assert "Nodes" in flowchart.text
|
||||||
assert "Edges" in flowchart.text
|
assert "Edges" in flowchart.text
|
||||||
|
|||||||
Reference in New Issue
Block a user