feat: 评估页改成页面内提交,任务列表放在下面,去掉两个弹窗
- 单个提交直接在页面上填:左边评估对象(按小区或按站点),右边拆除信息 - 导入清单在页面上传:左边选文件和地市,右边是填写说明或预览 - 提交后不再弹出详情,新任务排到列表最前面并短暂标亮;单个提交后保留拆除信息 - 从表格粘贴 CGI 和小区名两列时名称一起带上,表头行和重复的 CGI 跳过 - 列表里下载按钮带文字;只有一个站点的任务显示正在做哪一步(接口新增 stage) - 窗口不够宽时提交时间并到评估对象下面,再窄换成卡片,表格不再横向滚动
This commit is contained in:
@@ -241,11 +241,15 @@ def list_jobs(actor: Actor = Depends(current_actor), session: Session = db_sessi
|
||||
.limit(200)
|
||||
).all()
|
||||
kinds: dict[int, dict] = {}
|
||||
stages: dict[int, str] = {}
|
||||
if jobs:
|
||||
for job_id, kind in session.execute(select(EvalTask.job_id, EvalTask.kind).where(EvalTask.job_id.in_([job.id for job in jobs]))):
|
||||
rows = session.execute(select(EvalTask.job_id, EvalTask.kind, EvalTask.status, EvalTask.stage).where(EvalTask.job_id.in_([job.id for job in jobs])))
|
||||
for job_id, kind, status, stage in rows:
|
||||
counter = kinds.setdefault(job_id, {"pinduan": 0, "dixiao": 0})
|
||||
counter[kind] = counter.get(kind, 0) + 1
|
||||
return {"jobs": [_public_job(job, kinds.get(job.id)) for job in jobs]}
|
||||
if status == "running" and stage:
|
||||
stages[job_id] = stage
|
||||
return {"jobs": [_public_job(job, kinds.get(job.id), stages.get(job.id, "")) for job in jobs]}
|
||||
|
||||
|
||||
@router.get("/jobs/{job_id}")
|
||||
@@ -256,7 +260,8 @@ def job_detail(job_id: int, actor: Actor = Depends(current_actor), session: Sess
|
||||
counts = {"pinduan": 0, "dixiao": 0}
|
||||
for task in tasks:
|
||||
counts[task.kind] = counts.get(task.kind, 0) + 1
|
||||
return {"job": _public_job(job, counts), "tasks": [_public_task(task) for task in tasks]}
|
||||
stage = next((task.stage for task in tasks if task.status == "running" and task.stage), "")
|
||||
return {"job": _public_job(job, counts, stage), "tasks": [_public_task(task) for task in tasks]}
|
||||
|
||||
|
||||
@router.get("/jobs/{job_id}/files/{kind}")
|
||||
@@ -291,7 +296,7 @@ def _iso(value: date | datetime | None) -> str | None:
|
||||
return value.isoformat()
|
||||
|
||||
|
||||
def _public_job(job: EvalJob, kinds: dict | None = None) -> dict:
|
||||
def _public_job(job: EvalJob, kinds: dict | None = None, stage: str = "") -> dict:
|
||||
return {
|
||||
"id": job.id,
|
||||
"mode": job.mode,
|
||||
@@ -299,6 +304,8 @@ def _public_job(job: EvalJob, kinds: dict | None = None) -> dict:
|
||||
"city": job.city,
|
||||
"sourceName": job.source_name,
|
||||
"status": job.status,
|
||||
# 只有一个站点的任务,列表里直接显示它做到哪一步;多个站点看完成数。
|
||||
"stage": stage if job.total == 1 and job.status not in JOB_FINAL else "",
|
||||
"total": job.total,
|
||||
"finished": job.finished,
|
||||
"failed": job.failed,
|
||||
|
||||
@@ -364,6 +364,24 @@ def client(monkeypatch):
|
||||
shutil.rmtree(data)
|
||||
|
||||
|
||||
def test_job_stage_shows_only_for_a_single_site_still_running():
|
||||
from types import SimpleNamespace
|
||||
|
||||
from app.api.evaluate import _public_job
|
||||
|
||||
def job(total: int, status: str) -> SimpleNamespace:
|
||||
return SimpleNamespace(
|
||||
id=1, mode="single", title="站A", city="江门", source_name="", status=status, total=total, finished=0, failed=0,
|
||||
results=[], warnings=[], error="", created_at=None, finished_at=None,
|
||||
)
|
||||
|
||||
assert _public_job(job(1, "running"), None, "查询停闭前后指标")["stage"] == "查询停闭前后指标"
|
||||
# 多个站点同时在跑,说不清是哪一步,列表里只看完成数。
|
||||
assert _public_job(job(3, "running"), None, "查询停闭前后指标")["stage"] == ""
|
||||
assert _public_job(job(1, "done"), None, "完成")["stage"] == ""
|
||||
assert _public_job(job(1, "queued"))["stage"] == ""
|
||||
|
||||
|
||||
def wait_job(client: TestClient, headers: dict, job_id: int) -> dict:
|
||||
for _ in range(100):
|
||||
detail = client.get(f"/api/eval/jobs/{job_id}", headers=headers).json()
|
||||
@@ -428,5 +446,6 @@ def test_eval_api_end_to_end(client: TestClient):
|
||||
listing = client.get("/api/eval/jobs", headers=user).json()["jobs"]
|
||||
assert [job["id"] for job in listing][:3] == [by_site["id"], single["id"], created["id"]]
|
||||
assert listing[-1]["kinds"] == {"pinduan": 1, "dixiao": 1}
|
||||
assert all(job["stage"] == "" for job in listing) and site_detail["job"]["stage"] == ""
|
||||
assert client.delete(f"/api/eval/jobs/{created['id']}", headers=user).json() == {"ok": True}
|
||||
assert client.get(f"/api/eval/jobs/{created['id']}", headers=user).status_code == 404
|
||||
|
||||
Reference in New Issue
Block a user