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
Browse files at this commit1d5ec7d8c80fbcc8ca25bdfeb606a4521e8c66a8Parent: 9df12666 changed files +696 -62
- crates/im-core/src/events.rs +255 -7
- crates/im-web/assets/main.css +28 -1
- crates/im-web/src/admin.rs +287 -51
- crates/im-web/src/i18n.rs +81 -0
- crates/im-web/src/layout.rs +8 -0
- style/main.scss +37 -3
crates/im-core/src/events.rsmodified+255 -7
| @@ -35,14 +35,106 @@ pub async fn log(store: &Store, kind: &str, actor: Option<&str>, detail: Option< | |||
| 35 | } | 35 | } |
| 36 | } | 36 | } |
| 37 | 37 | ||
| 38 | -/// Newest-first page of the log for the admin panel. | 38 | +/// Log read filters, izlek's `ActivityFilter` shape: every present field |
| 39 | -pub async fn list(store: &Store, limit: i64) -> Result<Vec<Event>> { | 39 | +/// narrows (AND), an absent one matches all. |
| 40 | +#[derive(Debug, Default, Clone)] | ||
| 41 | +pub struct EventFilter { | ||
| 42 | + pub kind: Option<String>, | ||
| 43 | + pub actor: Option<String>, | ||
| 44 | + /// Half-open day range `[from, to)`; both ends UTC stamps. | ||
| 45 | + pub day: Option<(time::OffsetDateTime, time::OffsetDateTime)>, | ||
| 46 | +} | ||
| 47 | + | ||
| 48 | +/// A place in the log: the ordered pair, never a row count — rows arrive | ||
| 49 | +/// while the admin reads, and an offset lies the moment one lands. | ||
| 50 | +#[derive(Debug, Clone)] | ||
| 51 | +pub struct EventCursor { | ||
| 52 | + pub at: time::OffsetDateTime, | ||
| 53 | + pub id: String, | ||
| 54 | +} | ||
| 55 | + | ||
| 56 | +/// The window asked for: the freshest rows, the rows older than a cursor, | ||
| 57 | +/// or the rows newer than one (walking back toward the top). | ||
| 58 | +#[derive(Debug)] | ||
| 59 | +pub enum EventPage { | ||
| 60 | + Newest, | ||
| 61 | + Before(EventCursor), | ||
| 62 | + After(EventCursor), | ||
| 63 | +} | ||
| 64 | + | ||
| 65 | +/// Read direction: newest-first is the default; Oldest flips both the | ||
| 66 | +/// ordering and which side of a cursor Before/After mean. | ||
| 67 | +#[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
| 68 | +pub enum Dir { | ||
| 69 | + Newest, | ||
| 70 | + Oldest, | ||
| 71 | +} | ||
| 72 | + | ||
| 73 | +fn filter_sql(filter: &EventFilter, params: &mut Vec<turso::Value>) -> String { | ||
| 74 | + let mut sql = String::new(); | ||
| 75 | + if let Some(kind) = &filter.kind { | ||
| 76 | + sql += " AND kind = ?"; | ||
| 77 | + params.push(kind.clone().into()); | ||
| 78 | + } | ||
| 79 | + if let Some(actor) = &filter.actor { | ||
| 80 | + sql += " AND actor = ?"; | ||
| 81 | + params.push(actor.clone().into()); | ||
| 82 | + } | ||
| 83 | + if let Some((from, to)) = &filter.day { | ||
| 84 | + sql += " AND at >= ? AND at < ?"; | ||
| 85 | + params.push(store::stamp(*from).expect("rfc3339 of range start").into()); | ||
| 86 | + params.push(store::stamp(*to).expect("rfc3339 of range end").into()); | ||
| 87 | + } | ||
| 88 | + sql | ||
| 89 | +} | ||
| 90 | + | ||
| 91 | +/// One window of the log under the filters. The caller asks for one row more | ||
| 92 | +/// than the page shows: the extra row is the "there is more" signal, trimmed | ||
| 93 | +/// before render. `After` reads the newer side in mirrored order and flips it | ||
| 94 | +/// back in memory, so the page always presents in `dir` order. | ||
| 95 | +pub async fn list_filtered( | ||
| 96 | + store: &Store, | ||
| 97 | + limit: i64, | ||
| 98 | + page: &EventPage, | ||
| 99 | + dir: Dir, | ||
| 100 | + filter: &EventFilter, | ||
| 101 | +) -> Result<Vec<Event>> { | ||
| 102 | + let oldest = dir == Dir::Oldest; | ||
| 103 | + let base = if oldest { "ASC" } else { "DESC" }; | ||
| 104 | + let mut params: Vec<turso::Value> = Vec::new(); | ||
| 105 | + let mut sql = "SELECT id, at, kind, actor, detail FROM events WHERE 1=1".to_string(); | ||
| 106 | + sql += &filter_sql(filter, &mut params); | ||
| 107 | + let mut reversed = false; | ||
| 108 | + match page { | ||
| 109 | + EventPage::Newest => {} | ||
| 110 | + EventPage::Before(cursor) => { | ||
| 111 | + let cmp = if oldest { ">" } else { "<" }; | ||
| 112 | + sql += &format!(" AND (at {cmp} ? OR (at = ? AND id {cmp} ?))"); | ||
| 113 | + let at = store::stamp(cursor.at)?; | ||
| 114 | + params.push(at.clone().into()); | ||
| 115 | + params.push(at.into()); | ||
| 116 | + params.push(cursor.id.clone().into()); | ||
| 117 | + } | ||
| 118 | + EventPage::After(cursor) => { | ||
| 119 | + let cmp = if oldest { "<" } else { ">" }; | ||
| 120 | + sql += &format!(" AND (at {cmp} ? OR (at = ? AND id {cmp} ?))"); | ||
| 121 | + let at = store::stamp(cursor.at)?; | ||
| 122 | + params.push(at.clone().into()); | ||
| 123 | + params.push(at.into()); | ||
| 124 | + params.push(cursor.id.clone().into()); | ||
| 125 | + reversed = true; | ||
| 126 | + } | ||
| 127 | + } | ||
| 128 | + let order = if reversed { | ||
| 129 | + if oldest { "DESC" } else { "ASC" } | ||
| 130 | + } else { | ||
| 131 | + base | ||
| 132 | + }; | ||
| 133 | + sql += &format!(" ORDER BY at {order}, id {order} LIMIT ?"); | ||
| 134 | + params.push(limit.into()); | ||
| 40 | let conn = store.conn.lock().await; | 135 | let conn = store.conn.lock().await; |
| 41 | let mut rows = conn | 136 | let mut rows = conn |
| 42 | - .query( | 137 | + .query(&sql, turso::params_from_iter(params)) |
| 43 | - "SELECT id, at, kind, actor, detail FROM events ORDER BY at DESC, id DESC LIMIT ?1", | ||
| 44 | - turso::params![limit], | ||
| 45 | - ) | ||
| 46 | .await | 138 | .await |
| 47 | .map_err(backend)?; | 139 | .map_err(backend)?; |
| 48 | let mut events = Vec::new(); | 140 | let mut events = Vec::new(); |
| @@ -55,9 +147,91 @@ pub async fn list(store: &Store, limit: i64) -> Result<Vec<Event>> { | |||
| 55 | detail: store::opt_text(&row, 4)?, | 147 | detail: store::opt_text(&row, 4)?, |
| 56 | }); | 148 | }); |
| 57 | } | 149 | } |
| 150 | + if reversed { | ||
| 151 | + events.reverse(); | ||
| 152 | + } | ||
| 58 | Ok(events) | 153 | Ok(events) |
| 59 | } | 154 | } |
| 60 | 155 | ||
| 156 | +/// How many rows the filters admit at all. | ||
| 157 | +pub async fn count_filtered(store: &Store, filter: &EventFilter) -> Result<u64> { | ||
| 158 | + let mut params: Vec<turso::Value> = Vec::new(); | ||
| 159 | + let mut sql = "SELECT COUNT(*) FROM events WHERE 1=1".to_string(); | ||
| 160 | + sql += &filter_sql(filter, &mut params); | ||
| 161 | + let conn = store.conn.lock().await; | ||
| 162 | + let mut rows = conn | ||
| 163 | + .query(&sql, turso::params_from_iter(params)) | ||
| 164 | + .await | ||
| 165 | + .map_err(backend)?; | ||
| 166 | + let count = match rows.next().await.map_err(backend)? { | ||
| 167 | + Some(row) => store::int(&row, 0)? as u64, | ||
| 168 | + None => 0, | ||
| 169 | + }; | ||
| 170 | + Ok(count) | ||
| 171 | +} | ||
| 172 | + | ||
| 173 | +/// How many matching rows sit on the newer side of the page's top row — the | ||
| 174 | +/// "X–Y" half of the position note. No cursor means the page starts at the | ||
| 175 | +/// very top: nothing precedes it. | ||
| 176 | +pub async fn count_preceding( | ||
| 177 | + store: &Store, | ||
| 178 | + filter: &EventFilter, | ||
| 179 | + dir: Dir, | ||
| 180 | + cursor: Option<&EventCursor>, | ||
| 181 | +) -> Result<u64> { | ||
| 182 | + let Some(cursor) = cursor else { return Ok(0) }; | ||
| 183 | + let cmp = if dir == Dir::Oldest { "<" } else { ">" }; | ||
| 184 | + let mut params: Vec<turso::Value> = Vec::new(); | ||
| 185 | + let mut sql = "SELECT COUNT(*) FROM events WHERE 1=1".to_string(); | ||
| 186 | + sql += &filter_sql(filter, &mut params); | ||
| 187 | + sql += &format!(" AND (at {cmp} ? OR (at = ? AND id {cmp} ?))"); | ||
| 188 | + let at = store::stamp(cursor.at)?; | ||
| 189 | + params.push(at.clone().into()); | ||
| 190 | + params.push(at.into()); | ||
| 191 | + params.push(cursor.id.clone().into()); | ||
| 192 | + let conn = store.conn.lock().await; | ||
| 193 | + let mut rows = conn | ||
| 194 | + .query(&sql, turso::params_from_iter(params)) | ||
| 195 | + .await | ||
| 196 | + .map_err(backend)?; | ||
| 197 | + let count = match rows.next().await.map_err(backend)? { | ||
| 198 | + Some(row) => store::int(&row, 0)? as u64, | ||
| 199 | + None => 0, | ||
| 200 | + }; | ||
| 201 | + Ok(count) | ||
| 202 | +} | ||
| 203 | + | ||
| 204 | +/// The kind and actor dropdowns list what the log actually contains — im's | ||
| 205 | +/// kinds are free strings, so the vocabulary is read, not hardcoded. | ||
| 206 | +pub async fn distinct_kinds(store: &Store) -> Result<Vec<String>> { | ||
| 207 | + let conn = store.conn.lock().await; | ||
| 208 | + let mut rows = conn | ||
| 209 | + .query("SELECT DISTINCT kind FROM events ORDER BY kind", ()) | ||
| 210 | + .await | ||
| 211 | + .map_err(backend)?; | ||
| 212 | + let mut kinds = Vec::new(); | ||
| 213 | + while let Some(row) = rows.next().await.map_err(backend)? { | ||
| 214 | + kinds.push(store::text(&row, 0)?); | ||
| 215 | + } | ||
| 216 | + Ok(kinds) | ||
| 217 | +} | ||
| 218 | + | ||
| 219 | +pub async fn distinct_actors(store: &Store) -> Result<Vec<String>> { | ||
| 220 | + let conn = store.conn.lock().await; | ||
| 221 | + let mut rows = conn | ||
| 222 | + .query( | ||
| 223 | + "SELECT DISTINCT actor FROM events WHERE actor IS NOT NULL ORDER BY actor", | ||
| 224 | + (), | ||
| 225 | + ) | ||
| 226 | + .await | ||
| 227 | + .map_err(backend)?; | ||
| 228 | + let mut actors = Vec::new(); | ||
| 229 | + while let Some(row) = rows.next().await.map_err(backend)? { | ||
| 230 | + actors.push(store::text(&row, 0)?); | ||
| 231 | + } | ||
| 232 | + Ok(actors) | ||
| 233 | +} | ||
| 234 | + | ||
| 61 | #[cfg(test)] | 235 | #[cfg(test)] |
| 62 | mod tests { | 236 | mod tests { |
| 63 | use super::*; | 237 | use super::*; |
| @@ -74,9 +248,83 @@ mod tests { | |||
| 74 | Some("wrong password"), | 248 | Some("wrong password"), |
| 75 | ) | 249 | ) |
| 76 | .await; | 250 | .await; |
| 77 | - let events = list(&store, 10).await.unwrap(); | 251 | + let events = list_filtered( |
| 252 | + &store, | ||
| 253 | + 10, | ||
| 254 | + &EventPage::Newest, | ||
| 255 | + Dir::Newest, | ||
| 256 | + &EventFilter::default(), | ||
| 257 | + ) | ||
| 258 | + .await | ||
| 259 | + .unwrap(); | ||
| 78 | assert_eq!(events.len(), 2); | 260 | assert_eq!(events.len(), 2); |
| 79 | assert_eq!(events[0].kind, "login_fail"); | 261 | assert_eq!(events[0].kind, "login_fail"); |
| 80 | assert_eq!(events[1].actor.as_deref(), Some("ann@example.com")); | 262 | assert_eq!(events[1].actor.as_deref(), Some("ann@example.com")); |
| 81 | } | 263 | } |
| 264 | + | ||
| 265 | + #[tokio::test] | ||
| 266 | + async fn filtered_paging_walks_the_log() { | ||
| 267 | + let store = Store::open(Path::new(":memory:")).await.unwrap(); | ||
| 268 | + for i in 0..7 { | ||
| 269 | + let kind = if i % 2 == 0 { "login_ok" } else { "logout" }; | ||
| 270 | + log(&store, kind, Some("ann@example.com"), None).await; | ||
| 271 | + } | ||
| 272 | + let filter = EventFilter::default(); | ||
| 273 | + // First page of three: newest rows, plus the has-more signal row. | ||
| 274 | + let first = list_filtered(&store, 4, &EventPage::Newest, Dir::Newest, &filter) | ||
| 275 | + .await | ||
| 276 | + .unwrap(); | ||
| 277 | + assert_eq!(first.len(), 4); | ||
| 278 | + let cursor = EventCursor { | ||
| 279 | + at: first[2].at, | ||
| 280 | + id: first[2].id.clone(), | ||
| 281 | + }; | ||
| 282 | + let second = list_filtered( | ||
| 283 | + &store, | ||
| 284 | + 4, | ||
| 285 | + &EventPage::Before(cursor.clone()), | ||
| 286 | + Dir::Newest, | ||
| 287 | + &filter, | ||
| 288 | + ) | ||
| 289 | + .await | ||
| 290 | + .unwrap(); | ||
| 291 | + assert_eq!(second.len(), 4); | ||
| 292 | + assert!(second.iter().all(|e| e.at <= cursor.at)); | ||
| 293 | + assert!(!second.iter().any(|e| e.id == cursor.id)); | ||
| 294 | + // Walking back up returns the same top rows. | ||
| 295 | + let up = list_filtered(&store, 4, &EventPage::After(cursor), Dir::Newest, &filter) | ||
| 296 | + .await | ||
| 297 | + .unwrap(); | ||
| 298 | + assert_eq!(up.len(), 2); | ||
| 299 | + assert_eq!(up.first().unwrap().id, first.first().unwrap().id); | ||
| 300 | + // Filters narrow, counts agree, and the position note's input exists. | ||
| 301 | + let only_logins = EventFilter { | ||
| 302 | + kind: Some("login_ok".into()), | ||
| 303 | + ..Default::default() | ||
| 304 | + }; | ||
| 305 | + assert_eq!(count_filtered(&store, &only_logins).await.unwrap(), 4); | ||
| 306 | + assert_eq!(count_filtered(&store, &filter).await.unwrap(), 7); | ||
| 307 | + assert_eq!( | ||
| 308 | + count_preceding( | ||
| 309 | + &store, | ||
| 310 | + &filter, | ||
| 311 | + Dir::Newest, | ||
| 312 | + Some(&EventCursor { | ||
| 313 | + at: first[1].at, | ||
| 314 | + id: first[1].id.clone(), | ||
| 315 | + }) | ||
| 316 | + ) | ||
| 317 | + .await | ||
| 318 | + .unwrap(), | ||
| 319 | + 1 | ||
| 320 | + ); | ||
| 321 | + assert_eq!( | ||
| 322 | + distinct_kinds(&store).await.unwrap(), | ||
| 323 | + vec!["login_ok", "logout"] | ||
| 324 | + ); | ||
| 325 | + assert_eq!( | ||
| 326 | + distinct_actors(&store).await.unwrap(), | ||
| 327 | + vec!["ann@example.com"] | ||
| 328 | + ); | ||
| 329 | + } | ||
| 82 | } | 330 | } |
crates/im-web/assets/main.cssmodified+28 -1
| @@ -796,12 +796,13 @@ textarea.auth-input { | |||
| 796 | body:has(.admin-shell) { | 796 | body:has(.admin-shell) { |
| 797 | min-height: 100vh; | 797 | min-height: 100vh; |
| 798 | min-height: 100dvh; | 798 | min-height: 100dvh; |
| 799 | + scrollbar-gutter: stable; | ||
| 799 | } | 800 | } |
| 800 | 801 | ||
| 801 | .admin-shell { | 802 | .admin-shell { |
| 802 | display: flex; | 803 | display: flex; |
| 803 | justify-content: center; | 804 | justify-content: center; |
| 804 | - padding: 24px 24px 48px; | 805 | + padding: max(24px, (100dvh - 640px) / 2) 24px 48px; |
| 805 | } | 806 | } |
| 806 | 807 | ||
| 807 | .admin-column { | 808 | .admin-column { |
| @@ -868,6 +869,32 @@ a.wordmark-home { | |||
| 868 | overflow-x: auto; | 869 | overflow-x: auto; |
| 869 | } | 870 | } |
| 870 | 871 | ||
| 872 | +.logs-filters { | ||
| 873 | + display: flex; | ||
| 874 | + flex-wrap: wrap; | ||
| 875 | + gap: 10px 14px; | ||
| 876 | +} | ||
| 877 | +.logs-filters .auth-field { | ||
| 878 | + flex: 1 1 120px; | ||
| 879 | + min-width: 0; | ||
| 880 | +} | ||
| 881 | + | ||
| 882 | +.logs-foot { | ||
| 883 | + display: flex; | ||
| 884 | + align-items: center; | ||
| 885 | + justify-content: space-between; | ||
| 886 | + gap: 12px; | ||
| 887 | +} | ||
| 888 | +.logs-foot .log-count { | ||
| 889 | + font-family: var(--font-mono); | ||
| 890 | + font-size: 11px; | ||
| 891 | + color: var(--muted-soft); | ||
| 892 | +} | ||
| 893 | +.logs-foot .logs-links { | ||
| 894 | + display: flex; | ||
| 895 | + gap: 16px; | ||
| 896 | +} | ||
| 897 | + | ||
| 871 | .admin-table { | 898 | .admin-table { |
| 872 | width: 100%; | 899 | width: 100%; |
| 873 | border-collapse: collapse; | 900 | border-collapse: collapse; |
crates/im-web/src/admin.rsmodified+287 -51
| @@ -114,6 +114,7 @@ async fn admin_page(cx: &Cx) -> Result<Response> { | |||
| 114 | [ | 114 | [ |
| 115 | ("users", t(lang, Key::NavUsers)), | 115 | ("users", t(lang, Key::NavUsers)), |
| 116 | ("mail", t(lang, Key::NavMail)), | 116 | ("mail", t(lang, Key::NavMail)), |
| 117 | + ("message", t(lang, Key::NavMessage)), | ||
| 117 | ("settings", t(lang, Key::NavSettings)), | 118 | ("settings", t(lang, Key::NavSettings)), |
| 118 | ("logs", t(lang, Key::NavLogs)), | 119 | ("logs", t(lang, Key::NavLogs)), |
| 119 | ] | 120 | ] |
| @@ -129,6 +130,7 @@ async fn admin_page(cx: &Cx) -> Result<Response> { | |||
| 129 | 130 | ||
| 130 | let section_html = match section.as_str() { | 131 | let section_html = match section.as_str() { |
| 131 | "mail" => mail_section(cx, lang).await?, | 132 | "mail" => mail_section(cx, lang).await?, |
| 133 | + "message" => message_section(cx, lang).await?, | ||
| 132 | "settings" => settings_section(cx, lang).await?, | 134 | "settings" => settings_section(cx, lang).await?, |
| 133 | "logs" => logs_section(cx, lang).await?, | 135 | "logs" => logs_section(cx, lang).await?, |
| 134 | "users" => users_section(cx, &me, invited.as_deref(), lang).await?, | 136 | "users" => users_section(cx, &me, invited.as_deref(), lang).await?, |
| @@ -511,38 +513,6 @@ async fn mail_section(cx: &Cx, lang: i18n::Lang) -> Result<String, topcoat::Erro | |||
| 511 | } else { | 513 | } else { |
| 512 | format!(r#"<div class="admin-standing">{lede}</div>"#) | 514 | format!(r#"<div class="admin-standing">{lede}</div>"#) |
| 513 | }; | 515 | }; |
| 514 | - let users = accounts::list_users(store).await?; | ||
| 515 | - let mut options = format!( | ||
| 516 | - r#"<option value="everyone">{}</option>"#, | ||
| 517 | - t(lang, Key::EveryoneOption) | ||
| 518 | - ); | ||
| 519 | - for person in &users { | ||
| 520 | - options.push_str(&format!( | ||
| 521 | - r#"<option value="{}">{} · {}</option>"#, | ||
| 522 | - escape(person.id.as_str()), | ||
| 523 | - escape(&person.name), | ||
| 524 | - escape(&person.email), | ||
| 525 | - )); | ||
| 526 | - } | ||
| 527 | - let message_card = format!( | ||
| 528 | - r#"<div class="admin-card"> | ||
| 529 | - <div class="admin-card-head"><div class="auth-title">{msg_title}</div></div> | ||
| 530 | - <form method="post" action="/admin/message" class="admin-form"> | ||
| 531 | - <label class="auth-field"><span class="auth-label">{to_label}</span> | ||
| 532 | - <select class="auth-input" name="to">{options}</select></label> | ||
| 533 | - <label class="auth-field"><span class="auth-label">{subject_label}</span> | ||
| 534 | - <input class="auth-input" type="text" name="subject" required></label> | ||
| 535 | - <label class="auth-field"><span class="auth-label">{body_label}</span> | ||
| 536 | - <textarea class="auth-input" name="body" rows="5" required></textarea></label> | ||
| 537 | - <button class="auth-submit admin-action-wide" type="submit"><span class="auth-submit-text">{send}</span></button> | ||
| 538 | - </form> | ||
| 539 | -</div>"#, | ||
| 540 | - msg_title = t(lang, Key::MessageTitle), | ||
| 541 | - to_label = t(lang, Key::MessageToLabel), | ||
| 542 | - subject_label = t(lang, Key::MessageSubjectLabel), | ||
| 543 | - body_label = t(lang, Key::MessageBodyLabel), | ||
| 544 | - send = t(lang, Key::SendMessageButton), | ||
| 545 | - ); | ||
| 546 | Ok(format!( | 516 | Ok(format!( |
| 547 | r#"<div class="admin-card"> | 517 | r#"<div class="admin-card"> |
| 548 | <div class="admin-card-head"><div class="auth-title">{title}</div><span class="{chip_class}">{chip_text}</span></div> | 518 | <div class="admin-card-head"><div class="auth-title">{title}</div><span class="{chip_class}">{chip_text}</span></div> |
| @@ -585,36 +555,302 @@ async fn mail_section(cx: &Cx, lang: i18n::Lang) -> Result<String, topcoat::Erro | |||
| 585 | check = t(lang, Key::CheckConnectionButton), | 555 | check = t(lang, Key::CheckConnectionButton), |
| 586 | test = t(lang, Key::SendTestMailButton), | 556 | test = t(lang, Key::SendTestMailButton), |
| 587 | )) | 557 | )) |
| 588 | - .map(|smtp_card| smtp_card + &message_card) | 558 | +} |
| 559 | + | ||
| 560 | +/// The compose half of mail, its own tab like izlek's settings rail keeps | ||
| 561 | +/// Message beside Outgoing: the sender's settings live one tab over, this | ||
| 562 | +/// page is only "to whom, what, send". | ||
| 563 | +async fn message_section(cx: &Cx, lang: i18n::Lang) -> Result<String, topcoat::Error> { | ||
| 564 | + let store = &app(cx).store; | ||
| 565 | + let users = accounts::list_users(store).await?; | ||
| 566 | + let mut options = format!( | ||
| 567 | + r#"<option value="everyone">{}</option>"#, | ||
| 568 | + t(lang, Key::EveryoneOption) | ||
| 569 | + ); | ||
| 570 | + for person in &users { | ||
| 571 | + options.push_str(&format!( | ||
| 572 | + r#"<option value="{}">{} · {}</option>"#, | ||
| 573 | + escape(person.id.as_str()), | ||
| 574 | + escape(&person.name), | ||
| 575 | + escape(&person.email), | ||
| 576 | + )); | ||
| 577 | + } | ||
| 578 | + Ok(format!( | ||
| 579 | + r#"<div class="admin-card"> | ||
| 580 | + <div class="admin-card-head"><div class="auth-title">{msg_title}</div></div> | ||
| 581 | + <form method="post" action="/admin/message" class="admin-form"> | ||
| 582 | + <label class="auth-field"><span class="auth-label">{to_label}</span> | ||
| 583 | + <select class="auth-input" name="to">{options}</select></label> | ||
| 584 | + <label class="auth-field"><span class="auth-label">{subject_label}</span> | ||
| 585 | + <input class="auth-input" type="text" name="subject" required></label> | ||
| 586 | + <label class="auth-field"><span class="auth-label">{body_label}</span> | ||
| 587 | + <textarea class="auth-input" name="body" rows="5" required></textarea></label> | ||
| 588 | + <button class="auth-submit admin-action-wide" type="submit"><span class="auth-submit-text">{send}</span></button> | ||
| 589 | + </form> | ||
| 590 | +</div>"#, | ||
| 591 | + msg_title = t(lang, Key::MessageTitle), | ||
| 592 | + to_label = t(lang, Key::MessageToLabel), | ||
| 593 | + subject_label = t(lang, Key::MessageSubjectLabel), | ||
| 594 | + body_label = t(lang, Key::MessageBodyLabel), | ||
| 595 | + send = t(lang, Key::SendMessageButton), | ||
| 596 | + )) | ||
| 597 | +} | ||
| 598 | + | ||
| 599 | +/// One page of the log: fifty rows, izlek's default. The log grows without | ||
| 600 | +/// bound; the page does not. | ||
| 601 | +const LOGS_LIMIT: i64 = 50; | ||
| 602 | + | ||
| 603 | +/// The cursor on the wire: `rfc3339~id`, percent-encoded into `before`/`after`. | ||
| 604 | +fn cursor_q(cursor: &events::EventCursor) -> String { | ||
| 605 | + crate::oidc::urlencode(&format!("{}~{}", events_cursor_stamp(cursor), cursor.id)) | ||
| 606 | +} | ||
| 607 | + | ||
| 608 | +fn events_cursor_stamp(cursor: &events::EventCursor) -> String { | ||
| 609 | + cursor | ||
| 610 | + .at | ||
| 611 | + .format(&time::macros::format_description!( | ||
| 612 | + "[year]-[month]-[day]T[hour]:[minute]:[second]Z" | ||
| 613 | + )) | ||
| 614 | + .unwrap_or_default() | ||
| 615 | +} | ||
| 616 | + | ||
| 617 | +fn parse_cursor(raw: Option<String>) -> Option<events::EventCursor> { | ||
| 618 | + let raw = raw?; | ||
| 619 | + let (at, id) = raw.split_once('~')?; | ||
| 620 | + let at = | ||
| 621 | + time::OffsetDateTime::parse(at, &time::format_description::well_known::Rfc3339).ok()?; | ||
| 622 | + if id.is_empty() { | ||
| 623 | + return None; | ||
| 624 | + } | ||
| 625 | + Some(events::EventCursor { | ||
| 626 | + at, | ||
| 627 | + id: id.to_string(), | ||
| 628 | + }) | ||
| 629 | +} | ||
| 630 | + | ||
| 631 | +/// YYYY-MM-DD at the UTC midnight that opens the day; `to` is handed the | ||
| 632 | +/// midnight that closes it. Backwards ranges swap, garbage opens the end. | ||
| 633 | +fn parse_day(raw: Option<String>) -> Option<time::OffsetDateTime> { | ||
| 634 | + let raw = raw?; | ||
| 635 | + let date = time::Date::parse( | ||
| 636 | + &raw, | ||
| 637 | + &time::macros::format_description!("[year]-[month]-[day]"), | ||
| 638 | + ) | ||
| 639 | + .ok()?; | ||
| 640 | + date.with_hms(0, 0, 0).ok().map(|dt| dt.assume_utc()) | ||
| 589 | } | 641 | } |
| 590 | 642 | ||
| 591 | async fn logs_section(cx: &Cx, lang: i18n::Lang) -> Result<String, topcoat::Error> { | 643 | async fn logs_section(cx: &Cx, lang: i18n::Lang) -> Result<String, topcoat::Error> { |
| 592 | - let entries = events::list(&app(cx).store, 200).await?; | 644 | + let store = &app(cx).store; |
| 645 | + let query = topcoat::router::request::uri(cx) | ||
| 646 | + .query() | ||
| 647 | + .unwrap_or("") | ||
| 648 | + .to_string(); | ||
| 649 | + let pick = |name: &str| query_value(&query, name).filter(|v| !v.is_empty()); | ||
| 650 | + | ||
| 651 | + let from = parse_day(pick("from")); | ||
| 652 | + let to = parse_day(pick("to")).and_then(|d| d.checked_add(time::Duration::days(1))); | ||
| 653 | + let day = match (from, to) { | ||
| 654 | + (Some(a), Some(b)) if a > b => Some((b, a)), | ||
| 655 | + (Some(a), Some(b)) => Some((a, b)), | ||
| 656 | + (Some(a), None) => Some((a, time::Date::MAX.with_hms(0, 0, 0).unwrap().assume_utc())), | ||
| 657 | + (None, Some(b)) => Some((time::OffsetDateTime::UNIX_EPOCH, b)), | ||
| 658 | + (None, None) => None, | ||
| 659 | + }; | ||
| 660 | + let filter = events::EventFilter { | ||
| 661 | + kind: pick("kind"), | ||
| 662 | + actor: pick("actor"), | ||
| 663 | + day, | ||
| 664 | + }; | ||
| 665 | + let dir = if pick("dir").as_deref() == Some("oldest") { | ||
| 666 | + events::Dir::Oldest | ||
| 667 | + } else { | ||
| 668 | + events::Dir::Newest | ||
| 669 | + }; | ||
| 670 | + let mut page = match (parse_cursor(pick("before")), parse_cursor(pick("after"))) { | ||
| 671 | + (Some(cursor), _) => events::EventPage::Before(cursor), | ||
| 672 | + (None, Some(cursor)) => events::EventPage::After(cursor), | ||
| 673 | + _ => events::EventPage::Newest, | ||
| 674 | + }; | ||
| 675 | + let mut window = events::list_filtered(store, LOGS_LIMIT + 1, &page, dir, &filter).await?; | ||
| 676 | + // Ran off the top walking back: answer with the freshest page instead. | ||
| 677 | + if matches!(page, events::EventPage::After(_)) && window.is_empty() { | ||
| 678 | + page = events::EventPage::Newest; | ||
| 679 | + window = events::list_filtered(store, LOGS_LIMIT + 1, &page, dir, &filter).await?; | ||
| 680 | + } | ||
| 681 | + let has_more = window.len() as i64 > LOGS_LIMIT; | ||
| 682 | + window.truncate(LOGS_LIMIT as usize); | ||
| 683 | + | ||
| 684 | + let total = events::count_filtered(store, &filter).await?; | ||
| 685 | + let preceding = events::count_preceding( | ||
| 686 | + store, | ||
| 687 | + &filter, | ||
| 688 | + dir, | ||
| 689 | + window | ||
| 690 | + .first() | ||
| 691 | + .map(|e| events::EventCursor { | ||
| 692 | + at: e.at, | ||
| 693 | + id: e.id.clone(), | ||
| 694 | + }) | ||
| 695 | + .as_ref(), | ||
| 696 | + ) | ||
| 697 | + .await?; | ||
| 698 | + | ||
| 699 | + // A page turn re-appends every filter: turning never drops the narrowing. | ||
| 700 | + let mut suffix = String::new(); | ||
| 701 | + if let Some(kind) = &filter.kind { | ||
| 702 | + suffix += &format!("&kind={}", crate::oidc::urlencode(kind)); | ||
| 703 | + } | ||
| 704 | + if let Some(actor) = &filter.actor { | ||
| 705 | + suffix += &format!("&actor={}", crate::oidc::urlencode(actor)); | ||
| 706 | + } | ||
| 707 | + if let Some(raw) = pick("from") { | ||
| 708 | + suffix += &format!("&from={}", crate::oidc::urlencode(&raw)); | ||
| 709 | + } | ||
| 710 | + if let Some(raw) = pick("to") { | ||
| 711 | + suffix += &format!("&to={}", crate::oidc::urlencode(&raw)); | ||
| 712 | + } | ||
| 713 | + if dir == events::Dir::Oldest { | ||
| 714 | + suffix += "&dir=oldest"; | ||
| 715 | + } | ||
| 716 | + | ||
| 717 | + let kinds = events::distinct_kinds(store).await?; | ||
| 718 | + let actors = events::distinct_actors(store).await?; | ||
| 719 | + let mut kind_options = format!(r#"<option value="">{}</option>"#, t(lang, Key::AllOption)); | ||
| 720 | + for kind in &kinds { | ||
| 721 | + kind_options.push_str(&format!( | ||
| 722 | + r#"<option value="{}"{}>{}</option>"#, | ||
| 723 | + escape(kind), | ||
| 724 | + if filter.kind.as_deref() == Some(kind) { | ||
| 725 | + " selected" | ||
| 726 | + } else { | ||
| 727 | + "" | ||
| 728 | + }, | ||
| 729 | + escape(&i18n::kind_word(lang, kind)), | ||
| 730 | + )); | ||
| 731 | + } | ||
| 732 | + let mut actor_options = format!(r#"<option value="">{}</option>"#, t(lang, Key::AllOption)); | ||
| 733 | + for actor in &actors { | ||
| 734 | + actor_options.push_str(&format!( | ||
| 735 | + r#"<option value="{}"{}>{}</option>"#, | ||
| 736 | + escape(actor), | ||
| 737 | + if filter.actor.as_deref() == Some(actor) { | ||
| 738 | + " selected" | ||
| 739 | + } else { | ||
| 740 | + "" | ||
| 741 | + }, | ||
| 742 | + escape(actor), | ||
| 743 | + )); | ||
| 744 | + } | ||
| 745 | + | ||
| 593 | let mut rows = String::new(); | 746 | let mut rows = String::new(); |
| 594 | - for event in &entries { | 747 | + for event in &window { |
| 595 | rows.push_str(&format!( | 748 | rows.push_str(&format!( |
| 596 | "<tr><td class=\"mono muted\">{}</td><td class=\"mono\">{}</td><td>{}</td><td class=\"muted\">{}</td></tr>", | 749 | "<tr><td class=\"mono muted\">{}</td><td class=\"mono\">{}</td><td>{}</td><td class=\"muted\">{}</td></tr>", |
| 597 | escape(&event.at.format(&time::macros::format_description!("[year]-[month]-[day] [hour]:[minute]:[second]")).unwrap_or_default()), | 750 | escape(&event.at.format(&time::macros::format_description!("[year]-[month]-[day] [hour]:[minute]:[second]")).unwrap_or_default()), |
| 598 | - escape(&event.kind), | 751 | + escape(&i18n::kind_word(lang, &event.kind)), |
| 599 | escape(event.actor.as_deref().unwrap_or("")), | 752 | escape(event.actor.as_deref().unwrap_or("")), |
| 600 | escape(event.detail.as_deref().unwrap_or("")), | 753 | escape(event.detail.as_deref().unwrap_or("")), |
| 601 | )); | 754 | )); |
| 602 | } | 755 | } |
| 756 | + | ||
| 757 | + let body = if window.is_empty() { | ||
| 758 | + format!(r#"<div class="muted">{}</div>"#, t(lang, Key::LogsEmpty)) | ||
| 759 | + } else { | ||
| 760 | + format!( | ||
| 761 | + r#"<table class="admin-table"> | ||
| 762 | + <thead><tr><th>{when}</th><th>{what}</th><th>{who}</th><th>{detail}</th></tr></thead> | ||
| 763 | + <tbody>{rows}</tbody> | ||
| 764 | + </table>"#, | ||
| 765 | + when = t(lang, Key::WhenCol), | ||
| 766 | + what = t(lang, Key::WhatCol), | ||
| 767 | + who = t(lang, Key::WhoCol), | ||
| 768 | + detail = t(lang, Key::DetailCol), | ||
| 769 | + ) | ||
| 770 | + }; | ||
| 771 | + | ||
| 772 | + // izlek's link visibility: the freshest page shows only Older, a middle | ||
| 773 | + // page shows both, the last page hides Older. | ||
| 774 | + let mut foot = String::new(); | ||
| 775 | + if !window.is_empty() { | ||
| 776 | + let newest = events::EventCursor { | ||
| 777 | + at: window.first().unwrap().at, | ||
| 778 | + id: window.first().unwrap().id.clone(), | ||
| 779 | + }; | ||
| 780 | + let oldest = events::EventCursor { | ||
| 781 | + at: window.last().unwrap().at, | ||
| 782 | + id: window.last().unwrap().id.clone(), | ||
| 783 | + }; | ||
| 784 | + let show_older = matches!(page, events::EventPage::After(_)) || has_more; | ||
| 785 | + let show_newer = matches!(page, events::EventPage::Before(_)) | ||
| 786 | + || (matches!(page, events::EventPage::After(_)) && has_more); | ||
| 787 | + let mut links = String::new(); | ||
| 788 | + if show_newer { | ||
| 789 | + links += &format!( | ||
| 790 | + r#"<a class="auth-alt" href="/admin?section=logs{suffix}&after={}">{}</a>"#, | ||
| 791 | + cursor_q(&newest), | ||
| 792 | + t(lang, Key::NewerLink), | ||
| 793 | + ); | ||
| 794 | + } | ||
| 795 | + if show_older { | ||
| 796 | + links += &format!( | ||
| 797 | + r#"<a class="auth-alt" href="/admin?section=logs{suffix}&before={}">{}</a>"#, | ||
| 798 | + cursor_q(&oldest), | ||
| 799 | + t(lang, Key::OlderLink), | ||
| 800 | + ); | ||
| 801 | + } | ||
| 802 | + foot = format!( | ||
| 803 | + r#"<div class="logs-foot"><span class="log-count">{}–{} / {}</span><div class="logs-links">{links}</div></div>"#, | ||
| 804 | + preceding + 1, | ||
| 805 | + preceding + window.len() as u64, | ||
| 806 | + total, | ||
| 807 | + ); | ||
| 808 | + } | ||
| 809 | + | ||
| 603 | Ok(format!( | 810 | Ok(format!( |
| 604 | r#"<div class="admin-card"> | 811 | r#"<div class="admin-card"> |
| 605 | <div class="auth-title">{title}</div> | 812 | <div class="auth-title">{title}</div> |
| 606 | <div class="auth-sub">{sub}</div> | 813 | <div class="auth-sub">{sub}</div> |
| 607 | - <table class="admin-table"> | 814 | + <form method="get" action="/admin" class="logs-filters"> |
| 608 | - <thead><tr><th>{when}</th><th>{what}</th><th>{who}</th><th>{detail}</th></tr></thead> | 815 | + <input type="hidden" name="section" value="logs"> |
| 609 | - <tbody>{rows}</tbody> | 816 | + <label class="auth-field"><span class="auth-label">{kind_label}</span> |
| 610 | - </table> | 817 | + <select class="auth-input" name="kind" data-autosubmit>{kind_options}</select></label> |
| 818 | + <label class="auth-field"><span class="auth-label">{actor_label}</span> | ||
| 819 | + <select class="auth-input" name="actor" data-autosubmit>{actor_options}</select></label> | ||
| 820 | + <label class="auth-field"><span class="auth-label">{from_label}</span> | ||
| 821 | + <input class="auth-input" type="date" name="from" value="{from_value}" data-autosubmit></label> | ||
| 822 | + <label class="auth-field"><span class="auth-label">{to_label}</span> | ||
| 823 | + <input class="auth-input" type="date" name="to" value="{to_value}" data-autosubmit></label> | ||
| 824 | + <label class="auth-field"><span class="auth-label">{dir_label}</span> | ||
| 825 | + <select class="auth-input" name="dir" data-autosubmit>{dir_options}</select></label> | ||
| 826 | + </form> | ||
| 827 | + {body} | ||
| 828 | + {foot} | ||
| 611 | </div>"#, | 829 | </div>"#, |
| 612 | title = t(lang, Key::LogsTitle), | 830 | title = t(lang, Key::LogsTitle), |
| 613 | sub = t(lang, Key::LogsSub), | 831 | sub = t(lang, Key::LogsSub), |
| 614 | - when = t(lang, Key::WhenCol), | 832 | + kind_label = t(lang, Key::KindLabel), |
| 615 | - what = t(lang, Key::WhatCol), | 833 | + actor_label = t(lang, Key::ActorLabel), |
| 616 | - who = t(lang, Key::WhoCol), | 834 | + from_label = t(lang, Key::FromLabel), |
| 617 | - detail = t(lang, Key::DetailCol), | 835 | + to_label = t(lang, Key::ToLabel), |
| 836 | + dir_label = t(lang, Key::OrderLabel), | ||
| 837 | + from_value = escape(&pick("from").unwrap_or_default()), | ||
| 838 | + to_value = escape(&pick("to").unwrap_or_default()), | ||
| 839 | + dir_options = format!( | ||
| 840 | + r#"<option value=""{}>{}</option><option value="oldest"{}>{}</option>"#, | ||
| 841 | + if dir == events::Dir::Newest { | ||
| 842 | + " selected" | ||
| 843 | + } else { | ||
| 844 | + "" | ||
| 845 | + }, | ||
| 846 | + t(lang, Key::NewestFirst), | ||
| 847 | + if dir == events::Dir::Oldest { | ||
| 848 | + " selected" | ||
| 849 | + } else { | ||
| 850 | + "" | ||
| 851 | + }, | ||
| 852 | + t(lang, Key::OldestFirst), | ||
| 853 | + ), | ||
| 618 | )) | 854 | )) |
| 619 | } | 855 | } |
| 620 | 856 | ||
| @@ -892,15 +1128,15 @@ async fn message(cx: &Cx, Form(input): Form<MessageForm>) -> Result<Response> { | |||
| 892 | }; | 1128 | }; |
| 893 | let store = &app(cx).store; | 1129 | let store = &app(cx).store; |
| 894 | if !settings::smtp(store).await?.configured() { | 1130 | if !settings::smtp(store).await?.configured() { |
| 895 | - return back(cx, "mail", "&error=sender_unset"); | 1131 | + return back(cx, "message", "&error=sender_unset"); |
| 896 | } | 1132 | } |
| 897 | let subject = input.subject.trim(); | 1133 | let subject = input.subject.trim(); |
| 898 | if subject.is_empty() { | 1134 | if subject.is_empty() { |
| 899 | - return back(cx, "mail", "&error=empty_subject"); | 1135 | + return back(cx, "message", "&error=empty_subject"); |
| 900 | } | 1136 | } |
| 901 | let body = input.body.trim(); | 1137 | let body = input.body.trim(); |
| 902 | if body.is_empty() { | 1138 | if body.is_empty() { |
| 903 | - return back(cx, "mail", "&error=empty_body"); | 1139 | + return back(cx, "message", "&error=empty_body"); |
| 904 | } | 1140 | } |
| 905 | let users = accounts::list_users(store).await?; | 1141 | let users = accounts::list_users(store).await?; |
| 906 | let recipients: Vec<String> = if input.to == "everyone" { | 1142 | let recipients: Vec<String> = if input.to == "everyone" { |
| @@ -915,18 +1151,18 @@ async fn message(cx: &Cx, Form(input): Form<MessageForm>) -> Result<Response> { | |||
| 915 | .find(|person| person.id.as_str() == input.to) | 1151 | .find(|person| person.id.as_str() == input.to) |
| 916 | { | 1152 | { |
| 917 | Some(person) => vec![person.email], | 1153 | Some(person) => vec![person.email], |
| 918 | - None => return back(cx, "mail", "&error=no_such_user"), | 1154 | + None => return back(cx, "message", "&error=no_such_user"), |
| 919 | } | 1155 | } |
| 920 | }; | 1156 | }; |
| 921 | if recipients.is_empty() { | 1157 | if recipients.is_empty() { |
| 922 | - return back(cx, "mail", "&error=no_such_user"); | 1158 | + return back(cx, "message", "&error=no_such_user"); |
| 923 | } | 1159 | } |
| 924 | for recipient in &recipients { | 1160 | for recipient in &recipients { |
| 925 | if let Err(e) = mailer::send_message(store, recipient, subject, body.to_string()).await { | 1161 | if let Err(e) = mailer::send_message(store, recipient, subject, body.to_string()).await { |
| 926 | server::log_event(cx, "message_failed", Some(&me.email), Some(&e.to_string())).await; | 1162 | server::log_event(cx, "message_failed", Some(&me.email), Some(&e.to_string())).await; |
| 927 | return back( | 1163 | return back( |
| 928 | cx, | 1164 | cx, |
| 929 | - "mail", | 1165 | + "message", |
| 930 | &format!( | 1166 | &format!( |
| 931 | "&error=message&why={}", | 1167 | "&error=message&why={}", |
| 932 | crate::oidc::urlencode(&e.to_string()) | 1168 | crate::oidc::urlencode(&e.to_string()) |
| @@ -935,7 +1171,7 @@ async fn message(cx: &Cx, Form(input): Form<MessageForm>) -> Result<Response> { | |||
| 935 | } | 1171 | } |
| 936 | } | 1172 | } |
| 937 | server::log_event(cx, "message_sent", Some(&me.email), Some(subject)).await; | 1173 | server::log_event(cx, "message_sent", Some(&me.email), Some(subject)).await; |
| 938 | - back(cx, "mail", "&ok=message") | 1174 | + back(cx, "message", "&ok=message") |
| 939 | } | 1175 | } |
| 940 | /// Dials the mail server without sending, on an admin's say-so, and writes | 1176 | /// Dials the mail server without sending, on an admin's say-so, and writes |
| 941 | /// down what it said. The result shows on the Mail section as the standing | 1177 | /// down what it said. The result shows on the Mail section as the standing |
crates/im-web/src/i18n.rsmodified+81 -0
| @@ -144,6 +144,7 @@ pub enum Key { | |||
| 144 | NavMail, | 144 | NavMail, |
| 145 | NavSettings, | 145 | NavSettings, |
| 146 | NavLogs, | 146 | NavLogs, |
| 147 | + NavMessage, | ||
| 147 | OkInvited, | 148 | OkInvited, |
| 148 | OkRevoked, | 149 | OkRevoked, |
| 149 | OkDisabled, | 150 | OkDisabled, |
| @@ -168,6 +169,19 @@ pub enum Key { | |||
| 168 | ErrMessageFailed, | 169 | ErrMessageFailed, |
| 169 | ErrSenderUnset, | 170 | ErrSenderUnset, |
| 170 | 171 | ||
| 172 | + // Logs filtering and paging. | ||
| 173 | + AllOption, | ||
| 174 | + KindLabel, | ||
| 175 | + ActorLabel, | ||
| 176 | + FromLabel, | ||
| 177 | + ToLabel, | ||
| 178 | + NewestFirst, | ||
| 179 | + OldestFirst, | ||
| 180 | + NewerLink, | ||
| 181 | + OlderLink, | ||
| 182 | + LogsEmpty, | ||
| 183 | + OrderLabel, | ||
| 184 | + | ||
| 171 | // Landing password pane. | 185 | // Landing password pane. |
| 172 | AccountPasswordNote, | 186 | AccountPasswordNote, |
| 173 | 187 | ||
| @@ -465,6 +479,8 @@ pub fn t(lang: Lang, key: Key) -> &'static str { | |||
| 465 | (NavSettings, Tr) => "Ayarlar", | 479 | (NavSettings, Tr) => "Ayarlar", |
| 466 | (NavLogs, En) => "Logs", | 480 | (NavLogs, En) => "Logs", |
| 467 | (NavLogs, Tr) => "Kayıtlar", | 481 | (NavLogs, Tr) => "Kayıtlar", |
| 482 | + (NavMessage, En) => "Message", | ||
| 483 | + (NavMessage, Tr) => "Mesaj", | ||
| 468 | (OkInvited, En) => "Invite created.", | 484 | (OkInvited, En) => "Invite created.", |
| 469 | (OkInvited, Tr) => "Davet oluşturuldu.", | 485 | (OkInvited, Tr) => "Davet oluşturuldu.", |
| 470 | (OkRevoked, En) => "Sessions revoked — every device is signed out.", | 486 | (OkRevoked, En) => "Sessions revoked — every device is signed out.", |
| @@ -509,6 +525,29 @@ pub fn t(lang: Lang, key: Key) -> &'static str { | |||
| 509 | (ErrSenderUnset, En) => "Set up the sender above first.", | 525 | (ErrSenderUnset, En) => "Set up the sender above first.", |
| 510 | (ErrSenderUnset, Tr) => "Önce yukarıdan göndereni kur.", | 526 | (ErrSenderUnset, Tr) => "Önce yukarıdan göndereni kur.", |
| 511 | 527 | ||
| 528 | + (AllOption, En) => "All", | ||
| 529 | + (AllOption, Tr) => "Tümü", | ||
| 530 | + (KindLabel, En) => "Kind", | ||
| 531 | + (KindLabel, Tr) => "Tür", | ||
| 532 | + (ActorLabel, En) => "Actor", | ||
| 533 | + (ActorLabel, Tr) => "Yapan", | ||
| 534 | + (FromLabel, En) => "From", | ||
| 535 | + (FromLabel, Tr) => "Başlangıç", | ||
| 536 | + (ToLabel, En) => "To", | ||
| 537 | + (ToLabel, Tr) => "Bitiş", | ||
| 538 | + (NewestFirst, En) => "Newest first", | ||
| 539 | + (NewestFirst, Tr) => "Önce en yeni", | ||
| 540 | + (OldestFirst, En) => "Oldest first", | ||
| 541 | + (OldestFirst, Tr) => "Önce en eski", | ||
| 542 | + (NewerLink, En) => "← Newer", | ||
| 543 | + (NewerLink, Tr) => "← Daha yeni", | ||
| 544 | + (OlderLink, En) => "Older →", | ||
| 545 | + (OlderLink, Tr) => "Daha eski →", | ||
| 546 | + (LogsEmpty, En) => "Nothing matches.", | ||
| 547 | + (OrderLabel, En) => "Order", | ||
| 548 | + (OrderLabel, Tr) => "Sıra", | ||
| 549 | + (LogsEmpty, Tr) => "Eşleşen kayıt yok.", | ||
| 550 | + | ||
| 512 | (AccountPasswordNote, En) => "Changing it signs every other device out — this one stays.", | 551 | (AccountPasswordNote, En) => "Changing it signs every other device out — this one stays.", |
| 513 | (AccountPasswordNote, Tr) => { | 552 | (AccountPasswordNote, Tr) => { |
| 514 | "Değiştirince diğer tüm cihazların oturumu kapanır — bu cihaz açık kalır." | 553 | "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 { | |||
| 702 | } | 741 | } |
| 703 | } | 742 | } |
| 704 | 743 | ||
| 744 | +/// A log row's kind as a word, izlek's `activity_kind_word`: the stored | ||
| 745 | +/// string is the stable identifier, the words are presentation. A kind this | ||
| 746 | +/// build does not know shows as itself. | ||
| 747 | +pub fn kind_word(lang: Lang, kind: &str) -> String { | ||
| 748 | + let pair = match kind { | ||
| 749 | + "login_ok" => ("Sign-in", "Giriş"), | ||
| 750 | + "login_fail" => ("Failed sign-in", "Başarısız giriş"), | ||
| 751 | + "login_limited" => ("Rate-limited sign-in", "Sınırlanmış giriş"), | ||
| 752 | + "totp_fail" => ("Failed 2FA code", "Başarısız 2FA kodu"), | ||
| 753 | + "invite_accepted" => ("Invite accepted", "Davet kabul edildi"), | ||
| 754 | + "invite_created" => ("Invite created", "Davet oluşturuldu"), | ||
| 755 | + "invite_revoked" => ("Invite revoked", "Davet iptal edildi"), | ||
| 756 | + "enrolled" => ("2FA set up", "2FA kuruldu"), | ||
| 757 | + "logout" => ("Sign-out", "Çıkış"), | ||
| 758 | + "reset_sent" => ("Reset mail sent", "Sıfırlama postası gönderildi"), | ||
| 759 | + "password_reset" => ("Password reset", "Parola sıfırlandı"), | ||
| 760 | + "password_changed" => ("Password changed", "Parola değiştirildi"), | ||
| 761 | + "session_revoked" => ("Session revoked", "Oturum kapatıldı"), | ||
| 762 | + "sessions_revoked" => ("Sessions revoked", "Oturumlar kapatıldı"), | ||
| 763 | + "preferences_saved" => ("Preferences saved", "Tercihler kaydedildi"), | ||
| 764 | + "photo_saved" => ("Photo updated", "Fotoğraf güncellendi"), | ||
| 765 | + "photo_removed" => ("Photo removed", "Fotoğraf kaldırıldı"), | ||
| 766 | + "code_exchanged" => ("App sign-in", "Uygulama girişi"), | ||
| 767 | + "settings_updated" => ("Settings updated", "Ayarlar güncellendi"), | ||
| 768 | + "user_deleted" => ("User deleted", "Kullanıcı silindi"), | ||
| 769 | + "user_disabled" => ("User disabled", "Kullanıcı devre dışı"), | ||
| 770 | + "user_enabled" => ("User enabled", "Kullanıcı etkin"), | ||
| 771 | + "user_promoted" => ("Admin granted", "Yönetici yetkisi verildi"), | ||
| 772 | + "smtp_updated" => ("Mail settings saved", "Posta ayarları kaydedildi"), | ||
| 773 | + "smtp_test_sent" => ("Test mail sent", "Test postası gönderildi"), | ||
| 774 | + "smtp_test_failed" => ("Test mail failed", "Test postası başarısız"), | ||
| 775 | + "smtp_checked" => ("Mail server checked", "Posta sunucusu denetlendi"), | ||
| 776 | + "message_sent" => ("Message sent", "Mesaj gönderildi"), | ||
| 777 | + "message_failed" => ("Message failed", "Mesaj başarısız"), | ||
| 778 | + _ => return kind.to_string(), | ||
| 779 | + }; | ||
| 780 | + match lang { | ||
| 781 | + Lang::En => pair.0.to_string(), | ||
| 782 | + Lang::Tr => pair.1.to_string(), | ||
| 783 | + } | ||
| 784 | +} | ||
| 785 | + | ||
| 705 | /// A pending invite's "waiting · until <date>" cell, in the viewer's language. | 786 | /// A pending invite's "waiting · until <date>" cell, in the viewer's language. |
| 706 | pub fn waiting_label(lang: Lang, date: &str) -> String { | 787 | pub fn waiting_label(lang: Lang, date: &str) -> String { |
| 707 | match lang { | 788 | match lang { |
crates/im-web/src/layout.rsmodified+8 -0
| @@ -277,6 +277,14 @@ pub async fn soft_nav_script(cx: &Cx) -> Result { | |||
| 277 | 277 | ||
| 278 | window.addEventListener('popstate', function () { go(location.pathname + location.search, false, false); }); | 278 | window.addEventListener('popstate', function () { go(location.pathname + location.search, false, false); }); |
| 279 | 279 | ||
| 280 | + // Filter controls submit their form on pick; file inputs with | ||
| 281 | + // data-autosubmit belong to the avatar script's uploader, not to this. | ||
| 282 | + document.addEventListener('change', function (e) { | ||
| 283 | + var c = e.target && e.target.closest ? e.target.closest('[data-autosubmit]') : null; | ||
| 284 | + if (!c || !c.form || c.type === 'file') { return; } | ||
| 285 | + c.form.requestSubmit(); | ||
| 286 | + }); | ||
| 287 | + | ||
| 280 | window.__imRefresh = function () { | 288 | window.__imRefresh = function () { |
| 281 | var active = document.activeElement; | 289 | var active = document.activeElement; |
| 282 | if (active && /^(INPUT|SELECT|TEXTAREA)$/.test(active.tagName)) { return; } | 290 | if (active && /^(INPUT|SELECT|TEXTAREA)$/.test(active.tagName)) { return; } |
style/main.scssmodified+37 -3
| @@ -808,18 +808,21 @@ textarea.auth-input { | |||
| 808 | } | 808 | } |
| 809 | 809 | ||
| 810 | // --- Admin panel ------------------------------------------------------------ | 810 | // --- Admin panel ------------------------------------------------------------ |
| 811 | -// Same skin, different posture: top-anchored and wider than the auth stage — | 811 | +// Same skin, same posture as the landing: the bar holds the landing's line |
| 812 | -// a tool, not a gate. | 812 | +// (the tallest-section centre line) so the mouse never moves between the two |
| 813 | +// panels, and the scrollbar's gutter is reserved so a section that grows a | ||
| 814 | +// scrollbar does not push the bar sideways. | ||
| 813 | 815 | ||
| 814 | body:has(.admin-shell) { | 816 | body:has(.admin-shell) { |
| 815 | min-height: 100vh; | 817 | min-height: 100vh; |
| 816 | min-height: 100dvh; | 818 | min-height: 100dvh; |
| 819 | + scrollbar-gutter: stable; | ||
| 817 | } | 820 | } |
| 818 | 821 | ||
| 819 | .admin-shell { | 822 | .admin-shell { |
| 820 | display: flex; | 823 | display: flex; |
| 821 | justify-content: center; | 824 | justify-content: center; |
| 822 | - padding: 24px 24px 48px; | 825 | + padding: max(24px, calc((100dvh - 640px) / 2)) 24px 48px; |
| 823 | } | 826 | } |
| 824 | 827 | ||
| 825 | .admin-column { | 828 | .admin-column { |
| @@ -885,6 +888,37 @@ a.wordmark-home { | |||
| 885 | overflow-x: auto; | 888 | overflow-x: auto; |
| 886 | } | 889 | } |
| 887 | 890 | ||
| 891 | +// The logs filter row: five small fields in one wrapping line; a page turn's | ||
| 892 | +// foot splits the position note from the Newer/Older links. | ||
| 893 | +.logs-filters { | ||
| 894 | + display: flex; | ||
| 895 | + flex-wrap: wrap; | ||
| 896 | + gap: 10px 14px; | ||
| 897 | + | ||
| 898 | + .auth-field { | ||
| 899 | + flex: 1 1 120px; | ||
| 900 | + min-width: 0; | ||
| 901 | + } | ||
| 902 | +} | ||
| 903 | + | ||
| 904 | +.logs-foot { | ||
| 905 | + display: flex; | ||
| 906 | + align-items: center; | ||
| 907 | + justify-content: space-between; | ||
| 908 | + gap: 12px; | ||
| 909 | + | ||
| 910 | + .log-count { | ||
| 911 | + font-family: var(--font-mono); | ||
| 912 | + font-size: 11px; | ||
| 913 | + color: var(--muted-soft); | ||
| 914 | + } | ||
| 915 | + | ||
| 916 | + .logs-links { | ||
| 917 | + display: flex; | ||
| 918 | + gap: 16px; | ||
| 919 | + } | ||
| 920 | +} | ||
| 921 | + | ||
| 888 | .admin-table { | 922 | .admin-table { |
| 889 | width: 100%; | 923 | width: 100%; |
| 890 | border-collapse: collapse; | 924 | border-collapse: collapse; |