From 1d5ec7d8c80fbcc8ca25bdfeb606a4521e8c66a8 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 09:32:09 +0300 Subject: [PATCH] Logs filter by kind, actor, day range and direction behind dropdowns, and page by cursor with a position note; composing mail moves to its own tab; the admin bar holds the landing's line --- crates/im-core/src/events.rs | 262 +++++++++++++++++++++++++- crates/im-web/assets/main.css | 29 ++- crates/im-web/src/admin.rs | 338 +++++++++++++++++++++++++++++----- crates/im-web/src/i18n.rs | 81 ++++++++ crates/im-web/src/layout.rs | 8 + style/main.scss | 40 +++- 6 files changed, 696 insertions(+), 62 deletions(-) diff --git a/crates/im-core/src/events.rs b/crates/im-core/src/events.rs index f65b9fe..9eb494e 100644 --- a/crates/im-core/src/events.rs +++ b/crates/im-core/src/events.rs @@ -35,14 +35,106 @@ pub async fn log(store: &Store, kind: &str, actor: Option<&str>, detail: Option< } } -/// Newest-first page of the log for the admin panel. -pub async fn list(store: &Store, limit: i64) -> Result> { +/// Log read filters, izlek's `ActivityFilter` shape: every present field +/// narrows (AND), an absent one matches all. +#[derive(Debug, Default, Clone)] +pub struct EventFilter { + pub kind: Option, + pub actor: Option, + /// Half-open day range `[from, to)`; both ends UTC stamps. + pub day: Option<(time::OffsetDateTime, time::OffsetDateTime)>, +} + +/// A place in the log: the ordered pair, never a row count — rows arrive +/// while the admin reads, and an offset lies the moment one lands. +#[derive(Debug, Clone)] +pub struct EventCursor { + pub at: time::OffsetDateTime, + pub id: String, +} + +/// The window asked for: the freshest rows, the rows older than a cursor, +/// or the rows newer than one (walking back toward the top). +#[derive(Debug)] +pub enum EventPage { + Newest, + Before(EventCursor), + After(EventCursor), +} + +/// Read direction: newest-first is the default; Oldest flips both the +/// ordering and which side of a cursor Before/After mean. +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum Dir { + Newest, + Oldest, +} + +fn filter_sql(filter: &EventFilter, params: &mut Vec) -> String { + let mut sql = String::new(); + if let Some(kind) = &filter.kind { + sql += " AND kind = ?"; + params.push(kind.clone().into()); + } + if let Some(actor) = &filter.actor { + sql += " AND actor = ?"; + params.push(actor.clone().into()); + } + if let Some((from, to)) = &filter.day { + sql += " AND at >= ? AND at < ?"; + params.push(store::stamp(*from).expect("rfc3339 of range start").into()); + params.push(store::stamp(*to).expect("rfc3339 of range end").into()); + } + sql +} + +/// One window of the log under the filters. The caller asks for one row more +/// than the page shows: the extra row is the "there is more" signal, trimmed +/// before render. `After` reads the newer side in mirrored order and flips it +/// back in memory, so the page always presents in `dir` order. +pub async fn list_filtered( + store: &Store, + limit: i64, + page: &EventPage, + dir: Dir, + filter: &EventFilter, +) -> Result> { + let oldest = dir == Dir::Oldest; + let base = if oldest { "ASC" } else { "DESC" }; + let mut params: Vec = Vec::new(); + let mut sql = "SELECT id, at, kind, actor, detail FROM events WHERE 1=1".to_string(); + sql += &filter_sql(filter, &mut params); + let mut reversed = false; + match page { + EventPage::Newest => {} + EventPage::Before(cursor) => { + let cmp = if oldest { ">" } else { "<" }; + sql += &format!(" AND (at {cmp} ? OR (at = ? AND id {cmp} ?))"); + let at = store::stamp(cursor.at)?; + params.push(at.clone().into()); + params.push(at.into()); + params.push(cursor.id.clone().into()); + } + EventPage::After(cursor) => { + let cmp = if oldest { "<" } else { ">" }; + sql += &format!(" AND (at {cmp} ? OR (at = ? AND id {cmp} ?))"); + let at = store::stamp(cursor.at)?; + params.push(at.clone().into()); + params.push(at.into()); + params.push(cursor.id.clone().into()); + reversed = true; + } + } + let order = if reversed { + if oldest { "DESC" } else { "ASC" } + } else { + base + }; + sql += &format!(" ORDER BY at {order}, id {order} LIMIT ?"); + params.push(limit.into()); let conn = store.conn.lock().await; let mut rows = conn - .query( - "SELECT id, at, kind, actor, detail FROM events ORDER BY at DESC, id DESC LIMIT ?1", - turso::params![limit], - ) + .query(&sql, turso::params_from_iter(params)) .await .map_err(backend)?; let mut events = Vec::new(); @@ -55,9 +147,91 @@ pub async fn list(store: &Store, limit: i64) -> Result> { detail: store::opt_text(&row, 4)?, }); } + if reversed { + events.reverse(); + } Ok(events) } +/// How many rows the filters admit at all. +pub async fn count_filtered(store: &Store, filter: &EventFilter) -> Result { + let mut params: Vec = Vec::new(); + let mut sql = "SELECT COUNT(*) FROM events WHERE 1=1".to_string(); + sql += &filter_sql(filter, &mut params); + let conn = store.conn.lock().await; + let mut rows = conn + .query(&sql, turso::params_from_iter(params)) + .await + .map_err(backend)?; + let count = match rows.next().await.map_err(backend)? { + Some(row) => store::int(&row, 0)? as u64, + None => 0, + }; + Ok(count) +} + +/// How many matching rows sit on the newer side of the page's top row — the +/// "X–Y" half of the position note. No cursor means the page starts at the +/// very top: nothing precedes it. +pub async fn count_preceding( + store: &Store, + filter: &EventFilter, + dir: Dir, + cursor: Option<&EventCursor>, +) -> Result { + let Some(cursor) = cursor else { return Ok(0) }; + let cmp = if dir == Dir::Oldest { "<" } else { ">" }; + let mut params: Vec = Vec::new(); + let mut sql = "SELECT COUNT(*) FROM events WHERE 1=1".to_string(); + sql += &filter_sql(filter, &mut params); + sql += &format!(" AND (at {cmp} ? OR (at = ? AND id {cmp} ?))"); + let at = store::stamp(cursor.at)?; + params.push(at.clone().into()); + params.push(at.into()); + params.push(cursor.id.clone().into()); + let conn = store.conn.lock().await; + let mut rows = conn + .query(&sql, turso::params_from_iter(params)) + .await + .map_err(backend)?; + let count = match rows.next().await.map_err(backend)? { + Some(row) => store::int(&row, 0)? as u64, + None => 0, + }; + Ok(count) +} + +/// The kind and actor dropdowns list what the log actually contains — im's +/// kinds are free strings, so the vocabulary is read, not hardcoded. +pub async fn distinct_kinds(store: &Store) -> Result> { + let conn = store.conn.lock().await; + let mut rows = conn + .query("SELECT DISTINCT kind FROM events ORDER BY kind", ()) + .await + .map_err(backend)?; + let mut kinds = Vec::new(); + while let Some(row) = rows.next().await.map_err(backend)? { + kinds.push(store::text(&row, 0)?); + } + Ok(kinds) +} + +pub async fn distinct_actors(store: &Store) -> Result> { + let conn = store.conn.lock().await; + let mut rows = conn + .query( + "SELECT DISTINCT actor FROM events WHERE actor IS NOT NULL ORDER BY actor", + (), + ) + .await + .map_err(backend)?; + let mut actors = Vec::new(); + while let Some(row) = rows.next().await.map_err(backend)? { + actors.push(store::text(&row, 0)?); + } + Ok(actors) +} + #[cfg(test)] mod tests { use super::*; @@ -74,9 +248,83 @@ mod tests { Some("wrong password"), ) .await; - let events = list(&store, 10).await.unwrap(); + let events = list_filtered( + &store, + 10, + &EventPage::Newest, + Dir::Newest, + &EventFilter::default(), + ) + .await + .unwrap(); assert_eq!(events.len(), 2); assert_eq!(events[0].kind, "login_fail"); assert_eq!(events[1].actor.as_deref(), Some("ann@example.com")); } + + #[tokio::test] + async fn filtered_paging_walks_the_log() { + let store = Store::open(Path::new(":memory:")).await.unwrap(); + for i in 0..7 { + let kind = if i % 2 == 0 { "login_ok" } else { "logout" }; + log(&store, kind, Some("ann@example.com"), None).await; + } + let filter = EventFilter::default(); + // First page of three: newest rows, plus the has-more signal row. + let first = list_filtered(&store, 4, &EventPage::Newest, Dir::Newest, &filter) + .await + .unwrap(); + assert_eq!(first.len(), 4); + let cursor = EventCursor { + at: first[2].at, + id: first[2].id.clone(), + }; + let second = list_filtered( + &store, + 4, + &EventPage::Before(cursor.clone()), + Dir::Newest, + &filter, + ) + .await + .unwrap(); + assert_eq!(second.len(), 4); + assert!(second.iter().all(|e| e.at <= cursor.at)); + assert!(!second.iter().any(|e| e.id == cursor.id)); + // Walking back up returns the same top rows. + let up = list_filtered(&store, 4, &EventPage::After(cursor), Dir::Newest, &filter) + .await + .unwrap(); + assert_eq!(up.len(), 2); + assert_eq!(up.first().unwrap().id, first.first().unwrap().id); + // Filters narrow, counts agree, and the position note's input exists. + let only_logins = EventFilter { + kind: Some("login_ok".into()), + ..Default::default() + }; + assert_eq!(count_filtered(&store, &only_logins).await.unwrap(), 4); + assert_eq!(count_filtered(&store, &filter).await.unwrap(), 7); + assert_eq!( + count_preceding( + &store, + &filter, + Dir::Newest, + Some(&EventCursor { + at: first[1].at, + id: first[1].id.clone(), + }) + ) + .await + .unwrap(), + 1 + ); + assert_eq!( + distinct_kinds(&store).await.unwrap(), + vec!["login_ok", "logout"] + ); + assert_eq!( + distinct_actors(&store).await.unwrap(), + vec!["ann@example.com"] + ); + } } diff --git a/crates/im-web/assets/main.css b/crates/im-web/assets/main.css index 0e5278f..e6d3b22 100644 --- a/crates/im-web/assets/main.css +++ b/crates/im-web/assets/main.css @@ -796,12 +796,13 @@ textarea.auth-input { body:has(.admin-shell) { min-height: 100vh; min-height: 100dvh; + scrollbar-gutter: stable; } .admin-shell { display: flex; justify-content: center; - padding: 24px 24px 48px; + padding: max(24px, (100dvh - 640px) / 2) 24px 48px; } .admin-column { @@ -868,6 +869,32 @@ a.wordmark-home { overflow-x: auto; } +.logs-filters { + display: flex; + flex-wrap: wrap; + gap: 10px 14px; +} +.logs-filters .auth-field { + flex: 1 1 120px; + min-width: 0; +} + +.logs-foot { + display: flex; + align-items: center; + justify-content: space-between; + gap: 12px; +} +.logs-foot .log-count { + font-family: var(--font-mono); + font-size: 11px; + color: var(--muted-soft); +} +.logs-foot .logs-links { + display: flex; + gap: 16px; +} + .admin-table { width: 100%; border-collapse: collapse; diff --git a/crates/im-web/src/admin.rs b/crates/im-web/src/admin.rs index 3ffce1e..240b161 100644 --- a/crates/im-web/src/admin.rs +++ b/crates/im-web/src/admin.rs @@ -114,6 +114,7 @@ async fn admin_page(cx: &Cx) -> Result { [ ("users", t(lang, Key::NavUsers)), ("mail", t(lang, Key::NavMail)), + ("message", t(lang, Key::NavMessage)), ("settings", t(lang, Key::NavSettings)), ("logs", t(lang, Key::NavLogs)), ] @@ -129,6 +130,7 @@ async fn admin_page(cx: &Cx) -> Result { let section_html = match section.as_str() { "mail" => mail_section(cx, lang).await?, + "message" => message_section(cx, lang).await?, "settings" => settings_section(cx, lang).await?, "logs" => logs_section(cx, lang).await?, "users" => users_section(cx, &me, invited.as_deref(), lang).await?, @@ -511,38 +513,6 @@ async fn mail_section(cx: &Cx, lang: i18n::Lang) -> Result{lede}"#) }; - let users = accounts::list_users(store).await?; - let mut options = format!( - r#""#, - t(lang, Key::EveryoneOption) - ); - for person in &users { - options.push_str(&format!( - r#""#, - escape(person.id.as_str()), - escape(&person.name), - escape(&person.email), - )); - } - let message_card = format!( - r#"
-
{msg_title}
-
- - - - -
-
"#, - msg_title = t(lang, Key::MessageTitle), - to_label = t(lang, Key::MessageToLabel), - subject_label = t(lang, Key::MessageSubjectLabel), - body_label = t(lang, Key::MessageBodyLabel), - send = t(lang, Key::SendMessageButton), - ); Ok(format!( r#"
{title}
{chip_text}
@@ -585,36 +555,302 @@ async fn mail_section(cx: &Cx, lang: i18n::Lang) -> Result Result { + let store = &app(cx).store; + let users = accounts::list_users(store).await?; + let mut options = format!( + r#""#, + t(lang, Key::EveryoneOption) + ); + for person in &users { + options.push_str(&format!( + r#""#, + escape(person.id.as_str()), + escape(&person.name), + escape(&person.email), + )); + } + Ok(format!( + r#"
+
{msg_title}
+
+ + + + +
+
"#, + msg_title = t(lang, Key::MessageTitle), + to_label = t(lang, Key::MessageToLabel), + subject_label = t(lang, Key::MessageSubjectLabel), + body_label = t(lang, Key::MessageBodyLabel), + send = t(lang, Key::SendMessageButton), + )) +} + +/// One page of the log: fifty rows, izlek's default. The log grows without +/// bound; the page does not. +const LOGS_LIMIT: i64 = 50; + +/// 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)) +} + +fn events_cursor_stamp(cursor: &events::EventCursor) -> String { + cursor + .at + .format(&time::macros::format_description!( + "[year]-[month]-[day]T[hour]:[minute]:[second]Z" + )) + .unwrap_or_default() +} + +fn parse_cursor(raw: Option) -> Option { + let raw = raw?; + let (at, id) = raw.split_once('~')?; + let at = + time::OffsetDateTime::parse(at, &time::format_description::well_known::Rfc3339).ok()?; + if id.is_empty() { + return None; + } + Some(events::EventCursor { + at, + id: id.to_string(), + }) +} + +/// YYYY-MM-DD at the UTC midnight that opens the day; `to` is handed the +/// midnight that closes it. Backwards ranges swap, garbage opens the end. +fn parse_day(raw: Option) -> Option { + let raw = raw?; + let date = time::Date::parse( + &raw, + &time::macros::format_description!("[year]-[month]-[day]"), + ) + .ok()?; + date.with_hms(0, 0, 0).ok().map(|dt| dt.assume_utc()) } async fn logs_section(cx: &Cx, lang: i18n::Lang) -> Result { - let entries = events::list(&app(cx).store, 200).await?; + let store = &app(cx).store; + let query = topcoat::router::request::uri(cx) + .query() + .unwrap_or("") + .to_string(); + let pick = |name: &str| query_value(&query, name).filter(|v| !v.is_empty()); + + let from = parse_day(pick("from")); + let to = parse_day(pick("to")).and_then(|d| d.checked_add(time::Duration::days(1))); + let day = match (from, to) { + (Some(a), Some(b)) if a > b => Some((b, a)), + (Some(a), Some(b)) => Some((a, b)), + (Some(a), None) => Some((a, time::Date::MAX.with_hms(0, 0, 0).unwrap().assume_utc())), + (None, Some(b)) => Some((time::OffsetDateTime::UNIX_EPOCH, b)), + (None, None) => None, + }; + let filter = events::EventFilter { + kind: pick("kind"), + actor: pick("actor"), + day, + }; + let dir = if pick("dir").as_deref() == Some("oldest") { + events::Dir::Oldest + } else { + events::Dir::Newest + }; + let mut page = match (parse_cursor(pick("before")), parse_cursor(pick("after"))) { + (Some(cursor), _) => events::EventPage::Before(cursor), + (None, Some(cursor)) => events::EventPage::After(cursor), + _ => events::EventPage::Newest, + }; + let mut window = events::list_filtered(store, LOGS_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?; + } + let has_more = window.len() as i64 > LOGS_LIMIT; + window.truncate(LOGS_LIMIT as usize); + + let total = events::count_filtered(store, &filter).await?; + let preceding = events::count_preceding( + store, + &filter, + dir, + window + .first() + .map(|e| events::EventCursor { + at: e.at, + id: e.id.clone(), + }) + .as_ref(), + ) + .await?; + + // A page turn re-appends every filter: turning never drops the narrowing. + let mut suffix = String::new(); + if let Some(kind) = &filter.kind { + suffix += &format!("&kind={}", crate::oidc::urlencode(kind)); + } + if let Some(actor) = &filter.actor { + suffix += &format!("&actor={}", crate::oidc::urlencode(actor)); + } + if let Some(raw) = pick("from") { + suffix += &format!("&from={}", crate::oidc::urlencode(&raw)); + } + if let Some(raw) = pick("to") { + suffix += &format!("&to={}", crate::oidc::urlencode(&raw)); + } + if dir == events::Dir::Oldest { + suffix += "&dir=oldest"; + } + + let kinds = events::distinct_kinds(store).await?; + let actors = events::distinct_actors(store).await?; + let mut kind_options = format!(r#""#, t(lang, Key::AllOption)); + for kind in &kinds { + kind_options.push_str(&format!( + r#""#, + escape(kind), + if filter.kind.as_deref() == Some(kind) { + " selected" + } else { + "" + }, + escape(&i18n::kind_word(lang, kind)), + )); + } + let mut actor_options = format!(r#""#, t(lang, Key::AllOption)); + for actor in &actors { + actor_options.push_str(&format!( + r#""#, + escape(actor), + if filter.actor.as_deref() == Some(actor) { + " selected" + } else { + "" + }, + escape(actor), + )); + } + let mut rows = String::new(); - for event in &entries { + for event in &window { rows.push_str(&format!( "{}{}{}{}", escape(&event.at.format(&time::macros::format_description!("[year]-[month]-[day] [hour]:[minute]:[second]")).unwrap_or_default()), - escape(&event.kind), + escape(&i18n::kind_word(lang, &event.kind)), escape(event.actor.as_deref().unwrap_or("")), escape(event.detail.as_deref().unwrap_or("")), )); } + + let body = if window.is_empty() { + format!(r#"
{}
"#, t(lang, Key::LogsEmpty)) + } else { + format!( + r#" + + {rows} +
{when}{what}{who}{detail}
"#, + when = t(lang, Key::WhenCol), + what = t(lang, Key::WhatCol), + who = t(lang, Key::WhoCol), + detail = t(lang, Key::DetailCol), + ) + }; + + // izlek's link visibility: the freshest page shows only Older, a middle + // page shows both, the last page hides Older. + let mut foot = String::new(); + if !window.is_empty() { + let newest = events::EventCursor { + at: window.first().unwrap().at, + id: window.first().unwrap().id.clone(), + }; + let oldest = events::EventCursor { + at: window.last().unwrap().at, + id: window.last().unwrap().id.clone(), + }; + let show_older = matches!(page, events::EventPage::After(_)) || has_more; + let show_newer = matches!(page, events::EventPage::Before(_)) + || (matches!(page, events::EventPage::After(_)) && has_more); + let mut links = String::new(); + if show_newer { + links += &format!( + r#"{}"#, + cursor_q(&newest), + t(lang, Key::NewerLink), + ); + } + if show_older { + links += &format!( + r#"{}"#, + cursor_q(&oldest), + t(lang, Key::OlderLink), + ); + } + foot = format!( + r#"
{}–{} / {}
"#, + preceding + 1, + preceding + window.len() as u64, + total, + ); + } + Ok(format!( r#"
{title}
{sub}
- - - {rows} -
{when}{what}{who}{detail}
+
+ + + + + + +
+ {body} + {foot}
"#, title = t(lang, Key::LogsTitle), sub = t(lang, Key::LogsSub), - when = t(lang, Key::WhenCol), - what = t(lang, Key::WhatCol), - who = t(lang, Key::WhoCol), - detail = t(lang, Key::DetailCol), + kind_label = t(lang, Key::KindLabel), + actor_label = t(lang, Key::ActorLabel), + from_label = t(lang, Key::FromLabel), + to_label = t(lang, Key::ToLabel), + dir_label = t(lang, Key::OrderLabel), + from_value = escape(&pick("from").unwrap_or_default()), + to_value = escape(&pick("to").unwrap_or_default()), + dir_options = format!( + r#""#, + if dir == events::Dir::Newest { + " selected" + } else { + "" + }, + t(lang, Key::NewestFirst), + if dir == events::Dir::Oldest { + " selected" + } else { + "" + }, + t(lang, Key::OldestFirst), + ), )) } @@ -892,15 +1128,15 @@ async fn message(cx: &Cx, Form(input): Form) -> Result { }; let store = &app(cx).store; if !settings::smtp(store).await?.configured() { - return back(cx, "mail", "&error=sender_unset"); + return back(cx, "message", "&error=sender_unset"); } let subject = input.subject.trim(); if subject.is_empty() { - return back(cx, "mail", "&error=empty_subject"); + return back(cx, "message", "&error=empty_subject"); } let body = input.body.trim(); if body.is_empty() { - return back(cx, "mail", "&error=empty_body"); + return back(cx, "message", "&error=empty_body"); } let users = accounts::list_users(store).await?; let recipients: Vec = if input.to == "everyone" { @@ -915,18 +1151,18 @@ async fn message(cx: &Cx, Form(input): Form) -> Result { .find(|person| person.id.as_str() == input.to) { Some(person) => vec![person.email], - None => return back(cx, "mail", "&error=no_such_user"), + None => return back(cx, "message", "&error=no_such_user"), } }; if recipients.is_empty() { - return back(cx, "mail", "&error=no_such_user"); + return back(cx, "message", "&error=no_such_user"); } for recipient in &recipients { if let Err(e) = mailer::send_message(store, recipient, subject, body.to_string()).await { server::log_event(cx, "message_failed", Some(&me.email), Some(&e.to_string())).await; return back( cx, - "mail", + "message", &format!( "&error=message&why={}", crate::oidc::urlencode(&e.to_string()) @@ -935,7 +1171,7 @@ async fn message(cx: &Cx, Form(input): Form) -> Result { } } server::log_event(cx, "message_sent", Some(&me.email), Some(subject)).await; - back(cx, "mail", "&ok=message") + back(cx, "message", "&ok=message") } /// Dials the mail server without sending, on an admin's say-so, and writes /// down what it said. The result shows on the Mail section as the standing diff --git a/crates/im-web/src/i18n.rs b/crates/im-web/src/i18n.rs index cadd0c4..1ac2918 100644 --- a/crates/im-web/src/i18n.rs +++ b/crates/im-web/src/i18n.rs @@ -144,6 +144,7 @@ pub enum Key { NavMail, NavSettings, NavLogs, + NavMessage, OkInvited, OkRevoked, OkDisabled, @@ -168,6 +169,19 @@ pub enum Key { ErrMessageFailed, ErrSenderUnset, + // Logs filtering and paging. + AllOption, + KindLabel, + ActorLabel, + FromLabel, + ToLabel, + NewestFirst, + OldestFirst, + NewerLink, + OlderLink, + LogsEmpty, + OrderLabel, + // Landing password pane. AccountPasswordNote, @@ -465,6 +479,8 @@ pub fn t(lang: Lang, key: Key) -> &'static str { (NavSettings, Tr) => "Ayarlar", (NavLogs, En) => "Logs", (NavLogs, Tr) => "Kayıtlar", + (NavMessage, En) => "Message", + (NavMessage, Tr) => "Mesaj", (OkInvited, En) => "Invite created.", (OkInvited, Tr) => "Davet oluşturuldu.", (OkRevoked, En) => "Sessions revoked — every device is signed out.", @@ -509,6 +525,29 @@ pub fn t(lang: Lang, key: Key) -> &'static str { (ErrSenderUnset, En) => "Set up the sender above first.", (ErrSenderUnset, Tr) => "Önce yukarıdan göndereni kur.", + (AllOption, En) => "All", + (AllOption, Tr) => "Tümü", + (KindLabel, En) => "Kind", + (KindLabel, Tr) => "Tür", + (ActorLabel, En) => "Actor", + (ActorLabel, Tr) => "Yapan", + (FromLabel, En) => "From", + (FromLabel, Tr) => "Başlangıç", + (ToLabel, En) => "To", + (ToLabel, Tr) => "Bitiş", + (NewestFirst, En) => "Newest first", + (NewestFirst, Tr) => "Önce en yeni", + (OldestFirst, En) => "Oldest first", + (OldestFirst, Tr) => "Önce en eski", + (NewerLink, En) => "← Newer", + (NewerLink, Tr) => "← Daha yeni", + (OlderLink, En) => "Older →", + (OlderLink, Tr) => "Daha eski →", + (LogsEmpty, En) => "Nothing matches.", + (OrderLabel, En) => "Order", + (OrderLabel, Tr) => "Sıra", + (LogsEmpty, Tr) => "Eşleşen kayıt yok.", + (AccountPasswordNote, En) => "Changing it signs every other device out — this one stays.", (AccountPasswordNote, Tr) => { "Değiştirince diğer tüm cihazların oturumu kapanır — bu cihaz açık kalır." @@ -702,6 +741,48 @@ pub fn sessions_summary(lang: Lang, n: usize) -> String { } } +/// A log row's kind as a word, izlek's `activity_kind_word`: the stored +/// string is the stable identifier, the words are presentation. A kind this +/// build does not know shows as itself. +pub fn kind_word(lang: Lang, kind: &str) -> String { + let pair = match kind { + "login_ok" => ("Sign-in", "Giriş"), + "login_fail" => ("Failed sign-in", "Başarısız giriş"), + "login_limited" => ("Rate-limited sign-in", "Sınırlanmış giriş"), + "totp_fail" => ("Failed 2FA code", "Başarısız 2FA kodu"), + "invite_accepted" => ("Invite accepted", "Davet kabul edildi"), + "invite_created" => ("Invite created", "Davet oluşturuldu"), + "invite_revoked" => ("Invite revoked", "Davet iptal edildi"), + "enrolled" => ("2FA set up", "2FA kuruldu"), + "logout" => ("Sign-out", "Çıkış"), + "reset_sent" => ("Reset mail sent", "Sıfırlama postası gönderildi"), + "password_reset" => ("Password reset", "Parola sıfırlandı"), + "password_changed" => ("Password changed", "Parola değiştirildi"), + "session_revoked" => ("Session revoked", "Oturum kapatıldı"), + "sessions_revoked" => ("Sessions revoked", "Oturumlar kapatıldı"), + "preferences_saved" => ("Preferences saved", "Tercihler kaydedildi"), + "photo_saved" => ("Photo updated", "Fotoğraf güncellendi"), + "photo_removed" => ("Photo removed", "Fotoğraf kaldırıldı"), + "code_exchanged" => ("App sign-in", "Uygulama girişi"), + "settings_updated" => ("Settings updated", "Ayarlar güncellendi"), + "user_deleted" => ("User deleted", "Kullanıcı silindi"), + "user_disabled" => ("User disabled", "Kullanıcı devre dışı"), + "user_enabled" => ("User enabled", "Kullanıcı etkin"), + "user_promoted" => ("Admin granted", "Yönetici yetkisi verildi"), + "smtp_updated" => ("Mail settings saved", "Posta ayarları kaydedildi"), + "smtp_test_sent" => ("Test mail sent", "Test postası gönderildi"), + "smtp_test_failed" => ("Test mail failed", "Test postası başarısız"), + "smtp_checked" => ("Mail server checked", "Posta sunucusu denetlendi"), + "message_sent" => ("Message sent", "Mesaj gönderildi"), + "message_failed" => ("Message failed", "Mesaj başarısız"), + _ => return kind.to_string(), + }; + match lang { + Lang::En => pair.0.to_string(), + Lang::Tr => pair.1.to_string(), + } +} + /// A pending invite's "waiting · until " cell, in the viewer's language. pub fn waiting_label(lang: Lang, date: &str) -> String { match lang { diff --git a/crates/im-web/src/layout.rs b/crates/im-web/src/layout.rs index 2c30295..75c1890 100644 --- a/crates/im-web/src/layout.rs +++ b/crates/im-web/src/layout.rs @@ -277,6 +277,14 @@ pub async fn soft_nav_script(cx: &Cx) -> Result { window.addEventListener('popstate', function () { go(location.pathname + location.search, false, false); }); + // Filter controls submit their form on pick; file inputs with + // data-autosubmit belong to the avatar script's uploader, not to this. + document.addEventListener('change', function (e) { + var c = e.target && e.target.closest ? e.target.closest('[data-autosubmit]') : null; + if (!c || !c.form || c.type === 'file') { return; } + c.form.requestSubmit(); + }); + window.__imRefresh = function () { var active = document.activeElement; if (active && /^(INPUT|SELECT|TEXTAREA)$/.test(active.tagName)) { return; } diff --git a/style/main.scss b/style/main.scss index c6fc5c0..e2cb6ed 100644 --- a/style/main.scss +++ b/style/main.scss @@ -808,18 +808,21 @@ textarea.auth-input { } // --- Admin panel ------------------------------------------------------------ -// Same skin, different posture: top-anchored and wider than the auth stage — -// a tool, not a gate. +// 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. body:has(.admin-shell) { min-height: 100vh; min-height: 100dvh; + scrollbar-gutter: stable; } .admin-shell { display: flex; justify-content: center; - padding: 24px 24px 48px; + padding: max(24px, calc((100dvh - 640px) / 2)) 24px 48px; } .admin-column { @@ -885,6 +888,37 @@ a.wordmark-home { overflow-x: auto; } +// The logs filter row: five small fields in one wrapping line; a page turn's +// foot splits the position note from the Newer/Older links. +.logs-filters { + display: flex; + flex-wrap: wrap; + gap: 10px 14px; + + .auth-field { + flex: 1 1 120px; + min-width: 0; + } +} + +.logs-foot { + display: flex; + align-items: center; + justify-content: space-between; + gap: 12px; + + .log-count { + font-family: var(--font-mono); + font-size: 11px; + color: var(--muted-soft); + } + + .logs-links { + display: flex; + gap: 16px; + } +} + .admin-table { width: 100%; border-collapse: collapse;