diff --git a/crates/forge-web/assets/nav.js b/crates/forge-web/assets/nav.js index 0b30f22..97ac615 100644 --- a/crates/forge-web/assets/nav.js +++ b/crates/forge-web/assets/nav.js @@ -8,7 +8,8 @@ window.__forgeSoft = true; var root = document.documentElement; - var latest = 0; // id of the newest request; older responses are dropped + root.classList.add('js'); // CSS hides JS-only controls (a Save that shows on change) under html.js + var latest = 0; // id of the newest request; older responses are dropped var userBusy = 0; // navigations and form posts on the wire (not live refreshes) var liveDirty = false; // a live change came while a navigation or a live fetch was on the wire var liveForced = false; // that change re-renders the page even with no stream of its own @@ -755,6 +756,29 @@ searchTimer = setTimeout(function () { searchTimer = null; liveSearch(input); }, 250); }); + // A form marked data-dirty-form shows its Save only once a field differs from its rendered value: + // the input sets data-dirty on the form, and the stepper buttons (data-step) move the number field + // inside their form, clamped to its min and max, then fire `input` like typing does. + document.addEventListener('input', function (e) { + var form = e.target && e.target.form ? e.target.form : null; + if (!form || !form.hasAttribute('data-dirty-form')) { return; } + if (e.target.defaultValue !== e.target.value) { form.setAttribute('data-dirty', ''); } + else { form.removeAttribute('data-dirty'); } + }); + document.addEventListener('click', function (e) { + var btn = e.target && e.target.closest ? e.target.closest('[data-step]') : null; + if (!btn || !btn.form) { return; } + var field = btn.form.querySelector('input[type="number"]'); + if (!field) { return; } + var next = (parseFloat(field.value) || 0) + (parseFloat(btn.getAttribute('data-step')) || 0); + var min = parseFloat(field.min); + var max = parseFloat(field.max); + if (!isNaN(min)) { next = Math.max(min, next); } + if (!isNaN(max)) { next = Math.min(max, next); } + field.value = String(next); + field.dispatchEvent(new Event('input', { bubbles: true })); + }); + // A checkbox marked data-select-all="" ticks or clears every checkbox inside the first // element that matches the selector (the bulk import list). document.addEventListener('change', function (e) { diff --git a/crates/forge-web/src/i18n/admin.rs b/crates/forge-web/src/i18n/admin.rs index 3169be6..476fb21 100644 --- a/crates/forge-web/src/i18n/admin.rs +++ b/crates/forge-web/src/i18n/admin.rs @@ -159,7 +159,6 @@ pub enum K { TableError, TableKind, TableLastError, - TableName, TableQueued, TableRepo, TableResult, @@ -552,8 +551,6 @@ pub fn t(lang: Lang, key: K) -> &'static str { (TableKind, Tr) => "Tür", (TableLastError, En) => "Last error", (TableLastError, Tr) => "Son hata", - (TableName, En) => "Name", - (TableName, Tr) => "Ad", (TableQueued, En) => "Queued", (TableQueued, Tr) => "Kuyruğa alındı", (TableRepo, En) => "Repo", @@ -948,7 +945,6 @@ mod tests { K::TableError, K::TableKind, K::TableLastError, - K::TableName, K::TableQueued, K::TableRepo, K::TableResult, diff --git a/crates/forge-web/src/pages/admin_runners.rs b/crates/forge-web/src/pages/admin_runners.rs index d1c55a1..f2528b0 100644 --- a/crates/forge-web/src/pages/admin_runners.rs +++ b/crates/forge-web/src/pages/admin_runners.rs @@ -9,6 +9,7 @@ use forge_ci::build::{self, Freshness}; use forge_core::AuditAction; use forge_core::ci::{CiRunner, FieldKind, RUNNER_FIELDS, RestartMode, runner_field}; +use forge_core::store::health::RUNNER_ONLINE_SECS; use serde::Deserialize; use time::OffsetDateTime; use time::format_description::well_known::Rfc3339; @@ -138,7 +139,12 @@ struct DisableForm { /// One runner row, already formatted. struct RunnerRow { name: String, - labels: Vec, + /// The labels as plain text, joined with " · ". + labels: String, + /// The status dot's class: online, offline or disabled. + dot_class: &'static str, + /// The dot's accessible name and tooltip. + state_text: &'static str, /// "5 minutes ago", or "never". last_seen: String, /// The absolute time in the viewer's zone, for the `title` tooltip. Empty when never seen. @@ -165,17 +171,42 @@ struct RunnerRow { build: String, /// Its commit sha alone, for the table and the stat strip; the full string is the tooltip. build_short: String, - /// "up to date", "outdated" or "unknown", with the `.ci-state` class that colours it. + /// "up to date", "outdated" or "unknown", with the `.ci-state` class the detail page colours it with. build_label: &'static str, build_class: &'static str, + /// "ok", "warn" or "muted": how the version status is coloured on the list. + build_tone: &'static str, + /// The concurrency the admin set or the runner reported, for the load meter's maximum. + /// Empty when the runner has not reported one. + concurrency_max: u32, } -/// How the runner's reported build compares with this server's, as a badge label and class. -fn build_badge(lang: Lang, runner: &CiRunner) -> (&'static str, &'static str) { +/// How the runner's reported build compares with this server's: the label, the `.ci-state` class +/// and the list tone. +fn build_badge(lang: Lang, runner: &CiRunner) -> (&'static str, &'static str, &'static str) { match build::compare(runner.reported.build.as_deref(), &build::display()) { - Freshness::UpToDate => (s(lang, "up to date", "güncel"), "ci-success"), - Freshness::Outdated => (s(lang, "outdated", "eski"), "ci-queued"), - Freshness::Unknown => (s(lang, "unknown", "bilinmiyor"), "runner-disabled"), + Freshness::UpToDate => (s(lang, "up to date", "güncel"), "ci-success", "ok"), + Freshness::Outdated => (s(lang, "outdated", "eski"), "ci-queued", "warn"), + Freshness::Unknown => (s(lang, "unknown", "bilinmiyor"), "runner-disabled", "muted"), + } +} + +/// The status dot and its word: a disabled runner is a warning, a runner that checked in within +/// the online window is green, and anything else is offline. +fn dot_of(lang: Lang, runner: &CiRunner, now: i64) -> (&'static str, &'static str) { + if runner.disabled { + return ("runner-dot is-disabled", g::t(lang, K::Disabled)); + } + let limit = i64::try_from(RUNNER_ONLINE_SECS).unwrap_or(i64::MAX); + let online = runner + .last_seen_at + .as_deref() + .and_then(|stamp| OffsetDateTime::parse(stamp, &Rfc3339).ok()) + .is_some_and(|at| at.unix_timestamp() >= now.saturating_sub(limit)); + if online { + ("runner-dot is-online", s(lang, "online", "çevrimiçi")) + } else { + ("runner-dot is-offline", s(lang, "offline", "çevrimdışı")) } } @@ -214,10 +245,14 @@ fn runner_row(runner: &CiRunner, tz: &str, lang: Lang, now: i64) -> RunnerRow { None => (i18n::t(lang, Key::Never).to_owned(), String::new()), }; let (concurrency, concurrency_source) = concurrency_of(runner); - let (build_label, build_class) = build_badge(lang, runner); + let (build_label, build_class, build_tone) = build_badge(lang, runner); + let (dot_class, state_text) = dot_of(lang, runner, now); + let concurrency_max = concurrency.parse().unwrap_or(0); RunnerRow { name: runner.name.clone(), - labels: runner.labels.clone(), + labels: runner.labels.join(" · "), + dot_class, + state_text, last_seen, last_seen_full, last_seen_at: runner.last_seen_at.clone().unwrap_or_default(), @@ -242,6 +277,8 @@ fn runner_row(runner: &CiRunner, tz: &str, lang: Lang, now: i64) -> RunnerRow { build: runner.reported.build.clone().unwrap_or_default(), build_label, build_class, + build_tone, + concurrency_max, } } @@ -298,74 +335,59 @@ async fn runners_view( if rows.is_empty() {

