Compare commits

...

6 Commits

Author SHA1 Message Date
m b7876db8ef Add HTML5 authoring completion preview
CI / python (push) Has been cancelled
CI / rust (push) Has been cancelled
2026-05-16 23:06:50 +03:00
m a62e213b2f Add HTML5 authoring rollback form 2026-05-16 23:02:28 +03:00
m d2c42cabda Add HTML5 authoring rollback detail 2026-05-16 22:57:52 +03:00
m 165f218e1c Add HTML5 authoring changes panel 2026-05-16 22:53:03 +03:00
m 9f11c07781 Add HTML5 source context panel 2026-05-16 22:49:09 +03:00
m 0c3953e6bd Add HTML5 symbol detail fragment 2026-05-16 22:45:24 +03:00
3 changed files with 499 additions and 10 deletions
+345 -9
View File
@@ -227,10 +227,13 @@ def render_html5_editor(
<ul class="compact">{''.join(f'<li><span>{escape(kind)}</span><b>{count}</b></li>' for kind, count in counts.most_common(10))}</ul>
<div class="panel-title">Результаты</div>
<div data-html5-symbol-results>
{render_html5_symbols(snapshot, q)}
{render_html5_symbols(snapshot, q, project_id)}
</div>
{render_html5_symbol_detail(project_id, None)}
{render_html5_project_report(project_id, None)}
{render_html5_review(project_id, None)}
{render_html5_authoring_preview(project_id, None)}
{render_html5_authoring_changes(project_id, None)}
</aside>
</section>
<footer class="status" data-html5-status hx-ext="sse" sse-connect="/html5/projects/{quote(project_id)}/events" sse-swap="status">
@@ -311,6 +314,174 @@ def render_html5_review(project_id: str, findings: list[dict] | None) -> str:
"""
def render_html5_authoring_changes(project_id: str, changes: Iterable[object] | None) -> str:
if changes is None:
return f"""
<div
class="authoring-panel"
data-html5-authoring-changes
hx-get="/html5/projects/{quote(project_id)}/authoring/changes"
hx-trigger="load"
hx-swap="outerHTML"
>
<div class="panel-title">Authoring</div>
<p class="muted padded">Сервер загружает историю рабочих изменений.</p>
</div>
"""
change_list = list(changes)
if not change_list:
body = '<p class="muted padded">Изменений пока нет</p>'
else:
body = "".join(_authoring_change_item(change) for change in change_list[:12])
return f"""
<div
class="authoring-panel"
data-html5-authoring-changes
hx-get="/html5/projects/{quote(project_id)}/authoring/changes"
hx-trigger="every 15s"
hx-swap="outerHTML"
>
<div class="panel-title">Authoring · {len(change_list)}</div>
<div class="review-list">{body}</div>
{render_html5_authoring_change_detail(project_id, None)}
</div>
"""
def render_html5_authoring_preview(project_id: str, preview: object | None, error: str | None = None) -> str:
if preview is None and error is None:
return f"""
<div class="authoring-preview" data-html5-authoring-preview>
<div class="panel-title">Authoring preview</div>
<form
class="authoring-preview-form"
data-html5-authoring-preview-form
method="post"
action="/html5/projects/{quote(project_id)}/authoring/completion-preview"
hx-post="/html5/projects/{quote(project_id)}/authoring/completion-preview"
hx-target="[data-html5-authoring-preview-result]"
hx-swap="outerHTML"
>
<input name="object_name" placeholder="object_name" />
<input name="routine_name" placeholder="routine_name" />
<input name="cursor_line" placeholder="line" />
<input name="intent" value="fill-check" />
<input name="user_id" placeholder="user_id" />
<textarea name="source_text" placeholder="BSL source"></textarea>
<button type="submit">Preview</button>
</form>
{render_html5_authoring_preview_result(project_id)}
</div>
"""
return render_html5_authoring_preview_result(project_id, preview, error)
def render_html5_authoring_preview_result(project_id: str, preview: object | None = None, error: str | None = None) -> str:
if preview is None and error is None:
return '<div class="authoring-preview-result" data-html5-authoring-preview-result></div>'
if error:
return f"""
<div class="authoring-preview-result" data-html5-authoring-preview-result>
<div class="panel-title">Preview result</div>
<p class="muted padded">{escape(error)}</p>
</div>
"""
allowed = bool(getattr(preview, "allowed", False))
insert_text = str(getattr(preview, "insert_text", ""))
checks = getattr(preview, "checks", []) or []
diff = getattr(preview, "semantic_diff", []) or []
context = getattr(preview, "context", None)
object_node = getattr(context, "object", None)
routine_node = getattr(context, "routine", None)
object_name = getattr(object_node, "qualified_name", None) or getattr(object_node, "name", None) or "object unavailable"
routine_name = getattr(routine_node, "name", None) or "routine unavailable"
check_rows = "".join(_authoring_check_item(check) for check in checks[:8])
diff_rows = "".join(_authoring_diff_item(line) for line in diff[:8]) or '<p class="muted padded">Diff пустой</p>'
return f"""
<div class="authoring-preview-result" data-html5-authoring-preview-result data-html5-project-id="{escape(project_id)}">
<div class="panel-title">Preview result · {'allowed' if allowed else 'blocked'}</div>
<article class="authoring-change">
<strong>{escape(str(object_name))}</strong>
<span>{escape(str(routine_name))}</span>
<small>{escape(insert_text[:180] or "insert text unavailable")}</small>
</article>
<div class="check-list">{check_rows}</div>
<div class="diff-list">{diff_rows}</div>
</div>
"""
def render_html5_authoring_change_detail(project_id: str, preview: object | None) -> str:
if preview is None:
return f"""
<div class="authoring-detail" data-html5-authoring-detail>
<div class="panel-title">Rollback preview</div>
<p class="muted padded">Выберите изменение, чтобы сервер рассчитал rollback diff для проекта {escape(project_id)}.</p>
</div>
"""
change_id = str(getattr(preview, "change_id", ""))
original_version_id = str(getattr(preview, "original_version_id", ""))
rollback_version_id = str(getattr(preview, "rollback_version_id", ""))
target = getattr(preview, "target", None)
target_name = getattr(target, "qualified_name", None) or getattr(target, "name", None) or "target unavailable"
diff = getattr(preview, "semantic_diff", []) or []
checks = getattr(preview, "checks", []) or []
apply_available = bool(getattr(preview, "apply_available", False))
diff_rows = "".join(_authoring_diff_item(line) for line in diff[:12]) or '<p class="muted padded">Diff пустой</p>'
check_rows = "".join(_authoring_check_item(check) for check in checks[:8])
apply_form = _authoring_rollback_form(project_id, change_id, rollback_version_id) if apply_available else ""
return f"""
<div
class="authoring-detail"
data-html5-authoring-detail
data-html5-authoring-change="{escape(change_id)}"
>
<div class="panel-title">Rollback preview · {'ready' if apply_available else 'blocked'}</div>
<article class="authoring-change">
<strong>{escape(str(target_name))}</strong>
<span>{escape(original_version_id)} -> {escape(rollback_version_id)}</span>
<small>{escape(change_id)}</small>
</article>
<div class="check-list">{check_rows}</div>
<div class="diff-list">{diff_rows}</div>
{apply_form}
</div>
"""
def render_html5_authoring_rollback_result(project_id: str, result: object | None = None, error: str | None = None) -> str:
if result is None and error is None:
return '<div class="authoring-result" data-html5-authoring-result></div>'
if error:
return f"""
<div class="authoring-result" data-html5-authoring-result>
<div class="panel-title">Rollback apply</div>
<p class="muted padded">{escape(error)}</p>
</div>
"""
status = str(getattr(result, "status", "UNKNOWN"))
change_id = str(getattr(result, "change_id", ""))
rollback_change_id = str(getattr(result, "rollback_change_id", ""))
version = getattr(result, "version", None)
version_id = str(getattr(version, "version_id", ""))
return f"""
<div
class="authoring-result"
data-html5-authoring-result
data-html5-authoring-change="{escape(change_id)}"
data-html5-version-id="{escape(version_id)}"
>
<div class="panel-title">Rollback apply</div>
<article class="authoring-change">
<strong>{escape(status)}</strong>
<span>{escape(rollback_change_id)}</span>
<small>{escape(version_id)}</small>
</article>
<p class="muted padded">Rollback применен в workspace для проекта {escape(project_id)}.</p>
</div>
"""
def render_html5_project_setup(*, project_id: str, projects: Iterable[object], setup: object) -> str:
project_nav = "\n".join(_project_link(project, project_id) for project in projects)
name = _setup_name(setup)
@@ -560,16 +731,81 @@ def html5_symbol_results(snapshot: SirSnapshot, q: str) -> list[object]:
][:30]
def render_html5_symbols(snapshot: SirSnapshot, q: str) -> str:
def render_html5_symbols(snapshot: SirSnapshot, q: str, project_id: str | None = None) -> str:
results = html5_symbol_results(snapshot, q)
if not results:
return '<p class="muted">Нет результатов</p>'
return "".join(_symbol_result(node) for node in results)
return "".join(_symbol_result(node, project_id) for node in results)
def render_html5_symbol_detail(project_id: str, references: object | None) -> str:
if references is None:
return f"""
<div class="symbol-detail" data-html5-symbol-detail>
<div class="panel-title">Символ</div>
<p class="muted padded">Выберите результат поиска для server-side definition/references по проекту {escape(project_id)}.</p>
</div>
"""
symbol = getattr(references, "symbol", None)
node = getattr(symbol, "node", None)
source = getattr(symbol, "source", None)
name = getattr(node, "qualified_name", None) or getattr(node, "name", "symbol")
kind = getattr(node, "kind", "")
source_path = getattr(source, "source_path", None) or ""
line = getattr(source, "line_start", None)
location = f"{source_path}:{line}" if source_path and line else source_path or "source unavailable"
refs = getattr(references, "references", []) or []
ref_items = "".join(_symbol_reference_item(ref) for ref in refs[:10]) or '<p class="muted padded">References не найдены</p>'
lineage_id = str(getattr(node, "lineage_id", ""))
return f"""
<div
class="symbol-detail"
data-html5-symbol-detail
data-html5-lineage-id="{escape(lineage_id)}"
>
<div class="panel-title">Символ · {escape(str(kind))}</div>
<article class="symbol-focus">
<strong>{escape(str(name))}</strong>
<small>{escape(str(location))}</small>
</article>
<div class="review-list">{ref_items}</div>
</div>
"""
def render_html5_source(node: object | None) -> str:
name = "source" if node is None else getattr(node, "qualified_name", None) or getattr(node, "name", "source")
return f'<pre class="code" data-html5-source data-html5-source-name="{escape(str(name))}">{escape(_node_source_text(node))}</pre>'
kind = "" if node is None else _enum_text(getattr(node, "kind", ""))
lineage_id = "" if node is None else str(getattr(node, "lineage_id", ""))
source_path = "" if node is None else str(
getattr(node, "source_path", None) or getattr(getattr(node, "source_ref", None), "source_path", None) or ""
)
line = "" if node is None else str(
getattr(node, "line_start", None) or getattr(getattr(node, "source_ref", None), "line_start", None) or ""
)
location = f"{source_path}:{line}" if source_path and line else source_path or "source unavailable"
source_text = _node_source_text(node)
line_count = len(source_text.splitlines()) or 1
return f"""
<article
class="source-panel"
data-html5-source
data-html5-source-name="{escape(str(name))}"
data-html5-lineage-id="{escape(lineage_id)}"
>
<header class="source-head">
<div>
<strong>{escape(str(name))}</strong>
<small>{escape(kind or "source")}</small>
</div>
<dl>
{_metric("Lines", line_count)}
{_metric("Location", location)}
</dl>
</header>
<pre class="code">{escape(source_text)}</pre>
</article>
"""
def _page(title: str, body: str) -> str:
@@ -773,21 +1009,121 @@ def _tree_item(project_id: str, node: object) -> str:
)
def _symbol_result(node: object) -> str:
def _symbol_result(node: object, project_id: str | None = None) -> str:
name = getattr(node, "qualified_name", None) or getattr(node, "name", "")
kind = getattr(node, "kind", "")
kind_value = str(kind.value if hasattr(kind, "value") else kind)
lineage_id = str(getattr(node, "lineage_id", ""))
source_path = getattr(node, "source_path", None) or getattr(getattr(node, "source_ref", None), "source_path", None) or ""
line = getattr(node, "line_start", None) or getattr(getattr(node, "source_ref", None), "line_start", None)
location = f"{source_path}:{line}" if source_path and line else source_path or "source unavailable"
htmx_attrs = (
f'hx-get="/html5/projects/{quote(project_id)}/symbols/{quote(lineage_id, safe="")}/detail" '
'hx-target="[data-html5-symbol-detail]" hx-swap="outerHTML"'
if project_id and lineage_id
else ""
)
return f"""
<article class="symbol" data-html5-symbol>
<article class="symbol" data-html5-symbol data-html5-lineage-id="{escape(lineage_id)}" {htmx_attrs}>
<strong>{escape(str(name))}</strong>
<span>{escape(kind_value)}</span>
<small>{escape(str(location))}</small>
</article>"""
def _symbol_reference_item(reference: object) -> str:
kind = str(getattr(reference, "kind", ""))
direction = str(getattr(reference, "direction", ""))
source = getattr(reference, "source", None)
target = getattr(reference, "target", None)
location = getattr(reference, "location", None)
source_name = getattr(source, "qualified_name", None) or getattr(source, "name", "")
target_name = getattr(target, "qualified_name", None) or getattr(target, "name", "")
source_path = getattr(location, "source_path", None) or ""
line = getattr(location, "line_start", None)
place = f"{source_path}:{line}" if source_path and line else source_path
label = f"{source_name} -> {target_name}".strip(" ->")
return f"""
<article class="symbol-reference" data-html5-symbol-reference>
<strong>{escape(label or kind)}</strong>
<span>{escape(direction)} · {escape(kind)}</span>
<small>{escape(place or "source unavailable")}</small>
</article>
"""
def _authoring_change_item(change: object) -> str:
change_id = str(getattr(change, "change_id", ""))
status = str(getattr(change, "status", ""))
target = getattr(change, "target", None)
target_name = getattr(target, "qualified_name", None) or getattr(target, "name", None) or "target unavailable"
approved_by = str(getattr(change, "approved_by", "") or "not approved")
task_id = str(getattr(change, "task_id", "") or "no task")
added = getattr(change, "added_lines", 0)
removed = getattr(change, "removed_lines", 0)
production = "production" if bool(getattr(change, "production_applied", False)) else "workspace"
project_id = str(getattr(change, "project_id", ""))
detail_attrs = (
f'hx-get="/html5/projects/{quote(project_id)}/authoring/changes/{quote(change_id, safe="")}" '
'hx-target="[data-html5-authoring-detail]" hx-swap="outerHTML"'
if change_id and project_id
else ""
)
return f"""
<article class="authoring-change" data-html5-authoring-change="{escape(change_id)}" {detail_attrs}>
<strong>{escape(str(target_name))}</strong>
<span>{escape(status)} · +{escape(str(added))} / -{escape(str(removed))} · {escape(production)}</span>
<small>{escape(task_id)} · {escape(approved_by)} · {escape(change_id)}</small>
</article>
"""
def _authoring_diff_item(line: object) -> str:
kind = str(getattr(line, "kind", ""))
text = str(getattr(line, "text", ""))
return f"""
<article class="diff-item" data-html5-authoring-diff="{escape(kind)}">
<span>{escape(kind)}</span>
<code>{escape(text)}</code>
</article>
"""
def _authoring_check_item(check: object) -> str:
name = str(getattr(check, "name", "check"))
status = str(getattr(check, "status", "UNKNOWN"))
message = str(getattr(check, "message", ""))
return f"""
<article class="check-item" data-html5-authoring-check="{escape(status)}">
<strong>{escape(name)}</strong>
<span>{escape(status)}</span>
<small>{escape(message)}</small>
</article>
"""
def _authoring_rollback_form(project_id: str, change_id: str, rollback_version_id: str) -> str:
return f"""
<form
class="rollback-form"
data-html5-authoring-rollback-form
method="post"
action="/html5/projects/{quote(project_id)}/authoring/changes/{quote(change_id, safe="")}/apply-rollback"
hx-post="/html5/projects/{quote(project_id)}/authoring/changes/{quote(change_id, safe="")}/apply-rollback"
hx-target="[data-html5-authoring-result]"
hx-swap="outerHTML"
>
<input type="hidden" name="expected_rollback_version_id" value="{escape(rollback_version_id)}" />
<input name="approved_by" placeholder="approved_by" required />
<input name="task_id" placeholder="task_id" />
<input name="session_id" placeholder="session_id" />
<input name="approval_note" placeholder="Комментарий" />
<button type="submit">Apply rollback</button>
</form>
{render_html5_authoring_rollback_result(project_id)}
"""
def _node_source_text(node: object | None) -> str:
if node is None:
return "// Модуль не найден в snapshot.\n// HTML5 IDE показывает серверный fallback без клиентского JS."
@@ -807,9 +1143,9 @@ def _css() -> str:
.band,.panel,.editor{border:1px solid var(--line);background:var(--card)}.band{max-width:1180px;margin:auto;padding:18px}.section-title,.topbar,.editor-head{display:flex;align-items:center;justify-content:space-between;gap:12px}.button,button{display:inline-flex;align-items:center;justify-content:center;height:32px;border:1px solid var(--line);background:#fff;padding:0 12px;text-decoration:none;font-weight:700;cursor:pointer}table{width:100%;border-collapse:collapse}th,td{border-top:1px solid var(--line);padding:12px;text-align:left}td small{display:block;color:var(--muted)}td .button,td form{margin-right:6px}.delete-project{display:inline-flex;gap:4px;vertical-align:middle}.delete-project input{height:32px;width:120px;border:1px solid var(--line);padding:0 6px}
.workspace{min-height:100vh;padding-bottom:34px}.topbar{position:sticky;top:0;z-index:2;height:54px;border-bottom:1px solid var(--line);background:rgba(255,255,255,.94);padding:0 14px}.brand{font-weight:900;text-decoration:none;color:var(--brand)}.project-nav{display:flex;gap:6px;overflow:auto;flex:1}.project-link{white-space:nowrap;text-decoration:none;border:1px solid var(--line);padding:6px 10px;background:#fff}.project-link.active{background:var(--brand);border-color:var(--brand);color:#fff}
.layout{display:grid;grid-template-columns:280px minmax(0,1fr)320px;height:calc(100vh - 88px)}.panel{overflow:auto}.panel-title{padding:12px;border-bottom:1px solid var(--line);font-size:12px;font-weight:900;text-transform:uppercase;color:var(--muted)}.tree-item{display:block;padding:10px 12px;border-bottom:1px solid var(--line);text-decoration:none}.tree-item span{display:block;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.tree-item small{color:var(--muted)}
.editor{min-width:0;overflow:hidden;border-top:0;border-bottom:0}.editor-head{height:72px;border-bottom:1px solid var(--line);padding:0 14px}.editor-head h1{margin:0;font-size:18px}.search{display:flex;gap:6px}.search input{height:32px;width:260px;border:1px solid var(--line);padding:0 10px}.code{height:calc(100% - 72px);margin:0;overflow:auto;padding:16px;background:#fbfaf7;font:13px/1.55 ui-monospace,SFMono-Regular,Consolas,monospace;white-space:pre-wrap}
.metrics{display:grid;grid-template-columns:1fr 1fr;margin:0}.metrics div{padding:12px;border-bottom:1px solid var(--line)}.metrics dt{color:var(--muted);font-size:12px}.metrics dd{margin:2px 0 0;font-size:22px;font-weight:800}.compact{list-style:none;margin:0;padding:0}.compact li{display:flex;justify-content:space-between;padding:8px 12px;border-bottom:1px solid var(--line)}.symbol{display:grid;gap:3px;padding:10px 12px;border-bottom:1px solid var(--line)}.symbol span,.symbol small{color:var(--muted)}.report-grid{display:grid;grid-template-columns:1fr 1fr;margin:0}.report-grid div{padding:10px 12px;border-bottom:1px solid var(--line)}.report-grid dt{color:var(--muted);font-size:12px}.report-grid dd{margin:2px 0 0;font-size:20px;font-weight:900}.review-item{display:grid;gap:3px;padding:10px 12px;border-bottom:1px solid var(--line)}.review-item span,.review-item small{color:var(--muted)}.status{position:fixed;bottom:0;left:0;right:0;display:flex;gap:18px;overflow:auto;height:34px;align-items:center;border-top:1px solid var(--line);background:#fff;padding:0 12px;color:var(--muted);font-size:12px}.empty-state{max-width:720px;margin:80px auto;background:#fff;border:1px solid var(--line);padding:28px}
.setup-layout{display:grid;grid-template-columns:340px minmax(0,1fr);gap:16px;max-width:1180px;margin:18px auto;padding:0 16px}.setup-workspace{background:#f3f6fb}.setup-card{padding:16px;border-bottom:1px solid var(--line)}.setup-card h1{margin:0;font-size:24px}.setup-actions{display:flex;gap:8px;flex-wrap:wrap;margin-top:14px}.setup-main{min-height:620px}.settings-form{display:grid;grid-template-columns:2fr 1fr 1fr auto;gap:8px;align-items:end;padding:12px 16px;border-bottom:1px solid var(--line);background:#fff}.settings-form label{display:grid;gap:4px;font-size:12px;font-weight:800;color:var(--muted);text-transform:uppercase}.settings-form input{height:32px;border:1px solid var(--line);padding:0 8px}.saved{float:right;color:var(--ok);font-weight:900}.setup-actions-panel{display:flex;gap:8px;flex-wrap:wrap;align-items:end;padding:12px 16px;border-bottom:1px solid var(--line);background:#fbfcfe}.inline-form{display:flex;gap:8px;align-items:end}.inline-form label{display:grid;gap:4px;font-size:12px;font-weight:800;color:var(--muted);text-transform:uppercase}.inline-form select{height:32px;min-width:240px;border:1px solid var(--line);background:#fff;padding:0 8px}.setup-summary{display:grid;gap:0}.compact-lead{margin:0;padding:0 16px 16px}.setup-metrics,.ops-summary{display:grid;grid-template-columns:repeat(4,1fr);margin:0;border-top:1px solid var(--line)}.ops-summary{grid-template-columns:repeat(5,1fr);margin:12px 0}.setup-metrics div,.ops-summary div{padding:16px;border-right:1px solid var(--line);border-bottom:1px solid var(--line);background:#fff}.setup-metrics div:last-child,.ops-summary div:last-child{border-right:0}.setup-metrics dt,.ops-summary dt{font-size:12px;color:var(--muted)}.setup-metrics dd,.ops-summary dd{margin:4px 0 0;font-size:28px;font-weight:900}.status-pill{border:1px solid var(--line);padding:6px 10px;background:#eef6f1;color:var(--ok);font-weight:800}.flush{border-top:1px solid var(--line)}.padded{padding:12px 16px;margin:0}.setup-detail,.history-item,.source-card,.check-item{display:grid;gap:3px;padding:12px 16px;border-bottom:1px solid var(--line)}.setup-detail span,.setup-detail small,.history-item span,.history-item small,.source-card span,.source-card small,.check-item span,.check-item small,.check-head span,.check-head small{color:var(--muted)}.source-list,.history-list,.check-list{display:grid}.check-head{display:flex;gap:10px;align-items:center;padding:12px 16px;border-bottom:1px solid var(--line);background:#fff}.job-log{margin:0;padding:0;list-style:none}.job-log li{padding:8px 16px;border-bottom:1px solid var(--line);color:var(--muted);font-family:ui-monospace,SFMono-Regular,Consolas,monospace;font-size:12px}
.editor{min-width:0;overflow:hidden;border-top:0;border-bottom:0}.editor-head{height:72px;border-bottom:1px solid var(--line);padding:0 14px}.editor-head h1{margin:0;font-size:18px}.search{display:flex;gap:6px}.search input{height:32px;width:260px;border:1px solid var(--line);padding:0 10px}.source-panel{height:calc(100% - 72px);display:grid;grid-template-rows:auto minmax(0,1fr);overflow:hidden}.source-head{display:flex;justify-content:space-between;gap:12px;align-items:center;min-height:54px;padding:10px 14px;border-bottom:1px solid var(--line);background:#fff}.source-head strong,.source-head small{display:block}.source-head small{color:var(--muted)}.source-head dl{display:flex;gap:12px;margin:0}.source-head div div{padding:0}.source-head dt{font-size:11px;color:var(--muted)}.source-head dd{margin:0;font-weight:800}.code{height:100%;margin:0;overflow:auto;padding:16px;background:#fbfaf7;font:13px/1.55 ui-monospace,SFMono-Regular,Consolas,monospace;white-space:pre-wrap}
.metrics{display:grid;grid-template-columns:1fr 1fr;margin:0}.metrics div{padding:12px;border-bottom:1px solid var(--line)}.metrics dt{color:var(--muted);font-size:12px}.metrics dd{margin:2px 0 0;font-size:22px;font-weight:800}.compact{list-style:none;margin:0;padding:0}.compact li{display:flex;justify-content:space-between;padding:8px 12px;border-bottom:1px solid var(--line)}.symbol{display:grid;gap:3px;padding:10px 12px;border-bottom:1px solid var(--line);cursor:pointer}.symbol:hover{background:#f8fbff}.symbol span,.symbol small{color:var(--muted)}.symbol-focus,.symbol-reference{display:grid;gap:3px;padding:10px 12px;border-bottom:1px solid var(--line)}.symbol-focus small,.symbol-reference span,.symbol-reference small{color:var(--muted)}.report-grid{display:grid;grid-template-columns:1fr 1fr;margin:0}.report-grid div{padding:10px 12px;border-bottom:1px solid var(--line)}.report-grid dt{color:var(--muted);font-size:12px}.report-grid dd{margin:2px 0 0;font-size:20px;font-weight:900}.review-item,.authoring-change{display:grid;gap:3px;padding:10px 12px;border-bottom:1px solid var(--line)}.authoring-change[hx-get]{cursor:pointer}.authoring-change[hx-get]:hover{background:#f8fbff}.review-item span,.review-item small,.authoring-change span,.authoring-change small{color:var(--muted)}.diff-item{display:grid;grid-template-columns:72px minmax(0,1fr);gap:8px;padding:8px 12px;border-bottom:1px solid var(--line)}.diff-item span{color:var(--muted);font-weight:800}.diff-item code{white-space:pre-wrap;font-family:ui-monospace,SFMono-Regular,Consolas,monospace;font-size:12px}.status{position:fixed;bottom:0;left:0;right:0;display:flex;gap:18px;overflow:auto;height:34px;align-items:center;border-top:1px solid var(--line);background:#fff;padding:0 12px;color:var(--muted);font-size:12px}.empty-state{max-width:720px;margin:80px auto;background:#fff;border:1px solid var(--line);padding:28px}
.setup-layout{display:grid;grid-template-columns:340px minmax(0,1fr);gap:16px;max-width:1180px;margin:18px auto;padding:0 16px}.setup-workspace{background:#f3f6fb}.setup-card{padding:16px;border-bottom:1px solid var(--line)}.setup-card h1{margin:0;font-size:24px}.setup-actions{display:flex;gap:8px;flex-wrap:wrap;margin-top:14px}.setup-main{min-height:620px}.settings-form{display:grid;grid-template-columns:2fr 1fr 1fr auto;gap:8px;align-items:end;padding:12px 16px;border-bottom:1px solid var(--line);background:#fff}.settings-form label{display:grid;gap:4px;font-size:12px;font-weight:800;color:var(--muted);text-transform:uppercase}.settings-form input{height:32px;border:1px solid var(--line);padding:0 8px}.saved{float:right;color:var(--ok);font-weight:900}.setup-actions-panel{display:flex;gap:8px;flex-wrap:wrap;align-items:end;padding:12px 16px;border-bottom:1px solid var(--line);background:#fbfcfe}.inline-form{display:flex;gap:8px;align-items:end}.inline-form label{display:grid;gap:4px;font-size:12px;font-weight:800;color:var(--muted);text-transform:uppercase}.inline-form select{height:32px;min-width:240px;border:1px solid var(--line);background:#fff;padding:0 8px}.rollback-form,.authoring-preview-form{display:grid;grid-template-columns:1fr 1fr;gap:8px;padding:12px;border-bottom:1px solid var(--line);background:#fbfcfe}.rollback-form input,.authoring-preview-form input,.authoring-preview-form textarea{min-width:0;border:1px solid var(--line);padding:0 8px}.rollback-form input,.authoring-preview-form input{height:32px}.authoring-preview-form textarea{grid-column:1/-1;min-height:88px;padding:8px;resize:vertical;font:12px/1.45 ui-monospace,SFMono-Regular,Consolas,monospace}.rollback-form button,.authoring-preview-form button{grid-column:1/-1}.setup-summary{display:grid;gap:0}.compact-lead{margin:0;padding:0 16px 16px}.setup-metrics,.ops-summary{display:grid;grid-template-columns:repeat(4,1fr);margin:0;border-top:1px solid var(--line)}.ops-summary{grid-template-columns:repeat(5,1fr);margin:12px 0}.setup-metrics div,.ops-summary div{padding:16px;border-right:1px solid var(--line);border-bottom:1px solid var(--line);background:#fff}.setup-metrics div:last-child,.ops-summary div:last-child{border-right:0}.setup-metrics dt,.ops-summary dt{font-size:12px;color:var(--muted)}.setup-metrics dd,.ops-summary dd{margin:4px 0 0;font-size:28px;font-weight:900}.status-pill{border:1px solid var(--line);padding:6px 10px;background:#eef6f1;color:var(--ok);font-weight:800}.flush{border-top:1px solid var(--line)}.padded{padding:12px 16px;margin:0}.setup-detail,.history-item,.source-card,.check-item{display:grid;gap:3px;padding:12px 16px;border-bottom:1px solid var(--line)}.setup-detail span,.setup-detail small,.history-item span,.history-item small,.source-card span,.source-card small,.check-item span,.check-item small,.check-head span,.check-head small{color:var(--muted)}.source-list,.history-list,.check-list{display:grid}.check-head{display:flex;gap:10px;align-items:center;padding:12px 16px;border-bottom:1px solid var(--line);background:#fff}.job-log{margin:0;padding:0;list-style:none}.job-log li{padding:8px 16px;border-bottom:1px solid var(--line);color:var(--muted);font-family:ui-monospace,SFMono-Regular,Consolas,monospace;font-size:12px}
@media(max-width:980px){.layout{grid-template-columns:1fr;height:auto}.tree,.inspector{max-height:320px}.editor{min-height:520px}.hero{display:block}.shell{padding:16px}}
@media(max-width:980px){.setup-layout{grid-template-columns:1fr}.setup-metrics{grid-template-columns:1fr 1fr}.settings-form{grid-template-columns:1fr}}
"""
+73 -1
View File
@@ -36,12 +36,17 @@ from neo4j import AsyncGraphDatabase
from pydantic import BaseModel, Field
from api_server.html5 import (
render_html5_authoring_changes,
render_html5_authoring_change_detail,
render_html5_authoring_preview_result,
render_html5_authoring_rollback_result,
render_html5_editor,
render_html5_index,
render_html5_project_setup,
render_html5_project_rows,
render_html5_project_report,
render_html5_review,
render_html5_symbol_detail,
render_html5_import_check,
render_html5_import_job,
render_html5_operation_rows,
@@ -1687,7 +1692,16 @@ async def html5_project_events(project_id: str, once: bool = False) -> Streaming
async def html5_project_symbols(project_id: str, q: str = "") -> Response:
snapshot = _project_snapshot_or_404(project_id)
return Response(
render_html5_symbols(snapshot, q),
render_html5_symbols(snapshot, q, project_id),
media_type="text/html; charset=utf-8",
)
@app.get("/html5/projects/{project_id}/symbols/{lineage_id}/detail")
async def html5_project_symbol_detail(project_id: str, lineage_id: str) -> Response:
references = await project_symbol_references(project_id, lineage_id, direction="both")
return Response(
render_html5_symbol_detail(project_id, references),
media_type="text/html; charset=utf-8",
)
@@ -1722,6 +1736,64 @@ async def html5_project_review(project_id: str) -> Response:
)
@app.get("/html5/projects/{project_id}/authoring/changes")
async def html5_project_authoring_changes(project_id: str) -> Response:
return Response(
render_html5_authoring_changes(project_id, _authoring_change_summaries(project_id)),
media_type="text/html; charset=utf-8",
)
@app.get("/html5/projects/{project_id}/authoring/changes/{change_id}")
async def html5_project_authoring_change_detail(project_id: str, change_id: str) -> Response:
return Response(
render_html5_authoring_change_detail(project_id, _authoring_rollback_preview(project_id, change_id)),
media_type="text/html; charset=utf-8",
)
@app.post("/html5/projects/{project_id}/authoring/changes/{change_id}/apply-rollback")
async def html5_project_authoring_apply_rollback(project_id: str, change_id: str, request: Request) -> Response:
form = await _html5_form_data(request)
payload = AuthoringApplyRollbackRequest(
expected_rollback_version_id=_form_value(form, "expected_rollback_version_id") or "",
approved_by=_form_value(form, "approved_by") or "",
approval_note=_form_value(form, "approval_note"),
task_id=_form_value(form, "task_id"),
session_id=_form_value(form, "session_id"),
)
try:
result = await authoring_apply_rollback(project_id, change_id, payload)
html = render_html5_authoring_rollback_result(project_id, result)
except HTTPException as error:
html = render_html5_authoring_rollback_result(project_id, error=str(error.detail))
return Response(html, media_type="text/html; charset=utf-8")
@app.post("/html5/projects/{project_id}/authoring/completion-preview")
async def html5_project_authoring_completion_preview(project_id: str, request: Request) -> Response:
form = await _html5_form_data(request)
cursor_line_value = _form_value(form, "cursor_line")
try:
cursor_line = int(cursor_line_value) if cursor_line_value else None
except ValueError:
cursor_line = None
payload = AuthoringCompletionPreviewRequest(
object_name=_form_value(form, "object_name"),
routine_name=_form_value(form, "routine_name"),
cursor_line=cursor_line,
source_text=_form_value(form, "source_text"),
intent=_form_value(form, "intent") or "guarded-return",
user_id=_form_value(form, "user_id"),
)
try:
preview = await authoring_completion_preview(project_id, payload)
html = render_html5_authoring_preview_result(project_id, preview)
except HTTPException as error:
html = render_html5_authoring_preview_result(project_id, error=str(error.detail))
return Response(html, media_type="text/html; charset=utf-8")
@app.get("/html5/projects/{project_id}/setup")
async def html5_project_setup(project_id: str) -> Response:
setup = _project_setup_response(project_id)
+81
View File
@@ -107,12 +107,19 @@ def test_html5_server_rendered_project_editor(tmp_path: Path):
assert 'data-html5-page="editor"' in editor.text
assert "data-html5-editor" in editor.text
assert "data-html5-symbol-results" in editor.text
assert "data-html5-symbol-detail" in editor.text
assert "data-html5-project-report" in editor.text
assert f'hx-get="/html5/projects/{project_id}/report"' in editor.text
assert "data-html5-review" in editor.text
assert f'hx-get="/html5/projects/{project_id}/review"' in editor.text
assert "data-html5-authoring-preview" in editor.text
assert "data-html5-authoring-preview-form" in editor.text
assert f'hx-post="/html5/projects/{project_id}/authoring/completion-preview"' in editor.text
assert "data-html5-authoring-changes" in editor.text
assert f'hx-get="/html5/projects/{project_id}/authoring/changes"' in editor.text
assert 'hx-get="/html5/projects/' in editor.text
assert 'hx-target="[data-html5-symbol-results]"' in editor.text
assert 'hx-target="[data-html5-symbol-detail]"' in editor.text
assert 'hx-target="[data-html5-source]"' in editor.text
assert 'hx-swap="outerHTML"' in editor.text
assert "hx-ext=\"sse\"" in editor.text
@@ -133,18 +140,31 @@ def test_html5_server_rendered_project_editor(tmp_path: Path):
assert symbols.status_code == 200
assert "text/html" in symbols.headers["content-type"]
assert 'data-html5-symbol' in symbols.text
assert 'data-html5-lineage-id' in symbols.text
assert 'hx-target="[data-html5-symbol-detail]"' in symbols.text
assert "Проверить" in symbols.text
assert "<html" not in symbols.text
snapshot = client.get(f"/projects/{project_id}/snapshot/export").json()
module_node = next(node for node in snapshot["nodes"] if node["kind"] == "MODULE")
procedure_node = next(node for node in snapshot["nodes"] if node["kind"] == "PROCEDURE")
source = client.get(f"/html5/projects/{project_id}/source/{module_node['lineage_id']}")
assert source.status_code == 200
assert "text/html" in source.headers["content-type"]
assert "data-html5-source" in source.text
assert "data-html5-source-name" in source.text
assert "data-html5-lineage-id" in source.text
assert "Lines" in source.text
assert "Проверить" in source.text
assert "<html" not in source.text
detail = client.get(f"/html5/projects/{project_id}/symbols/{procedure_node['lineage_id']}/detail")
assert detail.status_code == 200
assert "text/html" in detail.headers["content-type"]
assert "data-html5-symbol-detail" in detail.text
assert "Проверить" in detail.text
assert "<html" not in detail.text
report = client.get(f"/html5/projects/{project_id}/report")
assert report.status_code == 200
assert "text/html" in report.headers["content-type"]
@@ -158,6 +178,14 @@ def test_html5_server_rendered_project_editor(tmp_path: Path):
assert "data-html5-review" in review.text
assert "<html" not in review.text
authoring = client.get(f"/html5/projects/{project_id}/authoring/changes")
assert authoring.status_code == 200
assert "text/html" in authoring.headers["content-type"]
assert "data-html5-authoring-changes" in authoring.text
assert "data-html5-authoring-detail" in authoring.text
assert "Изменений пока нет" in authoring.text
assert "<html" not in authoring.text
def test_html5_project_index_creates_project_with_fragment():
client = TestClient(app)
@@ -2250,6 +2278,24 @@ def test_authoring_context_and_completion_preview(tmp_path: Path):
assert any(check["name"] == "apply" and check["status"] == "BLOCKED" for check in preview_payload["checks"])
assert preview_payload["semantic_diff"][0]["kind"] == "ADD"
html5_preview = client.post(
f"/html5/projects/{project_id}/authoring/completion-preview",
data={
"object_name": "Документ.ЗаказПокупателя",
"routine_name": "Проведение",
"cursor_line": "3",
"source_text": source_text,
"intent": "fill-check",
},
)
assert html5_preview.status_code == 200
assert "text/html" in html5_preview.headers["content-type"]
assert "data-html5-authoring-preview-result" in html5_preview.text
assert "ЗначениеЗаполнено(Контрагент)" in html5_preview.text
assert "BLOCKED" in html5_preview.text
assert "ADD" in html5_preview.text
assert "<html" not in html5_preview.text
diff_preview = client.post(
f"/projects/{project_id}/authoring/semantic-diff-preview",
json={
@@ -2312,6 +2358,15 @@ def test_authoring_context_and_completion_preview(tmp_path: Path):
assert changes.json()[0]["added_lines"] == 3
assert changes.json()[0]["production_applied"] is False
html5_changes = client.get(f"/html5/projects/{project_id}/authoring/changes")
assert html5_changes.status_code == 200
assert "text/html" in html5_changes.headers["content-type"]
assert "data-html5-authoring-changes" in html5_changes.text
assert "data-html5-authoring-detail" in html5_changes.text
assert 'hx-target="[data-html5-authoring-detail]"' in html5_changes.text
assert apply_payload["change_id"] in html5_changes.text
assert "<html" not in html5_changes.text
rollback = client.get(
f"/projects/{project_id}/authoring/changes/{apply_payload['change_id']}/rollback-preview"
)
@@ -2322,6 +2377,32 @@ def test_authoring_context_and_completion_preview(tmp_path: Path):
assert any(line["kind"] == "REMOVE" for line in rollback_payload["semantic_diff"])
assert any(check["name"] == "apply" and check["status"] == "READY" for check in rollback_payload["checks"])
html5_detail = client.get(f"/html5/projects/{project_id}/authoring/changes/{apply_payload['change_id']}")
assert html5_detail.status_code == 200
assert "text/html" in html5_detail.headers["content-type"]
assert "data-html5-authoring-detail" in html5_detail.text
assert "Rollback preview" in html5_detail.text
assert "data-html5-authoring-rollback-form" in html5_detail.text
assert f'hx-post="/html5/projects/{project_id}/authoring/changes/{apply_payload["change_id"]}/apply-rollback"' in html5_detail.text
assert "data-html5-authoring-result" in html5_detail.text
assert "READY" in html5_detail.text
assert "REMOVE" in html5_detail.text
assert apply_payload["change_id"] in html5_detail.text
assert "<html" not in html5_detail.text
html5_blocked_apply = client.post(
f"/html5/projects/{project_id}/authoring/changes/{apply_payload['change_id']}/apply-rollback",
data={
"expected_rollback_version_id": rollback_payload["rollback_version_id"],
"approved_by": "dev.ivan",
},
)
assert html5_blocked_apply.status_code == 200
assert "text/html" in html5_blocked_apply.headers["content-type"]
assert "data-html5-authoring-result" in html5_blocked_apply.text
assert "Task id is required" in html5_blocked_apply.text
assert "<html" not in html5_blocked_apply.text
rollback_apply = client.post(
f"/projects/{project_id}/authoring/changes/{apply_payload['change_id']}/apply-rollback",
json={