forked from janek/mostr
feat: toggleable activity recursion
This commit is contained in:
parent
28d1f4c983
commit
3d389e8d52
3 changed files with 32 additions and 17 deletions
21
src/main.rs
21
src/main.rs
|
@ -437,18 +437,27 @@ async fn main() -> Result<()> {
|
||||||
Some(',') =>
|
Some(',') =>
|
||||||
match arg {
|
match arg {
|
||||||
None => {
|
None => {
|
||||||
tasks.get_current_task().map_or_else(
|
match tasks.get_current_task() {
|
||||||
|| info!("With a task selected, use ,NOTE to attach NOTE and , to list all its notes"),
|
None => {
|
||||||
|task| println!("{}", task.description_events().map(|e| format!("{} {}", format_timestamp_local(&e.created_at), e.content)).join("\n")),
|
info!("With a task selected, use ,NOTE to attach NOTE and , to list all its notes");
|
||||||
);
|
tasks.recurse_activities = !tasks.recurse_activities;
|
||||||
continue 'repl;
|
info!("Toggled activities recursion to {}", tasks.recurse_activities);
|
||||||
|
}
|
||||||
|
Some(task) => {
|
||||||
|
println!("{}",
|
||||||
|
task.description_events()
|
||||||
|
.map(|e| format!("{} {}", format_timestamp_local(&e.created_at), e.content))
|
||||||
|
.join("\n"));
|
||||||
|
continue 'repl;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Some(arg) => {
|
Some(arg) => {
|
||||||
if arg.len() < CHARACTER_THRESHOLD {
|
if arg.len() < CHARACTER_THRESHOLD {
|
||||||
warn!("Note needs at least {CHARACTER_THRESHOLD} characters!");
|
warn!("Note needs at least {CHARACTER_THRESHOLD} characters!");
|
||||||
continue 'repl;
|
continue 'repl;
|
||||||
}
|
}
|
||||||
tasks.make_note(arg)
|
tasks.make_note(arg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -94,9 +94,10 @@ impl Task {
|
||||||
self.event.kind == TASK_KIND
|
self.event.kind == TASK_KIND
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Whether this is an actionable task - false if stateless
|
||||||
pub(crate) fn is_task(&self) -> bool {
|
pub(crate) fn is_task(&self) -> bool {
|
||||||
self.is_task_kind() ||
|
self.is_task_kind() ||
|
||||||
self.states().next().is_some()
|
self.props.iter().any(|event| State::try_from(event.kind).is_ok())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn states(&self) -> impl DoubleEndedIterator<Item=TaskState> + '_ {
|
fn states(&self) -> impl DoubleEndedIterator<Item=TaskState> + '_ {
|
||||||
|
|
25
src/tasks.rs
25
src/tasks.rs
|
@ -388,9 +388,12 @@ impl TasksRelay {
|
||||||
if !self.state.matches(task) {
|
if !self.state.matches(task) {
|
||||||
return vec![]
|
return vec![]
|
||||||
}
|
}
|
||||||
let mut new_depth = depth - 1;
|
let mut new_depth = depth;
|
||||||
if sparse && new_depth > self.view_depth && self.filter(task) {
|
if !self.recurse_activities || task.is_task() {
|
||||||
new_depth = self.view_depth;
|
new_depth = depth - 1;
|
||||||
|
if sparse && new_depth > self.view_depth && self.filter(task) {
|
||||||
|
new_depth = self.view_depth;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if new_depth > 0 {
|
if new_depth > 0 {
|
||||||
let mut children = self.resolve_tasks_rec(self.tasks.children_of(&task), sparse, new_depth);
|
let mut children = self.resolve_tasks_rec(self.tasks.children_of(&task), sparse, new_depth);
|
||||||
|
@ -1082,12 +1085,11 @@ impl TasksRelay {
|
||||||
Some(self.set_state_for(*id, comment, state))
|
Some(self.set_state_for(*id, comment, state))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn make_note(&mut self, note: &str) {
|
pub(crate) fn make_note(&mut self, note: &str) -> EventId {
|
||||||
if let Some(id) = self.get_position_ref() {
|
if let Some(id) = self.get_position_ref() {
|
||||||
if self.get_by_id(id).is_some_and(|t| t.is_task()) {
|
if self.get_by_id(id).is_some_and(|t| t.is_task()) {
|
||||||
let prop = build_prop(Kind::TextNote, note.trim(), *id);
|
let prop = build_prop(Kind::TextNote, note.trim(), *id);
|
||||||
self.submit(prop);
|
return self.submit(prop)
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let (input, tags) = extract_tags(note.trim());
|
let (input, tags) = extract_tags(note.trim());
|
||||||
|
@ -1095,7 +1097,7 @@ impl TasksRelay {
|
||||||
build_task(input, tags, Some(("activity", Kind::TextNote)))
|
build_task(input, tags, Some(("activity", Kind::TextNote)))
|
||||||
.add_tags(self.parent_tag())
|
.add_tags(self.parent_tag())
|
||||||
.add_tags(self.tags.iter().cloned())
|
.add_tags(self.tags.iter().cloned())
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Properties
|
// Properties
|
||||||
|
@ -1635,10 +1637,11 @@ mod tasks_test {
|
||||||
fn test_depth() {
|
fn test_depth() {
|
||||||
let mut tasks = stub_tasks();
|
let mut tasks = stub_tasks();
|
||||||
|
|
||||||
let t1 = tasks.make_task("t1");
|
let t1 = tasks.make_note("t1");
|
||||||
let task1 = tasks.get_by_id(&t1).unwrap();
|
let activity_t1 = tasks.get_by_id(&t1).unwrap();
|
||||||
|
assert!(!activity_t1.is_task());
|
||||||
assert_eq!(tasks.view_depth, 0);
|
assert_eq!(tasks.view_depth, 0);
|
||||||
assert_eq!(task1.pure_state(), State::Open);
|
assert_eq!(activity_t1.pure_state(), State::Open);
|
||||||
debug!("{:?}", tasks);
|
debug!("{:?}", tasks);
|
||||||
assert_eq!(tasks.visible_tasks().len(), 1);
|
assert_eq!(tasks.visible_tasks().len(), 1);
|
||||||
tasks.search_depth = 0;
|
tasks.search_depth = 0;
|
||||||
|
@ -1687,6 +1690,8 @@ mod tasks_test {
|
||||||
assert_tasks!(tasks, [t11, t12]);
|
assert_tasks!(tasks, [t11, t12]);
|
||||||
|
|
||||||
tasks.move_to(None);
|
tasks.move_to(None);
|
||||||
|
assert_tasks!(tasks, [t11, t12]);
|
||||||
|
tasks.recurse_activities = false;
|
||||||
assert_tasks!(tasks, [t1]);
|
assert_tasks!(tasks, [t1]);
|
||||||
tasks.view_depth = 1;
|
tasks.view_depth = 1;
|
||||||
assert_tasks!(tasks, [t11, t12]);
|
assert_tasks!(tasks, [t11, t12]);
|
||||||
|
|
Loading…
Add table
Reference in a new issue