Add HTML5 background import job status
This commit is contained in:
@@ -226,6 +226,16 @@ def render_html5_setup_actions(project_id: str, setup: object) -> str:
|
||||
>
|
||||
<button type="submit">Проверить</button>
|
||||
</form>
|
||||
<form
|
||||
class="inline-form"
|
||||
method="post"
|
||||
action="/html5/projects/{quote(project_id)}/setup/import-job"
|
||||
hx-post="/html5/projects/{quote(project_id)}/setup/import-job"
|
||||
hx-target="[data-html5-import-job]"
|
||||
hx-swap="outerHTML"
|
||||
>
|
||||
<button type="submit">Импорт в фоне</button>
|
||||
</form>
|
||||
<form
|
||||
class="inline-form"
|
||||
method="post"
|
||||
@@ -248,6 +258,7 @@ def render_html5_setup_actions(project_id: str, setup: object) -> str:
|
||||
</form>
|
||||
</div>
|
||||
{render_html5_import_check(project_id)}
|
||||
{render_html5_import_job(project_id)}
|
||||
"""
|
||||
|
||||
|
||||
@@ -277,6 +288,42 @@ def render_html5_import_check(project_id: str, check: object | None = None) -> s
|
||||
"""
|
||||
|
||||
|
||||
def render_html5_import_job(project_id: str, job: object | None = None) -> str:
|
||||
if job is None:
|
||||
return f"""
|
||||
<div class="import-job" data-html5-import-job>
|
||||
<div class="panel-title flush">Фоновый импорт</div>
|
||||
<p class="muted padded">Фоновая задача импорта для проекта {escape(project_id)} еще не запускалась.</p>
|
||||
</div>
|
||||
"""
|
||||
job_id = str(getattr(job, "job_id", ""))
|
||||
status = _enum_text(getattr(job, "status", "unknown"))
|
||||
payload = getattr(job, "payload", {}) or {}
|
||||
message = str(payload.get("message") or "")
|
||||
source = str(payload.get("source") or "")
|
||||
stage = str(payload.get("stage") or "")
|
||||
logs = payload.get("logs") if isinstance(payload.get("logs"), list) else []
|
||||
poll = ' hx-trigger="every 2s" hx-swap="outerHTML"' if status in {"QUEUED", "RUNNING"} else ""
|
||||
logs_html = "".join(f"<li>{escape(str(item))}</li>" for item in logs[-6:])
|
||||
return f"""
|
||||
<div
|
||||
class="import-job"
|
||||
data-html5-import-job
|
||||
hx-get="/html5/projects/{quote(project_id)}/setup/jobs/{quote(job_id)}"
|
||||
{poll}
|
||||
>
|
||||
<div class="panel-title flush">Фоновый импорт</div>
|
||||
<div class="check-head">
|
||||
<strong>{escape(status)}</strong>
|
||||
<span>{escape(source)}</span>
|
||||
<small>{escape(stage or job_id)}</small>
|
||||
</div>
|
||||
<p class="muted padded">{escape(message or "Ожидание обновления статуса")}</p>
|
||||
<ul class="job-log">{logs_html or '<li>Лог пока пустой</li>'}</ul>
|
||||
</div>
|
||||
"""
|
||||
|
||||
|
||||
def render_html5_setup_summary(project_id: str, setup: object) -> str:
|
||||
status = _enum_text(getattr(setup, "status", "unknown"))
|
||||
message = str(getattr(setup, "message", ""))
|
||||
@@ -536,7 +583,7 @@ def _css() -> str:
|
||||
.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)}.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}.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{display:grid;grid-template-columns:repeat(4,1fr);margin:0;border-top:1px solid var(--line)}.setup-metrics div{padding:16px;border-right:1px solid var(--line);border-bottom:1px solid var(--line)}.setup-metrics div:last-child{border-right:0}.setup-metrics dt{font-size:12px;color:var(--muted)}.setup-metrics 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}
|
||||
.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}.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{display:grid;grid-template-columns:repeat(4,1fr);margin:0;border-top:1px solid var(--line)}.setup-metrics div{padding:16px;border-right:1px solid var(--line);border-bottom:1px solid var(--line)}.setup-metrics div:last-child{border-right:0}.setup-metrics dt{font-size:12px;color:var(--muted)}.setup-metrics 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}}
|
||||
"""
|
||||
|
||||
@@ -41,6 +41,7 @@ from api_server.html5 import (
|
||||
render_html5_project_setup,
|
||||
render_html5_project_rows,
|
||||
render_html5_import_check,
|
||||
render_html5_import_job,
|
||||
render_html5_setup_summary,
|
||||
render_html5_source,
|
||||
render_html5_status,
|
||||
@@ -1717,6 +1718,28 @@ async def html5_project_setup_import(project_id: str, request: Request) -> Respo
|
||||
)
|
||||
|
||||
|
||||
@app.post("/html5/projects/{project_id}/setup/import-job")
|
||||
async def html5_project_setup_import_job(project_id: str, request: Request) -> Response:
|
||||
form = await _html5_form_data(request)
|
||||
source = ImportSourceKind(_form_value(form, "source") or _current_import_source(project_id).value)
|
||||
job = await start_project_import_job(project_id, source, ImportRequest(source=source))
|
||||
return Response(
|
||||
render_html5_import_job(project_id, job),
|
||||
media_type="text/html; charset=utf-8",
|
||||
)
|
||||
|
||||
|
||||
@app.get("/html5/projects/{project_id}/setup/jobs/{job_id}")
|
||||
async def html5_project_setup_job(project_id: str, job_id: str) -> Response:
|
||||
job = _operations.jobs.get(job_id)
|
||||
if job is None or job.payload.get("project_id") != project_id:
|
||||
raise HTTPException(status_code=404, detail=f"Unknown import job: {job_id}")
|
||||
return Response(
|
||||
render_html5_import_job(project_id, job),
|
||||
media_type="text/html; charset=utf-8",
|
||||
)
|
||||
|
||||
|
||||
@app.post("/html5/projects/{project_id}/setup/reindex")
|
||||
async def html5_project_setup_reindex(project_id: str) -> Response:
|
||||
await reindex_project(project_id)
|
||||
|
||||
Reference in New Issue
Block a user