From 9d62d4d555dc92be7c6f72f09bcfb43436d7ca60 Mon Sep 17 00:00:00 2001 From: Campbell Alden Date: Tue, 24 Dec 2024 11:56:52 +0900 Subject: [PATCH] Update the day reporter to use lists instead of report types --- Cargo.lock | 2 +- src/main.rs | 50 +++++++++++++------------------------ src/things/logbook_cycle.js | 42 ------------------------------- src/things/task.rs | 6 +---- 4 files changed, 19 insertions(+), 81 deletions(-) delete mode 100644 src/things/logbook_cycle.js diff --git a/Cargo.lock b/Cargo.lock index 208356e..c73a052 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -173,7 +173,7 @@ checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa" [[package]] name = "day-reporter" -version = "1.4.0" +version = "1.4.1" dependencies = [ "anyhow", "chrono", diff --git a/src/main.rs b/src/main.rs index 1af7bf4..ea0a082 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,32 +5,31 @@ mod names; use reporter::{MarkdownReporter, Reporter, Resolution, ReportOptions}; -use things::task::{Task, Status}; +use things::task::Task; use anyhow::Result; use clap::{Parser, ValueEnum}; #[derive(ValueEnum, Copy, Clone, Eq, PartialEq)] -enum ReportTypes { - /// report projected work for the day and a morning message - Morning, - /// report what major tasks were completed in the last cycle. - Cycle, - /// report what was actually done today and a signoff message - Signoff, +enum ListType { + /// Generate a report from the Things today list + Today, + /// Generate a report from the Things logbook + Logbook, } -impl ReportTypes { +impl ListType { fn format_tasks(&self, tasks: Vec, tags: &Vec, sanitize_names: bool) -> String { match self { - ReportTypes::Morning => { + ListType::Today => { let task_report = MarkdownReporter.report(tasks, &ReportOptions { resolution: Resolution::FullTask, tags: tags.to_vec(), sanitize_names, }); + // TODO: Use a cli flag to determine if the emoji should be included. format!("{}\n\n{}", emoji::pick(3).join(" "), task_report) }, - ReportTypes::Signoff => { + ListType::Logbook => { let task_report = MarkdownReporter.report(tasks, &ReportOptions { resolution: Resolution::FullTask, tags: tags.to_vec(), @@ -38,27 +37,13 @@ impl ReportTypes { }); format!("Stopping now\n\n{}", task_report) }, - ReportTypes::Cycle => { - let further_filtered = tasks.into_iter().filter(|t| { - if let Some(p) = &t.project { - return p.status == Status::Completed; - } - return false; - }).collect::>(); - let task_report = MarkdownReporter.report(further_filtered, &ReportOptions { - resolution: Resolution::Project, - tags: tags.to_vec(), - sanitize_names, - }); - format!("*Cycle Report*\n\n{}", task_report) - }, } } } -impl Default for ReportTypes { - fn default() -> ReportTypes { - ReportTypes::Morning +impl Default for ListType { + fn default() -> ListType { + ListType::Today } } @@ -76,9 +61,9 @@ struct CliArgs { omit: Vec, /// Select the type of report to generate - #[arg(short, long, default_value_t = ReportTypes::default())] + #[arg(short, long, default_value_t = ListType::default())] #[clap(value_enum)] - report: ReportTypes, + report: ListType, /// By default, any @ style tags will be sanitized in the output to avoid @-mentions in /// Slack. This is done by replacing vowel characters with unicode lookalikes. If this @@ -90,9 +75,8 @@ struct CliArgs { fn main() -> Result<()> { let args = CliArgs::parse(); let tasks = match args.report { - ReportTypes::Morning => Task::today(), - ReportTypes::Signoff => Task::logbook_today(), - ReportTypes::Cycle => Task::logbook_this_cycle(), + ListType::Today => Task::today(), + ListType::Logbook => Task::logbook(), }?; let mut reported: Vec = tasks.into_iter().filter(|task| { // Filter down to tasks with all selected tags and without any of the omitted tags diff --git a/src/things/logbook_cycle.js b/src/things/logbook_cycle.js deleted file mode 100644 index 292a7f5..0000000 --- a/src/things/logbook_cycle.js +++ /dev/null @@ -1,42 +0,0 @@ -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(), - status: proj.status(), - notes: proj.notes(), - tags: proj.tagNames().split(', '), - }, - 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 61a2f20..0d69863 100644 --- a/src/things/task.rs +++ b/src/things/task.rs @@ -59,14 +59,10 @@ impl Task { } /// Get all tasks in the logbook list from Things - pub fn logbook_today() -> Result> { + pub fn logbook() -> 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)) }