Logs page size fits the window — measured from a real row, re-measured as the geometry moves, sized so the page never needs a scrollbar; admin bar top-anchors at a fixed line
Browse files at this commit02a64a4f8e445f5e5bed6f5f8a5e8ae5eaec82d6Parent: 22061eb3 changed files +91 -11
- crates/im-web/assets/main.css +1 -1
- crates/im-web/src/admin.rs +84 -5
- style/main.scss +6 -5
crates/im-web/assets/main.cssmodified+1 -1
| @@ -803,7 +803,7 @@ body:has(.admin-shell) { | |||
| 803 | .admin-shell { | 803 | .admin-shell { |
| 804 | display: flex; | 804 | display: flex; |
| 805 | justify-content: center; | 805 | justify-content: center; |
| 806 | - padding: max(24px, (100dvh - 640px) / 2) 24px 48px; | 806 | + padding: 24px 24px 48px; |
| 807 | } | 807 | } |
| 808 | 808 | ||
| 809 | .admin-column { | 809 | .admin-column { |
crates/im-web/src/admin.rsmodified+84 -5
| @@ -9,6 +9,7 @@ use im_core::settings::{self, Smtp}; | |||
| 9 | use serde::Deserialize; | 9 | use serde::Deserialize; |
| 10 | use topcoat::Result; | 10 | use topcoat::Result; |
| 11 | use topcoat::context::Cx; | 11 | use topcoat::context::Cx; |
| 12 | +use topcoat::cookie::Cookies; | ||
| 12 | use topcoat::router::content::Form; | 13 | use topcoat::router::content::Form; |
| 13 | use topcoat::router::response::{IntoResponse, Response}; | 14 | use topcoat::router::response::{IntoResponse, Response}; |
| 14 | use topcoat::router::{HeaderValue, StatusCode, header, route}; | 15 | use topcoat::router::{HeaderValue, StatusCode, header, route}; |
| @@ -600,6 +601,19 @@ async fn message_section(cx: &Cx, lang: i18n::Lang) -> Result<String, topcoat::E | |||
| 600 | /// bound; the page does not. | 601 | /// bound; the page does not. |
| 601 | const LOGS_LIMIT: i64 = 50; | 602 | const LOGS_LIMIT: i64 = 50; |
| 602 | 603 | ||
| 604 | +/// The page size fitted to the browser's own viewport: the log-fit script | ||
| 605 | +/// measures a real rendered row against the window and says how many rows | ||
| 606 | +/// fit, through the `im_rows_logs` cookie — read clamped, so a stale or | ||
| 607 | +/// tampered value cannot ask for an absurd window. `LOGS_LIMIT` when the | ||
| 608 | +/// cookie is absent or unparsable. Ported from izlek's `resolve_limit`. | ||
| 609 | +fn resolve_log_limit(cx: &Cx) -> i64 { | ||
| 610 | + topcoat::cookie::cookies(cx) | ||
| 611 | + .get("im_rows_logs") | ||
| 612 | + .and_then(|c| c.value().parse::<i64>().ok()) | ||
| 613 | + .map(|rows| rows.clamp(5, 200)) | ||
| 614 | + .unwrap_or(LOGS_LIMIT) | ||
| 615 | +} | ||
| 616 | + | ||
| 603 | /// The cursor on the wire: `rfc3339~id`, percent-encoded into `before`/`after`. | 617 | /// The cursor on the wire: `rfc3339~id`, percent-encoded into `before`/`after`. |
| 604 | fn cursor_q(cursor: &events::EventCursor) -> String { | 618 | fn cursor_q(cursor: &events::EventCursor) -> String { |
| 605 | crate::oidc::urlencode(&format!("{}~{}", events_cursor_stamp(cursor), cursor.id)) | 619 | crate::oidc::urlencode(&format!("{}~{}", events_cursor_stamp(cursor), cursor.id)) |
| @@ -675,14 +689,15 @@ async fn logs_section(cx: &Cx, lang: i18n::Lang) -> Result<String, topcoat::Erro | |||
| 675 | (None, Some(cursor)) => events::EventPage::After(cursor), | 689 | (None, Some(cursor)) => events::EventPage::After(cursor), |
| 676 | _ => events::EventPage::Newest, | 690 | _ => events::EventPage::Newest, |
| 677 | }; | 691 | }; |
| 678 | - let mut window = events::list_filtered(store, LOGS_LIMIT + 1, &page, dir, &filter).await?; | 692 | + let limit = resolve_log_limit(cx); |
| 693 | + let mut window = events::list_filtered(store, limit + 1, &page, dir, &filter).await?; | ||
| 679 | // Ran off the top walking back: answer with the freshest page instead. | 694 | // Ran off the top walking back: answer with the freshest page instead. |
| 680 | if matches!(page, events::EventPage::After(_)) && window.is_empty() { | 695 | if matches!(page, events::EventPage::After(_)) && window.is_empty() { |
| 681 | page = events::EventPage::Newest; | 696 | page = events::EventPage::Newest; |
| 682 | - window = events::list_filtered(store, LOGS_LIMIT + 1, &page, dir, &filter).await?; | 697 | + window = events::list_filtered(store, limit + 1, &page, dir, &filter).await?; |
| 683 | } | 698 | } |
| 684 | - let has_more = window.len() as i64 > LOGS_LIMIT; | 699 | + let has_more = window.len() as i64 > limit; |
| 685 | - window.truncate(LOGS_LIMIT as usize); | 700 | + window.truncate(limit as usize); |
| 686 | 701 | ||
| 687 | let total = events::count_filtered(store, &filter).await?; | 702 | let total = events::count_filtered(store, &filter).await?; |
| 688 | let preceding = events::count_preceding( | 703 | let preceding = events::count_preceding( |
| @@ -764,7 +779,7 @@ async fn logs_section(cx: &Cx, lang: i18n::Lang) -> Result<String, topcoat::Erro | |||
| 764 | format!(r#"<div class="muted">{}</div>"#, t(lang, Key::LogsEmpty)) | 779 | format!(r#"<div class="muted">{}</div>"#, t(lang, Key::LogsEmpty)) |
| 765 | } else { | 780 | } else { |
| 766 | format!( | 781 | format!( |
| 767 | - r#"<table class="admin-table"> | 782 | + r#"<table class="admin-table log-list" data-rows="{limit}" data-section="logs"> |
| 768 | <thead><tr><th>{when}</th><th>{what}</th><th>{who}</th><th>{detail}</th></tr></thead> | 783 | <thead><tr><th>{when}</th><th>{what}</th><th>{who}</th><th>{detail}</th></tr></thead> |
| 769 | <tbody>{rows}</tbody> | 784 | <tbody>{rows}</tbody> |
| 770 | </table>"#, | 785 | </table>"#, |
| @@ -862,7 +877,71 @@ async fn logs_section(cx: &Cx, lang: i18n::Lang) -> Result<String, topcoat::Erro | |||
| 862 | t(lang, Key::OldestFirst), | 877 | t(lang, Key::OldestFirst), |
| 863 | ), | 878 | ), |
| 864 | )) | 879 | )) |
| 880 | + .map(|card| card + LOG_FIT_SCRIPT) | ||
| 865 | } | 881 | } |
| 882 | +/// Fits the log's page size to the browser's own viewport: measured against | ||
| 883 | +/// the first rendered row, never against a guess at the row height. A fit | ||
| 884 | +/// that would change the page size reloads once through a fresh | ||
| 885 | +/// `im_rows_logs` cookie; the `sessionStorage` guard, keyed to the exact fit | ||
| 886 | +/// computed, stops a borderline measurement from reloading forever. The | ||
| 887 | +/// measure runs again once fonts settle — a row measured under the fallback | ||
| 888 | +/// face is shorter than the row the webfont draws, and the first fit would | ||
| 889 | +/// otherwise overflow by exactly that difference. A container too short to | ||
| 890 | +/// measure (no rows yet) is left alone rather than guessed at. Ported from | ||
| 891 | +/// izlek's `log_fit_script`. | ||
| 892 | +const LOG_FIT_SCRIPT: &str = r#"<script>(function () { | ||
| 893 | + var waits = 0; | ||
| 894 | + function measure() { | ||
| 895 | + // Never measure while the document's fonts are still arriving — every | ||
| 896 | + // fresh document repaints the rows in the fallback face first, and a | ||
| 897 | + // fit confirmed under it is wrong by half. Defer until the set is done; | ||
| 898 | + // after forty waits the CDN is presumed dead and the fallback face is | ||
| 899 | + // the truth the page will keep. | ||
| 900 | + if (document.fonts && document.fonts.status === 'loading' && waits < 40) { | ||
| 901 | + waits++; | ||
| 902 | + setTimeout(measure, 300); | ||
| 903 | + return; | ||
| 904 | + } | ||
| 905 | + var list = document.querySelector('.log-list[data-rows]'); | ||
| 906 | + if (!list) { return; } | ||
| 907 | + var current = parseInt(list.dataset.rows, 10); | ||
| 908 | + | ||
| 909 | + var row = list.querySelector('tbody tr'); | ||
| 910 | + if (!row || !row.offsetHeight) { return; } | ||
| 911 | + var avail = window.innerHeight - list.getBoundingClientRect().top - 100; | ||
| 912 | + var fit = Math.min(200, Math.max(5, Math.floor(avail / row.offsetHeight))); | ||
| 913 | + if (fit === current) { lastFit = -1; window.sessionStorage.removeItem('imLogFitHops'); return; } | ||
| 914 | + // A fit is committed only when two measures in a row — geometry events | ||
| 915 | + // are at least the debounce apart — agree on it. The font swap flips | ||
| 916 | + // row heights once, so the transient value never confirms; the settled | ||
| 917 | + // one always does. The hop budget — not a per-value veto — stops the | ||
| 918 | + // loop if the geometry never settles: a vetoed value would otherwise | ||
| 919 | + // stay wrong for the whole session. | ||
| 920 | + if (fit !== lastFit) { lastFit = fit; setTimeout(measure, 350); return; } | ||
| 921 | + var hops = parseInt(window.sessionStorage.getItem('imLogFitHops') || '0', 10); | ||
| 922 | + if (hops >= 5) { return; } | ||
| 923 | + window.sessionStorage.setItem('imLogFitHops', String(hops + 1)); | ||
| 924 | + document.cookie = 'im_rows_logs=' + fit + ';path=/'; | ||
| 925 | + location.replace(location.href); | ||
| 926 | + } | ||
| 927 | + var lastFit = -1; | ||
| 928 | + // No event is the right moment to measure: `load` can precede the | ||
| 929 | + // webfont, and a face that arrives late redraws every row taller. So the | ||
| 930 | + // measurement is driven by the geometry itself — a ResizeObserver on the | ||
| 931 | + // first row re-measures whenever its height changes (font swap, layout | ||
| 932 | + // settle), a window resize re-measures for the new viewport, and the | ||
| 933 | + // debounce folds the burst into one. A wrong early value is corrected by | ||
| 934 | + // the next firing; the reload guard caps the round trips. | ||
| 935 | + var timer = null; | ||
| 936 | + function schedule() { | ||
| 937 | + if (timer) { clearTimeout(timer); } | ||
| 938 | + timer = setTimeout(function () { timer = null; measure(); }, 200); | ||
| 939 | + } | ||
| 940 | + var row = document.querySelector('.log-list[data-rows] tbody tr'); | ||
| 941 | + if (row && window.ResizeObserver) { new ResizeObserver(schedule).observe(row); } | ||
| 942 | + window.addEventListener('resize', schedule); | ||
| 943 | + schedule(); | ||
| 944 | +})();</script>"#; | ||
| 866 | 945 | ||
| 867 | // --------------------------------------------------------------------------- | 946 | // --------------------------------------------------------------------------- |
| 868 | // Handlers | 947 | // Handlers |
style/main.scssmodified+6 -5
| @@ -808,10 +808,11 @@ textarea.auth-input { | |||
| 808 | } | 808 | } |
| 809 | 809 | ||
| 810 | // --- Admin panel ------------------------------------------------------------ | 810 | // --- Admin panel ------------------------------------------------------------ |
| 811 | -// Same skin, same posture as the landing: the bar holds the landing's line | 811 | +// Same skin, tool posture: the bar top-anchors at a fixed line so it never |
| 812 | -// (the tallest-section centre line) so the mouse never moves between the two | 812 | +// moves between sections, and the scrollbar's gutter is reserved so a |
| 813 | -// panels, and the scrollbar's gutter is reserved so a section that grows a | 813 | +// section that grows a scrollbar does not push the bar sideways. The |
| 814 | -// scrollbar does not push the bar sideways. | 814 | +// landing's centred line is not copied here — the logs fit their page size |
| 815 | +// to the window, and a viewport-scaled offset would eat the room that buys. | ||
| 815 | 816 | ||
| 816 | body:has(.admin-shell) { | 817 | body:has(.admin-shell) { |
| 817 | min-height: 100vh; | 818 | min-height: 100vh; |
| @@ -822,7 +823,7 @@ body:has(.admin-shell) { | |||
| 822 | .admin-shell { | 823 | .admin-shell { |
| 823 | display: flex; | 824 | display: flex; |
| 824 | justify-content: center; | 825 | justify-content: center; |
| 825 | - padding: max(24px, calc((100dvh - 640px) / 2)) 24px 48px; | 826 | + padding: 24px 24px 48px; |
| 826 | } | 827 | } |
| 827 | 828 | ||
| 828 | .admin-column { | 829 | .admin-column { |