feat(tasks): enable excluding tags from view
This commit is contained in:
parent
c83d8a2f55
commit
b3d70ab0b7
26
src/tasks.rs
26
src/tasks.rs
|
@ -41,6 +41,8 @@ pub(crate) struct Tasks {
|
||||||
position: Option<EventId>,
|
position: Option<EventId>,
|
||||||
/// Currently active tags
|
/// Currently active tags
|
||||||
tags: BTreeSet<Tag>,
|
tags: BTreeSet<Tag>,
|
||||||
|
/// Tags filtered out
|
||||||
|
tags_excluded: BTreeSet<Tag>,
|
||||||
/// Current active state
|
/// Current active state
|
||||||
state: StateFilter,
|
state: StateFilter,
|
||||||
/// A filtered view of the current tasks
|
/// A filtered view of the current tasks
|
||||||
|
@ -130,6 +132,7 @@ impl Tasks {
|
||||||
position: None, // TODO persist position
|
position: None, // TODO persist position
|
||||||
view: Default::default(),
|
view: Default::default(),
|
||||||
tags: Default::default(),
|
tags: Default::default(),
|
||||||
|
tags_excluded: Default::default(),
|
||||||
state: Default::default(),
|
state: Default::default(),
|
||||||
depth: 1,
|
depth: 1,
|
||||||
sender,
|
sender,
|
||||||
|
@ -265,9 +268,10 @@ impl Tasks {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn get_prompt_suffix(&self) -> String {
|
pub(crate) fn get_prompt_suffix(&self) -> String {
|
||||||
self.tags
|
self.tags.iter()
|
||||||
.iter()
|
|
||||||
.map(|t| format!(" #{}", t.content().unwrap()))
|
.map(|t| format!(" #{}", t.content().unwrap()))
|
||||||
|
.chain(self.tags_excluded.iter()
|
||||||
|
.map(|t| format!(" -#{}", t.content().unwrap())))
|
||||||
.chain(once(self.state.indicator()))
|
.chain(once(self.state.indicator()))
|
||||||
.join("")
|
.join("")
|
||||||
}
|
}
|
||||||
|
@ -364,9 +368,12 @@ impl Tasks {
|
||||||
self.resolve_tasks(self.children_of(self.position)).into_iter()
|
self.resolve_tasks(self.children_of(self.position)).into_iter()
|
||||||
.filter(|t| {
|
.filter(|t| {
|
||||||
// TODO apply filters in transit
|
// TODO apply filters in transit
|
||||||
let state = t.pure_state();
|
self.state.matches(t) &&
|
||||||
self.state.matches(t) && (self.tags.is_empty()
|
t.tags.as_ref().map_or(true, |tags| {
|
||||||
|| t.tags.as_ref().map_or(false, |tags| {
|
tags.iter().find(|tag| self.tags_excluded.contains(tag)).is_none()
|
||||||
|
}) &&
|
||||||
|
(self.tags.is_empty() ||
|
||||||
|
t.tags.as_ref().map_or(false, |tags| {
|
||||||
let mut iter = tags.iter();
|
let mut iter = tags.iter();
|
||||||
self.tags.iter().all(|tag| iter.any(|t| t == tag))
|
self.tags.iter().all(|tag| iter.any(|t| t == tag))
|
||||||
}))
|
}))
|
||||||
|
@ -483,10 +490,12 @@ impl Tasks {
|
||||||
pub(crate) fn clear_filter(&mut self) {
|
pub(crate) fn clear_filter(&mut self) {
|
||||||
self.view.clear();
|
self.view.clear();
|
||||||
self.tags.clear();
|
self.tags.clear();
|
||||||
|
self.tags_excluded.clear();
|
||||||
info!("Removed all filters");
|
info!("Removed all filters");
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn set_tag(&mut self, tag: String) {
|
pub(crate) fn set_tag(&mut self, tag: String) {
|
||||||
|
self.tags_excluded.clear();
|
||||||
self.tags.clear();
|
self.tags.clear();
|
||||||
self.add_tag(tag);
|
self.add_tag(tag);
|
||||||
}
|
}
|
||||||
|
@ -494,7 +503,9 @@ impl Tasks {
|
||||||
pub(crate) fn add_tag(&mut self, tag: String) {
|
pub(crate) fn add_tag(&mut self, tag: String) {
|
||||||
self.view.clear();
|
self.view.clear();
|
||||||
info!("Added tag filter for #{tag}");
|
info!("Added tag filter for #{tag}");
|
||||||
self.tags.insert(Hashtag(tag).into());
|
let tag: Tag = Hashtag(tag).into();
|
||||||
|
self.tags_excluded.remove(&tag);
|
||||||
|
self.tags.insert(tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn remove_tag(&mut self, tag: &str) {
|
pub(crate) fn remove_tag(&mut self, tag: &str) {
|
||||||
|
@ -504,7 +515,8 @@ impl Tasks {
|
||||||
if self.tags.len() < len {
|
if self.tags.len() < len {
|
||||||
info!("Removed tag filters starting with {tag}");
|
info!("Removed tag filters starting with {tag}");
|
||||||
} else {
|
} else {
|
||||||
info!("Found no tag filters starting with {tag} to remove");
|
self.tags_excluded.insert(Hashtag(tag.to_string()).into());
|
||||||
|
info!("Excluding #{tag} from view");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue