From 96ca9452630b9471b8c8b993629bd4b2757ccfd3 Mon Sep 17 00:00:00 2001 From: xeruf <27jf@pm.me> Date: Mon, 23 Sep 2024 13:51:16 +0200 Subject: [PATCH] feat: allow viewing tracking history for user --- README.md | 2 +- src/main.rs | 26 +++++++++++++++++++++----- src/tasks.rs | 7 ++++++- 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 0af6e6a..c96a5fa 100644 --- a/README.md +++ b/README.md @@ -111,7 +111,7 @@ Append `@TIME` to any task creation or change command to record the action with - `:[IND][PROP]` - add property column PROP at IND or end, if it already exists remove property column PROP or IND; empty: list properties - `::[PROP]` - sort by property PROP (multiple space-separated values allowed) -- `([TIME]` - list tracked times or insert timetracking with the specified offset +- `([TIME]` - list tracked times or insert timetracking with the specified offset (double to view all history) such as `-1d`, `-15 minutes`, `yesterday 17:20`, `in 2 fortnights` - `)[TIME]` - stop timetracking with optional offset - also convenience helper to move to root - `>[TEXT]` - complete active task and move up, with optional status description diff --git a/src/main.rs b/src/main.rs index 159d47e..4bf8c90 100644 --- a/src/main.rs +++ b/src/main.rs @@ -602,15 +602,31 @@ async fn main() -> Result<()> { Some('(') => { if let Some(arg) = arg { - if tasks.track_from(arg) { - let (label, times) = tasks.times_tracked(); + let (first, remaining) = arg.split_at(1); + if first == "(" { + let mut max = usize::MAX; + match remaining.parse::() { + Ok(number) => max = number, + Err(e) => warn!("Unsure what to do with {:?}", e), + } + let (label, mut times) = tasks.times_tracked(); println!("{}\n{}", label.italic(), - times.rev().take(15).collect_vec().iter().rev().join("\n")); + times.rev().take(max).collect_vec().iter().rev().join("\n")); + } else if let Ok(key) = PublicKey::parse(arg) { // TODO also match name + let (label, mut times) = tasks.times_tracked_for(&key); + println!("{}\n{}", label.italic(), + times.join("\n")); + } else { + if tasks.track_from(arg) { + let (label, times) = tasks.times_tracked(); + println!("{}\n{}", label.italic(), + times.rev().take(15).collect_vec().iter().rev().join("\n")); + } } - // TODO show history of author / pubkey } else { let (label, mut times) = tasks.times_tracked(); - println!("{}\n{}", label.italic(), times.join("\n")); + println!("{}\n{}", label.italic(), + times.rev().take(80).collect_vec().iter().rev().join("\n")); } continue 'repl; } diff --git a/src/tasks.rs b/src/tasks.rs index 54cfe97..65cd1e2 100644 --- a/src/tasks.rs +++ b/src/tasks.rs @@ -226,9 +226,13 @@ impl TasksRelay { /// Dynamic time tracking overview for current task or current user. pub(crate) fn times_tracked(&self) -> (String, Box>) { + self.times_tracked_for(&self.sender.pubkey()) + } + + pub(crate) fn times_tracked_for(&self, key: &PublicKey) -> (String, Box>) { match self.get_position_ref() { None => { - if let Some(hist) = self.history.get(&self.sender.pubkey()) { + if let Some(hist) = self.history.get(key) { let mut last = None; let mut full = Vec::with_capacity(hist.len()); for event in hist.values() { @@ -249,6 +253,7 @@ impl TasksRelay { } } Some(id) => { + // TODO consider pubkey let ids = vec![id]; let history = self.history.iter().flat_map(|(key, set)| {