From fd94de7149ab47ec4973c4ab1f04021665292a88 Mon Sep 17 00:00:00 2001 From: xeruf <27jf@pm.me> Date: Thu, 25 Jul 2024 22:50:57 +0300 Subject: [PATCH] feat: tags property column --- src/task.rs | 10 ++++++++-- src/tasks.rs | 6 ++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/task.rs b/src/task.rs index 4018ab6..580d659 100644 --- a/src/task.rs +++ b/src/task.rs @@ -8,14 +8,14 @@ pub(crate) struct Task { pub(crate) children: HashSet, pub(crate) props: BTreeSet, /// Cached sorted tags of the event - pub(crate) tags: BTreeSet, + pub(crate) tags: Option>, } impl Task { pub(crate) fn new(event: Event) -> Task { Task { children: Default::default(), props: Default::default(), - tags: event.tags.iter().cloned().collect(), + tags: if event.tags.is_empty() { None } else { Some(event.tags.iter().cloned().collect()) }, event, } } @@ -103,6 +103,12 @@ impl Task { "state" => self.state().map(|s| s.to_string()), "name" => Some(self.event.content.clone()), "time" => Some(self.time_tracked().to_string()), // TODO: format properly + "tags" => self.tags.as_ref().map(|tags| { + tags.iter() + .map(|t| format!("{}", t.content().unwrap())) + .collect::>() + .join(" ") + }), "props" => Some(format!( "{:?}", self.props diff --git a/src/tasks.rs b/src/tasks.rs index b2550d9..66a4a60 100644 --- a/src/tasks.rs +++ b/src/tasks.rs @@ -172,8 +172,10 @@ impl Tasks { tasks .into_iter() .filter(|t| { - let mut iter = t.tags.iter(); - self.tags.iter().all(|tag| iter.any(|t| t == tag)) + t.tags.as_ref().map_or(false, |tags| { + let mut iter = tags.iter(); + self.tags.iter().all(|tag| iter.any(|t| t == tag)) + }) }) .collect() }