(g::t(lang, K::NoRunnersYet))

} else { -
- - - - - - - - - - - - - - for row in rows.iter() { - - - - - - - - - - } - -
(g::t(lang, K::TableName))(s(lang, "Concurrency", "Eşzamanlılık"))(s(lang, "Running", "Çalışan"))(s(lang, "Version", "Sürüm"))(g::t(lang, K::LastSeen))(g::t(lang, K::TableState))(s(lang, "Actions", "İşlemler"))
- (row.name.as_str()) - - for label in row.labels.iter() { - (label.as_str()) - } - - - concurrency_form(lang: lang, csrf: csrf.as_str(), action: row.config_action.as_str(), key: "concurrency", value: row.concurrency.as_str(), source: row.concurrency_source, has_override: row.has_override, back: "list") - (row.running.to_string()) - if !row.build_short.is_empty() { - (row.build_short.as_str()) - } - (row.build_label) - - if row.disabled { - (g::t(lang, K::Disabled)) - } else { - (g::t(lang, K::Enabled)) - } - if row.restart_pending.is_some() { - (s(lang, "restart pending", "yeniden başlatma bekliyor")) - } - -
- "⋯" - -
-
-
+ }
@@ -472,7 +494,9 @@ async fn restart_control( }) } -/// The inline number form for concurrency: input, Save, and a reset button while an override is set. +/// The load cell of a runner: the jobs running out of the concurrency, a meter of the two, and the +/// concurrency as a stepper. The − and + buttons step the input (nav.js); Save shows only once the +/// value has changed, and stays visible without JavaScript. A reset button shows while an override is set. #[component] async fn concurrency_form( lang: Lang, @@ -483,17 +507,29 @@ async fn concurrency_form( source: &'static str, has_override: bool, back: &'static str, + running: u32, + max: u32, ) -> Result { + let running = running.to_string(); + let meter_max = max.max(1).to_string(); Ok(view! { -
+ - - - if has_override { - - } + (s(lang, "Jobs", "İşler")) +
+ (running.as_str()) + "/" + + + + + if has_override { + + } +
+
}) } @@ -1640,7 +1676,7 @@ mod tests { // Only the hash is stored, so the list and the database hold no plain token. assert!(store.list_runners().await.expect("list").is_empty()); - // Labels are separate chips and the state is a badge that follows disabling. + // Labels are one plain line joined by " · ", and the dot follows disabling. store .register_runner( &token, @@ -1651,10 +1687,11 @@ mod tests { .expect("register"); let (status, page) = send(&router, "GET", "/admin/runners", Some(ADMIN_TOKEN), None).await; assert_eq!(status, 200); - assert!(page.contains(r#"linux"#)); - assert!(page.contains(r#"x86_64"#)); + assert!(page.contains(r#"linux · x86_64"#)); assert!(!page.contains("linux, x86_64"), "labels are not joined"); - assert!(page.contains(r#"enabled"#)); + // Never seen, so offline; not disabled, so no disabled word. + assert!(page.contains(r#"class="runner-dot is-offline""#)); + assert!(!page.contains(r#"disabled"#)); let runner = store.list_runners().await.expect("list").remove(0); store @@ -1662,7 +1699,8 @@ mod tests { .await .expect("disable"); let (_, page) = send(&router, "GET", "/admin/runners", Some(ADMIN_TOKEN), None).await; - assert!(page.contains(r#"disabled"#)); + assert!(page.contains(r#"class="runner-dot is-disabled""#)); + assert!(page.contains(r#"disabled"#)); } // Scenario: restart is capability-gated and audited, then the runner is disabled, enabled and deleted. diff --git a/style/main.scss b/style/main.scss index 3ebb7cc..00a06d6 100644 --- a/style/main.scss +++ b/style/main.scss @@ -5177,85 +5177,6 @@ $ansi-colours: ( } } -// Admin runners table: every column but the actions sizes to its content, and the name is capped and -// truncates with an ellipsis. The actions column takes the slack, so its menu sits at the right edge -// of the card and the other columns stay compact. The label chips sit under the name. All text is -// left aligned and th and td share one padding, so a header sits over its cell. The row actions live -// in a menu; its panel is absolutely positioned, so the wrapper must not clip it. State reuses `.ci-state`. -.table-wrap.runners-wrap { - overflow: visible; -} - -.table.runners { - // Every header and cell takes the same 16px gap on its right, so each header sits over its - // content with room to the next column; the last column has none. - th, - td { - padding: 10px 16px 10px 0; - vertical-align: middle; - } - - th:last-child, - td:last-child { - padding-right: 0; - } - - th.runner-name, - td.runner-name, - th.runner-conc, - td.runner-conc, - th.runner-running, - td.runner-running, - th.runner-build, - td.runner-build, - th.runner-seen, - td.runner-seen, - th.runner-state, - td.runner-state { - width: 1%; - white-space: nowrap; - } - - td.runner-running { - font-variant-numeric: tabular-nums; - } - - th.runner-actions, - td.runner-actions { - padding-right: 0; - text-align: right; - white-space: nowrap; - } - - // The name is capped at 28rem and truncates with an ellipsis; the full name is the link text. - td.runner-name { - > a { - display: block; - max-width: 28rem; - overflow: hidden; - text-overflow: ellipsis; - white-space: nowrap; - } - - .runner-label-list { - margin-top: 4px; - } - } - - // The commit hash and its status pill sit on one line with a small gap between them. - td.runner-build { - code { - margin-right: 8px; - } - } - - td.runner-build > *, - td.runner-conc > *, - td.runner-state > * { - vertical-align: middle; - } -} - // The row actions menu: a "..." button that opens a small panel of the actions. Each item is a plain // button or a `confirm-inline` summary; a confirm popover opens in the flow, so the panel grows to hold it. .row-menu { @@ -5392,117 +5313,258 @@ $ansi-colours: ( } } -// Phone: each runner is a card, every cell a label and value row, the menu at the card's end. -@media (max-width: 720px) { - .table.runners { - display: block; +// Admin runners: a vertical list, one card row per runner. Four columns: identity (dot, name, labels, +// last seen), load (the jobs meter and the concurrency stepper), version, and the actions menu. The +// load cell is the form that saves the concurrency. Its Save shows only once the value changes +// (nav.js sets data-dirty), and only where nav.js has run (html.js), so without JavaScript it stays. +.runner-list { + margin: 0 -20px; + padding: 0; + list-style: none; +} - thead { - display: none; - } +.runner-row { + display: grid; + grid-template-columns: minmax(180px, 1.4fr) 1fr 1fr auto; + align-items: center; + column-gap: 16px; + padding: 14px 20px; - tbody, - tr { - display: block; - } + &:hover { + background: var(--surface-2); + } - tr { - padding: 12px 0; - border-bottom: 1px solid var(--border); - } + > .row-menu { + justify-self: end; + } +} - th, - td, - td[class] { - display: block; - width: auto; - padding: 0; - border: 0; - } +.runner-row + .runner-row { + border-top: 1px solid var(--border); +} - tr { - position: relative; - } +.runner-id, +.runner-load, +.runner-version { + min-width: 0; +} - td.runner-name { - padding-bottom: 8px; - } +.runner-title { + display: flex; + align-items: center; + gap: 8px; + min-width: 0; +} - td[data-label] { - display: flex; - align-items: center; - justify-content: space-between; - gap: 12px; - min-height: 36px; +// The status dot: green online, muted offline, warning colour when disabled. +.runner-dot { + flex: none; + width: 8px; + height: 8px; + border-radius: 50%; + background: var(--muted); - &::before { - content: attr(data-label); - color: var(--muted); - font-size: 0.78125rem; - } - } + &.is-online { + background: var(--ok); + } - td.runner-name { - padding-right: 48px; - } + &.is-disabled { + background: var(--warn); + } +} - // The menu sits in the card's top right corner, beside the name. - td.runner-actions { - position: absolute; - top: 12px; - right: 0; - } +.runner-name { + min-width: 0; + overflow: hidden; + color: var(--text); + font-size: 0.9375rem; + font-weight: 600; + text-overflow: ellipsis; + white-space: nowrap; + + &:hover { + text-decoration: underline; } } -.runner-label-list { +.runner-off { + flex: none; + color: var(--warn); + font-size: 0.75rem; +} + +// The muted line under the name: labels, then when it was last seen. It lines up under the name. +.runner-meta { + margin: 4px 0 0 16px; + font-size: 0.75rem; + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; +} + +.runner-labels { + font-family: var(--mono); +} + +.runner-load { display: flex; - flex-wrap: wrap; + flex-direction: column; + align-items: flex-start; gap: 4px; + margin: 0; } -.runner-label { - display: inline-block; - padding: 0 8px; - border: 1px solid var(--border); - border-radius: var(--radius-full); - background: var(--code-bg); - font-family: var(--mono); +.runner-cap { font-size: 0.75rem; - line-height: 20px; - white-space: nowrap; } -// Runner concurrency form: a compact input, Save and, while an override is set, a small reset icon, -// all on one line. The value's source is the input's tooltip, so nothing else widens the cell. -form.runner-conc-form { +.runner-line { display: flex; - flex-wrap: nowrap; + flex-wrap: wrap; align-items: center; gap: 6px; - margin: 0; - // Room for a three digit value plus the spinner and the input's padding. input[type="number"] { - width: calc(3ch + 2.75rem); - min-width: 0; - text-align: left; + box-sizing: border-box; + flex: none; + width: 44px; + height: var(--control-h); + padding: 0; + text-align: center; + font-variant-numeric: tabular-nums; + -moz-appearance: textfield; + appearance: textfield; + + &::-webkit-inner-spin-button, + &::-webkit-outer-spin-button { + -webkit-appearance: none; + margin: 0; + } } - input, - select, - button { + .runner-count { + font-size: 0.9375rem; + font-variant-numeric: tabular-nums; + } + + .runner-step { + box-sizing: border-box; + flex: none; + width: 32px; + height: var(--control-h); + padding: 0; + font-size: 1rem; + line-height: 1; + } + + .runner-save { box-sizing: border-box; height: var(--control-h); - margin: 0; } button[name="reset"] { + box-sizing: border-box; min-width: var(--control-h); + height: var(--control-h); padding: 0; } } +html.js form.runner-load[data-dirty-form] .runner-save { + display: none; +} + +html.js form.runner-load[data-dirty-form][data-dirty] .runner-save { + display: inline-block; +} + +// The meter: running jobs out of the concurrency, 80 by 4 pixels, accent fill on a surface track. +progress.runner-meter { + -webkit-appearance: none; + appearance: none; + display: block; + box-sizing: border-box; + width: 80px; + height: 4px; + margin: 2px 0 0; + border: 0; + border-radius: 2px; + overflow: hidden; + background: var(--surface-2); + color: var(--accent); + + &::-webkit-progress-bar { + background: var(--surface-2); + } + + &::-webkit-progress-value { + background: var(--accent); + } + + &::-moz-progress-bar { + background: var(--accent); + } +} + +.runner-version { + display: flex; + flex-wrap: wrap; + align-items: center; + gap: 8px; + justify-self: start; +} + +.runner-hash { + padding: 0; + background: none; + font-family: var(--mono); + font-size: 0.8125rem; +} + +// Version status: muted text with a tick when up to date, the warning colour when outdated. +.runner-status { + color: var(--muted); + font-size: 0.8125rem; + white-space: nowrap; + + &.warn { + color: var(--warn); + } +} + +.runner-tick { + color: var(--ok); +} + +// Phone: each runner is two rows. Identity and the menu, then the load and the version. +@media (max-width: 700px) { + .runner-row { + grid-template-columns: minmax(0, 1fr) auto; + row-gap: 12px; + } + + .runner-id { + grid-column: 1; + grid-row: 1; + } + + .runner-row > .row-menu { + grid-column: 2; + grid-row: 1; + } + + .runner-load { + grid-column: 1; + grid-row: 2; + } + + .runner-version { + grid-column: 2; + grid-row: 2; + justify-self: end; + } +} + .runner-facts { display: grid; grid-template-columns: max-content 1fr;