Extract HTML5 editor controller
CI / python (push) Has been cancelled
CI / rust (push) Has been cancelled

This commit is contained in:
2026-05-17 19:11:24 +03:00
parent 02aa084634
commit 07d23d2ba9
2 changed files with 168 additions and 78 deletions
@@ -0,0 +1,134 @@
from __future__ import annotations
from collections.abc import Callable, Iterable
from typing import Any
from fastapi import HTTPException
from api_server.form_editor_service import form_module_for_form, select_form_semantics
from api_server.html5_editor import render_html5_editor, render_html5_source, render_html5_symbol_detail
from api_server.html5_form_editor import render_html5_form_editor
from api_server.html5_inspector import (
render_html5_flowchart,
render_html5_object_context,
render_html5_object_report,
render_html5_review,
)
from sir import SirSnapshot
def html5_editor_page(
*,
project_id: str,
q: str,
project_summaries: Callable[[], Iterable[object]],
project_snapshot: Callable[[str], SirSnapshot],
) -> str:
try:
snapshot = project_snapshot(project_id)
return render_html5_editor(
project_id=project_id,
projects=project_summaries(),
snapshot=snapshot,
q=q,
)
except HTTPException as error:
return render_html5_editor(
project_id=project_id,
projects=project_summaries(),
snapshot=None,
error=str(error.detail),
q=q,
)
def html5_form_editor_page(
*,
project_id: str,
form_id: str | None,
project_summaries: Callable[[], Iterable[object]],
project_snapshot: Callable[[str], SirSnapshot],
form_semantics_items: Callable[[SirSnapshot], Iterable[object]],
form_semantics_response: Callable[[object], Any],
) -> str:
try:
snapshot = project_snapshot(project_id)
forms = [form_semantics_response(item) for item in form_semantics_items(snapshot)]
selected = select_form_semantics(forms, form_id)
form_module = form_module_for_form(snapshot, selected.form if selected is not None else None)
return render_html5_form_editor(
project_id=project_id,
projects=project_summaries(),
snapshot=snapshot,
forms=forms,
selected_form_id=form_id,
form_module=form_module,
)
except HTTPException as error:
return render_html5_form_editor(
project_id=project_id,
projects=project_summaries(),
snapshot=None,
forms=[],
error=str(error.detail),
)
async def html5_object_context_fragment(
*,
project_id: str,
object_name: str,
mode: str,
object_schema: Callable[[str, str], Any],
object_impact: Callable[[str, str], Any],
object_access: Callable[[str, str], Any],
object_ui: Callable[[str, str], Any],
object_privacy: Callable[[str, str], Any],
project_flowchart: Callable[..., Any],
symbol_references: Callable[..., Any],
integrations_for_context: Callable[[str, Any], Iterable[object]],
runtime_for_context: Callable[[str, Any], Iterable[object]],
knowledge_for_context: Callable[[Any, Any, Any], Iterable[object]],
source_node_for_context: Callable[[str, Any], object | None],
review_for_context: Callable[[str, Any, Any, Any], Iterable[object]],
) -> str:
schema = await object_schema(project_id, object_name)
impact = await object_impact(project_id, object_name)
access = await object_access(project_id, object_name)
ui = await object_ui(project_id, object_name)
privacy = await object_privacy(project_id, object_name)
integrations = integrations_for_context(project_id, impact)
flowchart = await project_flowchart(project_id, focus=object_name, depth=1, limit=40)
runtime = runtime_for_context(project_id, impact)
knowledge = knowledge_for_context(schema, impact, ui)
source_node = source_node_for_context(project_id, impact)
references = await symbol_references(project_id, schema.object.lineage_id, direction="both")
findings = review_for_context(project_id, schema, impact, ui)
return (
render_html5_object_context(
project_id,
schema,
impact,
access,
ui,
runtime,
knowledge,
privacy,
integrations,
flowchart,
mode,
)
+ render_html5_flowchart(project_id, flowchart, focus=object_name, depth=1, oob=True)
+ (render_html5_source(source_node, oob=True) if source_node is not None else "")
+ render_html5_symbol_detail(project_id, references, oob=True)
+ render_html5_object_report(
project_id,
impact,
access=access,
privacy=privacy,
runtime=runtime,
integrations=integrations,
oob=True,
)
+ render_html5_review(project_id, findings, title="Review объекта", oob=True)
)
+34 -78
View File
@@ -42,9 +42,10 @@ from api_server.html5_forms import (
html5_metadata_payload as _html5_metadata_payload,
html5_metadata_request_payload as _html5_metadata_request_payload,
)
from api_server.form_editor_service import (
form_module_for_form as _form_module_for_form,
select_form_semantics as _select_form_semantics,
from api_server.html5_editor_controller import (
html5_editor_page as _html5_editor_page,
html5_form_editor_page as _html5_form_editor_page,
html5_object_context_fragment as _html5_object_context_fragment,
)
from api_server.html5_projects import render_html5_index, render_html5_project_rows
from api_server.html5_responses import (
@@ -74,13 +75,11 @@ from api_server.html5_authoring import (
render_html5_metadata_preview_result,
)
from api_server.html5_editor import (
render_html5_editor,
render_html5_source,
render_html5_status,
render_html5_symbol_detail,
render_html5_symbols,
)
from api_server.html5_form_editor import render_html5_form_editor
from api_server.html5_operations import (
filter_html5_operation_jobs,
latest_html5_import_job,
@@ -1716,49 +1715,28 @@ async def html5_operations_events(
@app.get("/html5/projects/{project_id}/editor")
async def html5_project_editor(project_id: str, q: str = "") -> Response:
try:
snapshot = _project_snapshot_or_404(project_id)
html = render_html5_editor(
return _html5_response(
_html5_editor_page(
project_id=project_id,
projects=_project_summaries(),
snapshot=snapshot,
q=q,
project_summaries=_project_summaries,
project_snapshot=_project_snapshot_or_404,
)
except HTTPException as error:
html = render_html5_editor(
project_id=project_id,
projects=_project_summaries(),
snapshot=None,
error=str(error.detail),
q=q,
)
return _html5_response(html)
)
@app.get("/html5/projects/{project_id}/forms/editor")
async def html5_project_form_editor(project_id: str, form: str | None = None) -> Response:
try:
snapshot = _project_snapshot_or_404(project_id)
forms = [_form_semantics_response(item) for item in form_semantics(snapshot)]
selected = _select_form_semantics(forms, form)
form_module = _form_module_for_form(snapshot, selected.form if selected is not None else None)
html = render_html5_form_editor(
return _html5_response(
_html5_form_editor_page(
project_id=project_id,
projects=_project_summaries(),
snapshot=snapshot,
forms=forms,
selected_form_id=form,
form_module=form_module,
form_id=form,
project_summaries=_project_summaries,
project_snapshot=_project_snapshot_or_404,
form_semantics_items=form_semantics,
form_semantics_response=_form_semantics_response,
)
except HTTPException as error:
html = render_html5_form_editor(
project_id=project_id,
projects=_project_summaries(),
snapshot=None,
forms=[],
error=str(error.detail),
)
return _html5_response(html)
)
@app.get("/html5/projects/{project_id}/events")
@@ -1866,46 +1844,24 @@ async def html5_project_flowchart(
@app.get("/html5/projects/{project_id}/objects/context/{object_name}")
async def html5_project_object_context(project_id: str, object_name: str, mode: str = "overview") -> Response:
schema = await get_object_schema(project_id, object_name)
impact = await get_object_impact(project_id, object_name)
access = await get_object_access(project_id, object_name)
ui = await get_object_ui(project_id, object_name)
privacy = await object_privacy(project_id, object_name)
integrations = _integrations_for_object_context(project_id, impact)
flowchart = await project_flowchart(project_id, focus=object_name, depth=1, limit=40)
runtime = _runtime_for_object_context(project_id, impact)
knowledge = _knowledge_for_object_context(schema, impact, ui)
source_node = _source_node_for_object_context(project_id, impact)
symbol_references = await project_symbol_references(project_id, schema.object.lineage_id, direction="both")
focused_findings = _review_for_object_context(project_id, schema, impact, ui)
object_context = render_html5_object_context(
project_id,
schema,
impact,
access,
ui,
runtime,
knowledge,
privacy,
integrations,
flowchart,
mode,
)
flowchart_context = render_html5_flowchart(project_id, flowchart, focus=object_name, depth=1, oob=True)
source_context = render_html5_source(source_node, oob=True) if source_node is not None else ""
symbol_context = render_html5_symbol_detail(project_id, symbol_references, oob=True)
report_context = render_html5_object_report(
project_id,
impact,
access=access,
privacy=privacy,
runtime=runtime,
integrations=integrations,
oob=True,
)
review_context = render_html5_review(project_id, focused_findings, title="Review объекта", oob=True)
return _html5_response(
object_context + flowchart_context + source_context + symbol_context + report_context + review_context,
await _html5_object_context_fragment(
project_id=project_id,
object_name=object_name,
mode=mode,
object_schema=get_object_schema,
object_impact=get_object_impact,
object_access=get_object_access,
object_ui=get_object_ui,
object_privacy=object_privacy,
project_flowchart=project_flowchart,
symbol_references=project_symbol_references,
integrations_for_context=_integrations_for_object_context,
runtime_for_context=_runtime_for_object_context,
knowledge_for_context=_knowledge_for_object_context,
source_node_for_context=_source_node_for_object_context,
review_for_context=_review_for_object_context,
)
)