diff --git a/main.py b/main.py index 6a851ae..d47e19a 100644 --- a/main.py +++ b/main.py @@ -3444,6 +3444,20 @@ async def reviews_report(review_id: int, request: Request): f"attachment; filename*=UTF-8''{quote(filename)}"}) +@app.get("/review", response_class=HTMLResponse) +async def review_list_page(): + from pathlib import Path as _P + return HTMLResponse(_P("static/review-list.html").read_text(encoding="utf-8"), + headers={"Cache-Control": "no-store"}) + + +@app.get("/review/{review_id}", response_class=HTMLResponse) +async def review_page(review_id: int): + from pathlib import Path as _P + return HTMLResponse(_P("static/review.html").read_text(encoding="utf-8"), + headers={"Cache-Control": "no-store"}) + + @app.get("/api/reviews/quota") async def reviews_quota(request: Request): user = _site_owner(request) diff --git a/static/chat.html b/static/chat.html index 5864f8c..97ca23c 100644 --- a/static/chat.html +++ b/static/chat.html @@ -754,6 +754,11 @@ html { color-scheme: light; }
+
@@ -1727,6 +1732,37 @@ async function connectProgram(){ } } function hideDevicePanel(){ document.getElementById('device-panel').style.display = 'none'; } +// Карточка проверки в чате (T6b): опрос раз в 10 с, пока вкладка видима. Пусто или +// ошибка — карточки нет: пустышка на экране хуже отсутствия карточки. +let _reviewCardId = null; +async function pollReviewCard(){ + if (document.hidden) return; + try { + const r = await fetch(API + '/api/reviews', {headers: authHeaders()}); + if (!r.ok) { document.getElementById('review-card').style.display = 'none'; return; } + const d = await r.json(); + const live = (d.items||[]).find(x => ['queued','running','paused'].includes(x.status)); + const card = document.getElementById('review-card'); + if (!live) { card.style.display = 'none'; _reviewCardId = null; return; } + _reviewCardId = live.id; + const closed = (live.n_fixed||0)+(live.n_partial||0)+(live.n_not_fixed||0)+(live.n_unknown||0); + document.getElementById('review-card-title').textContent = + 'Проверка №' + live.id + ' — ' + closed + ' из ' + (live.total||0); + const open = document.getElementById('review-card-open'); + open.href = '/review/' + live.id; + const stop = document.getElementById('review-card-stop'); + stop.style.display = live.status === 'stopped' ? 'none' : ''; + card.style.display = 'block'; + } catch (e) { document.getElementById('review-card').style.display = 'none'; } +} +document.getElementById('review-card-stop').onclick = async () => { + if (!_reviewCardId) return; + await fetch(API + '/api/reviews/' + _reviewCardId + '/cancel', + {method:'POST', headers: authHeaders()}); + pollReviewCard(); +}; +setInterval(pollReviewCard, 10000); +document.addEventListener('visibilitychange', () => { if (!document.hidden) pollReviewCard(); }); function hideInvitePanel() { document.getElementById('invite-panel').style.display = 'none'; document.getElementById('btn-invite').setAttribute('aria-expanded', 'false'); diff --git a/static/review-list.html b/static/review-list.html new file mode 100644 index 0000000..33def85 --- /dev/null +++ b/static/review-list.html @@ -0,0 +1,23 @@ + + +Проверки замечаний + +

Проверки замечаний

+ + +
№НазваниеСостояниеЗакрытоВсегоЦена, ₽Уведомление
Загрузка…
+ diff --git a/static/review.html b/static/review.html new file mode 100644 index 0000000..422bab9 --- /dev/null +++ b/static/review.html @@ -0,0 +1,109 @@ + + + + + +Проверка замечаний + + + +
+

Проверка

+ + + + + + + + Все проверки +
+
+ + +
№Текст замечанияФайлЛистСтрокаСостояниеЗаключениеБылоСталоСсылкаПричина
Загрузка…
+ + + diff --git a/tests/test_reviews_endpoints.py b/tests/test_reviews_endpoints.py index 8f67f47..0f49444 100644 --- a/tests/test_reviews_endpoints.py +++ b/tests/test_reviews_endpoints.py @@ -278,3 +278,17 @@ def test_stream_snapshot_then_item(env): env["db"].finish_item(row[0], item["lease"], "fixed", "ок", "{}", "") events = _read_events(env["client"], f"/api/reviews/{rid}/stream", env["site"], limit=3) assert events[0] == "snapshot" and "done" in events + + +def test_screen_pages_served(env): + r = env["client"].get("/review/1") + assert r.status_code == 200 and "Проверка" in r.text + assert "/api/reviews/" in r.text + r = env["client"].get("/review") + assert r.status_code == 200 and "Проверки" in r.text + + +def test_chat_has_review_card(env): + html = open(os.path.join(ROOT, "static", "chat.html"), encoding="utf-8").read() + assert "review-card" in html and "/api/reviews" in html + assert "остановить" in html