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" 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() { download_file() {
local file base local file base
file="$(param file)" file="$(param file)"
@@ -263,12 +276,13 @@ echo "Старт: \$(date)"
echo "Создание бэкапа запущено." echo "Создание бэкапа запущено."
$cmd $cmd
code="\$?" code="\$?"
echo "Код выхода: \$code"
echo "\$code" > "$(job_file "$id" code)" echo "\$code" > "$(job_file "$id" code)"
date +%s > "$(job_file "$id" finished)" date +%s > "$(job_file "$id" finished)"
if [ "\$code" = "0" ]; then if [ "\$code" = "0" ]; then
echo "Готово."
echo done > "$status" echo done > "$status"
else else
echo "Ошибка: код выхода \$code"
echo failed > "$status" echo failed > "$status"
fi fi
rm -f "$script" rm -f "$script"
@@ -463,7 +477,7 @@ backup_rows() {
} }
render_job_panel() { 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" id="$1"
valid_job_id "$id" || return valid_job_id "$id" || return
@@ -471,24 +485,36 @@ render_job_panel() {
meta="$(job_file "$id" meta)" meta="$(job_file "$id" meta)"
log="$(job_file "$id" log)" log="$(job_file "$id" log)"
code_file="$(job_file "$id" code)" 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')" 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')" 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="Создание бэкапа" [ -n "$title" ] || title="Создание бэкапа"
case "$started" in ''|*[!0-9]*) started="$(date +%s)" ;; esac case "$started" in ''|*[!0-9]*) started="$(date +%s)" ;; esac
now="$(date +%s)" 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="$((now - started))"
elapsed_text="$(format_seconds "$elapsed")"
estimate_text=""
case "$status" in case "$status" in
running) running)
state_class="running" state_class="running"
state_text="Выполняется" state_text="Выполняется"
job_note="Страница обновляется каждые 2 секунды. После завершения список архивов ниже обновится автоматически." estimate_text=" · Примерно: 1-3 мин"
job_note="Страница обновляется каждые 2 секунды. Время примерное: большой overlay, ROM или медленная флешка могут идти дольше."
button_text="Обновить лог" button_text="Обновить лог"
;; ;;
done) done)
state_class="ok" state_class="ok"
state_text="Завершено" state_text="Завершено"
job_note="Готово. Список архивов ниже уже обновлен." job_note="Готово. Архив уже появился в списке ниже."
button_text="Обновить список" button_text="Обновить список"
;; ;;
failed) failed)
@@ -506,20 +532,22 @@ render_job_panel() {
esac esac
printf '<section class="panel span12 job-card %s">' "$state_class" 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")" 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 [ -r "$code_file" ]; then if [ -n "$code" ] && [ "$code" != "0" ]; then
printf ' · Код выхода: %s' "$(h "$(cat "$code_file")")" printf ' · Код ошибки: %s' "$(h "$code")"
fi fi
printf '</p></div><a class="button small" href="%s?key=%s">%s</a></div>' "$(self_url)" "$(h "$(param key)")" "$button_text" 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 '<p>%s</p><div class="console-title">Журнал выполнения</div>' "$(h "$job_note")"
printf '<pre class="console">' printf '<pre class="console">'
if [ -r "$log" ]; then if [ -r "$log" ]; then
tail -n 120 "$log" | html_escape tail -n 120 "$log" | sed 's/^Код выхода: 0$/Готово./' | html_escape
else else
printf 'Лог пока пуст. Подожди пару секунд.\n' | html_escape printf 'Лог пока пуст. Подожди пару секунд.\n' | html_escape
fi fi
printf '</pre>' 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>' 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; } } @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; } * { 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; } 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; } h1 { margin: 0; font-size: 22px; }
h2 { margin: 0 0 12px; font-size: 16px; } h2 { margin: 0 0 12px; font-size: 16px; }
p { margin: 6px 0; color: var(--muted); } 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; } .result-output, .console { white-space: pre-wrap; overflow-wrap: anywhere; word-break: break-word; }
.console { max-height: 340px; } .console { max-height: 340px; }
.console-title { margin: 12px 0 6px; font-weight: 700; } .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; } 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; } pre { overflow: auto; background: rgba(127,127,127,.12); border-radius: 6px; padding: 10px; }
table { width: 100%; border-collapse: collapse; } table { width: 100%; border-collapse: collapse; }
@@ -632,17 +662,17 @@ EOF
cat <<EOF cat <<EOF
<section class="grid"> <section class="grid">
<div class="panel span4"> <div class="panel span6 device-card">
<h2>Устройство</h2> <h2>Устройство</h2>
<div class="status"> <div class="status">
<span class="pill">Имя: $(h "$(system_value host)")</span> <span class="pill">Имя: $(h "$(system_value host)")</span>
<span class="pill">Версия: $(h "$(system_value release)")</span> <span class="pill">Версия: $(h "$(system_value release)")</span>
<span class="pill">Плата: $(h "$(system_value board)")</span> <span class="pill">Плата: $(h "$(system_value board)")</span>
</div> </div>
<pre>$(df -h 2>/dev/null | html_escape)</pre> <pre class="device-disk">$(df -h 2>/dev/null | html_escape)</pre>
</div> </div>
<form class="panel span8" method="post" action="$(self_url)"> <form class="panel span6 create-card" method="post" action="$(self_url)">
<h2>Создать бэкап</h2> <h2>Создать бэкап</h2>
<input type="hidden" name="key" value="$key"> <input type="hidden" name="key" value="$key">
<input type="hidden" name="action" value="create"> <input type="hidden" name="action" value="create">