gitea user and pswd, some pages removed, logs

This commit is contained in:
JiriUhlir
2026-06-17 11:39:52 +02:00
parent 23bbcad835
commit 7897e3b876
18 changed files with 601 additions and 457 deletions
+47 -4
View File
@@ -325,7 +325,32 @@ def job_detail_page(job_id: int, request: Request, user=Depends(require_user)):
target_type = job.get("target_type", "") or ""
target_id = job.get("target_id", "") or ""
target_id_html = html.escape(target_id)
target_url = f"/portal/apps/{quote(target_id, safe='')}" if target_type == "app" else "/portal/jobs"
# Kontextová navigace: "Zpět" vede tam, odkud úloha typicky vznikla, a tlačítko na detail cíle
# se ukáže jen tehdy, když cíl má vlastní stránku (jinak nedávalo smysl a vedlo zpět na seznam úloh).
back_url = "/portal/jobs"
back_label = "Zpět na úlohy"
target_detail_button = ""
if target_type == "app" and target_id:
app_url = f"/portal/apps/{quote(target_id, safe='')}"
target_detail_button = (
f'<a class="btn btn-secondary" href="{app_url}">'
'<i class="fa-solid fa-arrow-up-right-from-square" aria-hidden="true"></i> Detail služby</a>'
)
elif target_type == "scheduled_script":
back_url = "/portal/scheduled-scripts"
back_label = "Zpět na plánované skripty"
try:
payload_obj = json.loads(job.get("payload_json") or "{}")
except (TypeError, ValueError):
payload_obj = {}
scheduled_script_id = payload_obj.get("scheduled_script_id")
if scheduled_script_id:
sid_html = html.escape(str(scheduled_script_id))
target_detail_button = (
f'<a class="btn btn-secondary" href="/portal/scheduled-scripts/{sid_html}">'
'<i class="fa-solid fa-arrow-up-right-from-square" aria-hidden="true"></i> Detail skriptu</a>'
)
duration = html.escape(calculate_duration(job.get("started_at"), job.get("finished_at")))
payload = html.escape(pretty_json(job.get("payload_json")))
result = html.escape(pretty_json(job.get("result_json")))
@@ -355,6 +380,7 @@ def job_detail_page(job_id: int, request: Request, user=Depends(require_user)):
log_blocks = ""
for log in get_job_logs(job_id):
log_id = html.escape(str(log.get("id", "")))
stream = html.escape(log.get("stream", "") or "system")
created_at = html.escape(log.get("created_at", "") or "")
message = html.escape(log.get("message", "") or "")
@@ -364,8 +390,9 @@ def job_detail_page(job_id: int, request: Request, user=Depends(require_user)):
class_name = "log-system"
else:
class_name = "log-stdout"
# id="log-{id}" umožní proklik z globálního prohlížeče logů přímo na konkrétní řádek.
log_blocks += f"""
<div class="job-log-entry">
<div class="job-log-entry" id="log-{log_id}">
<div class="muted">{created_at} · {stream}</div>
<pre class="log-viewer {class_name}">{message}</pre>
</div>
@@ -379,6 +406,10 @@ def job_detail_page(job_id: int, request: Request, user=Depends(require_user)):
(() => {{
const statusEl = document.getElementById("live-log-status");
const panel = document.getElementById("live-log-panel");
const banner = document.getElementById("job-finished-banner");
// Pokud úloha při načtení stránky ještě běžela, po jejím dokončení stránku obnovíme,
// aby se přepsal i horní stav a souhrn (jinak by zůstal viset na "běží").
const jobWasLive = {"true" if status_value in ("queued", "running", "cancelled_requested") else "false"};
if (!statusEl || !panel || !window.WebSocket) {{
if (statusEl) statusEl.textContent = "Disconnected";
return;
@@ -418,7 +449,18 @@ def job_detail_page(job_id: int, request: Request, user=Depends(require_user)):
}}
if (item.type === "job_finished") {{
statusEl.textContent = `Finished: ${{item.status}}`;
if (banner) {{
const labels = {{ success: "úspěšně", failed: "se selháním", cancelled: "zrušena" }};
banner.classList.toggle("alert-danger", item.status === "failed" || item.status === "cancelled");
banner.textContent = jobWasLive
? `Úloha doběhla (${{labels[item.status] || item.status}}). Načítám výsledek…`
: `Úloha doběhla (${{labels[item.status] || item.status}}).`;
banner.style.display = "block";
}}
socket.close();
if (jobWasLive) {{
setTimeout(() => window.location.reload(), 1200);
}}
}}
}});
socket.addEventListener("close", () => {{
@@ -440,9 +482,10 @@ def job_detail_page(job_id: int, request: Request, user=Depends(require_user)):
<div class="card">
<h2>{title}</h2>
<p>
<a class="btn" href="/portal/jobs">&larr; Zpět na úlohy</a>
<a class="btn btn-secondary" href="{target_url}"><i class="fa-solid fa-arrow-up-right-from-square" aria-hidden="true"></i> Detail cíle</a>
<a class="btn" href="{back_url}">&larr; {back_label}</a>
{target_detail_button}
</p>
<p id="job-finished-banner" class="alert" style="display:none;"></p>
{retry_blocked_notice}
{actions}
</div>