forked from janek/mostr
feat(tasks): include bookmarked tasks regardless of position
This commit is contained in:
parent
5a62e8f99e
commit
1297be43bc
58
src/tasks.rs
58
src/tasks.rs
|
@ -378,20 +378,23 @@ impl Tasks {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn filtered_tasks<'a>(&'a self, position: Option<&'a EventId>) -> impl Iterator<Item=&Task> + 'a {
|
pub(crate) fn filtered_tasks<'a>(&'a self, position: Option<&'a EventId>) -> impl Iterator<Item=&Task> + 'a {
|
||||||
|
let current: HashMap<&EventId, &Task> = self.resolve_tasks(self.children_of(position)).map(|t| (t.get_id(), t)).collect();
|
||||||
|
let bookmarks = self.bookmarks.iter().filter(|id| !current.contains_key(id)).filter_map(|id| self.get_by_id(id)).collect_vec();
|
||||||
// TODO use ChildIterator
|
// TODO use ChildIterator
|
||||||
self.resolve_tasks(self.children_of(position))
|
current.into_values().chain(
|
||||||
.filter(move |t| {
|
bookmarks
|
||||||
// TODO apply filters in transit
|
).filter(move |t| {
|
||||||
self.state.matches(t) &&
|
// TODO apply filters in transit
|
||||||
t.tags.as_ref().map_or(true, |tags| {
|
self.state.matches(t) &&
|
||||||
!tags.iter().any(|tag| self.tags_excluded.contains(tag))
|
t.tags.as_ref().map_or(true, |tags| {
|
||||||
}) &&
|
!tags.iter().any(|tag| self.tags_excluded.contains(tag))
|
||||||
(self.tags.is_empty() ||
|
}) &&
|
||||||
t.tags.as_ref().map_or(false, |tags| {
|
(self.tags.is_empty() ||
|
||||||
let mut iter = tags.iter();
|
t.tags.as_ref().map_or(false, |tags| {
|
||||||
self.tags.iter().all(|tag| iter.any(|t| t == tag))
|
let mut iter = tags.iter();
|
||||||
}))
|
self.tags.iter().all(|tag| iter.any(|t| t == tag))
|
||||||
})
|
}))
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn visible_tasks(&self) -> Vec<&Task> {
|
pub(crate) fn visible_tasks(&self) -> Vec<&Task> {
|
||||||
|
@ -1221,6 +1224,35 @@ mod tasks_test {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_bookmarks() {
|
||||||
|
let mut tasks = stub_tasks();
|
||||||
|
let zero = EventId::all_zeros();
|
||||||
|
let test = tasks.make_task("test: tag");
|
||||||
|
let parent = tasks.make_task("parent");
|
||||||
|
assert_eq!(tasks.visible_tasks().len(), 2);
|
||||||
|
tasks.move_to(Some(parent));
|
||||||
|
let pin = tasks.make_task("pin");
|
||||||
|
|
||||||
|
assert_eq!(tasks.filtered_tasks(None).count(), 2);
|
||||||
|
assert_eq!(tasks.filtered_tasks(Some(&zero)).count(), 0);
|
||||||
|
tasks.submit(EventBuilder::new(Kind::Bookmarks, "", [Tag::event(pin), Tag::event(zero)]));
|
||||||
|
assert_eq!(tasks.filtered_tasks(Some(&zero)).collect_vec(), vec![tasks.get_by_id(&pin).unwrap()]);
|
||||||
|
|
||||||
|
tasks.move_to(None);
|
||||||
|
assert_eq!(tasks.visible_tasks().len(), 3);
|
||||||
|
tasks.set_depth(2);
|
||||||
|
assert_eq!(tasks.visible_tasks().len(), 3);
|
||||||
|
tasks.add_tag("tag".to_string());
|
||||||
|
assert_eq!(tasks.visible_tasks().len(), 1);
|
||||||
|
assert_eq!(tasks.filtered_tasks(None).collect_vec(), vec![tasks.get_by_id(&test).unwrap()]);
|
||||||
|
tasks.submit(EventBuilder::new(Kind::Bookmarks, "", []));
|
||||||
|
tasks.clear_filters();
|
||||||
|
assert_eq!(tasks.visible_tasks().len(), 3);
|
||||||
|
tasks.set_depth(1);
|
||||||
|
assert_eq!(tasks.visible_tasks().len(), 2);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_procedures() {
|
fn test_procedures() {
|
||||||
let mut tasks = stub_tasks();
|
let mut tasks = stub_tasks();
|
||||||
|
|
Loading…
Reference in New Issue