Mark active HTML5 object context action
This commit is contained in:
@@ -515,7 +515,7 @@ def render_html5_object_context(
|
|||||||
<strong>{escape(str(name))}</strong>
|
<strong>{escape(str(name))}</strong>
|
||||||
<span>{escape(str(getattr(obj, "kind", "object")))}</span>
|
<span>{escape(str(getattr(obj, "kind", "object")))}</span>
|
||||||
</article>
|
</article>
|
||||||
{_object_action_links(project_id, str(name), getattr(obj, "lineage_id", ""), modules)}
|
{_object_action_links(project_id, str(name), getattr(obj, "lineage_id", ""), modules, normalized_mode)}
|
||||||
<dl class="report-grid">
|
<dl class="report-grid">
|
||||||
{_metric("Attrs", len(attributes))}
|
{_metric("Attrs", len(attributes))}
|
||||||
{_metric("Tables", len(sections))}
|
{_metric("Tables", len(sections))}
|
||||||
@@ -1541,7 +1541,13 @@ def _named_node_item(label: str, node: object) -> str:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
def _object_action_links(project_id: str, object_name: str, lineage_id: object, modules: Iterable[object]) -> str:
|
def _object_action_links(
|
||||||
|
project_id: str,
|
||||||
|
object_name: str,
|
||||||
|
lineage_id: object,
|
||||||
|
modules: Iterable[object],
|
||||||
|
active_mode: str,
|
||||||
|
) -> str:
|
||||||
quoted_project = quote(project_id)
|
quoted_project = quote(project_id)
|
||||||
quoted_object = quote(object_name, safe="")
|
quoted_object = quote(object_name, safe="")
|
||||||
lineage = str(lineage_id or "")
|
lineage = str(lineage_id or "")
|
||||||
@@ -1565,6 +1571,9 @@ def _object_action_links(project_id: str, object_name: str, lineage_id: object,
|
|||||||
if lineage
|
if lineage
|
||||||
else ""
|
else ""
|
||||||
)
|
)
|
||||||
|
def active_attrs(mode: str) -> str:
|
||||||
|
return ' aria-current="page" data-html5-object-action-active="true"' if mode == active_mode else ""
|
||||||
|
|
||||||
return f"""
|
return f"""
|
||||||
<nav class="object-actions" data-html5-object-actions>
|
<nav class="object-actions" data-html5-object-actions>
|
||||||
<a
|
<a
|
||||||
@@ -1573,6 +1582,7 @@ def _object_action_links(project_id: str, object_name: str, lineage_id: object,
|
|||||||
hx-get="/html5/projects/{quoted_project}/objects/context/{quoted_object}"
|
hx-get="/html5/projects/{quoted_project}/objects/context/{quoted_object}"
|
||||||
hx-target="[data-html5-object-context]"
|
hx-target="[data-html5-object-context]"
|
||||||
hx-swap="outerHTML"
|
hx-swap="outerHTML"
|
||||||
|
{active_attrs("overview")}
|
||||||
>Overview</a>
|
>Overview</a>
|
||||||
<a
|
<a
|
||||||
class="button"
|
class="button"
|
||||||
@@ -1580,6 +1590,7 @@ def _object_action_links(project_id: str, object_name: str, lineage_id: object,
|
|||||||
hx-get="/html5/projects/{quoted_project}/objects/context/{quoted_object}?mode=schema"
|
hx-get="/html5/projects/{quoted_project}/objects/context/{quoted_object}?mode=schema"
|
||||||
hx-target="[data-html5-object-context]"
|
hx-target="[data-html5-object-context]"
|
||||||
hx-swap="outerHTML"
|
hx-swap="outerHTML"
|
||||||
|
{active_attrs("schema")}
|
||||||
>Schema</a>
|
>Schema</a>
|
||||||
<a
|
<a
|
||||||
class="button"
|
class="button"
|
||||||
@@ -1587,6 +1598,7 @@ def _object_action_links(project_id: str, object_name: str, lineage_id: object,
|
|||||||
hx-get="/html5/projects/{quoted_project}/objects/context/{quoted_object}?mode=impact"
|
hx-get="/html5/projects/{quoted_project}/objects/context/{quoted_object}?mode=impact"
|
||||||
hx-target="[data-html5-object-context]"
|
hx-target="[data-html5-object-context]"
|
||||||
hx-swap="outerHTML"
|
hx-swap="outerHTML"
|
||||||
|
{active_attrs("impact")}
|
||||||
>Impact</a>
|
>Impact</a>
|
||||||
<a
|
<a
|
||||||
class="button"
|
class="button"
|
||||||
@@ -1594,6 +1606,7 @@ def _object_action_links(project_id: str, object_name: str, lineage_id: object,
|
|||||||
hx-get="/html5/projects/{quoted_project}/objects/context/{quoted_object}?mode=privacy"
|
hx-get="/html5/projects/{quoted_project}/objects/context/{quoted_object}?mode=privacy"
|
||||||
hx-target="[data-html5-object-context]"
|
hx-target="[data-html5-object-context]"
|
||||||
hx-swap="outerHTML"
|
hx-swap="outerHTML"
|
||||||
|
{active_attrs("privacy")}
|
||||||
>Privacy</a>
|
>Privacy</a>
|
||||||
<a
|
<a
|
||||||
class="button"
|
class="button"
|
||||||
|
|||||||
@@ -324,6 +324,8 @@ def test_html5_object_context_fragment(tmp_path: Path):
|
|||||||
assert "mode=privacy" in context.text
|
assert "mode=privacy" in context.text
|
||||||
assert 'data-html5-object-mode="overview"' in context.text
|
assert 'data-html5-object-mode="overview"' in context.text
|
||||||
assert "Object context · overview" in context.text
|
assert "Object context · overview" in context.text
|
||||||
|
assert 'data-html5-object-action-active="true"' in context.text
|
||||||
|
assert 'aria-current="page"' in context.text
|
||||||
assert 'hx-target="[data-html5-object-context]"' in context.text
|
assert 'hx-target="[data-html5-object-context]"' in context.text
|
||||||
assert 'hx-target="[data-html5-flowchart]"' in context.text
|
assert 'hx-target="[data-html5-flowchart]"' in context.text
|
||||||
assert 'hx-target="[data-html5-source]"' in context.text
|
assert 'hx-target="[data-html5-source]"' in context.text
|
||||||
@@ -371,6 +373,7 @@ def test_html5_object_context_fragment(tmp_path: Path):
|
|||||||
assert schema_context.status_code == 200
|
assert schema_context.status_code == 200
|
||||||
assert 'data-html5-object-mode="schema"' in schema_context.text
|
assert 'data-html5-object-mode="schema"' in schema_context.text
|
||||||
assert "Object context · schema" in schema_context.text
|
assert "Object context · schema" in schema_context.text
|
||||||
|
assert 'data-html5-object-action-active="true"' in schema_context.text
|
||||||
assert "Контрагент" in schema_context.text
|
assert "Контрагент" in schema_context.text
|
||||||
|
|
||||||
impact_context = client.get(
|
impact_context = client.get(
|
||||||
|
|||||||
Reference in New Issue
Block a user