feat: hashtag list and quick filter override

This commit is contained in:
xeruf 2024-08-08 13:04:22 +03:00
parent 08b0ba48a3
commit 6b7b6b91a8
4 changed files with 30 additions and 4 deletions

View File

@ -110,8 +110,9 @@ Dots can be repeated to move to parent tasks.
Property Filters:
- `+TAG` - filter by tag
- `-TAG` - remove filter by tag
- `#TAG` - set tag filter (empty: list all used tags)
- `+TAG` - add tag filter
- `-TAG` - remove tag filters
- `?STATE` - filter by state (type or description) - plain `?` to reset
State descriptions can be used for example for Kanban columns or review flows.

View File

@ -58,6 +58,6 @@ fn format_tag(tag: &Tag) -> String {
pub(crate) fn is_hashtag(tag: &Tag) -> bool {
tag.single_letter_tag()
.is_some_and(|sltag| sltag.character == Alphabet::T)
.is_some_and(|letter| letter.character == Alphabet::T)
}

View File

@ -331,7 +331,17 @@ async fn main() {
}
},
Some('#') | Some('+') => {
Some('#') => {
match arg {
Some(arg) => tasks.set_tag(arg.to_string()),
None => {
println!("Hashtags of all known tasks:\n{}", tasks.all_hashtags().join(" "));
continue
}
}
}
Some('+') => {
match arg {
Some(arg) => tasks.add_tag(arg.to_string()),
None => tasks.clear_filter()

View File

@ -103,6 +103,16 @@ impl Tasks {
children
}
pub(crate) fn all_hashtags(&self) -> impl Iterator<Item=&str> {
self.tasks.values()
.filter(|t| t.pure_state() != State::Closed)
.filter_map(|t| t.tags.as_ref()).flatten()
.filter(|tag| is_hashtag(tag))
.filter_map(|tag| tag.content().map(|s| s.trim()))
.sorted_unstable()
.dedup()
}
/// Total time in seconds tracked on this task by the current user.
pub(crate) fn time_tracked(&self, id: EventId) -> u64 {
TimesTracked::from(self.history.get(&self.sender.pubkey()).into_iter().flatten(), &vec![id]).sum::<Duration>().as_secs()
@ -350,6 +360,11 @@ impl Tasks {
info!("Removed all filters");
}
pub(crate) fn set_tag(&mut self, tag: String) {
self.tags.clear();
self.add_tag(tag);
}
pub(crate) fn add_tag(&mut self, tag: String) {
self.view.clear();
info!("Added tag filter for #{tag}");