From 4eea2ac43b66b1f14abd8901e5adddfc2ee90af7 Mon Sep 17 00:00:00 2001 From: Campbell Alden Date: Fri, 21 Jul 2023 19:47:55 +0900 Subject: [PATCH] Add a work in progress implementation of the cycle message --- src/main.rs | 4 ++-- src/things/logbook_cycle.js | 36 ++++++++++++++++++++++++++++++++++++ src/things/task.rs | 6 +++++- 3 files changed, 43 insertions(+), 3 deletions(-) create mode 100644 src/things/logbook_cycle.js diff --git a/src/main.rs b/src/main.rs index d15239d..47b5c7d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -51,8 +51,8 @@ fn main() -> Result<()> { let args = CliArgs::parse(); let tasks = match args.mode { Modes::Morning => Task::today(), - Modes::Signoff => Task::logbook(), - Modes::Cycle => panic!("Unimplemented"), + Modes::Signoff => Task::logbook_today(), + Modes::Cycle => Task::logbook_this_cycle(), }?; let reported: Vec = tasks.into_iter().filter(|task| { args.tags.iter().all(|tag| task.has_tag(tag)) diff --git a/src/things/logbook_cycle.js b/src/things/logbook_cycle.js new file mode 100644 index 0000000..320f66b --- /dev/null +++ b/src/things/logbook_cycle.js @@ -0,0 +1,36 @@ +var things = Application("Things"); +var logbook = things.lists.byName("Logbook").toDos(); +var objs = []; + +// From 6 weeks ago +var from = new Date(new Date().getTime() - (6 * 7 * 24 * 60 * 60 * 1000)); +from.setHours(0); +from.setMinutes(0); +from.setSeconds(0); +var to = new Date(); +to.setHours(23); +to.setMinutes(59); +to.setSeconds(59); + +logbook.filter(task => { + return task.completionDate() >= from && task.completionDate() < to; +}).forEach(todo => { + var proj = todo.project(); + var tags = []; + if (proj) { + tags.push(...proj.tagNames().split(', ')); + } + var area = todo.area() || proj && proj.area(); + objs.push({ + id: todo.id(), + title: todo.name(), + notes: todo.notes() || null, + status: todo.status(), + completion_date: todo.completionDate(), + project: proj && { id: proj.id(), title: proj.name() }, + area: area && { id: area.id(), title: area.name() }, + tags: [...tags, ...todo.tagNames().split(', ')].filter(t => t), + }); +}); + +return JSON.stringify(objs, undefined, 2); diff --git a/src/things/task.rs b/src/things/task.rs index 7aff94b..a5a1e05 100644 --- a/src/things/task.rs +++ b/src/things/task.rs @@ -54,10 +54,14 @@ impl Task { } /// Get all tasks in the logbook list from Things - pub fn logbook() -> Result> { + pub fn logbook_today() -> Result> { Task::from_script(include_bytes!("logbook.js")) } + pub fn logbook_this_cycle() -> Result> { + Task::from_script(include_bytes!("logbook_cycle.js")) + } + pub fn has_tag(&self, tag: &str) -> bool { self.tags.contains(&String::from(tag)) }