Add HTML5 authoring change apply form
This commit is contained in:
@@ -430,7 +430,12 @@ def render_html5_authoring_preview_result(project_id: str, preview: object | Non
|
||||
"""
|
||||
|
||||
|
||||
def render_html5_authoring_diff_result(project_id: str, preview: object | None = None, error: str | None = None) -> str:
|
||||
def render_html5_authoring_diff_result(
|
||||
project_id: str,
|
||||
preview: object | None = None,
|
||||
error: str | None = None,
|
||||
request_payload: dict | None = None,
|
||||
) -> str:
|
||||
if preview is None and error is None:
|
||||
return '<div class="authoring-diff-result" data-html5-authoring-diff-result></div>'
|
||||
if error:
|
||||
@@ -451,6 +456,11 @@ def render_html5_authoring_diff_result(project_id: str, preview: object | None =
|
||||
next_version_id = str(getattr(version_preview, "next_version_id", ""))
|
||||
check_rows = "".join(_authoring_check_item(check) for check in checks[:8])
|
||||
diff_rows = "".join(_authoring_diff_item(line) for line in diff[:12]) or '<p class="muted padded">Diff пустой</p>'
|
||||
apply_form = (
|
||||
_authoring_apply_change_set_form(project_id, request_payload or {}, next_version_id)
|
||||
if changed and next_version_id
|
||||
else ""
|
||||
)
|
||||
return f"""
|
||||
<div class="authoring-diff-result" data-html5-authoring-diff-result data-html5-project-id="{escape(project_id)}">
|
||||
<div class="panel-title">Diff preview · {'changed' if changed else 'unchanged'}</div>
|
||||
@@ -461,6 +471,39 @@ def render_html5_authoring_diff_result(project_id: str, preview: object | None =
|
||||
</article>
|
||||
<div class="check-list">{check_rows}</div>
|
||||
<div class="diff-list">{diff_rows}</div>
|
||||
{apply_form}
|
||||
</div>
|
||||
"""
|
||||
|
||||
|
||||
def render_html5_authoring_apply_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-apply-result" data-html5-authoring-apply-result></div>'
|
||||
if error:
|
||||
return f"""
|
||||
<div class="authoring-apply-result" data-html5-authoring-apply-result>
|
||||
<div class="panel-title">Apply change-set</div>
|
||||
<p class="muted padded">{escape(error)}</p>
|
||||
</div>
|
||||
"""
|
||||
status = str(getattr(result, "status", "UNKNOWN"))
|
||||
change_id = str(getattr(result, "change_id", ""))
|
||||
version = getattr(result, "version", None)
|
||||
version_id = str(getattr(version, "version_id", ""))
|
||||
return f"""
|
||||
<div
|
||||
class="authoring-apply-result"
|
||||
data-html5-authoring-apply-result
|
||||
data-html5-authoring-change="{escape(change_id)}"
|
||||
data-html5-version-id="{escape(version_id)}"
|
||||
>
|
||||
<div class="panel-title">Apply change-set</div>
|
||||
<article class="authoring-change">
|
||||
<strong>{escape(status)}</strong>
|
||||
<span>{escape(change_id)}</span>
|
||||
<small>{escape(version_id)}</small>
|
||||
</article>
|
||||
<p class="muted padded">Change-set применен в workspace для проекта {escape(project_id)}.</p>
|
||||
</div>
|
||||
"""
|
||||
|
||||
@@ -1178,6 +1221,33 @@ def _authoring_rollback_form(project_id: str, change_id: str, rollback_version_i
|
||||
"""
|
||||
|
||||
|
||||
def _authoring_apply_change_set_form(project_id: str, payload: dict, next_version_id: str) -> str:
|
||||
return f"""
|
||||
<form
|
||||
class="authoring-preview-form"
|
||||
data-html5-authoring-apply-form
|
||||
method="post"
|
||||
action="/html5/projects/{quote(project_id)}/authoring/apply-change-set"
|
||||
hx-post="/html5/projects/{quote(project_id)}/authoring/apply-change-set"
|
||||
hx-target="[data-html5-authoring-apply-result]"
|
||||
hx-swap="outerHTML"
|
||||
>
|
||||
<input type="hidden" name="routine_name" value="{escape(str(payload.get("routine_name") or ""))}" />
|
||||
<input type="hidden" name="source_path" value="{escape(str(payload.get("source_path") or ""))}" />
|
||||
<textarea hidden name="original_text">{escape(str(payload.get("original_text") or ""))}</textarea>
|
||||
<textarea hidden name="proposed_text">{escape(str(payload.get("proposed_text") or ""))}</textarea>
|
||||
<input type="hidden" name="task_id" value="{escape(str(payload.get("task_id") or ""))}" />
|
||||
<input type="hidden" name="session_id" value="{escape(str(payload.get("session_id") or ""))}" />
|
||||
<input type="hidden" name="user_id" value="{escape(str(payload.get("user_id") or ""))}" />
|
||||
<input type="hidden" name="expected_next_version_id" value="{escape(next_version_id)}" />
|
||||
<input name="approved_by" placeholder="approved_by" required />
|
||||
<input name="approval_note" placeholder="Комментарий" />
|
||||
<button type="submit">Apply change-set</button>
|
||||
</form>
|
||||
{render_html5_authoring_apply_result(project_id)}
|
||||
"""
|
||||
|
||||
|
||||
def _node_source_text(node: object | None) -> str:
|
||||
if node is None:
|
||||
return "// Модуль не найден в snapshot.\n// HTML5 IDE показывает серверный fallback без клиентского JS."
|
||||
|
||||
Reference in New Issue
Block a user