Polish backup progress status layout

This commit is contained in:
kzolotarev95 committed 2026-06-28 18:02:16 +04:00
1 parent ed018c06eb
commit 5eebe839b9
1 file changed
+43 -13
+43 -13
View File
@@ -138,6 +138,19 @@ job_file() {
printf '%s/%s.%s' "$JOB_DIR" "$1" "$2"
}
format_seconds() {
local seconds minutes rest
seconds="$1"
case "$seconds" in ''|*[!0-9]*) seconds=0 ;; esac
minutes="$((seconds / 60))"
rest="$((seconds % 60))"
if [ "$minutes" -gt 0 ]; then
printf '%s мин %s сек' "$minutes" "$rest"
else
printf '%s сек' "$rest"
fi
}
download_file() {
local file base
file="$(param file)"
@@ -263,12 +276,13 @@ echo "Старт: \$(date)"
echo "Создание бэкапа запущено."
$cmd
code="\$?"
echo "Код выхода: \$code"
echo "\$code" > "$(job_file "$id" code)"
date +%s > "$(job_file "$id" finished)"
if [ "\$code" = "0" ]; then
echo "Готово."
echo done > "$status"
else
echo "Ошибка: код выхода \$code"
echo failed > "$status"
fi
rm -f "$script"
@@ -463,7 +477,7 @@ backup_rows() {
}
render_job_panel() {
local id status meta log code_file started now elapsed title state_class state_text job_note button_text
local id status meta log code_file finished_file started finished now elapsed elapsed_text title state_class state_text job_note button_text code estimate_text
id="$1"
valid_job_id "$id" || return
@@ -471,24 +485,36 @@ render_job_panel() {
meta="$(job_file "$id" meta)"
log="$(job_file "$id" log)"
code_file="$(job_file "$id" code)"
finished_file="$(job_file "$id" finished)"
started="$(sed -n 's/^started=//p' "$meta" 2>/dev/null | sed -n '1p')"
title="$(sed -n 's/^title=//p' "$meta" 2>/dev/null | sed -n '1p')"
code="$(cat "$code_file" 2>/dev/null | sed -n '1p')"
finished="$(cat "$finished_file" 2>/dev/null | sed -n '1p')"
[ -n "$title" ] || title="Создание бэкапа"
case "$started" in ''|*[!0-9]*) started="$(date +%s)" ;; esac
now="$(date +%s)"
if [ "$status" != "running" ]; then
case "$finished" in
''|*[!0-9]*) ;;
*) [ "$finished" -ge "$started" ] 2>/dev/null && now="$finished" ;;
esac
fi
elapsed="$((now - started))"
elapsed_text="$(format_seconds "$elapsed")"
estimate_text=""
case "$status" in
running)
state_class="running"
state_text="Выполняется"
job_note="Страница обновляется каждые 2 секунды. После завершения список архивов ниже обновится автоматически."
estimate_text=" · Примерно: 1-3 мин"
job_note="Страница обновляется каждые 2 секунды. Время примерное: большой overlay, ROM или медленная флешка могут идти дольше."
button_text="Обновить лог"
;;
done)
state_class="ok"
state_text="Завершено"
job_note="Готово. Список архивов ниже уже обновлен."
job_note="Готово. Архив уже появился в списке ниже."
button_text="Обновить список"
;;
failed)
@@ -506,20 +532,22 @@ render_job_panel() {
esac
printf '<section class="panel span12 job-card %s">' "$state_class"
printf '<div class="section-head"><div><h2>%s</h2><p>Статус: %s · Время: <span id="job-timer" data-start="%s">%s сек</span>' "$(h "$title")" "$(h "$state_text")" "$(h "$started")" "$(h "$elapsed")"
if [ -r "$code_file" ]; then
printf ' · Код выхода: %s' "$(h "$(cat "$code_file")")"
printf '<div class="section-head"><div><h2>%s</h2><p>Статус: %s · Время: <span id="job-timer" data-start="%s">%s</span>%s' "$(h "$title")" "$(h "$state_text")" "$(h "$started")" "$(h "$elapsed_text")" "$(h "$estimate_text")"
if [ -n "$code" ] && [ "$code" != "0" ]; then
printf ' · Код ошибки: %s' "$(h "$code")"
fi
printf '</p></div><a class="button small" href="%s?key=%s">%s</a></div>' "$(self_url)" "$(h "$(param key)")" "$button_text"
printf '<p>%s</p><div class="console-title">Журнал выполнения</div>' "$(h "$job_note")"
printf '<pre class="console">'
if [ -r "$log" ]; then
tail -n 120 "$log" | html_escape
tail -n 120 "$log" | sed 's/^Код выхода: 0$/Готово./' | html_escape
else
printf 'Лог пока пуст. Подожди пару секунд.\n' | html_escape
fi
printf '</pre>'
printf '<script>(function(){var el=document.getElementById("job-timer");if(!el)return;var start=parseInt(el.dataset.start,10)||0;function tick(){var now=Math.floor(Date.now()/1000);el.textContent=Math.max(0,now-start)+" сек";}tick();setInterval(tick,1000);}());</script>'
if [ "$status" = "running" ]; then
printf '<script>(function(){var el=document.getElementById("job-timer");if(!el)return;var start=parseInt(el.dataset.start,10)||0;function fmt(s){s=Math.max(0,s|0);var m=Math.floor(s/60),r=s%%60;return m>0?m+" мин "+r+" сек":r+" сек";}function tick(){var now=Math.floor(Date.now()/1000);el.textContent=fmt(now-start);}tick();setInterval(tick,1000);}());</script>'
fi
printf '</section>'
}
@@ -558,7 +586,7 @@ $refresh_meta
@media (prefers-color-scheme: dark) { :root { --bg: #111418; --panel: #181d23; --text: #eef2f6; --muted: #a6b0bf; --line: #2d3642; --accent: #6aa4ff; --bad: #ff9b91; --ok: #7ee0a3; } }
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
main { max-width: 1180px; margin: 0 auto; padding: 18px; display: grid; gap: 14px; }
main { max-width: 1280px; margin: 0 auto; padding: 18px; display: grid; gap: 14px; }
h1 { margin: 0; font-size: 22px; }
h2 { margin: 0 0 12px; font-size: 16px; }
p { margin: 6px 0; color: var(--muted); }
@@ -588,6 +616,8 @@ button, .button { display: inline-flex; align-items: center; justify-content: ce
.result-output, .console { white-space: pre-wrap; overflow-wrap: anywhere; word-break: break-word; }
.console { max-height: 340px; }
.console-title { margin: 12px 0 6px; font-weight: 700; }
.device-card, .create-card { min-width: 0; }
.device-disk { white-space: pre; font-size: 12px; }
code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
pre { overflow: auto; background: rgba(127,127,127,.12); border-radius: 6px; padding: 10px; }
table { width: 100%; border-collapse: collapse; }
@@ -632,17 +662,17 @@ EOF
cat <<EOF
<section class="grid">
<div class="panel span4">
<div class="panel span6 device-card">
<h2>Устройство</h2>
<div class="status">
<span class="pill">Имя: $(h "$(system_value host)")</span>
<span class="pill">Версия: $(h "$(system_value release)")</span>
<span class="pill">Плата: $(h "$(system_value board)")</span>
</div>
<pre>$(df -h 2>/dev/null | html_escape)</pre>
<pre class="device-disk">$(df -h 2>/dev/null | html_escape)</pre>
</div>
<form class="panel span8" method="post" action="$(self_url)">
<form class="panel span6 create-card" method="post" action="$(self_url)">
<h2>Создать бэкап</h2>
<input type="hidden" name="key" value="$key">
<input type="hidden" name="action" value="create">