From 02a64a4f8e445f5e5bed6f5f8a5e8ae5eaec82d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Sat, 5 Sep 2026 14:03:54 +0300 Subject: [PATCH] =?UTF-8?q?Logs=20page=20size=20fits=20the=20window=20?= =?UTF-8?q?=E2=80=94=20measured=20from=20a=20real=20row,=20re-measured=20a?= =?UTF-8?q?s=20the=20geometry=20moves,=20sized=20so=20the=20page=20never?= =?UTF-8?q?=20needs=20a=20scrollbar;=20admin=20bar=20top-anchors=20at=20a?= =?UTF-8?q?=20fixed=20line?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/im-web/assets/main.css | 2 +- crates/im-web/src/admin.rs | 89 +++++++++++++++++++++++++++++++++-- style/main.scss | 11 +++-- 3 files changed, 91 insertions(+), 11 deletions(-) diff --git a/crates/im-web/assets/main.css b/crates/im-web/assets/main.css index 8db3396..5ff3e78 100644 --- a/crates/im-web/assets/main.css +++ b/crates/im-web/assets/main.css @@ -803,7 +803,7 @@ body:has(.admin-shell) { .admin-shell { display: flex; justify-content: center; - padding: max(24px, (100dvh - 640px) / 2) 24px 48px; + padding: 24px 24px 48px; } .admin-column { diff --git a/crates/im-web/src/admin.rs b/crates/im-web/src/admin.rs index 37a0d32..97af0e1 100644 --- a/crates/im-web/src/admin.rs +++ b/crates/im-web/src/admin.rs @@ -9,6 +9,7 @@ use im_core::settings::{self, Smtp}; use serde::Deserialize; use topcoat::Result; use topcoat::context::Cx; +use topcoat::cookie::Cookies; use topcoat::router::content::Form; use topcoat::router::response::{IntoResponse, Response}; use topcoat::router::{HeaderValue, StatusCode, header, route}; @@ -600,6 +601,19 @@ async fn message_section(cx: &Cx, lang: i18n::Lang) -> Result i64 { + topcoat::cookie::cookies(cx) + .get("im_rows_logs") + .and_then(|c| c.value().parse::().ok()) + .map(|rows| rows.clamp(5, 200)) + .unwrap_or(LOGS_LIMIT) +} + /// The cursor on the wire: `rfc3339~id`, percent-encoded into `before`/`after`. fn cursor_q(cursor: &events::EventCursor) -> String { crate::oidc::urlencode(&format!("{}~{}", events_cursor_stamp(cursor), cursor.id)) @@ -675,14 +689,15 @@ async fn logs_section(cx: &Cx, lang: i18n::Lang) -> Result events::EventPage::After(cursor), _ => events::EventPage::Newest, }; - let mut window = events::list_filtered(store, LOGS_LIMIT + 1, &page, dir, &filter).await?; + let limit = resolve_log_limit(cx); + let mut window = events::list_filtered(store, limit + 1, &page, dir, &filter).await?; // Ran off the top walking back: answer with the freshest page instead. if matches!(page, events::EventPage::After(_)) && window.is_empty() { page = events::EventPage::Newest; - window = events::list_filtered(store, LOGS_LIMIT + 1, &page, dir, &filter).await?; + window = events::list_filtered(store, limit + 1, &page, dir, &filter).await?; } - let has_more = window.len() as i64 > LOGS_LIMIT; - window.truncate(LOGS_LIMIT as usize); + let has_more = window.len() as i64 > limit; + window.truncate(limit as usize); let total = events::count_filtered(store, &filter).await?; let preceding = events::count_preceding( @@ -764,7 +779,7 @@ async fn logs_section(cx: &Cx, lang: i18n::Lang) -> Result{}"#, t(lang, Key::LogsEmpty)) } else { format!( - r#" + r#"
{rows}
{when}{what}{who}{detail}
"#, @@ -862,7 +877,71 @@ async fn logs_section(cx: &Cx, lang: i18n::Lang) -> Result(function () { + var waits = 0; + function measure() { + // Never measure while the document's fonts are still arriving — every + // fresh document repaints the rows in the fallback face first, and a + // fit confirmed under it is wrong by half. Defer until the set is done; + // after forty waits the CDN is presumed dead and the fallback face is + // the truth the page will keep. + if (document.fonts && document.fonts.status === 'loading' && waits < 40) { + waits++; + setTimeout(measure, 300); + return; + } + var list = document.querySelector('.log-list[data-rows]'); + if (!list) { return; } + var current = parseInt(list.dataset.rows, 10); + + var row = list.querySelector('tbody tr'); + if (!row || !row.offsetHeight) { return; } + var avail = window.innerHeight - list.getBoundingClientRect().top - 100; + var fit = Math.min(200, Math.max(5, Math.floor(avail / row.offsetHeight))); + if (fit === current) { lastFit = -1; window.sessionStorage.removeItem('imLogFitHops'); return; } + // A fit is committed only when two measures in a row — geometry events + // are at least the debounce apart — agree on it. The font swap flips + // row heights once, so the transient value never confirms; the settled + // one always does. The hop budget — not a per-value veto — stops the + // loop if the geometry never settles: a vetoed value would otherwise + // stay wrong for the whole session. + if (fit !== lastFit) { lastFit = fit; setTimeout(measure, 350); return; } + var hops = parseInt(window.sessionStorage.getItem('imLogFitHops') || '0', 10); + if (hops >= 5) { return; } + window.sessionStorage.setItem('imLogFitHops', String(hops + 1)); + document.cookie = 'im_rows_logs=' + fit + ';path=/'; + location.replace(location.href); + } + var lastFit = -1; + // No event is the right moment to measure: `load` can precede the + // webfont, and a face that arrives late redraws every row taller. So the + // measurement is driven by the geometry itself — a ResizeObserver on the + // first row re-measures whenever its height changes (font swap, layout + // settle), a window resize re-measures for the new viewport, and the + // debounce folds the burst into one. A wrong early value is corrected by + // the next firing; the reload guard caps the round trips. + var timer = null; + function schedule() { + if (timer) { clearTimeout(timer); } + timer = setTimeout(function () { timer = null; measure(); }, 200); + } + var row = document.querySelector('.log-list[data-rows] tbody tr'); + if (row && window.ResizeObserver) { new ResizeObserver(schedule).observe(row); } + window.addEventListener('resize', schedule); + schedule(); +})();"#; // --------------------------------------------------------------------------- // Handlers diff --git a/style/main.scss b/style/main.scss index 53df8d6..9c8dd86 100644 --- a/style/main.scss +++ b/style/main.scss @@ -808,10 +808,11 @@ textarea.auth-input { } // --- Admin panel ------------------------------------------------------------ -// Same skin, same posture as the landing: the bar holds the landing's line -// (the tallest-section centre line) so the mouse never moves between the two -// panels, and the scrollbar's gutter is reserved so a section that grows a -// scrollbar does not push the bar sideways. +// Same skin, tool posture: the bar top-anchors at a fixed line so it never +// moves between sections, and the scrollbar's gutter is reserved so a +// section that grows a scrollbar does not push the bar sideways. The +// landing's centred line is not copied here — the logs fit their page size +// to the window, and a viewport-scaled offset would eat the room that buys. body:has(.admin-shell) { min-height: 100vh; @@ -822,7 +823,7 @@ body:has(.admin-shell) { .admin-shell { display: flex; justify-content: center; - padding: max(24px, calc((100dvh - 640px) / 2)) 24px 48px; + padding: 24px 24px 48px; } .admin-column {