Adapt to filter returning Iterator
This commit is contained in:
parent
06af1a749f
commit
c03420d8fe
3 changed files with 23 additions and 16 deletions
|
@ -279,10 +279,10 @@ fn gen_match(a: &Task, b: &Task) -> bool {
|
||||||
}
|
}
|
||||||
impl TaskGenerator for TaskCache {
|
impl TaskGenerator for TaskCache {
|
||||||
fn get_by_gen(&self, generator: &Task) -> Option<&Task> {
|
fn get_by_gen(&self, generator: &Task) -> Option<&Task> {
|
||||||
self.filter(|t| gen_match(t, generator)).into_iter().next()
|
self.filter(|t| gen_match(t, generator)).next()
|
||||||
}
|
}
|
||||||
fn get_by_gen_mut(&mut self, generator: &Task) -> Option<&mut Task> {
|
fn get_by_gen_mut(&mut self, generator: &Task) -> Option<&mut Task> {
|
||||||
self.filter_mut(|t| gen_match(t, generator)).into_iter().next()
|
self.filter_mut(|t| gen_match(t, generator)).next()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn generate<T>(&mut self, generators: T) -> Result<()>
|
fn generate<T>(&mut self, generators: T) -> Result<()>
|
||||||
|
@ -304,7 +304,6 @@ where
|
||||||
.or_insert_with(|| {
|
.or_insert_with(|| {
|
||||||
self
|
self
|
||||||
.filter(|t| t.gen_name() == Some(name))
|
.filter(|t| t.gen_name() == Some(name))
|
||||||
.iter()
|
|
||||||
.filter_map(|t| t.gen_id().map(|id| (id.clone(), t.uuid().clone())))
|
.filter_map(|t| t.gen_id().map(|id| (id.clone(), t.uuid().clone())))
|
||||||
.collect()
|
.collect()
|
||||||
})
|
})
|
||||||
|
|
|
@ -215,8 +215,8 @@ impl Kassandra {
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_sorted_tasks<T: Fn(&Task) -> bool>(&self, filter: T) -> Vec<&Task> {
|
fn get_sorted_tasks(&self, filter: impl Fn(&Task) -> bool) -> Vec<&Task> {
|
||||||
let mut tasks = self.cache.filter(filter);
|
let mut tasks = self.cache.filter(filter).collect::<Vec<_>>();
|
||||||
tasks.sort_unstable_by_key(|t| t.entry().date());
|
tasks.sort_unstable_by_key(|t| t.entry().date());
|
||||||
tasks
|
tasks
|
||||||
}
|
}
|
||||||
|
@ -333,7 +333,8 @@ What's the progress?",
|
||||||
.filter(|t| {
|
.filter(|t| {
|
||||||
t.gen_name() == Some(&"Sortiere Tasktree".into()) && t.pending()
|
t.gen_name() == Some(&"Sortiere Tasktree".into()) && t.pending()
|
||||||
})
|
})
|
||||||
.len() > 0
|
.next()
|
||||||
|
.is_some()
|
||||||
{
|
{
|
||||||
while let Some(uuid) = self.get_sorted_uuids(|t| {
|
while let Some(uuid) = self.get_sorted_uuids(|t| {
|
||||||
!t.obsolete() && task_needs_sorting(&self.cache, t.uuid()).unwrap_or(false)
|
!t.obsolete() && task_needs_sorting(&self.cache, t.uuid()).unwrap_or(false)
|
||||||
|
@ -390,10 +391,12 @@ What's the progress?",
|
||||||
let mut parent = None;
|
let mut parent = None;
|
||||||
loop {
|
loop {
|
||||||
match {
|
match {
|
||||||
let mut options = self.cache.filter(|t| {
|
let mut options = self.cache
|
||||||
|
.filter(|t| {
|
||||||
t.pending() && t.partof().map(|partof| partof == parent).unwrap_or(false) &&
|
t.pending() && t.partof().map(|partof| partof == parent).unwrap_or(false) &&
|
||||||
(parent.is_some() || self.cache.is_project(t.uuid()))
|
(parent.is_some() || self.cache.is_project(t.uuid()))
|
||||||
});
|
})
|
||||||
|
.collect::<Vec<_>>();
|
||||||
options.sort_unstable_by_key(|t| t.entry().date());
|
options.sort_unstable_by_key(|t| t.entry().date());
|
||||||
match self.dialog.select_option(
|
match self.dialog.select_option(
|
||||||
format_msg(&self.cache, parent, "currently at")?,
|
format_msg(&self.cache, parent, "currently at")?,
|
||||||
|
@ -588,7 +591,8 @@ What's the progress?",
|
||||||
.filter(|t| {
|
.filter(|t| {
|
||||||
t.gen_name() == Some(&"Leere Inbox".into()) && t.pending()
|
t.gen_name() == Some(&"Leere Inbox".into()) && t.pending()
|
||||||
})
|
})
|
||||||
.len() > 0
|
.next()
|
||||||
|
.is_some()
|
||||||
{
|
{
|
||||||
while let Some(uuid) = self.get_sorted_uuids(|t| task_inbox(&self.cache, t))
|
while let Some(uuid) = self.get_sorted_uuids(|t| task_inbox(&self.cache, t))
|
||||||
.into_iter()
|
.into_iter()
|
||||||
|
@ -718,7 +722,8 @@ What's the progress?",
|
||||||
.filter(|t| {
|
.filter(|t| {
|
||||||
t.gen_name() == Some(&"Aktualisiere Buchhaltung".into()) && t.pending()
|
t.gen_name() == Some(&"Aktualisiere Buchhaltung".into()) && t.pending()
|
||||||
})
|
})
|
||||||
.len() > 0
|
.next()
|
||||||
|
.is_some()
|
||||||
{
|
{
|
||||||
str2cmd(&term_cmd("sh -c"))
|
str2cmd(&term_cmd("sh -c"))
|
||||||
.arg("jali -l. && task gen_id:'Aktualisiere Buchhaltung' done")
|
.arg("jali -l. && task gen_id:'Aktualisiere Buchhaltung' done")
|
||||||
|
@ -731,12 +736,14 @@ What's the progress?",
|
||||||
pub fn select_next_task(&mut self) -> Result<()> {
|
pub fn select_next_task(&mut self) -> Result<()> {
|
||||||
while self.cache
|
while self.cache
|
||||||
.filter(|t| t.start().is_some() && t.pending())
|
.filter(|t| t.start().is_some() && t.pending())
|
||||||
.len() == 0 &&
|
.next()
|
||||||
|
.is_none() &&
|
||||||
self.cache
|
self.cache
|
||||||
.filter(|t| {
|
.filter(|t| {
|
||||||
t.pending() && self.is_relevant(t) && !task_blocked(&self.cache, t)
|
t.pending() && self.is_relevant(t) && !task_blocked(&self.cache, t)
|
||||||
})
|
})
|
||||||
.len() > 0
|
.next()
|
||||||
|
.is_some()
|
||||||
{
|
{
|
||||||
if let Some(uuid) = {
|
if let Some(uuid) = {
|
||||||
let next_tasks = self.get_sorted_tasks(|t| {
|
let next_tasks = self.get_sorted_tasks(|t| {
|
||||||
|
|
|
@ -117,10 +117,12 @@ impl TreeCache for TaskCache {
|
||||||
|
|
||||||
fn get_children(&self, uuid: &Uuid) -> Vec<&Task> {
|
fn get_children(&self, uuid: &Uuid) -> Vec<&Task> {
|
||||||
self.filter(|t| t.partof().unwrap_or(None) == Some(*uuid))
|
self.filter(|t| t.partof().unwrap_or(None) == Some(*uuid))
|
||||||
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_children_mut(&mut self, uuid: &Uuid) -> Vec<&mut Task> {
|
fn get_children_mut(&mut self, uuid: &Uuid) -> Vec<&mut Task> {
|
||||||
self.filter_mut(|t| t.partof().unwrap_or(None) == Some(*uuid))
|
self.filter_mut(|t| t.partof().unwrap_or(None) == Some(*uuid))
|
||||||
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_project_path(&self, uuid: &Uuid) -> Result<String> {
|
fn get_project_path(&self, uuid: &Uuid) -> Result<String> {
|
||||||
|
@ -150,8 +152,7 @@ impl TreeCache for TaskCache {
|
||||||
.map(|path| path.as_ref() != t.project())
|
.map(|path| path.as_ref() != t.project())
|
||||||
.unwrap_or(false) ||
|
.unwrap_or(false) ||
|
||||||
(self.is_project(t.uuid()) != t.has_tag("project")))
|
(self.is_project(t.uuid()) != t.has_tag("project")))
|
||||||
}).iter()
|
}).map(|t| t.uuid().clone())
|
||||||
.map(|t| t.uuid().clone())
|
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
for task_uuid in task_uuids {
|
for task_uuid in task_uuids {
|
||||||
let new_project_name = get_project_name(self, self.get(&task_uuid).expect("Bug"))
|
let new_project_name = get_project_name(self, self.get(&task_uuid).expect("Bug"))
|
||||||
|
|
Loading…
Reference in a new issue