forked from janek/mostr
feat(tasks): display bookmarks and time summary
This commit is contained in:
parent
1533676bff
commit
613a8b3822
|
@ -2,6 +2,7 @@ use fmt::Display;
|
||||||
use std::cmp::Ordering;
|
use std::cmp::Ordering;
|
||||||
use std::collections::{BTreeSet, HashSet};
|
use std::collections::{BTreeSet, HashSet};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
use std::hash::{Hash, Hasher};
|
||||||
use std::string::ToString;
|
use std::string::ToString;
|
||||||
|
|
||||||
use colored::{ColoredString, Colorize};
|
use colored::{ColoredString, Colorize};
|
||||||
|
@ -40,6 +41,12 @@ impl Ord for Task {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Hash for Task {
|
||||||
|
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||||
|
self.event.id.hash(state);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Task {
|
impl Task {
|
||||||
pub(crate) fn new(event: Event) -> Task {
|
pub(crate) fn new(event: Event) -> Task {
|
||||||
let (refs, tags) = event.tags.iter().partition_map(|tag| match tag.as_standardized() {
|
let (refs, tags) = event.tags.iter().partition_map(|tag| match tag.as_standardized() {
|
||||||
|
|
54
src/tasks.rs
54
src/tasks.rs
|
@ -1105,13 +1105,14 @@ impl Display for TasksRelay {
|
||||||
writeln!(lock, "{}", t.descriptions().join("\n"))?;
|
writeln!(lock, "{}", t.descriptions().join("\n"))?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let position = self.get_position_ref();
|
||||||
let mut current = vec![];
|
let mut current = vec![];
|
||||||
let mut roots = self.view.iter().flat_map(|id| self.get_by_id(id)).collect_vec();
|
let mut roots = self.view.iter().flat_map(|id| self.get_by_id(id)).collect_vec();
|
||||||
if self.search_depth > 0 && roots.is_empty() {
|
if self.search_depth > 0 && roots.is_empty() {
|
||||||
current = self.resolve_tasks_rec(self.tasks.children_for(self.get_position_ref()), true, self.search_depth + self.view_depth);
|
current = self.resolve_tasks_rec(self.tasks.children_for(position), true, self.search_depth + self.view_depth);
|
||||||
if current.is_empty() {
|
if current.is_empty() {
|
||||||
if !self.tags.is_empty() {
|
if !self.tags.is_empty() {
|
||||||
let mut children = self.tasks.children_for(self.get_position_ref()).peekable();
|
let mut children = self.tasks.children_for(position).peekable();
|
||||||
if children.peek().is_some() {
|
if children.peek().is_some() {
|
||||||
current = self.resolve_tasks_rec(children, true, 9);
|
current = self.resolve_tasks_rec(children, true, 9);
|
||||||
if current.is_empty() {
|
if current.is_empty() {
|
||||||
|
@ -1135,23 +1136,18 @@ impl Display for TasksRelay {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
//let tree = current.iter().flat_map(|task| self.traverse_up_from(Some(task.event.id))).map(|task| task.get_id()).unique().collect_vec();
|
let tree = current.iter().flat_map(|task| self.traverse_up_from(Some(task.event.id))).unique();
|
||||||
//let ids = current.iter().map(|t| t.get_id()).collect_vec();
|
let ids: HashSet<&EventId> = tree.map(|t| t.get_id()).collect();
|
||||||
//let mut bookmarks =
|
let mut bookmarks =
|
||||||
// // TODO highlight bookmarks
|
// TODO add recent tasks
|
||||||
// // TODO add recent tasks
|
self.bookmarks.iter()
|
||||||
// self.bookmarks.iter()
|
.filter(|id| !position.is_some_and(|p| &p == id) && !ids.contains(id))
|
||||||
// .filter(|id| !position.is_some_and(|p| &p == id) && !ids.contains(id))
|
.filter_map(|id| self.get_by_id(id))
|
||||||
// .filter_map(|id| self.get_by_id(id))
|
.filter(|t| self.filter(t))
|
||||||
// .filter(|t| self.filter(t))
|
.peekable();
|
||||||
// .collect_vec();
|
if bookmarks.peek().is_some() {
|
||||||
//current.append(&mut bookmarks);
|
writeln!(lock, "{}", Colorize::bold("Bookmarks"))?;
|
||||||
|
for task in bookmarks {
|
||||||
// TODO proper column alignment
|
|
||||||
// TODO hide empty columns
|
|
||||||
writeln!(lock, "{}", self.properties.join(" \t").bold())?;
|
|
||||||
let count = current.len();
|
|
||||||
for task in current {
|
|
||||||
writeln!(
|
writeln!(
|
||||||
lock,
|
lock,
|
||||||
"{}",
|
"{}",
|
||||||
|
@ -1160,11 +1156,25 @@ impl Display for TasksRelay {
|
||||||
.join(" \t")
|
.join(" \t")
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO proper column alignment
|
||||||
|
// TODO hide empty columns
|
||||||
|
writeln!(lock, "{}", self.properties.join(" \t").bold())?;
|
||||||
|
|
||||||
|
let count = current.len();
|
||||||
let mut total_time = 0;
|
let mut total_time = 0;
|
||||||
//for root in roots {
|
for task in current {
|
||||||
// total_time += self.total_time_tracked(root.event.id)
|
writeln!(
|
||||||
//}
|
lock,
|
||||||
|
"{}",
|
||||||
|
self.properties.iter()
|
||||||
|
.map(|p| self.get_property(task, p.as_str()))
|
||||||
|
.join(" \t")
|
||||||
|
)?;
|
||||||
|
total_time += self.total_time_tracked(task.event.id) // TODO include parent if it matches
|
||||||
|
}
|
||||||
|
|
||||||
writeln!(lock, "{} visible tasks{}", count, display_time(" tracked a total of HHhMMm", total_time))?;
|
writeln!(lock, "{} visible tasks{}", count, display_time(" tracked a total of HHhMMm", total_time))?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue