The log answers questions — who, what, which, when, how many
Browse files at this commitc3fa33408f79c301c275535c4b202965a56e5ba8Parent: 0f59cb4- feat
- the log answers questions — who, what, which, when, how many
9 changed files +939 -77
- crates/izlek-core/src/store/mod.rs +61 -2
- crates/izlek-core/src/store/turso_store.rs +176 -27
- crates/izlek-core/tests/store.rs +59 -4
- crates/izlek-web/src/detail.rs +12 -5
- crates/izlek-web/src/i18n.rs +15 -0
- crates/izlek-web/src/logs.rs +296 -37
- crates/izlek-web/src/server.rs +7 -0
- crates/izlek-web/tests/http.rs +294 -2
- style/main.scss +19 -0
crates/izlek-core/src/store/mod.rsmodified+61 -2
| @@ -442,6 +442,31 @@ pub enum FeedPage { | |||
| 442 | After(FeedCursor), | 442 | After(FeedCursor), |
| 443 | } | 443 | } |
| 444 | 444 | ||
| 445 | +/// Which end of the activity feed reading order starts at. `Before` always | ||
| 446 | +/// means further along in this order (an "Older" turn from `Newest`, a | ||
| 447 | +/// "toward the end" turn from `Oldest`); `After` always means back toward | ||
| 448 | +/// the start — the two feel symmetric to the reader regardless of which | ||
| 449 | +/// direction is currently in play. | ||
| 450 | +#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] | ||
| 451 | +pub enum Dir { | ||
| 452 | + Newest, | ||
| 453 | + Oldest, | ||
| 454 | +} | ||
| 455 | + | ||
| 456 | +/// The activity tab's narrowing: every field is an AND'd equality (or a | ||
| 457 | +/// half-open range for `day`), and an absent field matches everything. | ||
| 458 | +#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)] | ||
| 459 | +pub struct ActivityFilter { | ||
| 460 | + /// A user id, or the literal `"system"` for a row with no actor. | ||
| 461 | + pub actor: Option<String>, | ||
| 462 | + /// An `ActivityKind::as_str()` value. | ||
| 463 | + pub kind: Option<String>, | ||
| 464 | + pub task_key: Option<String>, | ||
| 465 | + /// Half-open `[start, end)` in UTC, already resolved from the admin's | ||
| 466 | + /// timezone. | ||
| 467 | + pub day: Option<(OffsetDateTime, OffsetDateTime)>, | ||
| 468 | +} | ||
| 469 | + | ||
| 445 | /// A deletion that freed something, kept so a mail owed because of it can be | 470 | /// A deletion that freed something, kept so a mail owed because of it can be |
| 446 | /// rebuilt later. The task it names is gone by the time anyone reads this, so | 471 | /// rebuilt later. The task it names is gone by the time anyone reads this, so |
| 447 | /// its key and title are copied rather than looked up. | 472 | /// its key and title are copied rather than looked up. |
| @@ -982,11 +1007,45 @@ pub trait Store: BoardReads + DetailReads + 'static { | |||
| 982 | /// failed and may be tried again. | 1007 | /// failed and may be tried again. |
| 983 | async fn mail_queue(&self, limit: u32, page: FeedPage) -> Result<Vec<MailSend>>; | 1008 | async fn mail_queue(&self, limit: u32, page: FeedPage) -> Result<Vec<MailSend>>; |
| 984 | 1009 | ||
| 1010 | + /// How many rows `mail_queue` draws from, unpaged — for the tab's | ||
| 1011 | + /// position note. | ||
| 1012 | + async fn count_mail_queue(&self) -> Result<u64>; | ||
| 1013 | + | ||
| 1014 | + /// How many queue rows sit strictly ahead of `cursor` in the queue's own | ||
| 1015 | + /// order (soonest first); `None` (the newest page) is `0`. | ||
| 1016 | + async fn count_mail_queue_preceding(&self, cursor: Option<&FeedCursor>) -> Result<u64>; | ||
| 1017 | + | ||
| 985 | /// Every send, whatever its state, newest first. | 1018 | /// Every send, whatever its state, newest first. |
| 986 | async fn recent_sends(&self, limit: u32) -> Result<Vec<MailSend>>; | 1019 | async fn recent_sends(&self, limit: u32) -> Result<Vec<MailSend>>; |
| 987 | 1020 | ||
| 988 | - /// The workspace's activity feed across every task, newest first. | 1021 | + /// How many decisions there are in all, unpaged. |
| 989 | - async fn recent_activity(&self, limit: u32, page: FeedPage) -> Result<Vec<ActivityLine>>; | 1022 | + async fn count_mail_decisions(&self) -> Result<u64>; |
| 1023 | + | ||
| 1024 | + /// How many decision rows sit strictly ahead of `cursor` in the | ||
| 1025 | + /// decisions' own order (newest first); `None` is `0`. | ||
| 1026 | + async fn count_mail_decisions_preceding(&self, cursor: Option<&FeedCursor>) -> Result<u64>; | ||
| 1027 | + | ||
| 1028 | + /// The workspace's activity feed across every task, matching `filter`, | ||
| 1029 | + /// ordered per `dir`. | ||
| 1030 | + async fn recent_activity( | ||
| 1031 | + &self, | ||
| 1032 | + limit: u32, | ||
| 1033 | + page: FeedPage, | ||
| 1034 | + dir: Dir, | ||
| 1035 | + filter: &ActivityFilter, | ||
| 1036 | + ) -> Result<Vec<ActivityLine>>; | ||
| 1037 | + | ||
| 1038 | + /// How many activity rows match `filter`, unpaged. | ||
| 1039 | + async fn count_activity(&self, filter: &ActivityFilter) -> Result<u64>; | ||
| 1040 | + | ||
| 1041 | + /// How many rows matching `filter` sit strictly ahead of `cursor` in | ||
| 1042 | + /// `dir`'s reading order; `None` (the newest/oldest page) is `0`. | ||
| 1043 | + async fn count_activity_preceding( | ||
| 1044 | + &self, | ||
| 1045 | + filter: &ActivityFilter, | ||
| 1046 | + dir: Dir, | ||
| 1047 | + cursor: Option<&FeedCursor>, | ||
| 1048 | + ) -> Result<u64>; | ||
| 990 | 1049 | ||
| 991 | // -- who gets mailed --------------------------------------------------- | 1050 | // -- who gets mailed --------------------------------------------------- |
| 992 | 1051 | ||
crates/izlek-core/src/store/turso_store.rsmodified+176 -27
| @@ -10,15 +10,15 @@ use rand::Rng; | |||
| 10 | use time::OffsetDateTime; | 10 | use time::OffsetDateTime; |
| 11 | use time::format_description::well_known::Rfc3339; | 11 | use time::format_description::well_known::Rfc3339; |
| 12 | use turso::transaction::TransactionBehavior; | 12 | use turso::transaction::TransactionBehavior; |
| 13 | -use turso::{Builder, Connection, Row, params}; | 13 | +use turso::{Builder, Connection, Row, Value, params}; |
| 14 | use ulid::Ulid; | 14 | use ulid::Ulid; |
| 15 | 15 | ||
| 16 | use super::secret; | 16 | use super::secret; |
| 17 | use super::{ | 17 | use super::{ |
| 18 | - ActivityEvent, ActivityLine, Attachment, Audience, CommentWritten, Deletion, Event, FeedPage, | 18 | + ActivityEvent, ActivityFilter, ActivityLine, Attachment, Audience, CommentWritten, Deletion, |
| 19 | - Freeing, MailDecision, MailOutcome, MailRule, MailSend, NewAttachment, NewSender, NewTask, | 19 | + Dir, Event, FeedCursor, FeedPage, Freeing, MailDecision, MailOutcome, MailRule, MailSend, |
| 20 | - NewUser, Recipient, Result, SendKind, SendState, SenderTest, Session, SigninLink, Store, | 20 | + NewAttachment, NewSender, NewTask, NewUser, Recipient, Result, SendKind, SendState, |
| 21 | - StoreError, TaskCreated, Trigger, User, Workspace, | 21 | + SenderTest, Session, SigninLink, Store, StoreError, TaskCreated, Trigger, User, Workspace, |
| 22 | }; | 22 | }; |
| 23 | use crate::Role; | 23 | use crate::Role; |
| 24 | use crate::board::{BoardMeta, BoardReads, Column, Moved, Person, TaskRow, Transition}; | 24 | use crate::board::{BoardMeta, BoardReads, Column, Moved, Person, TaskRow, Transition}; |
| @@ -530,6 +530,41 @@ fn count_of(row: &Row) -> Result<u64> { | |||
| 530 | row.get::<i64>(0).map_err(backend).map(|n| n.max(0) as u64) | 530 | row.get::<i64>(0).map_err(backend).map(|n| n.max(0) as u64) |
| 531 | } | 531 | } |
| 532 | 532 | ||
| 533 | +/// The activity filter's AND clauses, as SQL text (leading `AND `, empty | ||
| 534 | +/// when the filter matches everything) and the values it binds, in the order | ||
| 535 | +/// the placeholders appear. | ||
| 536 | +fn activity_filter_sql(filter: &ActivityFilter) -> Result<(String, Vec<Value>)> { | ||
| 537 | + let mut clauses: Vec<String> = Vec::new(); | ||
| 538 | + let mut vals: Vec<Value> = Vec::new(); | ||
| 539 | + match filter.actor.as_deref() { | ||
| 540 | + Some("system") => clauses.push("a.actor_id IS NULL".to_string()), | ||
| 541 | + Some(actor) => { | ||
| 542 | + clauses.push("a.actor_id = ?".to_string()); | ||
| 543 | + vals.push(actor.to_string().into()); | ||
| 544 | + } | ||
| 545 | + None => {} | ||
| 546 | + } | ||
| 547 | + if let Some(kind) = &filter.kind { | ||
| 548 | + clauses.push("a.kind = ?".to_string()); | ||
| 549 | + vals.push(kind.clone().into()); | ||
| 550 | + } | ||
| 551 | + if let Some(task_key) = &filter.task_key { | ||
| 552 | + clauses.push("t.task_key = ?".to_string()); | ||
| 553 | + vals.push(task_key.clone().into()); | ||
| 554 | + } | ||
| 555 | + if let Some((start, end)) = &filter.day { | ||
| 556 | + clauses.push("(a.created_at >= ? AND a.created_at < ?)".to_string()); | ||
| 557 | + vals.push(stamp(*start)?.into()); | ||
| 558 | + vals.push(stamp(*end)?.into()); | ||
| 559 | + } | ||
| 560 | + let sql = if clauses.is_empty() { | ||
| 561 | + String::new() | ||
| 562 | + } else { | ||
| 563 | + format!(" AND {}", clauses.join(" AND ")) | ||
| 564 | + }; | ||
| 565 | + Ok((sql, vals)) | ||
| 566 | +} | ||
| 567 | + | ||
| 533 | fn workspace_from(row: &Row) -> Result<Workspace> { | 568 | fn workspace_from(row: &Row) -> Result<Workspace> { |
| 534 | let types_json = text(row, 4)?; | 569 | let types_json = text(row, 4)?; |
| 535 | let allowed_file_types: Vec<String> = if types_json.trim().is_empty() { | 570 | let allowed_file_types: Vec<String> = if types_json.trim().is_empty() { |
| @@ -2732,6 +2767,25 @@ impl Store for TursoStore { | |||
| 2732 | Ok(out) | 2767 | Ok(out) |
| 2733 | } | 2768 | } |
| 2734 | 2769 | ||
| 2770 | + async fn count_mail_decisions(&self) -> Result<u64> { | ||
| 2771 | + let row = self | ||
| 2772 | + .one_row("SELECT COUNT(*) FROM mail_decision", ()) | ||
| 2773 | + .await?; | ||
| 2774 | + row.as_ref().map(count_of).unwrap_or(Ok(0)) | ||
| 2775 | + } | ||
| 2776 | + | ||
| 2777 | + async fn count_mail_decisions_preceding(&self, cursor: Option<&FeedCursor>) -> Result<u64> { | ||
| 2778 | + let Some(cursor) = cursor else { return Ok(0) }; | ||
| 2779 | + let row = self | ||
| 2780 | + .one_row( | ||
| 2781 | + "SELECT COUNT(*) FROM mail_decision \ | ||
| 2782 | + WHERE created_at > ?1 OR (created_at = ?1 AND id > ?2)", | ||
| 2783 | + params![stamp(cursor.at)?, cursor.id.clone()], | ||
| 2784 | + ) | ||
| 2785 | + .await?; | ||
| 2786 | + row.as_ref().map(count_of).unwrap_or(Ok(0)) | ||
| 2787 | + } | ||
| 2788 | + | ||
| 2735 | async fn mail_rule_last_decision(&self) -> Result<Vec<(String, OffsetDateTime)>> { | 2789 | async fn mail_rule_last_decision(&self) -> Result<Vec<(String, OffsetDateTime)>> { |
| 2736 | let conn = self.conn.lock().await; | 2790 | let conn = self.conn.lock().await; |
| 2737 | let mut rows = conn | 2791 | let mut rows = conn |
| @@ -2801,6 +2855,28 @@ impl Store for TursoStore { | |||
| 2801 | Ok(out) | 2855 | Ok(out) |
| 2802 | } | 2856 | } |
| 2803 | 2857 | ||
| 2858 | + async fn count_mail_queue(&self) -> Result<u64> { | ||
| 2859 | + let row = self | ||
| 2860 | + .one_row( | ||
| 2861 | + "SELECT COUNT(*) FROM mail_send WHERE state IN ('pending', 'failed')", | ||
| 2862 | + (), | ||
| 2863 | + ) | ||
| 2864 | + .await?; | ||
| 2865 | + row.as_ref().map(count_of).unwrap_or(Ok(0)) | ||
| 2866 | + } | ||
| 2867 | + | ||
| 2868 | + async fn count_mail_queue_preceding(&self, cursor: Option<&FeedCursor>) -> Result<u64> { | ||
| 2869 | + let Some(cursor) = cursor else { return Ok(0) }; | ||
| 2870 | + let row = self | ||
| 2871 | + .one_row( | ||
| 2872 | + "SELECT COUNT(*) FROM mail_send WHERE state IN ('pending', 'failed') \ | ||
| 2873 | + AND (next_attempt_at < ?1 OR (next_attempt_at = ?1 AND id < ?2))", | ||
| 2874 | + params![stamp(cursor.at)?, cursor.id.clone()], | ||
| 2875 | + ) | ||
| 2876 | + .await?; | ||
| 2877 | + row.as_ref().map(count_of).unwrap_or(Ok(0)) | ||
| 2878 | + } | ||
| 2879 | + | ||
| 2804 | async fn recent_sends(&self, limit: u32) -> Result<Vec<MailSend>> { | 2880 | async fn recent_sends(&self, limit: u32) -> Result<Vec<MailSend>> { |
| 2805 | let conn = self.conn.lock().await; | 2881 | let conn = self.conn.lock().await; |
| 2806 | let sql = format!( | 2882 | let sql = format!( |
| @@ -2817,42 +2893,76 @@ impl Store for TursoStore { | |||
| 2817 | Ok(out) | 2893 | Ok(out) |
| 2818 | } | 2894 | } |
| 2819 | 2895 | ||
| 2820 | - async fn recent_activity(&self, limit: u32, page: FeedPage) -> Result<Vec<ActivityLine>> { | 2896 | + async fn recent_activity( |
| 2897 | + &self, | ||
| 2898 | + limit: u32, | ||
| 2899 | + page: FeedPage, | ||
| 2900 | + dir: Dir, | ||
| 2901 | + filter: &ActivityFilter, | ||
| 2902 | + ) -> Result<Vec<ActivityLine>> { | ||
| 2821 | const SELECT: &str = "SELECT a.id, a.task_id, t.title, u.display_name, a.kind, a.detail, \ | 2903 | const SELECT: &str = "SELECT a.id, a.task_id, t.title, u.display_name, a.kind, a.detail, \ |
| 2822 | a.created_at FROM activity a \ | 2904 | a.created_at FROM activity a \ |
| 2823 | LEFT JOIN task t ON t.id = a.task_id \ | 2905 | LEFT JOIN task t ON t.id = a.task_id \ |
| 2824 | LEFT JOIN user u ON u.id = a.actor_id"; | 2906 | LEFT JOIN user u ON u.id = a.actor_id"; |
| 2825 | let conn = self.conn.lock().await; | 2907 | let conn = self.conn.lock().await; |
| 2908 | + let (filter_sql, filter_vals) = activity_filter_sql(filter)?; | ||
| 2909 | + // The base order is the feed's own reading direction; `After` scans | ||
| 2910 | + // the opposite way (back toward the start) and the caller reverses | ||
| 2911 | + // the page below to restore it. | ||
| 2912 | + let base = match dir { | ||
| 2913 | + Dir::Newest => "DESC", | ||
| 2914 | + Dir::Oldest => "ASC", | ||
| 2915 | + }; | ||
| 2916 | + let opp = match dir { | ||
| 2917 | + Dir::Newest => "ASC", | ||
| 2918 | + Dir::Oldest => "DESC", | ||
| 2919 | + }; | ||
| 2826 | let reverse = matches!(page, FeedPage::After(_)); | 2920 | let reverse = matches!(page, FeedPage::After(_)); |
| 2827 | - let mut rows = match &page { | 2921 | + let mut vals: Vec<Value> = Vec::new(); |
| 2922 | + let sql = match &page { | ||
| 2828 | FeedPage::Newest => { | 2923 | FeedPage::Newest => { |
| 2829 | - let sql = format!("{SELECT} ORDER BY a.created_at DESC, a.id DESC LIMIT ?1"); | 2924 | + vals.extend(filter_vals); |
| 2830 | - conn.query(&sql, params![i64::from(limit)]).await | 2925 | + vals.push(i64::from(limit).into()); |
| 2926 | + format!("{SELECT} WHERE 1=1{filter_sql} ORDER BY a.created_at {base}, a.id {base} LIMIT ?") | ||
| 2831 | } | 2927 | } |
| 2832 | FeedPage::Before(cursor) => { | 2928 | FeedPage::Before(cursor) => { |
| 2833 | - let sql = format!( | 2929 | + // Further along in `dir`'s reading order: older when |
| 2834 | - "{SELECT} WHERE a.created_at < ?2 OR (a.created_at = ?2 AND a.id < ?3) \ | 2930 | + // Newest, newer when Oldest. |
| 2835 | - ORDER BY a.created_at DESC, a.id DESC LIMIT ?1" | 2931 | + let cmp = match dir { |
| 2836 | - ); | 2932 | + Dir::Newest => "<", |
| 2837 | - conn.query( | 2933 | + Dir::Oldest => ">", |
| 2838 | - &sql, | 2934 | + }; |
| 2839 | - params![i64::from(limit), stamp(cursor.at)?, cursor.id.clone()], | 2935 | + let at = stamp(cursor.at)?; |
| 2936 | + vals.push(at.clone().into()); | ||
| 2937 | + vals.push(at.into()); | ||
| 2938 | + vals.push(cursor.id.clone().into()); | ||
| 2939 | + vals.extend(filter_vals); | ||
| 2940 | + vals.push(i64::from(limit).into()); | ||
| 2941 | + format!( | ||
| 2942 | + "{SELECT} WHERE (a.created_at {cmp} ? OR (a.created_at = ? AND a.id {cmp} ?)){filter_sql} \ | ||
| 2943 | + ORDER BY a.created_at {base}, a.id {base} LIMIT ?" | ||
| 2840 | ) | 2944 | ) |
| 2841 | - .await | ||
| 2842 | } | 2945 | } |
| 2843 | FeedPage::After(cursor) => { | 2946 | FeedPage::After(cursor) => { |
| 2844 | - let sql = format!( | 2947 | + // Back toward the start: newer when Newest, older when |
| 2845 | - "{SELECT} WHERE a.created_at > ?2 OR (a.created_at = ?2 AND a.id > ?3) \ | 2948 | + // Oldest — scanned in the opposite order, then reversed. |
| 2846 | - ORDER BY a.created_at ASC, a.id ASC LIMIT ?1" | 2949 | + let cmp = match dir { |
| 2847 | - ); | 2950 | + Dir::Newest => ">", |
| 2848 | - conn.query( | 2951 | + Dir::Oldest => "<", |
| 2849 | - &sql, | 2952 | + }; |
| 2850 | - params![i64::from(limit), stamp(cursor.at)?, cursor.id.clone()], | 2953 | + let at = stamp(cursor.at)?; |
| 2954 | + vals.push(at.clone().into()); | ||
| 2955 | + vals.push(at.into()); | ||
| 2956 | + vals.push(cursor.id.clone().into()); | ||
| 2957 | + vals.extend(filter_vals); | ||
| 2958 | + vals.push(i64::from(limit).into()); | ||
| 2959 | + format!( | ||
| 2960 | + "{SELECT} WHERE (a.created_at {cmp} ? OR (a.created_at = ? AND a.id {cmp} ?)){filter_sql} \ | ||
| 2961 | + ORDER BY a.created_at {opp}, a.id {opp} LIMIT ?" | ||
| 2851 | ) | 2962 | ) |
| 2852 | - .await | ||
| 2853 | } | 2963 | } |
| 2854 | - } | 2964 | + }; |
| 2855 | - .map_err(backend)?; | 2965 | + let mut rows = conn.query(&sql, vals).await.map_err(backend)?; |
| 2856 | let mut out = Vec::new(); | 2966 | let mut out = Vec::new(); |
| 2857 | while let Some(row) = rows.next().await.map_err(backend)? { | 2967 | while let Some(row) = rows.next().await.map_err(backend)? { |
| 2858 | out.push(ActivityLine { | 2968 | out.push(ActivityLine { |
| @@ -2871,6 +2981,45 @@ impl Store for TursoStore { | |||
| 2871 | Ok(out) | 2981 | Ok(out) |
| 2872 | } | 2982 | } |
| 2873 | 2983 | ||
| 2984 | + async fn count_activity(&self, filter: &ActivityFilter) -> Result<u64> { | ||
| 2985 | + let (filter_sql, filter_vals) = activity_filter_sql(filter)?; | ||
| 2986 | + let sql = format!( | ||
| 2987 | + "SELECT COUNT(*) FROM activity a \ | ||
| 2988 | + LEFT JOIN task t ON t.id = a.task_id \ | ||
| 2989 | + LEFT JOIN user u ON u.id = a.actor_id WHERE 1=1{filter_sql}" | ||
| 2990 | + ); | ||
| 2991 | + let row = self.one_row(&sql, filter_vals).await?; | ||
| 2992 | + row.as_ref().map(count_of).unwrap_or(Ok(0)) | ||
| 2993 | + } | ||
| 2994 | + | ||
| 2995 | + async fn count_activity_preceding( | ||
| 2996 | + &self, | ||
| 2997 | + filter: &ActivityFilter, | ||
| 2998 | + dir: Dir, | ||
| 2999 | + cursor: Option<&FeedCursor>, | ||
| 3000 | + ) -> Result<u64> { | ||
| 3001 | + let Some(cursor) = cursor else { return Ok(0) }; | ||
| 3002 | + let (filter_sql, filter_vals) = activity_filter_sql(filter)?; | ||
| 3003 | + // Preceding = already shown on an earlier page: back toward the | ||
| 3004 | + // start of `dir`'s reading order, the same side `FeedPage::After` | ||
| 3005 | + // reads from. | ||
| 3006 | + let cmp = match dir { | ||
| 3007 | + Dir::Newest => ">", | ||
| 3008 | + Dir::Oldest => "<", | ||
| 3009 | + }; | ||
| 3010 | + let at = stamp(cursor.at)?; | ||
| 3011 | + let mut vals: Vec<Value> = vec![at.clone().into(), at.into(), cursor.id.clone().into()]; | ||
| 3012 | + vals.extend(filter_vals); | ||
| 3013 | + let sql = format!( | ||
| 3014 | + "SELECT COUNT(*) FROM activity a \ | ||
| 3015 | + LEFT JOIN task t ON t.id = a.task_id \ | ||
| 3016 | + LEFT JOIN user u ON u.id = a.actor_id \ | ||
| 3017 | + WHERE (a.created_at {cmp} ? OR (a.created_at = ? AND a.id {cmp} ?)){filter_sql}" | ||
| 3018 | + ); | ||
| 3019 | + let row = self.one_row(&sql, vals).await?; | ||
| 3020 | + row.as_ref().map(count_of).unwrap_or(Ok(0)) | ||
| 3021 | + } | ||
| 3022 | + | ||
| 2874 | // -- who gets mailed --------------------------------------------------- | 3023 | // -- who gets mailed --------------------------------------------------- |
| 2875 | 3024 | ||
| 2876 | async fn recipients_for_task(&self, task_id: &str) -> Result<Vec<Recipient>> { | 3025 | async fn recipients_for_task(&self, task_id: &str) -> Result<Vec<Recipient>> { |
crates/izlek-core/tests/store.rsmodified+59 -4
| @@ -2044,6 +2044,61 @@ async fn add_task( | |||
| 2044 | .id | 2044 | .id |
| 2045 | } | 2045 | } |
| 2046 | 2046 | ||
| 2047 | +/// The counting fns agree with a full read, and a filtered keyset walk | ||
| 2048 | +/// covers exactly the filtered set — no row skipped or repeated. | ||
| 2049 | +#[tokio::test] | ||
| 2050 | +async fn count_and_filtered_keyset_walk_cover_exactly_the_filtered_set() { | ||
| 2051 | + use izlek_core::store::{ActivityFilter, Dir, FeedCursor, FeedPage}; | ||
| 2052 | + | ||
| 2053 | + let (scratch, workspace, admin) = workspace_with_admin().await; | ||
| 2054 | + let store = &scratch.store; | ||
| 2055 | + let other = member(store, &workspace, "sam@izlek.sh", "Sam").await; | ||
| 2056 | + let t0 = OffsetDateTime::now_utc(); | ||
| 2057 | + for i in 0..20 { | ||
| 2058 | + let actor = if i % 2 == 0 { &admin } else { &other }; | ||
| 2059 | + store | ||
| 2060 | + .record_event( | ||
| 2061 | + Some(actor), | ||
| 2062 | + &izlek_core::detail::ActivityKind::Other("row".to_string()), | ||
| 2063 | + &format!("row {i}"), | ||
| 2064 | + t0 + Duration::seconds(i), | ||
| 2065 | + ) | ||
| 2066 | + .await | ||
| 2067 | + .unwrap(); | ||
| 2068 | + } | ||
| 2069 | + | ||
| 2070 | + let filter = ActivityFilter { actor: Some(admin.clone()), ..Default::default() }; | ||
| 2071 | + let total = store.count_activity(&filter).await.unwrap(); | ||
| 2072 | + assert_eq!(total, 10); | ||
| 2073 | + | ||
| 2074 | + let mut walked = Vec::new(); | ||
| 2075 | + let mut page = FeedPage::Newest; | ||
| 2076 | + loop { | ||
| 2077 | + let rows = store | ||
| 2078 | + .recent_activity(3, page, Dir::Newest, &filter) | ||
| 2079 | + .await | ||
| 2080 | + .unwrap(); | ||
| 2081 | + if rows.is_empty() { | ||
| 2082 | + break; | ||
| 2083 | + } | ||
| 2084 | + let last = rows.last().unwrap(); | ||
| 2085 | + page = FeedPage::Before(FeedCursor { at: last.at, id: last.id.clone() }); | ||
| 2086 | + walked.extend(rows); | ||
| 2087 | + } | ||
| 2088 | + assert_eq!(walked.len(), 10); | ||
| 2089 | + assert!(walked.iter().all(|r| r.actor_name.as_deref() == Some("Ada"))); | ||
| 2090 | + | ||
| 2091 | + let preceding = store | ||
| 2092 | + .count_activity_preceding( | ||
| 2093 | + &filter, | ||
| 2094 | + Dir::Newest, | ||
| 2095 | + Some(&FeedCursor { at: walked[3].at, id: walked[3].id.clone() }), | ||
| 2096 | + ) | ||
| 2097 | + .await | ||
| 2098 | + .unwrap(); | ||
| 2099 | + assert_eq!(preceding, 3); | ||
| 2100 | +} | ||
| 2101 | + | ||
| 2047 | #[tokio::test] | 2102 | #[tokio::test] |
| 2048 | async fn a_claimed_workspace_starts_with_four_named_columns() { | 2103 | async fn a_claimed_workspace_starts_with_four_named_columns() { |
| 2049 | let (scratch, workspace, _admin) = workspace_with_admin().await; | 2104 | let (scratch, workspace, _admin) = workspace_with_admin().await; |
| @@ -4732,7 +4787,7 @@ async fn the_activity_feed_is_the_whole_workspace_newest_first() { | |||
| 4732 | .await | 4787 | .await |
| 4733 | .unwrap(); | 4788 | .unwrap(); |
| 4734 | 4789 | ||
| 4735 | - let feed = store.recent_activity(10, izlek_core::store::FeedPage::Newest).await.unwrap(); | 4790 | + let feed = store.recent_activity(10, izlek_core::store::FeedPage::Newest, izlek_core::store::Dir::Newest, &izlek_core::store::ActivityFilter::default()).await.unwrap(); |
| 4736 | // Two "created" lines came free with the two tasks; the two just recorded | 4791 | // Two "created" lines came free with the two tasks; the two just recorded |
| 4737 | // sit newest first, ahead of both of those. | 4792 | // sit newest first, ahead of both of those. |
| 4738 | assert_eq!(feed.len(), 4); | 4793 | assert_eq!(feed.len(), 4); |
| @@ -4768,13 +4823,13 @@ async fn keyset_paging_covers_every_activity_row_once() { | |||
| 4768 | } | 4823 | } |
| 4769 | let _ = workspace; | 4824 | let _ = workspace; |
| 4770 | 4825 | ||
| 4771 | - let whole = store.recent_activity(100, FeedPage::Newest).await.unwrap(); | 4826 | + let whole = store.recent_activity(100, FeedPage::Newest, izlek_core::store::Dir::Newest, &izlek_core::store::ActivityFilter::default()).await.unwrap(); |
| 4772 | assert_eq!(whole.len(), 23); | 4827 | assert_eq!(whole.len(), 23); |
| 4773 | 4828 | ||
| 4774 | let mut walked = Vec::new(); | 4829 | let mut walked = Vec::new(); |
| 4775 | let mut page = FeedPage::Newest; | 4830 | let mut page = FeedPage::Newest; |
| 4776 | loop { | 4831 | loop { |
| 4777 | - let rows = store.recent_activity(7, page).await.unwrap(); | 4832 | + let rows = store.recent_activity(7, page, izlek_core::store::Dir::Newest, &izlek_core::store::ActivityFilter::default()).await.unwrap(); |
| 4778 | if rows.is_empty() { | 4833 | if rows.is_empty() { |
| 4779 | break; | 4834 | break; |
| 4780 | } | 4835 | } |
| @@ -4811,7 +4866,7 @@ async fn an_account_event_rides_the_feed_without_a_task() { | |||
| 4811 | .await | 4866 | .await |
| 4812 | .unwrap(); | 4867 | .unwrap(); |
| 4813 | 4868 | ||
| 4814 | - let feed = store.recent_activity(10, izlek_core::store::FeedPage::Newest).await.unwrap(); | 4869 | + let feed = store.recent_activity(10, izlek_core::store::FeedPage::Newest, izlek_core::store::Dir::Newest, &izlek_core::store::ActivityFilter::default()).await.unwrap(); |
| 4815 | // The sign-in sits newest with no task on it; the task's own lines below | 4870 | // The sign-in sits newest with no task on it; the task's own lines below |
| 4816 | // still name theirs. | 4871 | // still name theirs. |
| 4817 | assert_eq!(feed[0].kind, ActivityKind::SignedIn); | 4872 | assert_eq!(feed[0].kind, ActivityKind::SignedIn); |
crates/izlek-web/src/detail.rsmodified+12 -5
| @@ -899,7 +899,7 @@ async fn deadline_control( | |||
| 899 | <div class="edit-form pop-panel datepick-panel"> | 899 | <div class="edit-form pop-panel datepick-panel"> |
| 900 | <form class="pop-form" method="post" action="/api/save_task"> | 900 | <form class="pop-form" method="post" action="/api/save_task"> |
| 901 | <input type="hidden" name="task_id" value=(task.id.clone())> | 901 | <input type="hidden" name="task_id" value=(task.id.clone())> |
| 902 | - (datepicker_grid(cx, "deadline", &input_value, lang).await?) | 902 | + (datepicker_grid(cx, "deadline", &input_value, false, lang).await?) |
| 903 | <div class="edit-row"> | 903 | <div class="edit-row"> |
| 904 | <button class="edit-save" type="submit">(t(lang, Key::Save))</button> | 904 | <button class="edit-save" type="submit">(t(lang, Key::Save))</button> |
| 905 | <label class="edit-cancel" for=(toggle)>(t(lang, Key::Cancel))</label> | 905 | <label class="edit-cancel" for=(toggle)>(t(lang, Key::Cancel))</label> |
| @@ -916,10 +916,16 @@ async fn deadline_control( | |||
| 916 | /// grid — the grid cells and month title are blank until `datepicker_script` | 916 | /// grid — the grid cells and month title are blank until `datepicker_script` |
| 917 | /// fills them in on open (see that function's doc comment for why the fill | 917 | /// fills them in on open (see that function's doc comment for why the fill |
| 918 | /// happens in JS rather than here). | 918 | /// happens in JS rather than here). |
| 919 | -async fn datepicker_grid(cx: &Cx, name: &str, value: &str, lang: Lang) -> Result { | 919 | +pub(crate) async fn datepicker_grid( |
| 920 | + cx: &Cx, | ||
| 921 | + name: &str, | ||
| 922 | + value: &str, | ||
| 923 | + autosubmit: bool, | ||
| 924 | + lang: Lang, | ||
| 925 | +) -> Result { | ||
| 920 | view! { | 926 | view! { |
| 921 | cx => | 927 | cx => |
| 922 | - <input class="datepick-input" type="hidden" name=(name.to_string()) value=(value.to_string())> | 928 | + <input class="datepick-input" type="hidden" name=(name.to_string()) value=(value.to_string()) data-autosubmit=(autosubmit)> |
| 923 | <div class="datepick-head"> | 929 | <div class="datepick-head"> |
| 924 | <button class="datepick-nav datepick-prev" type="button" aria-label=(t(lang, Key::PreviousMonth))>(glyph::chevron(cx).await?)</button> | 930 | <button class="datepick-nav datepick-prev" type="button" aria-label=(t(lang, Key::PreviousMonth))>(glyph::chevron(cx).await?)</button> |
| 925 | <span class="datepick-title"></span> | 931 | <span class="datepick-title"></span> |
| @@ -945,7 +951,7 @@ async fn datepicker_grid(cx: &Cx, name: &str, value: &str, lang: Lang) -> Result | |||
| 945 | /// `Escape` closes the panel through the datepick resolver `board.rs`'s | 951 | /// `Escape` closes the panel through the datepick resolver `board.rs`'s |
| 946 | /// `card_menu_script` registers (priority 100 — see the table on | 952 | /// `card_menu_script` registers (priority 100 — see the table on |
| 947 | /// `layout.rs`'s `escape_manager_script`). | 953 | /// `layout.rs`'s `escape_manager_script`). |
| 948 | -async fn datepicker_script(cx: &Cx, lang: Lang) -> Result { | 954 | +pub(crate) async fn datepicker_script(cx: &Cx, lang: Lang) -> Result { |
| 949 | use crate::i18n::datepicker_js_literals; | 955 | use crate::i18n::datepicker_js_literals; |
| 950 | use topcoat::view::Unescaped; | 956 | use topcoat::view::Unescaped; |
| 951 | let (months, weekdays) = datepicker_js_literals(lang); | 957 | let (months, weekdays) = datepicker_js_literals(lang); |
| @@ -986,6 +992,7 @@ async fn datepicker_script(cx: &Cx, lang: Lang) -> Result { | |||
| 986 | if (label) {{ label.textContent = ymd ? (MONTHS[ymd.m - 1].slice(0, 3) + ' ' + pad(ymd.d)) : label.dataset.empty; }}\ | 992 | if (label) {{ label.textContent = ymd ? (MONTHS[ymd.m - 1].slice(0, 3) + ' ' + pad(ymd.d)) : label.dataset.empty; }}\ |
| 987 | var toggle = pop.querySelector('.edit-toggle');\ | 993 | var toggle = pop.querySelector('.edit-toggle');\ |
| 988 | if (toggle) {{ toggle.checked = false; }}\ | 994 | if (toggle) {{ toggle.checked = false; }}\ |
| 995 | + if (input.hasAttribute('data-autosubmit') && input.form) {{ input.form.requestSubmit(); }}\ | ||
| 989 | }}\ | 996 | }}\ |
| 990 | document.addEventListener('change', function(e) {{\ | 997 | document.addEventListener('change', function(e) {{\ |
| 991 | var toggle = e.target.closest('.datepick-pop > .edit-toggle');\ | 998 | var toggle = e.target.closest('.datepick-pop > .edit-toggle');\ |
| @@ -1653,7 +1660,7 @@ pub async fn new_task_modal(cx: &Cx, columns: &[(String, String)], lang: Lang) - | |||
| 1653 | <span class="field-text datepick-label" data-empty=(t(lang, Key::NoDeadline))>(t(lang, Key::NoDeadline))</span> | 1660 | <span class="field-text datepick-label" data-empty=(t(lang, Key::NoDeadline))>(t(lang, Key::NoDeadline))</span> |
| 1654 | </label> | 1661 | </label> |
| 1655 | <div class="edit-form pop-panel datepick-panel"> | 1662 | <div class="edit-form pop-panel datepick-panel"> |
| 1656 | - (datepicker_grid(cx, "deadline", "", lang).await?) | 1663 | + (datepicker_grid(cx, "deadline", "", false, lang).await?) |
| 1657 | </div> | 1664 | </div> |
| 1658 | </div> | 1665 | </div> |
| 1659 | </div> | 1666 | </div> |
crates/izlek-web/src/i18n.rsmodified+15 -0
| @@ -289,6 +289,11 @@ pub enum Key { | |||
| 289 | MonthOctober, | 289 | MonthOctober, |
| 290 | MonthNovember, | 290 | MonthNovember, |
| 291 | MonthDecember, | 291 | MonthDecember, |
| 292 | + All, | ||
| 293 | + Task, | ||
| 294 | + LogSystem, | ||
| 295 | + Newest, | ||
| 296 | + Oldest, | ||
| 292 | } | 297 | } |
| 293 | 298 | ||
| 294 | /// The lone templated phrase — a name in the middle reads worse as two | 299 | /// The lone templated phrase — a name in the middle reads worse as two |
| @@ -816,6 +821,16 @@ pub fn t(lang: Lang, key: Key) -> &'static str { | |||
| 816 | (MonthNovember, Tr) => "Kasım", | 821 | (MonthNovember, Tr) => "Kasım", |
| 817 | (MonthDecember, En) => "December", | 822 | (MonthDecember, En) => "December", |
| 818 | (MonthDecember, Tr) => "Aralık", | 823 | (MonthDecember, Tr) => "Aralık", |
| 824 | + (All, En) => "All", | ||
| 825 | + (All, Tr) => "Tümü", | ||
| 826 | + (Task, En) => "Task", | ||
| 827 | + (Task, Tr) => "Görev", | ||
| 828 | + (LogSystem, En) => "System", | ||
| 829 | + (LogSystem, Tr) => "Sistem", | ||
| 830 | + (Newest, En) => "Newest", | ||
| 831 | + (Newest, Tr) => "En yeni", | ||
| 832 | + (Oldest, En) => "Oldest", | ||
| 833 | + (Oldest, Tr) => "En eski", | ||
| 819 | } | 834 | } |
| 820 | } | 835 | } |
| 821 | 836 | ||
crates/izlek-web/src/logs.rsmodified+296 -37
| @@ -8,7 +8,7 @@ | |||
| 8 | //! every request, so `snapshot` — the shared read — backs both the page and | 8 | //! every request, so `snapshot` — the shared read — backs both the page and |
| 9 | //! the JSON route `tests/http.rs` polls. | 9 | //! the JSON route `tests/http.rs` polls. |
| 10 | 10 | ||
| 11 | -use izlek_core::store::{FeedCursor, FeedPage}; | 11 | +use izlek_core::store::{ActivityFilter, Dir, FeedCursor, FeedPage}; |
| 12 | use serde::{Deserialize, Serialize}; | 12 | use serde::{Deserialize, Serialize}; |
| 13 | use time::OffsetDateTime; | 13 | use time::OffsetDateTime; |
| 14 | use time::format_description::well_known::Rfc3339; | 14 | use time::format_description::well_known::Rfc3339; |
| @@ -18,7 +18,7 @@ use topcoat::router::content::Json; | |||
| 18 | use topcoat::router::{page, route}; | 18 | use topcoat::router::{page, route}; |
| 19 | use topcoat::view::view; | 19 | use topcoat::view::view; |
| 20 | 20 | ||
| 21 | -use crate::detail::Me; | 21 | +use crate::detail::{Me, datepicker_grid}; |
| 22 | use crate::i18n::{Key, Lang, t}; | 22 | use crate::i18n::{Key, Lang, t}; |
| 23 | use crate::server::{Refusal, accounts, require_admin}; | 23 | use crate::server::{Refusal, accounts, require_admin}; |
| 24 | use crate::settings::{decode_q, encode_q}; | 24 | use crate::settings::{decode_q, encode_q}; |
| @@ -84,6 +84,43 @@ struct LogsSnapshot { | |||
| 84 | /// capped so the screen stays a read a person can finish. | 84 | /// capped so the screen stays a read a person can finish. |
| 85 | const LIMIT: u32 = 50; | 85 | const LIMIT: u32 = 50; |
| 86 | 86 | ||
| 87 | +/// Every `ActivityKind::as_str()` value but `Other` — the Type filter's | ||
| 88 | +/// options. | ||
| 89 | +const ACTIVITY_KINDS: &[&str] = &[ | ||
| 90 | + "created", | ||
| 91 | + "retitled", | ||
| 92 | + "described", | ||
| 93 | + "deadline_set", | ||
| 94 | + "deadline_cleared", | ||
| 95 | + "assigned", | ||
| 96 | + "unassigned", | ||
| 97 | + "linked", | ||
| 98 | + "unlinked", | ||
| 99 | + "moved", | ||
| 100 | + "unblocked", | ||
| 101 | + "deleted", | ||
| 102 | + "commented", | ||
| 103 | + "workspace_claimed", | ||
| 104 | + "invited", | ||
| 105 | + "link_resent", | ||
| 106 | + "joined", | ||
| 107 | + "signed_in", | ||
| 108 | + "signed_out", | ||
| 109 | + "sign_in_failed", | ||
| 110 | + "password_changed", | ||
| 111 | + "role_changed", | ||
| 112 | + "profile_saved", | ||
| 113 | + "sender_saved", | ||
| 114 | + "limits_saved", | ||
| 115 | + "test_mail_sent", | ||
| 116 | + "rule_created", | ||
| 117 | + "rule_edited", | ||
| 118 | + "rule_toggled", | ||
| 119 | + "rule_deleted", | ||
| 120 | + "file_added", | ||
| 121 | + "file_removed", | ||
| 122 | +]; | ||
| 123 | + | ||
| 87 | /// The word the decisions panel prints for an outcome. Terse: the panel is | 124 | /// The word the decisions panel prints for an outcome. Terse: the panel is |
| 88 | /// read, not explained. | 125 | /// read, not explained. |
| 89 | fn outcome_word(outcome: izlek_core::store::MailOutcome, lang: Lang) -> &'static str { | 126 | fn outcome_word(outcome: izlek_core::store::MailOutcome, lang: Lang) -> &'static str { |
| @@ -264,17 +301,29 @@ async fn decision_detail( | |||
| 264 | } | 301 | } |
| 265 | 302 | ||
| 266 | /// Query width and cursor for one section's list: the extra row beyond | 303 | /// Query width and cursor for one section's list: the extra row beyond |
| 267 | -/// `LIMIT` only signals that an older page exists — it is trimmed before | 304 | +/// `limit` only signals that an older page exists — it is trimmed before |
| 268 | -/// rendering. Only the section actually showing is paged; the rest always | 305 | +/// rendering. Only the section actually showing is paged, at its own |
| 269 | -/// read the newest `LIMIT`. | 306 | +/// `limit`; the rest always read the newest `LIMIT`. |
| 270 | -fn feed_window(active: Section, target: Section, page: &FeedPage) -> (u32, FeedPage) { | 307 | +fn feed_window(active: Section, target: Section, page: &FeedPage, limit: u32) -> (u32, FeedPage) { |
| 271 | if active == target { | 308 | if active == target { |
| 272 | - (LIMIT + 1, page.clone()) | 309 | + (limit + 1, page.clone()) |
| 273 | } else { | 310 | } else { |
| 274 | (LIMIT, FeedPage::Newest) | 311 | (LIMIT, FeedPage::Newest) |
| 275 | } | 312 | } |
| 276 | } | 313 | } |
| 277 | 314 | ||
| 315 | +/// The active section's own page size: from `izlek_rows_<section>`, the | ||
| 316 | +/// cookie the page's own fit script sets once it has measured the browser's | ||
| 317 | +/// real viewport, clamped so a stale or tampered cookie can't ask for an | ||
| 318 | +/// absurd window. `LIMIT` — the same default the unpaged JSON route reads — | ||
| 319 | +/// when the cookie is absent or unparsable. | ||
| 320 | +fn resolve_limit(cx: &Cx, section: Section) -> u32 { | ||
| 321 | + crate::server::presented_cookie(cx, &format!("izlek_rows_{}", section_slug(section))) | ||
| 322 | + .and_then(|raw| raw.parse::<u32>().ok()) | ||
| 323 | + .map(|rows| rows.clamp(10, 200)) | ||
| 324 | + .unwrap_or(LIMIT) | ||
| 325 | +} | ||
| 326 | + | ||
| 278 | /// Where the reader can turn from the active section's current page: the | 327 | /// Where the reader can turn from the active section's current page: the |
| 279 | /// query fragment (`before=…`/`after=…`, already encoded) for each | 328 | /// query fragment (`before=…`/`after=…`, already encoded) for each |
| 280 | /// direction the rail may still show a link for. | 329 | /// direction the rail may still show a link for. |
| @@ -283,6 +332,9 @@ struct PageLinks { | |||
| 283 | show_older: bool, | 332 | show_older: bool, |
| 284 | newer_q: Option<String>, | 333 | newer_q: Option<String>, |
| 285 | older_q: Option<String>, | 334 | older_q: Option<String>, |
| 335 | + /// (X, Y, N) for the active section's "X–Y / N" note: rendered rows are | ||
| 336 | + /// X through Y of N matching rows. Absent when the list is empty. | ||
| 337 | + position: Option<(u64, u64, u64)>, | ||
| 286 | } | 338 | } |
| 287 | 339 | ||
| 288 | fn cursor_q(param: &str, cursor: &FeedCursor) -> String { | 340 | fn cursor_q(param: &str, cursor: &FeedCursor) -> String { |
| @@ -311,6 +363,57 @@ fn parse_page(query: &str) -> FeedPage { | |||
| 311 | } | 363 | } |
| 312 | } | 364 | } |
| 313 | 365 | ||
| 366 | +/// `dir=oldest` reverses the activity tab; anything else, including | ||
| 367 | +/// absence, reads newest first. | ||
| 368 | +fn parse_dir(query: &str) -> Dir { | ||
| 369 | + match query_value(query, "dir") { | ||
| 370 | + Some("oldest") => Dir::Oldest, | ||
| 371 | + _ => Dir::Newest, | ||
| 372 | + } | ||
| 373 | +} | ||
| 374 | + | ||
| 375 | +/// `on=YYYY-MM-DD`, resolved to a half-open UTC range in the admin's own | ||
| 376 | +/// timezone. Unparsable or absent is no filter, never a 500. | ||
| 377 | +fn parse_day(raw: &str, zone: time::UtcOffset) -> Option<(OffsetDateTime, OffsetDateTime)> { | ||
| 378 | + use time::macros::format_description; | ||
| 379 | + let day = time::Date::parse(raw, format_description!("[year]-[month]-[day]")).ok()?; | ||
| 380 | + let start = day | ||
| 381 | + .with_hms(0, 0, 0) | ||
| 382 | + .ok()? | ||
| 383 | + .assume_offset(zone) | ||
| 384 | + .to_offset(time::UtcOffset::UTC); | ||
| 385 | + Some((start, start + time::Duration::hours(24))) | ||
| 386 | +} | ||
| 387 | + | ||
| 388 | +/// The activity tab's filter, straight off the query: an absent or empty | ||
| 389 | +/// value narrows nothing. | ||
| 390 | +fn parse_activity_filter(query: &str, zone: time::UtcOffset) -> ActivityFilter { | ||
| 391 | + ActivityFilter { | ||
| 392 | + actor: query_value(query, "actor").filter(|v| !v.is_empty()).map(str::to_string), | ||
| 393 | + kind: query_value(query, "kind").filter(|v| !v.is_empty()).map(str::to_string), | ||
| 394 | + task_key: query_value(query, "task") | ||
| 395 | + .filter(|v| !v.is_empty()) | ||
| 396 | + .map(|v| v.to_uppercase()), | ||
| 397 | + day: query_value(query, "on").and_then(|raw| parse_day(raw, zone)), | ||
| 398 | + } | ||
| 399 | +} | ||
| 400 | + | ||
| 401 | +/// Every active activity-filter param, as a query fragment (leading `&`, | ||
| 402 | +/// empty when nothing is set) — round-tripped onto cursor hrefs and the | ||
| 403 | +/// filter form's own action so a page turn never drops a filter. | ||
| 404 | +fn activity_query_suffix(query: &str) -> String { | ||
| 405 | + let mut out = String::new(); | ||
| 406 | + for key in ["actor", "kind", "task", "on", "dir"] { | ||
| 407 | + if let Some(value) = query_value(query, key).filter(|v| !v.is_empty()) { | ||
| 408 | + out.push('&'); | ||
| 409 | + out.push_str(key); | ||
| 410 | + out.push('='); | ||
| 411 | + out.push_str(value); | ||
| 412 | + } | ||
| 413 | + } | ||
| 414 | + out | ||
| 415 | +} | ||
| 416 | + | ||
| 314 | /// The queue, the decisions, and the activity, admin only. Shared by the | 417 | /// The queue, the decisions, and the activity, admin only. Shared by the |
| 315 | /// `/logs` page and the `/api/current_logs` route so both answer the same | 418 | /// `/logs` page and the `/api/current_logs` route so both answer the same |
| 316 | /// read the same way. `active`/`page` widen and cursor only the section | 419 | /// read the same way. `active`/`page` widen and cursor only the section |
| @@ -320,6 +423,9 @@ async fn snapshot( | |||
| 320 | cx: &Cx, | 423 | cx: &Cx, |
| 321 | active: Section, | 424 | active: Section, |
| 322 | page: FeedPage, | 425 | page: FeedPage, |
| 426 | + dir: Dir, | ||
| 427 | + filter: &ActivityFilter, | ||
| 428 | + limit: u32, | ||
| 323 | ) -> Result<std::result::Result<(LogsSnapshot, PageLinks), Refusal>> { | 429 | ) -> Result<std::result::Result<(LogsSnapshot, PageLinks), Refusal>> { |
| 324 | use izlek_core::store::SendState; | 430 | use izlek_core::store::SendState; |
| 325 | 431 | ||
| @@ -339,15 +445,15 @@ async fn snapshot( | |||
| 339 | let mut newer_cursor: Option<FeedCursor> = None; | 445 | let mut newer_cursor: Option<FeedCursor> = None; |
| 340 | let mut older_cursor: Option<FeedCursor> = None; | 446 | let mut older_cursor: Option<FeedCursor> = None; |
| 341 | 447 | ||
| 342 | - let (queue_limit, queue_page) = feed_window(active, Section::Queue, &page); | 448 | + let (queue_limit, queue_page) = feed_window(active, Section::Queue, &page, limit); |
| 343 | let mut sends = store.mail_queue(queue_limit, queue_page).await?; | 449 | let mut sends = store.mail_queue(queue_limit, queue_page).await?; |
| 344 | if active == Section::Queue && matches!(page, FeedPage::After(_)) && sends.is_empty() { | 450 | if active == Section::Queue && matches!(page, FeedPage::After(_)) && sends.is_empty() { |
| 345 | effective_page = FeedPage::Newest; | 451 | effective_page = FeedPage::Newest; |
| 346 | - sends = store.mail_queue(LIMIT + 1, FeedPage::Newest).await?; | 452 | + sends = store.mail_queue(limit + 1, FeedPage::Newest).await?; |
| 347 | } | 453 | } |
| 348 | - if active == Section::Queue && sends.len() as u32 > LIMIT { | 454 | + if active == Section::Queue && sends.len() as u32 > limit { |
| 349 | has_more = true; | 455 | has_more = true; |
| 350 | - sends.truncate(LIMIT as usize); | 456 | + sends.truncate(limit as usize); |
| 351 | } | 457 | } |
| 352 | if active == Section::Queue { | 458 | if active == Section::Queue { |
| 353 | newer_cursor = sends | 459 | newer_cursor = sends |
| @@ -357,6 +463,7 @@ async fn snapshot( | |||
| 357 | .last() | 463 | .last() |
| 358 | .and_then(|s| s.next_attempt_at.map(|at| FeedCursor { at, id: s.id.clone() })); | 464 | .and_then(|s| s.next_attempt_at.map(|at| FeedCursor { at, id: s.id.clone() })); |
| 359 | } | 465 | } |
| 466 | + let queue_shown = sends.len() as u64; | ||
| 360 | let mut queue = Vec::with_capacity(sends.len()); | 467 | let mut queue = Vec::with_capacity(sends.len()); |
| 361 | for send in sends { | 468 | for send in sends { |
| 362 | let subject = match &send.subject { | 469 | let subject = match &send.subject { |
| @@ -392,16 +499,16 @@ async fn snapshot( | |||
| 392 | }); | 499 | }); |
| 393 | } | 500 | } |
| 394 | 501 | ||
| 395 | - let (decisions_limit, decisions_page) = feed_window(active, Section::Decisions, &page); | 502 | + let (decisions_limit, decisions_page) = feed_window(active, Section::Decisions, &page, limit); |
| 396 | let mut raw_decisions = store.recent_mail_decisions(decisions_limit, decisions_page).await?; | 503 | let mut raw_decisions = store.recent_mail_decisions(decisions_limit, decisions_page).await?; |
| 397 | if active == Section::Decisions && matches!(page, FeedPage::After(_)) && raw_decisions.is_empty() | 504 | if active == Section::Decisions && matches!(page, FeedPage::After(_)) && raw_decisions.is_empty() |
| 398 | { | 505 | { |
| 399 | effective_page = FeedPage::Newest; | 506 | effective_page = FeedPage::Newest; |
| 400 | - raw_decisions = store.recent_mail_decisions(LIMIT + 1, FeedPage::Newest).await?; | 507 | + raw_decisions = store.recent_mail_decisions(limit + 1, FeedPage::Newest).await?; |
| 401 | } | 508 | } |
| 402 | - if active == Section::Decisions && raw_decisions.len() as u32 > LIMIT { | 509 | + if active == Section::Decisions && raw_decisions.len() as u32 > limit { |
| 403 | has_more = true; | 510 | has_more = true; |
| 404 | - raw_decisions.truncate(LIMIT as usize); | 511 | + raw_decisions.truncate(limit as usize); |
| 405 | } | 512 | } |
| 406 | // Cursors come from the raw rows, before grouping by event — a group | 513 | // Cursors come from the raw rows, before grouping by event — a group |
| 407 | // split across a page boundary is accepted, unchanged from the offset | 514 | // split across a page boundary is accepted, unchanged from the offset |
| @@ -414,6 +521,7 @@ async fn snapshot( | |||
| 414 | .last() | 521 | .last() |
| 415 | .map(|d| FeedCursor { at: d.at, id: d.id.clone() }); | 522 | .map(|d| FeedCursor { at: d.at, id: d.id.clone() }); |
| 416 | } | 523 | } |
| 524 | + let decisions_shown = raw_decisions.len() as u64; | ||
| 417 | let mut decisions: Vec<DecisionGroup> = Vec::new(); | 525 | let mut decisions: Vec<DecisionGroup> = Vec::new(); |
| 418 | let mut columns_cache: std::collections::HashMap<String, Vec<izlek_core::board::Column>> = | 526 | let mut columns_cache: std::collections::HashMap<String, Vec<izlek_core::board::Column>> = |
| 419 | std::collections::HashMap::new(); | 527 | std::collections::HashMap::new(); |
| @@ -460,16 +568,23 @@ async fn snapshot( | |||
| 460 | }); | 568 | }); |
| 461 | } | 569 | } |
| 462 | 570 | ||
| 463 | - let (activity_limit, activity_page) = feed_window(active, Section::Activity, &page); | 571 | + let (activity_limit, activity_page) = feed_window(active, Section::Activity, &page, limit); |
| 464 | - let mut raw_activity = store.recent_activity(activity_limit, activity_page).await?; | 572 | + let activity_filter = if active == Section::Activity { |
| 573 | + filter.clone() | ||
| 574 | + } else { | ||
| 575 | + ActivityFilter::default() | ||
| 576 | + }; | ||
| 577 | + let mut raw_activity = | ||
| 578 | + store.recent_activity(activity_limit, activity_page, dir, &activity_filter).await?; | ||
| 465 | if active == Section::Activity && matches!(page, FeedPage::After(_)) && raw_activity.is_empty() | 579 | if active == Section::Activity && matches!(page, FeedPage::After(_)) && raw_activity.is_empty() |
| 466 | { | 580 | { |
| 467 | effective_page = FeedPage::Newest; | 581 | effective_page = FeedPage::Newest; |
| 468 | - raw_activity = store.recent_activity(LIMIT + 1, FeedPage::Newest).await?; | 582 | + raw_activity = |
| 583 | + store.recent_activity(limit + 1, FeedPage::Newest, dir, &activity_filter).await?; | ||
| 469 | } | 584 | } |
| 470 | - if active == Section::Activity && raw_activity.len() as u32 > LIMIT { | 585 | + if active == Section::Activity && raw_activity.len() as u32 > limit { |
| 471 | has_more = true; | 586 | has_more = true; |
| 472 | - raw_activity.truncate(LIMIT as usize); | 587 | + raw_activity.truncate(limit as usize); |
| 473 | } | 588 | } |
| 474 | if active == Section::Activity { | 589 | if active == Section::Activity { |
| 475 | newer_cursor = raw_activity | 590 | newer_cursor = raw_activity |
| @@ -479,6 +594,7 @@ async fn snapshot( | |||
| 479 | .last() | 594 | .last() |
| 480 | .map(|line| FeedCursor { at: line.at, id: line.id.clone() }); | 595 | .map(|line| FeedCursor { at: line.at, id: line.id.clone() }); |
| 481 | } | 596 | } |
| 597 | + let activity_shown = raw_activity.len() as u64; | ||
| 482 | let activity = raw_activity | 598 | let activity = raw_activity |
| 483 | .into_iter() | 599 | .into_iter() |
| 484 | .map(|line| ActivityRow { | 600 | .map(|line| ActivityRow { |
| @@ -494,11 +610,34 @@ async fn snapshot( | |||
| 494 | let show_older = matches!(effective_page, FeedPage::After(_)) || has_more; | 610 | let show_older = matches!(effective_page, FeedPage::After(_)) || has_more; |
| 495 | let show_newer = matches!(effective_page, FeedPage::Before(_)) | 611 | let show_newer = matches!(effective_page, FeedPage::Before(_)) |
| 496 | || (matches!(effective_page, FeedPage::After(_)) && has_more); | 612 | || (matches!(effective_page, FeedPage::After(_)) && has_more); |
| 613 | + | ||
| 614 | + let position = match active { | ||
| 615 | + Section::Queue if queue_shown > 0 => { | ||
| 616 | + let total = store.count_mail_queue().await?; | ||
| 617 | + let preceding = store.count_mail_queue_preceding(newer_cursor.as_ref()).await?; | ||
| 618 | + Some((preceding + 1, preceding + queue_shown, total)) | ||
| 619 | + } | ||
| 620 | + Section::Decisions if decisions_shown > 0 => { | ||
| 621 | + let total = store.count_mail_decisions().await?; | ||
| 622 | + let preceding = store.count_mail_decisions_preceding(newer_cursor.as_ref()).await?; | ||
| 623 | + Some((preceding + 1, preceding + decisions_shown, total)) | ||
| 624 | + } | ||
| 625 | + Section::Activity if activity_shown > 0 => { | ||
| 626 | + let total = store.count_activity(&activity_filter).await?; | ||
| 627 | + let preceding = store | ||
| 628 | + .count_activity_preceding(&activity_filter, dir, newer_cursor.as_ref()) | ||
| 629 | + .await?; | ||
| 630 | + Some((preceding + 1, preceding + activity_shown, total)) | ||
| 631 | + } | ||
| 632 | + _ => None, | ||
| 633 | + }; | ||
| 634 | + | ||
| 497 | let links = PageLinks { | 635 | let links = PageLinks { |
| 498 | show_newer, | 636 | show_newer, |
| 499 | show_older, | 637 | show_older, |
| 500 | newer_q: newer_cursor.as_ref().map(|c| cursor_q("after", c)), | 638 | newer_q: newer_cursor.as_ref().map(|c| cursor_q("after", c)), |
| 501 | older_q: older_cursor.as_ref().map(|c| cursor_q("before", c)), | 639 | older_q: older_cursor.as_ref().map(|c| cursor_q("before", c)), |
| 640 | + position, | ||
| 502 | }; | 641 | }; |
| 503 | 642 | ||
| 504 | Ok(Ok(( | 643 | Ok(Ok(( |
| @@ -517,9 +656,16 @@ async fn snapshot( | |||
| 517 | #[route(POST "/api/current_logs")] | 656 | #[route(POST "/api/current_logs")] |
| 518 | async fn current_logs(cx: &Cx) -> Result<Json<std::result::Result<LogsSnapshot, Refusal>>> { | 657 | async fn current_logs(cx: &Cx) -> Result<Json<std::result::Result<LogsSnapshot, Refusal>>> { |
| 519 | Ok(Json( | 658 | Ok(Json( |
| 520 | - snapshot(cx, Section::Activity, FeedPage::Newest) | 659 | + snapshot( |
| 521 | - .await? | 660 | + cx, |
| 522 | - .map(|(snapshot, _links)| snapshot), | 661 | + Section::Activity, |
| 662 | + FeedPage::Newest, | ||
| 663 | + Dir::Newest, | ||
| 664 | + &ActivityFilter::default(), | ||
| 665 | + LIMIT, | ||
| 666 | + ) | ||
| 667 | + .await? | ||
| 668 | + .map(|(snapshot, _links)| snapshot), | ||
| 523 | )) | 669 | )) |
| 524 | } | 670 | } |
| 525 | 671 | ||
| @@ -554,15 +700,25 @@ fn rail_class(current: Section, target: Section) -> &'static str { | |||
| 554 | #[page("/logs")] | 700 | #[page("/logs")] |
| 555 | async fn logs_page(cx: &Cx) -> Result { | 701 | async fn logs_page(cx: &Cx) -> Result { |
| 556 | let lang = Lang::En; | 702 | let lang = Lang::En; |
| 557 | - let query = topcoat::router::request::uri(cx).query().unwrap_or(""); | 703 | + let query = topcoat::router::request::uri(cx).query().unwrap_or("").to_string(); |
| 558 | - let section = match query_value(query, "section") { | 704 | + let section = match query_value(&query, "section") { |
| 559 | Some("queue") => Section::Queue, | 705 | Some("queue") => Section::Queue, |
| 560 | Some("decisions") => Section::Decisions, | 706 | Some("decisions") => Section::Decisions, |
| 561 | _ => Section::Activity, | 707 | _ => Section::Activity, |
| 562 | }; | 708 | }; |
| 563 | - let page = parse_page(query); | 709 | + let page = parse_page(&query); |
| 564 | - match snapshot(cx, section, page).await { | 710 | + let dir = parse_dir(&query); |
| 565 | - Ok(Ok((snapshot, links))) => logs_screen(cx, snapshot, section, links).await, | 711 | + // The admin's own timezone resolves `on=` before the session is known to |
| 712 | + // `snapshot` itself, so a signed-out visitor still gets a clean refusal | ||
| 713 | + // rather than a second, redundant lookup here. | ||
| 714 | + let zone = match require_admin(cx).await { | ||
| 715 | + Ok(user) => izlek_core::detail::parse_zone(&user.timezone), | ||
| 716 | + Err(_) => time::UtcOffset::UTC, | ||
| 717 | + }; | ||
| 718 | + let filter = parse_activity_filter(&query, zone); | ||
| 719 | + let limit = resolve_limit(cx, section); | ||
| 720 | + match snapshot(cx, section, page, dir, &filter, limit).await { | ||
| 721 | + Ok(Ok((snapshot, links))) => logs_screen(cx, snapshot, section, links, &query, limit).await, | ||
| 566 | // No `Me` here to read a language off of when the refusal itself is | 722 | // No `Me` here to read a language off of when the refusal itself is |
| 567 | // "no session" — English, same as the other admin pages' own gate. | 723 | // "no session" — English, same as the other admin pages' own gate. |
| 568 | Ok(Err(refusal)) => view! { | 724 | Ok(Err(refusal)) => view! { |
| @@ -590,7 +746,14 @@ fn section_slug(section: Section) -> &'static str { | |||
| 590 | } | 746 | } |
| 591 | } | 747 | } |
| 592 | 748 | ||
| 593 | -async fn logs_screen(cx: &Cx, snapshot: LogsSnapshot, section: Section, links: PageLinks) -> Result { | 749 | +async fn logs_screen( |
| 750 | + cx: &Cx, | ||
| 751 | + snapshot: LogsSnapshot, | ||
| 752 | + section: Section, | ||
| 753 | + links: PageLinks, | ||
| 754 | + query: &str, | ||
| 755 | + limit: u32, | ||
| 756 | +) -> Result { | ||
| 594 | let lang = Lang::from_code(&snapshot.me.language); | 757 | let lang = Lang::from_code(&snapshot.me.language); |
| 595 | let me = snapshot.me; | 758 | let me = snapshot.me; |
| 596 | let queue = snapshot.queue; | 759 | let queue = snapshot.queue; |
| @@ -600,14 +763,38 @@ async fn logs_screen(cx: &Cx, snapshot: LogsSnapshot, section: Section, links: P | |||
| 600 | let decisions_empty = decisions.is_empty(); | 763 | let decisions_empty = decisions.is_empty(); |
| 601 | let activity_empty = activity.is_empty(); | 764 | let activity_empty = activity.is_empty(); |
| 602 | let slug = section_slug(section); | 765 | let slug = section_slug(section); |
| 766 | + let extra = if section == Section::Activity { activity_query_suffix(query) } else { String::new() }; | ||
| 603 | let newer_href = links | 767 | let newer_href = links |
| 604 | .newer_q | 768 | .newer_q |
| 605 | .filter(|_| links.show_newer) | 769 | .filter(|_| links.show_newer) |
| 606 | - .map(|q| format!("/logs?section={slug}&{q}")); | 770 | + .map(|q| format!("/logs?section={slug}&{q}{extra}")); |
| 607 | let older_href = links | 771 | let older_href = links |
| 608 | .older_q | 772 | .older_q |
| 609 | .filter(|_| links.show_older) | 773 | .filter(|_| links.show_older) |
| 610 | - .map(|q| format!("/logs?section={slug}&{q}")); | 774 | + .map(|q| format!("/logs?section={slug}&{q}{extra}")); |
| 775 | + let position_note = links.position.map(|(x, y, n)| format!("{x}\u{2013}{y} / {n}")); | ||
| 776 | + | ||
| 777 | + let (filter_actor, filter_kind, filter_task, filter_on, filter_dir) = ( | ||
| 778 | + query_value(query, "actor").unwrap_or("").to_string(), | ||
| 779 | + query_value(query, "kind").unwrap_or("").to_string(), | ||
| 780 | + query_value(query, "task").unwrap_or("").to_string(), | ||
| 781 | + query_value(query, "on").unwrap_or("").to_string(), | ||
| 782 | + query_value(query, "dir").unwrap_or("").to_string(), | ||
| 783 | + ); | ||
| 784 | + let members: Vec<(String, String)> = if section == Section::Activity { | ||
| 785 | + let store = accounts(cx).store().clone(); | ||
| 786 | + match store.user(&me.id).await? { | ||
| 787 | + Some(admin) => store | ||
| 788 | + .users(&admin.workspace_id) | ||
| 789 | + .await? | ||
| 790 | + .into_iter() | ||
| 791 | + .map(|u| (u.id, u.display_name)) | ||
| 792 | + .collect(), | ||
| 793 | + None => Vec::new(), | ||
| 794 | + } | ||
| 795 | + } else { | ||
| 796 | + Vec::new() | ||
| 797 | + }; | ||
| 611 | 798 | ||
| 612 | view! { | 799 | view! { |
| 613 | cx => | 800 | cx => |
| @@ -639,7 +826,7 @@ async fn logs_screen(cx: &Cx, snapshot: LogsSnapshot, section: Section, links: P | |||
| 639 | <h2 class="panel-title">(t(lang, Key::MailQueue))</h2> | 826 | <h2 class="panel-title">(t(lang, Key::MailQueue))</h2> |
| 640 | </div> | 827 | </div> |
| 641 | <div class="panel-body"> | 828 | <div class="panel-body"> |
| 642 | - <div class="rule-list"> | 829 | + <div class="rule-list" data-rows=(limit) data-section="queue"> |
| 643 | for line in queue { | 830 | for line in queue { |
| 644 | let is_failed_or_held = line.state_kind == "failed" || line.state_kind == "held"; | 831 | let is_failed_or_held = line.state_kind == "failed" || line.state_kind == "held"; |
| 645 | let state_note = if is_failed_or_held { | 832 | let state_note = if is_failed_or_held { |
| @@ -664,9 +851,12 @@ async fn logs_screen(cx: &Cx, snapshot: LogsSnapshot, section: Section, links: P | |||
| 664 | } | 851 | } |
| 665 | </div> | 852 | </div> |
| 666 | </div> | 853 | </div> |
| 667 | - if newer_href.is_some() || older_href.is_some() { | 854 | + if !queue_empty { |
| 668 | <div class="panel-foot panel-foot-split"> | 855 | <div class="panel-foot panel-foot-split"> |
| 669 | <div class="foot-side"> | 856 | <div class="foot-side"> |
| 857 | + if let Some(note) = position_note.clone() { | ||
| 858 | + <span class="log-count">(note)</span> | ||
| 859 | + } | ||
| 670 | if let Some(newer_href) = newer_href.clone() { | 860 | if let Some(newer_href) = newer_href.clone() { |
| 671 | <a class="quiet" href=(newer_href)>(t(lang, Key::Newer))</a> | 861 | <a class="quiet" href=(newer_href)>(t(lang, Key::Newer))</a> |
| 672 | } | 862 | } |
| @@ -687,7 +877,7 @@ async fn logs_screen(cx: &Cx, snapshot: LogsSnapshot, section: Section, links: P | |||
| 687 | <h2 class="panel-title">(t(lang, Key::MailDecisions))</h2> | 877 | <h2 class="panel-title">(t(lang, Key::MailDecisions))</h2> |
| 688 | </div> | 878 | </div> |
| 689 | <div class="panel-body"> | 879 | <div class="panel-body"> |
| 690 | - <div class="rule-list"> | 880 | + <div class="rule-list" data-rows=(limit) data-section="decisions"> |
| 691 | for group in decisions { | 881 | for group in decisions { |
| 692 | let header = match group.happened { | 882 | let header = match group.happened { |
| 693 | Some(happened) => format!("{} · {}", group.task, happened), | 883 | Some(happened) => format!("{} · {}", group.task, happened), |
| @@ -715,9 +905,12 @@ async fn logs_screen(cx: &Cx, snapshot: LogsSnapshot, section: Section, links: P | |||
| 715 | } | 905 | } |
| 716 | </div> | 906 | </div> |
| 717 | </div> | 907 | </div> |
| 718 | - if newer_href.is_some() || older_href.is_some() { | 908 | + if !decisions_empty { |
| 719 | <div class="panel-foot panel-foot-split"> | 909 | <div class="panel-foot panel-foot-split"> |
| 720 | <div class="foot-side"> | 910 | <div class="foot-side"> |
| 911 | + if let Some(note) = position_note.clone() { | ||
| 912 | + <span class="log-count">(note)</span> | ||
| 913 | + } | ||
| 721 | if let Some(newer_href) = newer_href.clone() { | 914 | if let Some(newer_href) = newer_href.clone() { |
| 722 | <a class="quiet" href=(newer_href)>(t(lang, Key::Newer))</a> | 915 | <a class="quiet" href=(newer_href)>(t(lang, Key::Newer))</a> |
| 723 | } | 916 | } |
| @@ -738,7 +931,37 @@ async fn logs_screen(cx: &Cx, snapshot: LogsSnapshot, section: Section, links: P | |||
| 738 | <h2 class="panel-title">(t(lang, Key::Activity))</h2> | 931 | <h2 class="panel-title">(t(lang, Key::Activity))</h2> |
| 739 | </div> | 932 | </div> |
| 740 | <div class="panel-body"> | 933 | <div class="panel-body"> |
| 741 | - <div class="log-list"> | 934 | + <form class="filterbar log-filterbar" method="get" action="/logs"> |
| 935 | + <input type="hidden" name="section" value="activity"> | ||
| 936 | + <select class="field-input" name="actor" data-autosubmit=""> | ||
| 937 | + <option value="" selected=(filter_actor.is_empty())>(t(lang, Key::All))</option> | ||
| 938 | + <option value="system" selected=(filter_actor == "system")>(t(lang, Key::LogSystem))</option> | ||
| 939 | + for member in &members { | ||
| 940 | + <option value=(member.0.clone()) selected=(filter_actor == member.0)>(member.1.clone())</option> | ||
| 941 | + } | ||
| 942 | + </select> | ||
| 943 | + <select class="field-input" name="kind" data-autosubmit=""> | ||
| 944 | + <option value="" selected=(filter_kind.is_empty())>(t(lang, Key::All))</option> | ||
| 945 | + for kind in ACTIVITY_KINDS { | ||
| 946 | + <option value=(kind) selected=(filter_kind == *kind)>(crate::i18n::activity_kind_word(lang, kind))</option> | ||
| 947 | + } | ||
| 948 | + </select> | ||
| 949 | + <input class="field-input" type="text" name="task" value=(filter_task.clone()) placeholder=(t(lang, Key::Task))> | ||
| 950 | + <div class="edit edit-pop datepick-pop"> | ||
| 951 | + <input class="edit-toggle" type="checkbox" id="log-on-toggle" aria-label=(t(lang, Key::All))> | ||
| 952 | + <label class="field-box edit-view edit-hit" for="log-on-toggle"> | ||
| 953 | + <span class="field-text datepick-label" data-empty=(t(lang, Key::All))>(if filter_on.is_empty() { t(lang, Key::All).to_string() } else { filter_on.clone() })</span> | ||
| 954 | + </label> | ||
| 955 | + <div class="edit-form pop-panel datepick-panel"> | ||
| 956 | + (datepicker_grid(cx, "on", &filter_on, true, lang).await?) | ||
| 957 | + </div> | ||
| 958 | + </div> | ||
| 959 | + <select class="field-input" name="dir" data-autosubmit=""> | ||
| 960 | + <option value="" selected=(filter_dir != "oldest")>(t(lang, Key::Newest))</option> | ||
| 961 | + <option value="oldest" selected=(filter_dir == "oldest")>(t(lang, Key::Oldest))</option> | ||
| 962 | + </select> | ||
| 963 | + </form> | ||
| 964 | + <div class="log-list" data-rows=(limit) data-section="activity"> | ||
| 742 | for line in activity { | 965 | for line in activity { |
| 743 | let title = line.title; | 966 | let title = line.title; |
| 744 | <div class="log-row"> | 967 | <div class="log-row"> |
| @@ -755,9 +978,12 @@ async fn logs_screen(cx: &Cx, snapshot: LogsSnapshot, section: Section, links: P | |||
| 755 | } | 978 | } |
| 756 | </div> | 979 | </div> |
| 757 | </div> | 980 | </div> |
| 758 | - if newer_href.is_some() || older_href.is_some() { | 981 | + if !activity_empty { |
| 759 | <div class="panel-foot panel-foot-split"> | 982 | <div class="panel-foot panel-foot-split"> |
| 760 | <div class="foot-side"> | 983 | <div class="foot-side"> |
| 984 | + if let Some(note) = position_note.clone() { | ||
| 985 | + <span class="log-count">(note)</span> | ||
| 986 | + } | ||
| 761 | if let Some(newer_href) = newer_href.clone() { | 987 | if let Some(newer_href) = newer_href.clone() { |
| 762 | <a class="quiet" href=(newer_href)>(t(lang, Key::Newer))</a> | 988 | <a class="quiet" href=(newer_href)>(t(lang, Key::Newer))</a> |
| 763 | } | 989 | } |
| @@ -773,6 +999,39 @@ async fn logs_screen(cx: &Cx, snapshot: LogsSnapshot, section: Section, links: P | |||
| 773 | } | 999 | } |
| 774 | </main> | 1000 | </main> |
| 775 | </div> | 1001 | </div> |
| 1002 | + (crate::dropdown::dropdown_script(cx).await?) | ||
| 776 | (crate::layout::escape_script(cx).await?) | 1003 | (crate::layout::escape_script(cx).await?) |
| 1004 | + (crate::detail::datepicker_script(cx, lang).await?) | ||
| 1005 | + (log_fit_script(cx).await?) | ||
| 777 | } | 1006 | } |
| 778 | } | 1007 | } |
| 1008 | + | ||
| 1009 | +/// Fits the active tab's page size to the browser's own viewport: measured | ||
| 1010 | +/// once per load/swap against the first rendered row, never against a guess | ||
| 1011 | +/// at the row height. A fit that would change the page size reloads once | ||
| 1012 | +/// through a fresh `izlek_rows_<section>` cookie; the `sessionStorage` guard, | ||
| 1013 | +/// keyed to the exact fit computed, stops a borderline measurement from | ||
| 1014 | +/// reloading forever. A container too short to measure (no rows yet, or a | ||
| 1015 | +/// stage not yet laid out) is left alone rather than guessed at. | ||
| 1016 | +async fn log_fit_script(cx: &Cx) -> Result { | ||
| 1017 | + use topcoat::view::Unescaped; | ||
| 1018 | + let js = "(function() {\ | ||
| 1019 | + var list = document.querySelector('.rule-list[data-rows], .log-list[data-rows]');\ | ||
| 1020 | + if (!list) { return; }\ | ||
| 1021 | + var section = list.dataset.section;\ | ||
| 1022 | + var current = parseInt(list.dataset.rows, 10);\ | ||
| 1023 | + var row = list.firstElementChild;\ | ||
| 1024 | + if (!row || !row.offsetHeight) { return; }\ | ||
| 1025 | + var stage = list.closest('.settings-stage');\ | ||
| 1026 | + if (!stage) { return; }\ | ||
| 1027 | + var avail = stage.getBoundingClientRect().bottom - list.getBoundingClientRect().top - 44;\ | ||
| 1028 | + var fit = Math.max(10, Math.floor(avail / row.offsetHeight));\ | ||
| 1029 | + if (fit === current) { return; }\ | ||
| 1030 | + var guard = 'izlekLogFit:' + section + ':' + fit;\ | ||
| 1031 | + if (window.sessionStorage.getItem(guard)) { return; }\ | ||
| 1032 | + window.sessionStorage.setItem(guard, '1');\ | ||
| 1033 | + document.cookie = 'izlek_rows_' + section + '=' + fit + ';path=/';\ | ||
| 1034 | + location.replace(location.href);\ | ||
| 1035 | + })();"; | ||
| 1036 | + view! { cx => <script>(Unescaped::new_unchecked(js))</script> } | ||
| 1037 | +} | ||
crates/izlek-web/src/server.rsmodified+7 -0
| @@ -174,6 +174,13 @@ pub fn presented_session(cx: &Cx) -> Option<String> { | |||
| 174 | .map(|c| c.value().to_string()) | 174 | .map(|c| c.value().to_string()) |
| 175 | } | 175 | } |
| 176 | 176 | ||
| 177 | +/// Any other cookie the request presented, by name — the client-set, | ||
| 178 | +/// non-`HttpOnly` ones (e.g. `izlek_rows_<section>`) that JS reads and | ||
| 179 | +/// writes on its own. | ||
| 180 | +pub fn presented_cookie(cx: &Cx, name: &str) -> Option<String> { | ||
| 181 | + cookies(cx).get(name).map(|c| c.value().to_string()) | ||
| 182 | +} | ||
| 183 | + | ||
| 177 | /// A stable-enough label for the client, for rate limiting. A proxy header is | 184 | /// A stable-enough label for the client, for rate limiting. A proxy header is |
| 178 | /// only trusted because Izlek is meant to sit behind one; the address bucket is | 185 | /// only trusted because Izlek is meant to sit behind one; the address bucket is |
| 179 | /// the limit that actually protects the Argon2 work either way. | 186 | /// the limit that actually protects the Argon2 work either way. |
crates/izlek-web/tests/http.rsmodified+294 -2
| @@ -132,6 +132,19 @@ impl App { | |||
| 132 | /// regardless — [`Router::handle`] never follows a redirect, so the answer | 132 | /// regardless — [`Router::handle`] never follows a redirect, so the answer |
| 133 | /// is read straight off this response, same as `oneshot` did before. | 133 | /// is read straight off this response, same as `oneshot` did before. |
| 134 | async fn post(&self, path: &str, cookie: Option<&str>, form: &[(&str, &str)]) -> Answer { | 134 | async fn post(&self, path: &str, cookie: Option<&str>, form: &[(&str, &str)]) -> Answer { |
| 135 | + self.post_with_extra_cookie(path, cookie, form, None).await | ||
| 136 | + } | ||
| 137 | + | ||
| 138 | + /// Like `post`, but with a second `Cookie` header of the caller's own | ||
| 139 | + /// naming — for the `izlek_rows_<section>` page-size cookie, which lives | ||
| 140 | + /// beside the session cookie rather than replacing it. | ||
| 141 | + async fn post_with_extra_cookie( | ||
| 142 | + &self, | ||
| 143 | + path: &str, | ||
| 144 | + cookie: Option<&str>, | ||
| 145 | + form: &[(&str, &str)], | ||
| 146 | + extra_cookie: Option<&str>, | ||
| 147 | + ) -> Answer { | ||
| 135 | let body = form | 148 | let body = form |
| 136 | .iter() | 149 | .iter() |
| 137 | .map(|(key, value)| format!("{}={}", encode(key), encode(value))) | 150 | .map(|(key, value)| format!("{}={}", encode(key), encode(value))) |
| @@ -148,6 +161,9 @@ impl App { | |||
| 148 | HeaderValue::from_str(&format!("{SESSION_COOKIE}={cookie}")).unwrap(), | 161 | HeaderValue::from_str(&format!("{SESSION_COOKIE}={cookie}")).unwrap(), |
| 149 | ); | 162 | ); |
| 150 | } | 163 | } |
| 164 | + if let Some(extra) = extra_cookie { | ||
| 165 | + request = request.header(header::COOKIE, HeaderValue::from_str(extra).unwrap()); | ||
| 166 | + } | ||
| 151 | let response = self | 167 | let response = self |
| 152 | .router | 168 | .router |
| 153 | .handle(request.body(Body::from(body)).unwrap()) | 169 | .handle(request.body(Body::from(body)).unwrap()) |
| @@ -251,16 +267,23 @@ impl App { | |||
| 251 | self.get_with_range(path, cookie, None).await | 267 | self.get_with_range(path, cookie, None).await |
| 252 | } | 268 | } |
| 253 | 269 | ||
| 270 | + /// Like `get`, but with a second `Cookie` header of the caller's own | ||
| 271 | + /// naming — for the `izlek_rows_<section>` page-size cookie, which | ||
| 272 | + /// lives beside the session cookie rather than replacing it. | ||
| 273 | + async fn get_with_extra_cookie(&self, path: &str, cookie: Option<&str>, extra: &str) -> Raw { | ||
| 274 | + self.get_with(path, cookie, None, None, Some(extra)).await | ||
| 275 | + } | ||
| 276 | + | ||
| 254 | /// Like `get`, but with a `Range` header, for exercising the | 277 | /// Like `get`, but with a `Range` header, for exercising the |
| 255 | /// `/files/{id}` partial-content path. | 278 | /// `/files/{id}` partial-content path. |
| 256 | async fn get_with_range(&self, path: &str, cookie: Option<&str>, range: Option<&str>) -> Raw { | 279 | async fn get_with_range(&self, path: &str, cookie: Option<&str>, range: Option<&str>) -> Raw { |
| 257 | - self.get_with(path, cookie, range, None).await | 280 | + self.get_with(path, cookie, range, None, None).await |
| 258 | } | 281 | } |
| 259 | 282 | ||
| 260 | /// Like `get`, but with `If-None-Match`, for the `/photo/{user_id}` | 283 | /// Like `get`, but with `If-None-Match`, for the `/photo/{user_id}` |
| 261 | /// revalidate path. | 284 | /// revalidate path. |
| 262 | async fn get_with_if_none_match(&self, path: &str, cookie: Option<&str>, etag: &str) -> Raw { | 285 | async fn get_with_if_none_match(&self, path: &str, cookie: Option<&str>, etag: &str) -> Raw { |
| 263 | - self.get_with(path, cookie, None, Some(etag)).await | 286 | + self.get_with(path, cookie, None, Some(etag), None).await |
| 264 | } | 287 | } |
| 265 | 288 | ||
| 266 | async fn get_with( | 289 | async fn get_with( |
| @@ -269,6 +292,7 @@ impl App { | |||
| 269 | cookie: Option<&str>, | 292 | cookie: Option<&str>, |
| 270 | range: Option<&str>, | 293 | range: Option<&str>, |
| 271 | if_none_match: Option<&str>, | 294 | if_none_match: Option<&str>, |
| 295 | + extra_cookie: Option<&str>, | ||
| 272 | ) -> Raw { | 296 | ) -> Raw { |
| 273 | let mut request = Request::builder().method("GET").uri(path); | 297 | let mut request = Request::builder().method("GET").uri(path); |
| 274 | if let Some(cookie) = cookie { | 298 | if let Some(cookie) = cookie { |
| @@ -277,6 +301,9 @@ impl App { | |||
| 277 | HeaderValue::from_str(&format!("{SESSION_COOKIE}={cookie}")).unwrap(), | 301 | HeaderValue::from_str(&format!("{SESSION_COOKIE}={cookie}")).unwrap(), |
| 278 | ); | 302 | ); |
| 279 | } | 303 | } |
| 304 | + if let Some(extra) = extra_cookie { | ||
| 305 | + request = request.header(header::COOKIE, HeaderValue::from_str(extra).unwrap()); | ||
| 306 | + } | ||
| 280 | if let Some(range) = range { | 307 | if let Some(range) = range { |
| 281 | request = request.header(header::RANGE, range); | 308 | request = request.header(header::RANGE, range); |
| 282 | } | 309 | } |
| @@ -4705,6 +4732,271 @@ async fn the_logs_page_pages_past_the_truncation() { | |||
| 4705 | assert!(garbage_html.contains("row 59"), "{garbage_html}"); | 4732 | assert!(garbage_html.contains("row 59"), "{garbage_html}"); |
| 4706 | } | 4733 | } |
| 4707 | 4734 | ||
| 4735 | +/// The activity filter row narrows the feed by actor, kind, task and day, | ||
| 4736 | +/// and the pager foot's position note counts against the filtered total — | ||
| 4737 | +/// not the whole feed. | ||
| 4738 | +#[tokio::test] | ||
| 4739 | +async fn the_activity_filter_narrows_and_the_position_note_counts_the_match() { | ||
| 4740 | + let app = App::open().await; | ||
| 4741 | + let admin_cookie = admin(&app).await; | ||
| 4742 | + let admin_id = user_id(&app, "ada@izlek.sh").await; | ||
| 4743 | + let member = invited(&app, &admin_cookie, "deniz@izlek.sh", "Deniz", Role::Member).await; | ||
| 4744 | + let member_id = user_id(&app, "deniz@izlek.sh").await; | ||
| 4745 | + | ||
| 4746 | + let t0 = time::OffsetDateTime::now_utc(); | ||
| 4747 | + for i in 0..60 { | ||
| 4748 | + let actor = if i % 2 == 0 { Some(admin_id.as_str()) } else { Some(member_id.as_str()) }; | ||
| 4749 | + app.store | ||
| 4750 | + .record_event( | ||
| 4751 | + actor, | ||
| 4752 | + &izlek_core::detail::ActivityKind::Other("row".to_string()), | ||
| 4753 | + &format!("row {i}"), | ||
| 4754 | + t0 + time::Duration::seconds(i), | ||
| 4755 | + ) | ||
| 4756 | + .await | ||
| 4757 | + .unwrap(); | ||
| 4758 | + } | ||
| 4759 | + | ||
| 4760 | + let all = app.get("/logs?section=activity&kind=row", Some(&admin_cookie)).await; | ||
| 4761 | + let all_html = String::from_utf8_lossy(&all.bytes).into_owned(); | ||
| 4762 | + assert!(all_html.contains("1\u{2013}"), "{all_html}"); | ||
| 4763 | + assert!(all_html.contains("/ 60</span>"), "{all_html}"); | ||
| 4764 | + | ||
| 4765 | + let by_actor = app | ||
| 4766 | + .get(&format!("/logs?section=activity&kind=row&actor={member_id}"), Some(&admin_cookie)) | ||
| 4767 | + .await; | ||
| 4768 | + let by_actor_html = String::from_utf8_lossy(&by_actor.bytes).into_owned(); | ||
| 4769 | + assert!(by_actor_html.contains("/ 30</span>"), "{by_actor_html}"); | ||
| 4770 | + | ||
| 4771 | + let oldest = app.get("/logs?section=activity&kind=row&dir=oldest", Some(&admin_cookie)).await; | ||
| 4772 | + let oldest_html = String::from_utf8_lossy(&oldest.bytes).into_owned(); | ||
| 4773 | + assert!(oldest_html.contains("row 0<"), "{oldest_html}"); | ||
| 4774 | + | ||
| 4775 | + let garbage = app | ||
| 4776 | + .get("/logs?section=activity&actor=zz&kind=zz&on=zz", Some(&admin_cookie)) | ||
| 4777 | + .await; | ||
| 4778 | + assert_eq!(garbage.status, 200); | ||
| 4779 | + | ||
| 4780 | + let refused = app.get("/logs?section=activity&actor=x", Some(&member)).await; | ||
| 4781 | + let refused_html = String::from_utf8_lossy(&refused.bytes); | ||
| 4782 | + assert!(refused_html.contains("Not permitted."), "{refused_html}"); | ||
| 4783 | +} | ||
| 4784 | + | ||
| 4785 | +/// `kind=` alone narrows the feed to one activity kind, leaving the other | ||
| 4786 | +/// kind's rows out of the body entirely. | ||
| 4787 | +#[tokio::test] | ||
| 4788 | +async fn the_kind_filter_shows_only_that_kinds_rows() { | ||
| 4789 | + let app = App::open().await; | ||
| 4790 | + let admin_cookie = admin(&app).await; | ||
| 4791 | + | ||
| 4792 | + let t0 = time::OffsetDateTime::now_utc(); | ||
| 4793 | + for i in 0..5 { | ||
| 4794 | + app.store | ||
| 4795 | + .record_event(None, &izlek_core::detail::ActivityKind::Created, "", t0 + time::Duration::seconds(i)) | ||
| 4796 | + .await | ||
| 4797 | + .unwrap(); | ||
| 4798 | + } | ||
| 4799 | + for i in 0..3 { | ||
| 4800 | + app.store | ||
| 4801 | + .record_event( | ||
| 4802 | + None, | ||
| 4803 | + &izlek_core::detail::ActivityKind::Commented, | ||
| 4804 | + "", | ||
| 4805 | + t0 + time::Duration::seconds(100 + i), | ||
| 4806 | + ) | ||
| 4807 | + .await | ||
| 4808 | + .unwrap(); | ||
| 4809 | + } | ||
| 4810 | + | ||
| 4811 | + let narrowed = app | ||
| 4812 | + .get("/logs?section=activity&kind=created", Some(&admin_cookie)) | ||
| 4813 | + .await; | ||
| 4814 | + let html = String::from_utf8_lossy(&narrowed.bytes).into_owned(); | ||
| 4815 | + assert!(html.contains("created this task"), "{html}"); | ||
| 4816 | + assert!(!html.contains("log-line\">commented<"), "{html}"); | ||
| 4817 | + assert!(html.contains("/ 5</span>"), "{html}"); | ||
| 4818 | +} | ||
| 4819 | + | ||
| 4820 | +/// `task=` narrows the feed to one task's rows, by its key — not any other | ||
| 4821 | +/// task's, even one created in the same run. | ||
| 4822 | +#[tokio::test] | ||
| 4823 | +async fn the_task_filter_shows_only_that_tasks_rows() { | ||
| 4824 | + let app = App::open().await; | ||
| 4825 | + let admin_cookie = admin(&app).await; | ||
| 4826 | + let column = first_column(&app).await; | ||
| 4827 | + let alpha = a_task(&app, &admin_cookie, &column, "Task Alpha").await; | ||
| 4828 | + let _beta = a_task(&app, &admin_cookie, &column, "Task Beta").await; | ||
| 4829 | + let alpha_key = app | ||
| 4830 | + .store | ||
| 4831 | + .task(&alpha) | ||
| 4832 | + .await | ||
| 4833 | + .unwrap() | ||
| 4834 | + .expect("alpha task gone") | ||
| 4835 | + .row | ||
| 4836 | + .task_key; | ||
| 4837 | + | ||
| 4838 | + let narrowed = app | ||
| 4839 | + .get(&format!("/logs?section=activity&task={alpha_key}"), Some(&admin_cookie)) | ||
| 4840 | + .await; | ||
| 4841 | + let html = String::from_utf8_lossy(&narrowed.bytes).into_owned(); | ||
| 4842 | + assert!(html.contains("Task Alpha"), "{html}"); | ||
| 4843 | + assert!(!html.contains("Task Beta"), "{html}"); | ||
| 4844 | +} | ||
| 4845 | + | ||
| 4846 | +/// `on=YYYY-MM-DD` keeps only the rows recorded that day, in the admin's own | ||
| 4847 | +/// timezone (UTC by default in this fixture). | ||
| 4848 | +#[tokio::test] | ||
| 4849 | +async fn the_day_filter_keeps_only_that_days_rows() { | ||
| 4850 | + let app = App::open().await; | ||
| 4851 | + let admin_cookie = admin(&app).await; | ||
| 4852 | + | ||
| 4853 | + let today = time::OffsetDateTime::now_utc(); | ||
| 4854 | + let two_days_ago = today - time::Duration::days(2); | ||
| 4855 | + for i in 0..5 { | ||
| 4856 | + app.store | ||
| 4857 | + .record_event( | ||
| 4858 | + None, | ||
| 4859 | + &izlek_core::detail::ActivityKind::Other("row".to_string()), | ||
| 4860 | + &format!("today-row {i}"), | ||
| 4861 | + today + time::Duration::seconds(i), | ||
| 4862 | + ) | ||
| 4863 | + .await | ||
| 4864 | + .unwrap(); | ||
| 4865 | + } | ||
| 4866 | + for i in 0..5 { | ||
| 4867 | + app.store | ||
| 4868 | + .record_event( | ||
| 4869 | + None, | ||
| 4870 | + &izlek_core::detail::ActivityKind::Other("row".to_string()), | ||
| 4871 | + &format!("old-row {i}"), | ||
| 4872 | + two_days_ago + time::Duration::seconds(i), | ||
| 4873 | + ) | ||
| 4874 | + .await | ||
| 4875 | + .unwrap(); | ||
| 4876 | + } | ||
| 4877 | + let on = format!("{:04}-{:02}-{:02}", today.year(), today.month() as u8, today.day()); | ||
| 4878 | + | ||
| 4879 | + let narrowed = app | ||
| 4880 | + .get(&format!("/logs?section=activity&on={on}"), Some(&admin_cookie)) | ||
| 4881 | + .await; | ||
| 4882 | + let html = String::from_utf8_lossy(&narrowed.bytes).into_owned(); | ||
| 4883 | + assert!(html.contains("today-row"), "{html}"); | ||
| 4884 | + assert!(!html.contains("old-row"), "{html}"); | ||
| 4885 | +} | ||
| 4886 | + | ||
| 4887 | +/// The `izlek_rows_activity` cookie the page's own fit script sets caps the | ||
| 4888 | +/// page at that many rows, no more. | ||
| 4889 | +#[tokio::test] | ||
| 4890 | +async fn the_rows_cookie_caps_the_page_size() { | ||
| 4891 | + let app = App::open().await; | ||
| 4892 | + let admin_cookie = admin(&app).await; | ||
| 4893 | + | ||
| 4894 | + let t0 = time::OffsetDateTime::now_utc(); | ||
| 4895 | + for i in 0..60 { | ||
| 4896 | + app.store | ||
| 4897 | + .record_event( | ||
| 4898 | + None, | ||
| 4899 | + &izlek_core::detail::ActivityKind::Other("row".to_string()), | ||
| 4900 | + &format!("row {i}"), | ||
| 4901 | + t0 + time::Duration::seconds(i), | ||
| 4902 | + ) | ||
| 4903 | + .await | ||
| 4904 | + .unwrap(); | ||
| 4905 | + } | ||
| 4906 | + | ||
| 4907 | + let capped = app | ||
| 4908 | + .get_with_extra_cookie( | ||
| 4909 | + "/logs?section=activity", | ||
| 4910 | + Some(&admin_cookie), | ||
| 4911 | + "izlek_rows_activity=15", | ||
| 4912 | + ) | ||
| 4913 | + .await; | ||
| 4914 | + let html = String::from_utf8_lossy(&capped.bytes).into_owned(); | ||
| 4915 | + assert_eq!(html.matches("class=\"log-row\"").count(), 15, "{html}"); | ||
| 4916 | + assert!(html.contains("\">Older</a>"), "{html}"); | ||
| 4917 | +} | ||
| 4918 | + | ||
| 4919 | +/// The Older href carries an active `kind=`/`dir=oldest` filter along with | ||
| 4920 | +/// its own cursor, and following it never turns up the other kind's rows. | ||
| 4921 | +#[tokio::test] | ||
| 4922 | +async fn the_older_href_round_trips_the_active_filter() { | ||
| 4923 | + let app = App::open().await; | ||
| 4924 | + let admin_cookie = admin(&app).await; | ||
| 4925 | + | ||
| 4926 | + let t0 = time::OffsetDateTime::now_utc(); | ||
| 4927 | + for i in 0..60 { | ||
| 4928 | + app.store | ||
| 4929 | + .record_event( | ||
| 4930 | + None, | ||
| 4931 | + &izlek_core::detail::ActivityKind::Other("target".to_string()), | ||
| 4932 | + &format!("target {i}"), | ||
| 4933 | + t0 + time::Duration::seconds(i), | ||
| 4934 | + ) | ||
| 4935 | + .await | ||
| 4936 | + .unwrap(); | ||
| 4937 | + } | ||
| 4938 | + for i in 0..5 { | ||
| 4939 | + app.store | ||
| 4940 | + .record_event( | ||
| 4941 | + None, | ||
| 4942 | + &izlek_core::detail::ActivityKind::Other("foreign".to_string()), | ||
| 4943 | + &format!("foreign {i}"), | ||
| 4944 | + t0 + time::Duration::seconds(1000 + i), | ||
| 4945 | + ) | ||
| 4946 | + .await | ||
| 4947 | + .unwrap(); | ||
| 4948 | + } | ||
| 4949 | + | ||
| 4950 | + let first = app | ||
| 4951 | + .get("/logs?section=activity&kind=target&dir=oldest", Some(&admin_cookie)) | ||
| 4952 | + .await; | ||
| 4953 | + let first_html = String::from_utf8_lossy(&first.bytes).into_owned(); | ||
| 4954 | + assert!(!first_html.contains("foreign"), "{first_html}"); | ||
| 4955 | + let older_href = extract_href(&first_html, "/logs?section=activity&before=").replace("&", "&"); | ||
| 4956 | + assert!(older_href.contains("kind=target"), "{older_href}"); | ||
| 4957 | + assert!(older_href.contains("dir=oldest"), "{older_href}"); | ||
| 4958 | + | ||
| 4959 | + let second = app.get(&older_href, Some(&admin_cookie)).await; | ||
| 4960 | + let second_html = String::from_utf8_lossy(&second.bytes).into_owned(); | ||
| 4961 | + assert!(!second_html.contains("foreign"), "{second_html}"); | ||
| 4962 | +} | ||
| 4963 | + | ||
| 4964 | +/// `/api/current_logs` keeps reading the unpaged newest page regardless of a | ||
| 4965 | +/// small `izlek_rows_activity` cookie — the JSON route never widened by the | ||
| 4966 | +/// page's own fit cookie. | ||
| 4967 | +#[tokio::test] | ||
| 4968 | +async fn current_logs_json_ignores_the_rows_cookie() { | ||
| 4969 | + let app = App::open().await; | ||
| 4970 | + let admin_cookie = admin(&app).await; | ||
| 4971 | + | ||
| 4972 | + let t0 = time::OffsetDateTime::now_utc(); | ||
| 4973 | + for i in 0..60 { | ||
| 4974 | + app.store | ||
| 4975 | + .record_event( | ||
| 4976 | + None, | ||
| 4977 | + &izlek_core::detail::ActivityKind::Other("row".to_string()), | ||
| 4978 | + &format!("row {i}"), | ||
| 4979 | + t0 + time::Duration::seconds(i), | ||
| 4980 | + ) | ||
| 4981 | + .await | ||
| 4982 | + .unwrap(); | ||
| 4983 | + } | ||
| 4984 | + | ||
| 4985 | + let answer = app | ||
| 4986 | + .post_with_extra_cookie( | ||
| 4987 | + "/api/current_logs", | ||
| 4988 | + Some(&admin_cookie), | ||
| 4989 | + &[], | ||
| 4990 | + Some("izlek_rows_activity=5"), | ||
| 4991 | + ) | ||
| 4992 | + .await; | ||
| 4993 | + assert!(answer.body.contains("\"queue\""), "{}", answer.body); | ||
| 4994 | + assert!(answer.body.contains("\"decisions\""), "{}", answer.body); | ||
| 4995 | + assert!(answer.body.contains("\"activity\""), "{}", answer.body); | ||
| 4996 | + let activity_rows = answer.body.matches("\"sentence\":").count(); | ||
| 4997 | + assert!(activity_rows <= 50, "{} rows: {}", activity_rows, answer.body); | ||
| 4998 | +} | ||
| 4999 | + | ||
| 4708 | /// A photo needs a session: signed out gets the same 404 an unknown id | 5000 | /// A photo needs a session: signed out gets the same 404 an unknown id |
| 4709 | /// gets, and a second workspace's admin cannot see across the fence. | 5001 | /// gets, and a second workspace's admin cannot see across the fence. |
| 4710 | #[tokio::test] | 5002 | #[tokio::test] |
style/main.scssmodified+19 -0
| @@ -2893,6 +2893,25 @@ input[type="radio"] { | |||
| 2893 | min-width: 0; | 2893 | min-width: 0; |
| 2894 | font-size: 13px; | 2894 | font-size: 13px; |
| 2895 | color: var(--ink-soft); | 2895 | color: var(--ink-soft); |
| 2896 | + overflow: hidden; | ||
| 2897 | + text-overflow: ellipsis; | ||
| 2898 | + white-space: nowrap; | ||
| 2899 | +} | ||
| 2900 | + | ||
| 2901 | +// The filter row above `.log-list`: house field boxes, wrapping rather than | ||
| 2902 | +// squeezing when the rail narrows the stage. | ||
| 2903 | +.log-filterbar { | ||
| 2904 | + height: auto; | ||
| 2905 | + flex-wrap: wrap; | ||
| 2906 | + gap: 10px; | ||
| 2907 | + padding: 14px 18px; | ||
| 2908 | +} | ||
| 2909 | + | ||
| 2910 | +// The pager foot's read of where the rendered rows sit in the whole feed. | ||
| 2911 | +.log-count { | ||
| 2912 | + font-family: var(--font-mono); | ||
| 2913 | + font-size: 10px; | ||
| 2914 | + color: var(--muted); | ||
| 2896 | } | 2915 | } |
| 2897 | 2916 | ||
| 2898 | .log-title { | 2917 | .log-title { |