diff --git a/crates/izlek-web/src/dropdown.rs b/crates/izlek-web/src/dropdown.rs index c46eb48..595c89f 100644 --- a/crates/izlek-web/src/dropdown.rs +++ b/crates/izlek-web/src/dropdown.rs @@ -117,7 +117,7 @@ pub async fn dropdown_script(cx: &Cx) -> Result { panel.__ddTrigger = trigger;\ var allOpts = opts(select);\ var search = null;\ - if (allOpts.length > 7) {\ + if (allOpts.length > 7 || select.hasAttribute('data-search')) {\ search = document.createElement('input');\ search.type = 'text';\ search.className = 'dd-search';\ diff --git a/crates/izlek-web/src/i18n.rs b/crates/izlek-web/src/i18n.rs index ee265fb..2dd17c4 100644 --- a/crates/izlek-web/src/i18n.rs +++ b/crates/izlek-web/src/i18n.rs @@ -293,6 +293,8 @@ pub enum Key { LogSystem, Newest, Oldest, + From, + To, } /// The lone templated phrase — a name in the middle reads worse as two @@ -828,6 +830,10 @@ pub fn t(lang: Lang, key: Key) -> &'static str { (Newest, Tr) => "En yeni", (Oldest, En) => "Oldest", (Oldest, Tr) => "En eski", + (From, En) => "From", + (From, Tr) => "Başlangıç", + (To, En) => "To", + (To, Tr) => "Bitiş", } } diff --git a/crates/izlek-web/src/logs.rs b/crates/izlek-web/src/logs.rs index 6741a81..8a7aa38 100644 --- a/crates/izlek-web/src/logs.rs +++ b/crates/izlek-web/src/logs.rs @@ -373,17 +373,65 @@ fn parse_dir(query: &str) -> Dir { } } -/// `on=YYYY-MM-DD`, resolved to a half-open UTC range in the admin's own -/// timezone. Unparsable or absent is no filter, never a 500. -fn parse_day(raw: &str, zone: time::UtcOffset) -> Option<(OffsetDateTime, OffsetDateTime)> { +/// `YYYY-MM-DD`, resolved to that day's midnight in the admin's own +/// timezone then converted to UTC. Unparsable is no bound, never a 500. +fn parse_day_start(raw: &str, zone: time::UtcOffset) -> Option { use time::macros::format_description; let day = time::Date::parse(raw, format_description!("[year]-[month]-[day]")).ok()?; - let start = day - .with_hms(0, 0, 0) - .ok()? - .assume_offset(zone) - .to_offset(time::UtcOffset::UTC); - Some((start, start + time::Duration::hours(24))) + Some(day.with_hms(0, 0, 0).ok()?.assume_offset(zone).to_offset(time::UtcOffset::UTC)) +} + +/// A bound that can never exclude a real row, for the open side of a +/// one-sided range. `Date::MIN`'s negative year does not round-trip through +/// the store's Rfc3339 timestamp encoding (no sign, 4 digits only), so the +/// far ends stay inside that format's representable range instead. +fn far_past() -> OffsetDateTime { + time::PrimitiveDateTime::new( + time::Date::from_calendar_date(1, time::Month::January, 1).expect("valid"), + time::Time::MIDNIGHT, + ) + .assume_utc() +} + +fn far_future() -> OffsetDateTime { + time::PrimitiveDateTime::new(time::Date::MAX, time::Time::MIDNIGHT).assume_utc() +} + +/// `from=`/`to=YYYY-MM-DD` (or the `on=` shorthand for a single day), +/// resolved to a half-open UTC range in the admin's own timezone. `to` is +/// inclusive of its whole day. A backwards range is swapped rather than +/// read as empty. Unparsable or absent bounds fall back to the open ends, +/// so garbage input narrows nothing rather than 500ing. +fn parse_day_range( + query: &str, + zone: time::UtcOffset, +) -> Option<(OffsetDateTime, OffsetDateTime)> { + let (from_raw, to_raw) = match (query_value(query, "from"), query_value(query, "to")) { + (None, None) => match query_value(query, "on").filter(|v| !v.is_empty()) { + Some(on) => (Some(on), Some(on)), + None => return None, + }, + (from, to) => (from.filter(|v| !v.is_empty()), to.filter(|v| !v.is_empty())), + }; + if from_raw.is_none() && to_raw.is_none() { + return None; + } + // Compare the raw day starts — not `to`'s already-widened end-of-day — + // so a backwards pick swaps the two *days*, not a day boundary against + // one shifted 24h later. + let mut from_start = from_raw.and_then(|raw| parse_day_start(raw, zone)); + let mut to_start = to_raw.and_then(|raw| parse_day_start(raw, zone)); + if let (Some(f), Some(t)) = (from_start, to_start) { + if f > t { + std::mem::swap(&mut from_start, &mut to_start); + } + } + let start = from_start.unwrap_or_else(far_past); + let end = match to_start { + Some(to_start) => to_start + time::Duration::hours(24), + None => far_future(), + }; + Some((start, end)) } /// The activity tab's filter, straight off the query: an absent or empty @@ -395,7 +443,7 @@ fn parse_activity_filter(query: &str, zone: time::UtcOffset) -> ActivityFilter { task_key: query_value(query, "task") .filter(|v| !v.is_empty()) .map(|v| v.to_uppercase()), - day: query_value(query, "on").and_then(|raw| parse_day(raw, zone)), + day: parse_day_range(query, zone), } } @@ -404,7 +452,7 @@ fn parse_activity_filter(query: &str, zone: time::UtcOffset) -> ActivityFilter { /// filter form's own action so a page turn never drops a filter. fn activity_query_suffix(query: &str) -> String { let mut out = String::new(); - for key in ["actor", "kind", "task", "on", "dir"] { + for key in ["actor", "kind", "task", "from", "to", "on", "dir"] { if let Some(value) = query_value(query, key).filter(|v| !v.is_empty()) { out.push('&'); out.push_str(key); @@ -776,13 +824,21 @@ async fn logs_screen( .map(|q| format!("/logs?section={slug}&{q}{extra}")); let position_note = links.position.map(|(x, y, n)| format!("{x}\u{2013}{y} / {n}")); - let (filter_actor, filter_kind, filter_task, filter_on, filter_dir) = ( + let (filter_actor, filter_kind, filter_task, filter_dir) = ( query_value(query, "actor").unwrap_or("").to_string(), query_value(query, "kind").unwrap_or("").to_string(), query_value(query, "task").unwrap_or("").to_string(), - query_value(query, "on").unwrap_or("").to_string(), query_value(query, "dir").unwrap_or("").to_string(), ); + // `on=` is a shorthand for `from=to=on`; the boxes themselves only ever + // read/write `from`/`to`, so a link that arrived with only `on=` shows + // it in both. + let (filter_from, filter_to) = { + let on = query_value(query, "on").unwrap_or(""); + let from = query_value(query, "from").unwrap_or(on).to_string(); + let to = query_value(query, "to").unwrap_or(on).to_string(); + (from, to) + }; let members: Vec<(String, String)> = if section == Section::Activity { let store = accounts(cx).store().clone(); match store.user(&me.id).await? { @@ -940,32 +996,42 @@ async fn logs_screen(
- for member in &members { } - for kind in ACTIVITY_KINDS { } - for task in &tasks { }
- -
+ ("\u{2013}") +
+ +
- (datepicker_grid(cx, "on", &filter_on, true, lang).await?) + (datepicker_grid(cx, "to", &filter_to, true, lang).await?)